
    x-jb                    (   d dl mZ d dlZd dlmZmZmZmZmZ d dl	m
Z
 d dlZd dlmZ ddlmZ erd dlmZ  ed	          Z e
d
          Z G d de          Zed%d            Zed&d'd            Zd(dZ	 d(dddd)dZ	 d(d*dZ	 d(d+dZd,d$ZdS )-    )annotationsN)TYPE_CHECKINGCallableProtocolTypeVaroverload)	ParamSpec)DYNAMIC_DIMS_ATTR_NAME   )TransformOptions)Sequence_RetT_InputTc                  @    e Zd Zed	d            Zed
dd            ZdS )_NotToStaticDecoratorfuncCallable[_InputT, _RetT]returnc                    d S N selfr   s     Q/var/www/html/banglarbhumi/venv/lib/python3.11/site-packages/paddle/jit/marker.py__call__z_NotToStaticDecorator.__call__(   s	     $'3    .Nonec                    d S r   r   r   s     r   r   z_NotToStaticDecorator.__call__-   s    CF3r   Nr   r   r   r   .r   r   r   r   )__name__
__module____qualname__r   r   r   r   r   r   r   '   sI        ' ' ' X' FFFF XFFFr   r   r   r   r   c                    d S r   r   r   s    r   not_to_staticr'   1   s	      #sr   .r   c                    d S r   r   r&   s    r   r'   r'   7   s    >Acr   c                &    t          | dd          S )a  
    A Decorator to suppresses the convention of a function.

    Args:
        func(callable): The function to decorate.

    Returns:
        callable: A function which won't be converted in Dynamic-to-Static.

    Examples:
        .. code-block:: python

            >>> # doctest: +SKIP('`paddle.jit.to_static` can not run in xdoctest')
            >>> import paddle

            >>> @paddle.jit.not_to_static
            ... def func_not_to_static(x):
            ...     res = x - 1
            ...     return res

            >>> @paddle.jit.to_static
            ... def func(x):
            ...     if paddle.mean(x) < 0:
            ...         out = func_not_to_static(x)
            ...     else:
            ...         out = x + 1
            ...     return out
            ...
            >>> x = paddle.ones([1, 2], dtype='float32')
            >>> out = func(x)
            >>> print(out)
            Tensor(shape=[1, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
            [[2., 2.]])
    FTfor_sotfor_ast)unifiedr&   s    r   r'   r'   <   s    F 45555r   Tr*   fn7Callable[_InputT, _RetT] | type[paddle.nn.Layer] | Noner+   boolr,   c               >    dd| fdS  |           S )	aV  
    Mark a function already unified in dygraph and static mode. So
    that it won't be transformed again in SOT or AST mode.

    Args:
        fn(callable): The function to decorate.
        for_sot(bool): Whether to mark the function as unified in SOT mode.
        for_ast(bool): Whether to mark the function as unified in AST mode.
    r+   r0   r,   c                  t           j                                        }|r|t           j        j        z  }|r|t           j        j        z  }t                                          |          }|                    |            | S r   )r   ToStaticModeNilSOTASTwith_skip_transform_modeattach)r.   r+   r,   modeoptionss        r   _mark_as_unifiedz!unified.<locals>._mark_as_unifiedr   sx    ,0022 	6$155D 	6$155D"$$==dCCr	r   Nc                      |           S )Nr*   r   )r.   r;   r,   r+   s    r   <lambda>zunified.<locals>.<lambda>}   s    **2wPPP r   r*   )r+   r0   r,   r0   r   )r.   r+   r,   r;   s    ``@r   r-   r-   b   sM         
zPPPPPPPBAAAAr   Callable[_InputT, _RetT] | Nonec                &    d }| |S  ||           S )Nc                r    t                                          d          }|                    |            | S )NT)r   with_need_capture_control_flowr8   )r.   r:   s     r   "_mark_as_need_capture_control_flowz@capture_control_flow.<locals>._mark_as_need_capture_control_flow   s2    "$$CCDIIr	r   r   )r.   rB   s     r   capture_control_flowrC      s/      
 
z11--b111r   c                j   ddl m} t          j        |           r@t	          | t
          j        j                  r!|j        j	        
                    |            | S t          j        |           r!|j        j	                            |            | S t          dt          |           j         d          )z
    Mark a function or paddle.nn.Layer to be executed in dynamic mode, it will
    break the graph and prevent it from being converted to static mode.
    r   )sotz0Expected a callable or paddle.nn.Layer, but got .)
paddle.jitrE   inspectisclass
issubclasspaddlennLayerutilspaddle_api_configadd_break_graph_layer_class
isfunctionadd_break_graph_function	TypeErrortyper"   )r.   rE   s     r   force_dynamicrU      s     r z"fio>> 	#??CCC	" 	#<<R@@@	
O488;LOOO  r   tensorpaddle.Tensordimsint | Sequence[int]c                   t          | t          j                  s%t          dt	          |           j         d          t          |t                    r|f}t          |t          t          f          st          d          t          d |D                       st          d          t          | t          t          |                     dS )as  
    Mark a tensor as having dynamic dimensions.
    This is used to indicate that the tensor's shape may change dynamically
    during execution, which is particularly useful in dynamic-to-static
    conversion scenarios.
    Args:
        tensor (paddle.Tensor): The tensor to mark as dynamic.
        dims (int | Sequence[int]): The dimensions to mark as dynamic.
    z"Expected a paddle.Tensor, but got rF   z#Dimensions must be a list or tuple.c              3  @   K   | ]}t          |t                    V  d S r   )
isinstanceint).0dims     r   	<genexpr>zdynamic_dims.<locals>.<genexpr>   s,      44z#s##444444r   z All dimensions must be integers.N)r\   rK   TensorrS   rT   r"   r]   listtupleallsetattrr
   )rV   rX   s     r   dynamic_dimsrf      s     ffm,, 
If1FIII
 
 	
 $ wdT5M** ?=>>>44t44444 <:;;;F*E$KK88888r   r   r    r!   r   )r.   r/   r+   r0   r,   r0   r   r   )r.   r>   r   r   )r.   r/   r   r   )rV   rW   rX   rY   r   r   )
__future__r   rH   typingr   r   r   r   r   typing_extensionsr	   rK   paddle.jit.dy2static.utilsr
   dy2static.utilsr   collections.abcr   r   r   r   r'   r-   rC   rU   rf   r   r   r   <module>rm      s   # " " " " "  G G G G G G G G G G G G G G       = = = = = =       )(((((( 	
)I

G G G G GH G G G 
# # # 
#
 
 A A A A 
 A#6 #6 #6 #6N CGB 	B B B B B B@ +/
2 
2 
2 
2 
2 CG    *9 9 9 9 9 9r   