
    ϑin                       S SK Jr  S SKrS SKrS SKJr  S SKrS SKJr  S SK	J
r
  S SKJrJr  S SKJrJrJr  S SKJr  S S	KJr  S S
KJr  S SKJr  S SKJrJr  SSKJr  SSKJ r J!r!J"r"J#r#J$r$  / r%S<S jr&S r'S r(S<S jr)S r*S r+S r, S=S jr-S r.S r/S r0S r1S r2S r3S r4S r5S  r6S! r7S" r8S# r9 S<S$ jr:S% r;S& r<S' r=S( r>S) r?S* r@S+ rAS, rB " S- S.5      rCS/ rDS0 rES1 rFS2 rGS3 rHS>S4 jrIS5S6SS7S8.S9 jrJ\      S?S: j5       rKS@S; jrLg)A    )annotationsN)contextmanager)PyLayerMeta)convert_dtype)_convert_into_variablein_to_static_mode)Variablecoredefault_main_program)use_pir_api)
OrderedSet)Value)
AmpOptions)is_sequencemap_structure   )StaticPyLayer)RETURN_NO_VALUE_VAR_NAMEDygraph2StaticExceptionGetterSetterHelperUndefinedVarcreate_undefined_variablec                   [        U [        5      (       a  Uc  SOUn[        R                  " / XS9$ [        U [        5      (       a  Uc  SOUn[        R                  " / XS9$ [        U [
        5      (       a  Uc  SOUn[        R                  " / XS9$ [        5       (       d#  [        U [        5      (       d  U c   [        5       $ [        U 5      (       a  [        [        U 5      $ U $ )z?
Translate a Python Tensor to PaddlePaddle static graph Tensor
bool)shapedtype
fill_valuefloat64int64)
isinstancer   paddlefullfloatintr   r   r   r   r   to_static_variable)xr   s     f/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/jit/dy2static/convert_operators.pyr%   r%   ,   s     !T-U{{5??!U"]	{{5??!S =e{{5??==jL99QY	 )**1~~/33H    c                    [        U [        5      (       a5  [        U [        R                  5      (       d  US:X  a  U R	                  5       $ [        X5      $ )Nsize)r    r	   r!   Tensorr*   getattr)r&   attrs     r'   convert_attrr.   C   s?     	1h1fmm,,FNvvxqr(   c                   [        U [        5      (       a  [        U 5      $ [        5       (       Ga/  [        U [        R
                  5      (       a   [        U 5      $ [        U [        5      (       a9  SSKJ	n  UR                  [        R                  R                  5       U 5      nUb  U$ [        U [        5      (       ao  [        5       R                  5       nSSKJn  UR#                  5       R$                  R                  UR&                  U R(                  R+                  5       5      nUb  U$ U [        R,                  R.                  L a  [1        5       (       d  [2        $ U $ )Nr   _global_inplace_mapProgramTranslator)r    r   r   r   r!   r+   r   r   'paddle.jit.dy2static.parameter_recorderr1   getstaticr   r	   current_block'paddle.jit.dy2static.program_translatorr3   get_instance_inplace_mapprogramdescidamp	auto_castr   convert_auto_cast)r&   r1   new_var	cur_blockr3   s        r'   convert_loadrC   R   s   ![!!Qa'' *!,, a *--224aG "a"",.<<>I (446CCGG!!16699;G "

$$$[]]$$Hr(   c                    [        U [        [        45      (       a  U $ [        U S5      (       a  [	        U 5      $ [        U S5      (       a  [        U S5      (       a  U $ [        S5      e)N__iter____len____getitem__z"X can't be convert into indexable.)r    r	   r   hasattrlistRuntimeError)r&   codes     r'   	indexablerL   }   s`    !h&''	J		Aw	I		7	=$ $ ?@@r(   c                d    [        U [        [        45      (       a  [        X5      $ [	        X5      $ )z/unified unpack interface for paddle and python.)r    r	   r   _unpack_by_structure_paddle_unpack_by_structure_pythontarget	structures     r'   unpack_by_structurerS      s*    &8U+,,*6==*6==r(   c                    [        X5      $ )zJTODO(xiongkun): analysis the differences between python and paddle unpack.)rN   rP   s     r'   rO   rO      s    &v99r(   c                    US:X  a  U $ / n[        U5       H]  u  p4US:X  a  UR                  X   5        M   [        U[        5      (       a  UR                  [	        X   U5      5        MT  [        S5      e   U$ )Nr   z#structure element must be 1 or list)	enumerateappendr    rI   rS   AssertionError)rQ   rR   retidxeles        r'   rN   rN      su    A~
Ci(!8JJv{#c4  JJ*6;<=BCC ) Jr(   c                |    U " 5       n[        U[        [        45      (       a  [        XX#XE5        g[	        XX#5        g)a  
A function representation of a Python ``while`` statement.

Args:
    cond(Callable): A callable object that returns a boolean variable to control whether to execute the loop body. It takes ``loop_vars`` as arguments.
    body(Callable): A callable object that returns a tuple or list of variables with the same arguments ``loops_vars`` as ``cond`` .
    get_args(callable): Get all arguments that needed in true_fn and false_fn.
    set_args(callable): Update arguments that modified in trure_fn and false_fn.
    return_name_ids(list[string], optional): the returned names.
    push_pop_names(list[string], optional): the names on which called .append() or .pop().

Returns:
    A list or tuple of variables which returned by ``body``.
N)r    r	   r   _run_paddle_while_run_py_while)condbodygettersetterreturn_name_idspush_pop_namespreds          r'   convert_while_looprf      s8    ( 6D$5)**	
 	d&1r(   c           	         U R                  U5      nUc  g S nU R                  X Vs/ s H
  oC" U5      PM     sn5        g s  snf )Nc                    [        U [        5      (       a\  [        5       (       a.  [        R                  R
                  R                  R                  OSn[        R                  R                  XS9$ U $ )Nfloat32)initialized_list)
r    rI   r   r!   base	libpaddleDataType	UNDEFINEDtensorcreate_array)vr   s     r'   maybe_to_tensor_arrayA_convert_tensor_array_if_necessary.<locals>.maybe_to_tensor_array   sZ    a == %%..88 
 ==--e-HHHr(   )r5   set)setterhelperrd   push_pop_varsrr   rq   s        r'   "_convert_tensor_array_if_necessaryrw      sM     $$^4M	 =I=a.q1=IIs   A
c                  ^ ^^^ [        X#XE5      m[        TU5        U(       a  [        U5      O	[        5       U(       a  [        U5      O	[        5       -  m[        T5      mUUU4S jnU 4S jnTR	                  T5       Vs/ s H%  n[        U[        5      (       d  [        U5      OUPM'     n	nTR                  TU	5        SSK	J
n
  U
" XvU	5      n	TR                  TU	5        U	$ s  snf )Nc                 \   > U nTR                  TU5        T" 5         TR                  T5      $ )z\wrap the body() and add return value for `while_loop`
the args may be differ from getter().
)rt   r5   )argsmutable_loop_varsr`   helper
union_names     r'   new_body_fn&_run_paddle_while.<locals>.new_body_fn   s.     !

:01zz*%%r(   c                    > T" 5       $ )zIcond is a zero-args function, which is not
compatible with `while_loop`.
 )rz   r_   s    r'   new_cond_fn&_run_paddle_while.<locals>.new_cond_fn   s     vr(   r   )
while_loop)r   rw   r   rI   r5   r    r   r%   rt   paddle.static.nnr   )r_   r`   ra   rb   rc   rd   r~   r   var	loop_varsr   r|   r}   s   ``         @@r'   r]   r]      s      PF&v~> (7
?#JL'5N	#:<IJ j!J& ::j))C (2#|'D'D3#M)   JJz9%+;Y?I
JJz9%s   ,C%c                     U " 5       n[        U[        [        45      (       a  [        S5      eU(       d  g U" 5         M>  )Nz/python while pred change from bool to variable.)r    r	   r   r   )r_   r`   ra   rb   re   s        r'   r^   r^     s@    
vdXu-..)A   r(   c                   ^^ U " 5       m[        T[        [        45      (       d  [        U4S jU5      $ U" 5       m[        T[        [        45      (       d  [        U4S jU4S j5      $ [	        TT5      $ )aa  
A function representation of a Python ``and`` statement.

Args:
    x_func(callable): x_func() is the left hand operand of ``and`` operator. x_func() is bool or Tensor.
    y_func(callable): y_func() is the right hand operand of ``and`` operator.  y_func() is bool or Tensor.

Returns:
    A python bool variable or a bool Tensor.

NOTE(liym27):
    1) The operands are executed sequentially according to the running logic of Python. So here the arguments
    should be callable.
    2) If the left hand operand is False, the right hand operand should be executed.

    For example:
        a = x > 1 and y < 1
    Transformed code:
        a = paddle.jit.dy2static.convert_logical_and(lambda:x>1, lambda:y<1)

      In `convert_logical_and(lambda:x>1, lambda:y<1)`, `lambda:y<1` must be run after `lambda:x>1`. And
    if `x>1` is False, `y<1` should NOT be run.
c                    > T $ Nr   x_values   r'   <lambda>%convert_logical_and.<locals>.<lambda>'      7r(   c                    > T $ r   r   y_values   r'   r   r   +  r   r(   c                    > T $ r   r   r   s   r'   r   r   +  s    Gr(   )r    r	   r   _run_py_logical_and_run_paddle_logical_andx_funcy_funcr   r   s     @@r'   convert_logical_andr     s^    0 hGg%011"?F;;hGg%011"?ODD"7G44r(   c                Z    [        U 5      n [        U5      n[        R                  " X5      $ r   )cast_bool_if_necessaryr!   logical_andr&   ys     r'   r   r   0  s'    q!Aq!Aa##r(   c                j    U " 5       n[        U[        [        45      (       a   eU=(       a    U" 5       $ r   r    r	   r   r   r   r   s      r'   r   r   6  s0    hG'He#45555
 vxr(   c                   ^^ U " 5       m[        T[        [        45      (       d  [        U4S jU5      $ U" 5       m[        T[        [        45      (       d  [        U4S jU4S j5      $ [	        TT5      $ )aW  
A function representation of a Python ``or`` statement.

Args:
    x_func(callable): x_func() is the left hand operand of ``or`` operator. x_func() is bool or Tensor.
    y_func(callable): y_func() is the right hand operand of ``or`` operator.  y_func() is bool or Tensor.

Returns:
    A python bool variable or a bool Tensor.

NOTE(liym27):
    1) The operands are executed sequentially according to the running logic of Python. So here the arguments
    should be callable.
    2) If the left hand operand is True, the right hand operand should be executed.

    For example:
        a = x > 1 or y < 1
    Transformed code:
        a = paddle.jit.dy2static.convert_logical_or(lambda:x>1, lambda:y<1)

    In `convert_logical_or(lambda:x>1, lambda:y<1)`, `lambda:y<1` must be run after `lambda:x>1`. And
    if `x>1` is True, `y<1` should NOT be run.
c                    > T $ r   r   r   s   r'   r   $convert_logical_or.<locals>.<lambda>Z      'r(   c                    > T $ r   r   r   s   r'   r   r   ^  r   r(   c                    > T $ r   r   r   s   r'   r   r   ^  s    7r(   )r    r	   r   _run_py_logical_or_run_paddle_logical_orr   s     @@r'   convert_logical_orr   @  s^    0 hGg%011!/6::hGg%011!/?CC!'733r(   c                Z    [        U 5      n [        U5      n[        R                  " X5      $ r   )r   r!   
logical_orr   s     r'   r   r   c  s'    q!Aq!AQ""r(   c                j    U " 5       n[        U[        [        45      (       a   eU=(       d    U" 5       $ r   r   r   s      r'   r   r   i  s0    hG'He#45555
 fhr(   c                d    [        U [        [        45      (       a  [        U 5      $ [	        U 5      $ )z
A function representation of a Python ``not`` statement.

Args:
    x(bool|Tensor): Operand of ``not`` operator.

Returns:
    A python bool variable or a bool Tensor.
)r    r	   r   _run_paddle_logical_not_run_py_logical_notr&   s    r'   convert_logical_notr   s  s,     !h&''&q))"1%%r(   c                D    [        U 5      n [        R                  " U 5      $ r   )r   r!   logical_notr   s    r'   r   r     s    q!Aa  r(   c                    U (       + $ r   r   r   s    r'   r   r     s	    5Lr(   c           	     |    [        U [        [        45      (       a  [        U UUUUUU5      nU$ [	        XX#XE5      nU$ )a  
A function representation of a Python ``if/else`` statement.

Args:
    pred(bool|Tensor): A boolean Tensor which determines whether to return the result of ``true_fn`` or ``false_fn`` .
    true_fn(callable): A callable to be performed if ``pred`` is true.
    false_fn(callable): A callable to be performed if ``pred`` is false.
    get_args(callable): Get all arguments that needed in true_fn and false_fn.
    set_args(callable): Update arguments that modified in trure_fn and false_fn.
    return_name_ids(list[string], optional): the returned names.
    push_pop_names(list[string], optional): the names on which called .append() or .pop().

Returns:
    ``true_fn()`` if the predicate ``pred`` is true else ``false_fn()`` .

)r    r	   r   _run_paddle_cond_run_py_ifelse)re   true_fnfalse_fnget_argsset_argsrc   rd   outs           r'   convert_ifelser     sV    2 $5)**
 J	 8x
 Jr(   c                8  ^^^^^^^ [        X4TU5      m[        TU5        [        U 5      n TR                  T5      mSSKJn  SSKJn  [        5       (       a  UmOUR                  5       R                  mSmTc  Uc  SmODT(       a  [        T5      O	[        5       U(       a  [        U5      O	[        5       -  m[        T5      mUUUUUU4S jn	UUUUUU4S jn
 [        R                  R                  R!                  X	U
ST5      nUU4S jnUU4S jn[-        XUT5      $ ! ["         am  n[$        R&                  " S[)        U5      5      (       a  [+        SU 35      e[$        R&                  " S	[)        U5      5      (       a  [+        S
U 35      eUeSnAff = f)z@
Paddle cond API will evaluate both true_fn and false_fn codes.
r   r0   r2   Nc                    > TR                  5       n TR                  T[        R                  R	                  T5      5        T" 5       nUc  TR                  T5      nTR                  U 5        U$ r   save_checkpointrt   r!   utilscopy_mutable_varsr5   restore_checkpoint)inplace_map_checkpointrY   r|   	init_argsinplace_maprc   r   r}   s     r'   new_true_fn%_run_paddle_cond.<locals>.new_true_fn  sg     "-!<!<!>

LL**95	
 i ;**Z(C&&'=>
r(   c                    > TR                  5       n TR                  T[        R                  R	                  T5      5        T" 5       nUc  TR                  T5      nTR                  U 5        U$ r   r   )r   rY   r   r|   r   r   rc   r}   s     r'   new_false_fn&_run_paddle_cond.<locals>.new_false_fn  se     "-!<!<!>

LL**95	
 j;**Z(C&&'=>
r(   z7Unsupported return type of true_fn and false_fn in condzCYour if/else have different return type. TODO: add link to modify. zIncompatible return values ofzNYour if/else have different number of return value. TODO: add link to modify. c                 &   > T R                  T5      $ r   )r5   )r|   r}   s   r'   r   "_run_paddle_cond.<locals>.<lambda>  s    vzz*-r(   c                (   > TR                  TU 5      $ r   )rt   )vsr|   r}   s    r'   r   r     s    &**Z4r(   )r   rw   r   r5   r4   r1   r8   r3   r   r9   r:   r   rI   r!   r6   nnr_   	Exceptionresearchstrr   _recover_args_state)re   r   r   r   r   rc   rd   r1   r3   r   r   	cond_outser|   r   r   r}   s    ``  `       @@@@r'   r   r     s}     O^F 'v~>!$'D

?+IKI}})'446CCJ>#9
 ,;J'
+9Z'z|M
 *%
   MM$$))|T:
	 .H4HyHjII  99Es1v
 
 *UVWUXY  994c!f==)`ab`cd  s   ,D" "
F,A(FFc                4    U (       a	  U" 5       nU$ U" 5       nU$ )z3
Evaluate python original branch function if-else.
r   )re   r   r   r   r   rc   py_outss          r'   r   r     s       giGN &.ZGNr(   c                F   [        U [        5      (       Ga
  [        U 5      S:  a  U nU S   n[        U[        5      (       au  [        U5       Hf  u  p4[        U[        [
        45      (       d  M"  [        UR                  ;   d  M8  US:X  a
  S /U SS  Q7nOUS:X  a  US S U SS  -   nOUS U /U SS  Q7n  O   [        U5       H=  u  p4[        U[        [
        45      (       d  M"  [        UR                  ;   d  M8  US U nM?     U(       d  g [        U5      S:X  a  US   $ U$ U $ )Nr   r   )r    tuplelenrV   r	   r   r   name)r   processed_out	align_retindexitems        r'   _remove_no_value_return_varr     s#   #u#c(Q,F	i''(3dXu$566,		9 z)-(8AB(8!(1"1AB(?)26E):(ESW(E  4 %]3KE$5 122(DII5 -fu 5	 4 1$ ##   
r(   c                    Uc  g [        U [        [        45      (       d  U /n [        [        U 5      U5       H,  u  p4[        U[        5      (       d  M  [        SU SU S35      e   g )Nz
Required 'zO' must be initialized both in if-else branch, but found it not initialized in 'z'.)r    rI   r   zipr   
ValueError)outsnamesbranch_namer   r   s        r'   _check_no_undefined_varr   5  sp    }dT5M**vdU+	c<((TF"qr}q~  A  B  ,r(   c                    Uc  U $ U" 5       n[        U5      n[        U5      nXV::  d   eUS:X  a*  [        U [        [        45      (       d  U 4O
[        U 5      nOUS:X  a  U 4O
[        U 5      n XUS -   nU" U5        U$ )z
Currently we support variant length of early return statement by padding
_no_return_value.

# TODO(dev): We shall consider to evaluate whether should support this for Python if-else?
Nr   )r   r    rI   r   )r   r   r   rc   r   num_outsnum_args
final_outss           r'   r   r   A  s     
I?#H9~H1}%dT5M::TGd 	 #a-wU4[hi00
Zr(   c                   [        U [        5      (       GaC  U R                  S:  d   S5       eU R                  [        R
                  R                  R                  [        R
                  R                  R                  4;   am  U R                  S   S:  aA  U R                  [        R
                  R                  R                  :X  a  U R                  S   $ [        R                  " U 5      S   $ U R                  [        R
                  R                  R                  :X  a  [        R                  R                  U 5      $ [        S[        U 5       S35      e[        U [        5      (       a  U R!                  5       (       d  U R#                  5       (       ag  U R                  S:  d   S5       eU R                  S   S:  a$  U R!                  5       (       a  U R                  S   $ [        R                  " U 5      S   $ U R%                  5       (       a  [        R                  R                  U 5      $ [        SS[        U 5       S3-   5      e[        U [&        5      (       a  U R)                  5       $ [+        U 5      $ )z
Returns variable(length) from shape ops based on var.type

Note: In addition to some ast transformations, some block-related
      operations are added in `len` transformation, such as appending
      `shape_op` in var.block.
r   zlen() of a 0-D tensor is wrongzOlen(var) only supports DenseTensor/DenseTensorArray/SelectedRows, but received .zBlen(var) only supports DenseTensor/DenseTensorArray/SelectedRows, zbut received )r    r	   ndimtyper
   VarDescVarTypeDENSE_TENSORSELECTED_ROWSr   r!   DENSE_TENSOR_ARRAYro   array_length	TypeErrorr   is_dense_tensor_typeis_selected_row_typeis_dense_tensor_array_typeVariableTuplerF   r   r   s    r'   convert_lenr  ^  s    #x  xx!|===|88LL  --LL  ..
 
 		!q HH 4 4 A AAyy|#<<$Q''XX--@@@==--c22abfgjbkallmn  
C		##%%)A)A)C)C88a<A!AA< yy|aC$<$<$>$>yy|#<<$Q''++--==--c22T!$s)A./ 
 c=));;= 3xr(   c                     [        U 5       HD  u  p[        U[        [        45      (       d  M"  UR                  S   S:X  d  M7  [        SU S35      e   [        U 6 $ )Nr   zHNot support zip(tensor, ...) when tensor.shape[0] == -1, but found args[z].shape[0] == -1 in 'zip')rV   r    r	   r   r   rJ   r   )rz   iargs      r'   convert_zipr    s^    D/cHe,--#))A,"2D""#$=?  " :r(   c                &   ^  T [         L a  T $ U 4S j$ )Nc                   > T" 5       $ r   r   )clsinstancesuper_fns     r'   r   convert_super.<locals>.<lambda>  s    r(   )super)r  s   `r'   convert_superr    s    5++r(   c                  .    \ rS rSrSrSS jrS rS rSrg)	r   i  z
this class will cause enumerate can't be wrapped by other iterator change function.
this will be fixed when list<Variable> is produced.
VariableTuple can only deal with variables which is fixed.
c                
   Xl         [        U5      U l        [        U R                  [        [
        45      (       a+  [        R                  " X"U R                  -   SS5      U l        g [        X"U R                  -   5      U l        g )Nr   r   )
r   r  r   r    r	   r   r!   arangeragrange)selfr   starts      r'   __init__VariableTuple.__init__  s[    s#dhh5 122}}UDHH,<aIDHUDHH$45DHr(   c                >    U R                   U   U R                  U   4$ r   )r  r   )r  rZ   s     r'   rG   VariableTuple.__getitem__  s    xx}dhhsm++r(   c                    U R                   $ r   )r   )r  s    r'   rF   VariableTuple.__len__  s    xxr(   )r   r  r   N)r   )	__name__
__module____qualname____firstlineno____doc__r  rG   rF   __static_attributes__r   r(   r'   r   r     s    6,r(   r   c                 T    [        S U  5       5      nU(       a  [        U 6 $ [        U 6 $ )Nc              3  N   #    U  H  n[        U[        [        45      v   M     g 7fr   r   .0r&   s     r'   	<genexpr>$convert_enumerate.<locals>.<genexpr>       FAz!h%677   #%)anyr   rV   rz   has_variables     r'   convert_enumerater-    s+    FFFLd##dr(   c                 X   [        S U  5       5      nU(       a  [        U 5      S:X  a  [        R                  " SU S   SS5      $ [        U 5      S:X  a  [        R                  " U S   U S   SS5      $ [        U 5      S:X  a"  [        R                  " U S   U S   U S   S5      $ [	        U 6 $ )Nc              3  N   #    U  H  n[        U[        [        45      v   M     g 7fr   r   r$  s     r'   r&   convert_range.<locals>.<genexpr>  r(  r)  r   r   r         )r*  r   r!   r  r  r+  s     r'   convert_ranger3    s    FFFLt9>==DGQ88t9>==a$q'1g>>t9>==a$q'47GDD$<r(   c                   S n[        U [        [        45      (       a_  [        U R                  5      nU" U5      (       a;  [
        R                  " U 5      n[        U5       H  u  pEUb  US:  d  M  X4   X$'   M     U$ U R                  $ )z5
A function representation of the shape of variable.
c                &    [        S U  5       5      $ )Nc              3  *   #    U  H	  oS :  v   M     g7f)r   Nr   r$  s     r'   r&  6convert_shape.<locals>.has_negative.<locals>.<genexpr>  s     -*Qq5*s   )r*  )
list_shapes    r'   has_negative#convert_shape.<locals>.has_negative  s    -*---r(   r   )r    r	   r   rI   r   r!   rV   )r&   r9  valuesshape_tensorr  rq   s         r'   convert_shaper=    su    
. !h&''agg!<<?L!&)9A ,FI * wwr(   c                    [        U [        [        45      (       d   e[        U R                  5      S;  a  [
        R                  " U SS9n U $ )N)r   r   r   )r    r	   r   r   r   r!   castr   s    r'   r   r     s@    cHe,----SYYx/kk#V,Jr(   c                @   [        U [        [        45      (       ab  [        U R                  5      nUS;   d   SU R
                   SU S35       eUS;   d   SU S35       eSS	S
SS.n[        R                  " XU   S9$ US;   d   SU S35       e[        U5      " U 5      $ )N)r   float16ri   r   int32r   uint8zThe dtype of var z is z(, which is not supported in the cast op.)r   r$   r#   complexzThe casted target dtype is z), which is not supported in type casting.r   rC  ri   	complex64r?  )	r    r	   r   r   r   r   r!   r@  eval)r   r   	src_dtypecast_maps       r'   convert_var_dtyperJ    s    #%())!#)),	 
 
 
	
  zi[8`a
	
 
  
 
 	
 *%0YZ	
 
 "	
 {{3uo66 
 
 	
 *%0YZ	
 
 E{3r(   c                    [        U [        [        45      (       a%  [        R                  " U S5      n SSKJn  U" U 5      $ U (       d   U5       eg)z=
A function representation of a Python ``assert`` statement.
r   r   )AssertN)r    r	   r   r!   r@  paddle.static.nn.control_flowrL  )r_   messagerL  s      r'   convert_assertrO    s@     $5)**{{4(8d|Wtr(    
Fsependfileflushc                    U H?  n[        U[        [        45      (       d  M   [        R                  R                  U5        MA     [        X@XUS.6  g)z
A function representing Python ``print`` function. It will print all arguments
at compile time and only print the Tensor values at runtime.
rR  N)r    r	   r   r!   r6   Printprint)rS  rT  rU  rV  objectsobjs         r'   convert_printr\  #  s@    
 cHe,--MM$  
7u=r(   c              #    #    SSK Jn  [        R                  " S5        UR	                  5       R
                  n[        R                  R                  5       nUR                  n	UR                  5       n
[        U
R                  5      n[        XX#XE5      nS v   [        U
R                  5      nX;  a  / Xy'   Xy   R                  XU45        g 7f)Nr   r2   zopaddle.amp.auto_cast is an experimental features in auto parallel.This will take no effect in normal dy2static.)program_translatorr3   warningswarnr9   _amp_recordsr!   r6   r   current_block_idxr7   r   opsr   rW   )enablecustom_white_listcustom_black_listlevelr   use_promoter3   amp_recordsmain_programrb  r7   start_op_idxamp_options
end_op_idxs                 r'   r@   r@   .  s      6MM	:
 $002??K==557L$66 ..0M}(()L#4UK 
]&&'J+)+&"))	J/s   CCc                h    [        U [        [        45      (       a  [        R                  " / USS9$ U$ )z6
Create a bool variable, which type is the same as x.
r   )r   r   r   )r    r	   r   r!   r"   )r&   values     r'   create_bool_as_typerp  O  s.     !h&''{{VDDr(   r   )NN) )TNNO1rB  T)T)M
__future__r   r   r_  
contextlibr   r!   paddle.autograd.py_layerr   paddle.base.data_feederr   paddle.base.dygraph.baser   r   paddle.base.frameworkr	   r
   r   paddle.frameworkr   paddle.jit.utilsr   
paddle.pirr   paddle.static.amp.fp16_utilsr   paddle.utilsr   r   py_layerr   r   r   r   r   r   r   __all__r%   r.   rC   rL   rS   rO   rN   rf   rw   r]   r^   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r   r-  r3  r=  r   rJ  rO  r\  r@   rp  r   r(   r'   <module>r     sU   # 	  %  0 1 N F F ( '  3 3 #  . (V
A>:
  FJ2:*&R	 5F$  4F#&"!
 (VMJ` F	:0f, ,	4& R !$D > 

 @r(   