
    ёi                        S SK Jr  S SKJr  SSKJr  \(       a  S SKJr  S/r " S S5      r	\	" 5       q
S	 r " S
 S5      rg)    )annotations)TYPE_CHECKING   )	framework)TracebackType	LazyGuardc                  F    \ rS rSrSrS rS rS rS rS r	\
S 5       rS	rg
)LazyInitHelper   z{
A Helper Context to trigger switching mode between dygraph and static graph mode,
and holds the startup program resource.
c                .    SU l         S U l        SU l        g )NF)_state_tracer	_in_guardselfs    _/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/nn/initializer/lazy_init.py__init__LazyInitHelper.__init__"   s        c                x    U R                   (       a  g[        R                  " 5       (       d   S5       eSU l         g)z[
Switch into lazy mode.

NOTE(dev): This is a very low level API and not exposed for user.
Nz4LazyInit.enable() is only available in dygraph mode.T)r   r   in_dygraph_moder   s    r   enableLazyInitHelper.enable'   s6     ;;((** 	
B	
* r   c                6    U R                   (       d  gSU l         g)zY
Exit from lazy mode.

NOTE(dev): This is a very low level API and not exposed for user.
NFr   r   s    r   disableLazyInitHelper.disable4   s     {{r   c                    U R                  5         U R                  (       a  g[        R                  R                  U l        S[        R                  l        SU l        g)zj
Switch into lazy mode and set _dygraph_tracer_ with None to convert
dygraph mode into static graph mode.
NT)r   r   r   
global_var_dygraph_tracer_r   r   s    r   	__enter__LazyInitHelper.__enter__>   s?    
 	>> ++<<04	-r   c                    U R                  5         U R                  (       d  gU R                  c   eU R                  [        R                  l        SU l        SU l        g)z3
Exit from lazy mode and recover _dygraph_tracer_.
NF)r   r   r   r   r   r    )r   argskwargss      r   __exit__LazyInitHelper.__exit__J   sG     	~~||'''04	-r   c                    U R                   $ Nr   r   s    r   stateLazyInitHelper.stateV   s    {{r   )r   r   r   N)__name__
__module____qualname____firstlineno____doc__r   r   r   r!   r&   propertyr*   __static_attributes__ r   r   r
   r
      s4    



  r   r
   c                     [         $ r)   )_lazy_init_helperr3   r   r   lazy_init_helperr6   ^   s    r   c                  <    \ rS rSrSrSS jr        SS jrSrg)	r   c   au  
LazyGuard is a wrapper interface for nn.Layer, it forwards the construct
process of user defined Layer. Meanwhile, it provides necessary API to
trigger EagerParamBase Lazy Initialization and get startup Program.

Examples:

    .. code-block:: python

        >>> from paddle import LazyGuard
        >>> from paddle.nn import Linear

        >>> with LazyGuard():
        ...     # w and b are initialized lazily and have no memory.
        ...     net = Linear(10, 10)
        ...
        >>> for param in net.parameters():
        ...     # Initialize param and allocate memory explicitly.
        ...     param.initialize()
c                4    [        5       R                  5         g)ad  
Construct instance from class_obj by Lazy Initializing parameters.

Examples:

    .. code-block:: python

        >>> from paddle import LazyGuard
        >>> from paddle.nn import Linear

        >>> with LazyGuard():
        ...     fc = LazyInit(Linear)(10, 10)
        ...
        >>> for param in fc.parameters():
        ...     param.initialize()
N)r6   r   r   s    r   r!   LazyGuard.__enter__y   s    " 	!!#r   c                4    [        5       R                  5         g r)   )r6   r   )r   exc_typeexc_valexc_tbs       r   r&   LazyGuard.__exit__   s     	""$r   r3   N)returnNone)r<   ztype[BaseException] | Noner=   zBaseException | Noner>   zTracebackType | Noner@   rA   )r,   r-   r.   r/   r0   r!   r&   r2   r3   r   r   r   r   c   s7    *$&%,% &% %	%
 
%r   N)
__future__r   typingr   baser   typesr   __all__r
   r5   r6   r   r3   r   r   <module>rG      sD    #   # -< <~ #$ 
/% /%r   