
    rh                    j   d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlmZmZ ddlmZmZ ddl
mZmZmZ ddlZddlmZmZ ddlmZ ddlmZ d	d
lmZmZmZm Z  d	dl!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z( d	dl)m*Z*m+Z+ d	dl,m-Z- d	dl.m/Z/m0Z0m1Z1m2Z2m3Z3 d	dl4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZD ddlEmFZFmGZGmHZH ddlImJZJ ddlKmLZLmMZM ddlNmOZOmPZPmQZQmRZRmSZSmTZT ddlUmVZVmWZWmXZXmYZYmZZZm[Z[ ddl\m]Z]m^Z^m_Z_m`Z`maZa ddlbmcZcmdZd erddlemfZf ddlgmhZh  ej                  ej      Zkej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                   ej                  ej                  ej                  ej                  iZede
j                  e
j                  geHf   ZeeeH   eeeH   df   f   Zej                  ej                  ej                  ej                  ej                  ej                   ej"                  ej$                  ej&                  ej(                  ej*                  ej,                  iZ G d deH      Zej2                  d        Zy)a\  
Built-in function and type variable tracking for TorchDynamo's symbolic execution.

This module contains variable tracker classes for Python built-in functions, types,
and operations during graph compilation. It handles symbolic execution of:

- Built-in functions (len, getattr, isinstance, etc.)
- Type constructors (int, float, str, list, dict, etc.)
- Built-in operators and methods
- Special Python constructs (super, hasattr, etc.)

Key classes:
- BuiltinVariable: Tracks built-in functions and handles their execution
- TypeVariable: Manages type constructor calls and type checking
- SuperVariable: Handles super() calls in class hierarchies

These variable trackers ensure that built-in Python operations are correctly
handled during symbolic execution, either by executing them directly when safe
or by creating appropriate graph nodes when needed.
    N)defaultdictOrderedDict)KeysViewSequence)CallableTYPE_CHECKINGUnion)	sym_floatsym_int)is_sparse_any)is_traceable_wrapper_subclass   )configgraph_break_hints	polyfills	variables)AttributeMutationErrorObservedAttributeErrorraise_observed_exceptionunimplemented_v2Unsupported	UserErrorUserErrorType)GuardBuilderinstall_guard)DummyModule)
AttrSourceGetItemSourceGlobalSourceis_constant_source
TypeSource)check_constant_argscheck_numpy_ndarray_argscheck_unspec_or_constant_argscheck_unspec_python_argscmp_name_to_op_mappingdict_methodsextract_fake_example_valueget_fake_valueguard_if_dynis_tensor_getset_descriptoris_wrapper_or_member_descriptoristypenumpy_operator_wrapperproxy_args_kwargsstr_methodstensortype_to_dtype   )#AsPythonConstantNotImplementedErrorValueMutationNewVariableTrackerConstantVariable)EventVariableStreamVariable)ConstDictVariableDefaultDictVariableDictViewVariableFrozensetVariableis_hashableSetVariable)BaseListVariableListIteratorVariableListVariableSizeVariableTupleIteratorVariableTupleVariable)FakeItemVariablesupported_comparison_opsSymNodeVariableTensorVariableUnspecializedPythonVariable)UserDefinedObjectVariableUserDefinedVariable)	PyCodegen)InstructionTranslatorrN   .c            
           e Zd ZU dZ e       Zdhej                  Zed        Z	e
ej                  d               Zd Ze
ej                  d               Ze
ej                  deedef   eee   edef   f   f   fd	              Ze
ej                  d
               Ze
d        Zd Zd^ fdZdefdZd Z fdZd_dZd Zd Zd Z d Z!e
d        Z"d Z#e
dee$   de%fd       Z&d`dZ'i Z(eeedf   ede)e   eeef   gef   f   e*d<   ddde)d    d!d"dd fd#Z+	 	 	 	 	 	 da fd$Z,d`d%Z-e-Z.e-Z/d`d&Z0d`d'Z1d`d(Z2d`d)Z3d`d*Z4e2Z5e2Z6dbd,Z7dbd-Z8dbd.Z9d`d/Z:d`d0Z;d1 Z<d`d2Z=d`d3Z>	 dc	 d`d4Z?d5 Z@dcd6ZAd`d7ZBeAZCeAZDd`d8ZEd9 ZFd`d:ZGe
d`d;       ZHe
	 	 d`d<       ZId`d=ZJd`d>ZKd`d?ZLd`d@ZMd`dAZNd`dBZOd`dCZPd`dDZQddd+efdEZRd`dFZSd`dGZTd`dHZU	 dcdddIedJefdKZVdddIedJedLefdMZWdddIedJefdNZXdddIefdOZYdddIefdPZZdddIed!efdQZ[d`dRZ\d`dSZ]d`dTZ^d`dUZ_d`dVZ`d`dWZad`dXZbebZcd`dYZdedZed`dZZfddd[ed\efd]Zg xZhS )dBuiltinVariablea  
    A VariableTracker that represents a built-in value (functions and operators).
    A lot of the code here assumes it will be a function object.

    The BuiltinVariable class wraps Python built-in functions (like len, isinstance, etc.)
    and operators (like +, -, *, etc.) to enable symbolic execution during tracing. This allows
    Dynamo to properly handle these operations when converting Python code to FX graphs while
    maintaining correct semantics and enabling optimizations.
    fnc                 f    t        |j                  t        j                                | ||      S )Nsource)r   
make_guardr   BUILTIN_MATCH)clsvaluerT   s      r/var/www/html/ai-insurance-compliance-backend/venv/lib/python3.12/site-packages/torch/_dynamo/variables/builtin.pycreate_with_sourcez"BuiltinVariable.create_with_source   s(    f''(B(BCD5((    c                  .   h t         t        t        t        t        t
        t        t        t        t        t        t        t        t        t        t        t         t"        t"        j$                  t&        t(        t*        j                   t*        j,                  t*        j.                  t*        j0                  t*        j2                  t*        j4                  t*        j                  t*        j6                  t*        j8                  t*        j:                  t*        j<                  t*        j>                  t*        j@                  t*        jB                  t*        jD                  t*        jF                  t*        jH                  t*        jJ                  t*        jL                  t*        jN                  t*        jP                  t*        jR                  t*        jT                  t*        jV                  t*        jX                  t*        jZ                  t*        j\                  t*        j^                  t*        j`                  t*        jb                  t*        jd                  t*        jf                  t*        jh                  t*        jj                  t*        jl                  } ddl7m8} | js                   |jt                                | js                  d tv        jx                  ju                         D               | S )Nr2   )rG   c              3   h   K   | ]*  }t        |t        t        j                              s'| , y wN)
isinstancetypemathsqrt.0xs     rY   	<genexpr>z;BuiltinVariable._constant_fold_functions.<locals>.<genexpr>   s!     W
1d499o8V1Ws   (22)=absallanyboolcallablechrdivmodfloatgetattrintlenmaxminordpowreprroundstrformatsumr`   operatorposnegnot_truthinvertmulmatmulfloordivtruedivmodaddsubgetitemlength_hintlshiftrshiftand_or_xoripowimulimatmul	ifloordivitruedivimodiaddisubilshiftirshiftiandixoriorindextensorrG   updatevaluesra   __dict__)fnsrG   s     rY   _constant_fold_functionsz(BuiltinVariable._constant_fold_functions   sL   9
9
9
 9
 	9

 9
 9
 9
 9
 9
 9
 9
 9
 9
 9
 9
  !9
" #9
$ %9
& JJ'9
( )9
* +9
, LL-9
. LL/9
0 LL19
2 MM39
4 NN59
6 OO79
8 LL99
: LL;9
< OO=9
> ?9
@ A9
B LLC9
D LLE9
F LLG9
H I9
J   K9
L OOM9
N OOO9
P MMQ9
R LLS9
T LLU9
V MMW9
X MMY9
Z [9
\ ]9
^ _9
` MMa9
b MMc9
d MMe9
f g9
h i9
j MMk9
l MMm9
n LLo9
p NNq9
t 	5

2+2245

Wdmm224WW
r[   c                 :    | j                   | j                         v S r^   )rQ   r   selfs    rY   can_constant_fold_throughz)BuiltinVariable.can_constant_fold_through   s    ww$77999r[   c                     h t         j                  t         j                  t         j                  t         j                  t         j
                  t         j                  t         j                  t         j                  t         j                  t         j                  t         j                  t         j                  t         j                  t         j                  t         j                  t         j                   t         j"                  t         j$                  t         j&                  t         j(                  t         j*                  t         j,                  t         j.                  t         j0                  t         j2                  t         j4                  t         j6                  t         j8                  t         j:                  t         j<                  t         j>                  t         j@                  t         jB                  t         jD                  t         jF                  t         jH                  t         jJ                  t         jL                  t         jN                  } | S r^   )(r{   rg   r|   r}   r~   r   ru   r   r   r   r   r   r   ltgtgeleneeqr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   s    rY   _fx_graph_functionsz#BuiltinVariable._fx_graph_functions   sQ   (
LL(
LL(
 LL(
 MM	(

 OO(
 LL(
 LL(
 OO(
 (
 (
 LL(
 LL(
 KK(
 KK(
 KK(
  KK!(
" KK#(
$ KK%(
& LL'(
(   )(
* OO+(
, OO-(
. MM/(
0 LL1(
2 LL3(
4 MM5(
6 MM7(
8 9(
: ;(
< =(
> ?(
@ MMA(
B MMC(
D MME(
F G(
H I(
J MMK(
L MMM(
N LLO(
R 
r[   return.c                     t         j                  g dt         j                  ft         j                  g dt         j                  ft         j
                  g dt         j                  ft         j                  g dt         j                  ft         j                  g dt         j                  ft         j                  g dt         j                  ft        g dt         j                  ft         j                  g dt         j                  ft         j                  g dt         j                   ft         j"                  g d	t         j$                  fi
} | S )
N)__add____radd____iadd__)__sub____rsub____isub__)__mul____rmul____imul__)__truediv____rtruediv____itruediv__)__floordiv____rfloordiv____ifloordiv__)__mod____rmod____imod__)__pow____rpow____ipow__)
__lshift____rlshift____ilshift__)
__rshift____rrshift____irshift__)r{   r   r   r   r   r   r   r   r   r   r   r   r   ru   r   r   r   r   r   r   s    rY   _binopszBuiltinVariable._binops  s     LL>NLL>NLL>N?!! B""  LL>N5x}}ELL>NOO<   OO<  'U
> 
r[   c            
         ddl mm ddlm ddlm ddlm ddl	m
mm i } t        j                         j                         D ]!  \  }\  }}g | |<   g | |<   |\  }}}||dfd
}| |   j!                  t"        f|f       | |   j!                  t"        f|f       |d		 dd
}| |   j!                  t"        f|f       | |   j!                  t"        f|f       |ddd}	| |   j!                  t$        t"        f|	f       | |   j!                  t"        t$        f|	f       | |   j!                  t$        t"        f|	f       | |   j!                  t"        t$        f|	f       $ dd}
dd}t&        t&        f|ft&        t(        f|ft(        t&        f|ft(        t(        f|
ft(        t*        f|
ft*        t(        fd ft,        t.        t*        t0        ffd ft.        t.        fd fg}| t2        j4                     j7                  |       dd}t,        t"        f|ft(        t(        f|
ft(        t*        f|
fg}| t2        j8                     j7                  |       dd}t,        t*        f|ft(        t*        f|ft*        t,        f|ft*        t(        f|fg}| t2        j:                     j7                  |       fd}t=        j>                         D ]   }tA        |      sJ || vsJ  ||      | |<   " | S )Nr2   )BaseUserFunctionVariableUserFunctionVariableNNModuleVariable)supported_const_comparison_ops)BaseTorchVariable)UserDefinedClassVariablerK   rL   )forward_namereverse_namec                p    t        |      r|j                  | ||gi       S |j                  | ||gi       S r^   )r_   call_method)txabr   r   rL   s        rY   user_defined_handlerz=BuiltinVariable._binop_handlers.<locals>.user_defined_handlern  s>    , a!45==\A3CC==\A3CCr[   )r   c                ,    |j                  | ||gi       S r^   r   )r   r   r   r   s       rY   user_defined_inplace_handlerzEBuiltinVariable._binop_handlers.<locals>.user_defined_inplace_handler  s     }}RsB??r[   rQ   c          
      p    ddl m}  ||  | j                  j                  d|gt	        ||gi              S Nr2   wrap_fx_proxycall_function)builderr   outputcreate_proxyr/   )r   r   r   rQ   r   s        rY   dynamic_handlerz8BuiltinVariable._binop_handlers.<locals>.dynamic_handler  sA    2$*BII**'.?A.K r[   c                 R    t        g |j                  |j                  |             S r^   )rE   itemsunpack_var_sequencer   r   r   s      rY   tuple_add_handlerz:BuiltinVariable._binop_handlers.<locals>.tuple_add_handler  s'     !G177!GQ-B-B2-F!GHHr[   c                 R    t        g |j                  |j                  |             S r^   )rC   r   r   r   s      rY   size_add_handlerz9BuiltinVariable._binop_handlers.<locals>.size_add_handler  s'     F!'' FA,A,A",E FGGr[   c                 R    t        g |j                  |       |j                        S r^   )rE   r   r   r   s      rY   <lambda>z1BuiltinVariable._binop_handlers.<locals>.<lambda>  s/    ..r2" r[   c                 f    t        g |j                  |j                  |       t                     S Nmutation_type)rB   r   r   r4   r   s      rY   r   z1BuiltinVariable._binop_handlers.<locals>.<lambda>  s-    :agg: 5 5b 9:"2"4" r[   c                 T     t        |      g |j                  |j                        S r^   )r`   r   r   s      rY   r   z1BuiltinVariable._binop_handlers.<locals>.<lambda>  s.    a" r[   c                     |j                         s|j                  |       sy |j                  |       }| j                  j                  j                  |       |j                  j                  |       |S r^   )is_immutablehas_unpack_var_sequencer   r   side_effectsmutationr   extend)r   r   r   seqs       rY   list_iadd_handlerz:BuiltinVariable._binop_handlers.<locals>.list_iadd_handler  sY    ~~q'@'@'D''+CII""++A.GGNN3Hr[   c                     t        |t              r||}}|j                  |j                  |j	                         z  t                     S )N)r   r   )r_   r7   	__class__r   as_python_constantr4   )r   lstconsts      rY   expand_list_likez9BuiltinVariable._binop_handlers.<locals>.expand_list_like  sG    #/0"CU==ii%":":"<<.0 !  r[   c                 4   
 d fd}t         t         f|fg} t        v r}t         t         f|fg}t               }|j                  t        t
        f|j                  ft
        t        f|j                  fg        fd}|j                  t
        t
        f|f       |S t         t         f|fg} j                         v rX j                  j                  d      r<  t               d       
d
fd}|}|}t        t        t        t        f}|j                  |t         f|ft         |f|fg       t               }|j                  t        ft        ff fdff fdff|ff|ft        t         t         ft        t         t         ff|ft        t
        f|j"                  ft
        t        f|j"                  ft        t
        f|j                  ft
        t        f|j                  fg	       d fd}	|j                  t
        t
        f|	f       |S )	Nc                 P    t         |j                  |j                              S r^   )r7   rX   r   r   r   ops      rY   compare_by_valuezYBuiltinVariable._binop_handlers.<locals>.create_cmp_op_handlers.<locals>.compare_by_value4  s    '177AGG(<==r[   c                 d    | j                  t        j                  | t                 ||gi       S r^   )inline_user_function_returnr5   buildpolyfill_fn_mappingr	  s      rY   handlerzPBuiltinVariable._binop_handlers.<locals>.create_cmp_op_handlers.<locals>.handlerV  s6    99'--b2Eb2IJQPQFTV r[   is_c                     t              S r^   r6   )r   r   r   none_results      rY   neverzNBuiltinVariable._binop_handlers.<locals>.create_cmp_op_handlers.<locals>.neverf  s    +K88r[   c                 P    t         |j                  |j                              S r^   )r7   rQ   r	  s      rY   r   zQBuiltinVariable._binop_handlers.<locals>.create_cmp_op_handlers.<locals>.<lambda>  s    -=bqttn-M r[   c                     t         | j                  j                  |j                        | j                  j                  |j                                    S r^   )r7   r   get_submodule
module_keyr	  s      rY   r   zQBuiltinVariable._binop_handlers.<locals>.create_cmp_op_handlers.<locals>.<lambda>  sA    -= "$&II$;$;ALL$I$&II$;$;ALL$I!". r[   c                    t        |      t        |      ur"t        j                  j                  dk7        S ||u rt        j                   ||            S t	        |t
        j                        rPt	        |t
        j                        r5|j                  |j                  urt        j                   ||            S y y y )Nr  )r`   r7   create__name__r-   r   ExceptionVariableexc_type)r   leftrightr
  s      rY   	handle_iszRBuiltinVariable._binop_handlers.<locals>.create_cmp_op_handlers.<locals>.handle_is  s     Dze4/66r{{e7KLLu}/66r$GGtY%@%@A"5)*E*EF MM?/66r$GG @ G Br[   r   rN   )r7   r  rP   r   rH   r5   _comparison_with_symnodeappendr   r  
startswithobjectrI   r@   r:   r9   r8   _comparison_with_tensor)r
  r  resultop_varr  r  obj_op_nonenone_op_objtypes_that_are_never_noner   r  r   r   r   r   rK   rL   r   r   s   `         @rY   create_cmp_op_handlersz?BuiltinVariable._binop_handlers.<locals>.create_cmp_op_handlers3  s   > $%568HIJ  (( -.>?AQRS(, -o>";;
 -o>";;	
 A7KL(*:;=MNOF3::<<AWAWB !409 $# ##$$',%%	-)  78HI'
 ./HI'	 ), "6 G!5 G N !1 0 78QR,
 67OP, "0@P Q!/@P Q - ,_="::
 -n="::
 -o>";;
 -o>";;_35nH A9MNMr[   r!  )!	functionsr   r   	nn_moduler   r   r   torchr   user_definedr   rK   rL   rP   r   r   r#  r5   rH   rC   rE   r7   rB   r@   rA   r{   r   r   r   r   rG   r   rk   )op_handlersr
  magic_method_namesin_place_opr   r   inplace_namer   r   r   r   r   list_like_addition_handlersr   list_like_iadd_handlersr  list_like_expansion_handlersr,  r   r   r   r   rK   rL   r   r   s                     @@@@@@@@rY   _binop_handlerszBuiltinVariable._binop_handlersF  s    	N/:,	
 	
$  	 $$&,,.P	 
- KO')K$7I4L, *)D6 O""%79MN O""!#679MN
 DP@+@
 $++%79UV $++!#679UV
 JL  O""!?3_E O""!?3_E
 $++!?3_E $++!?3_E]P	j	I	H  |, 
 }- 
 - 
 .!
  01!
 "=1 !%'79MN	 "#34W4
 	$z 	HLL!(()DE	" /!
 .!
  01!
 	 & 	HMM"))*AB	 ,-/?@-.0@A-/?@.0@A	
 	% 	HLL!(()EFX	 X	t +113 	9BB<<[(((4R8KO	9
 r[   c                     t         j                         j                  |       }|y g }|D ]3  \  \  }}}t        ||      st        ||      s#|j	                  |       5 |S r^   )rP   r8  get
issubclassr#  )r
  a_typeb_typehandlersmatchestype1type2r  s           rY   _find_binop_handlerz#BuiltinVariable._find_binop_handler  sg    "22488<'/ 	(#NUEG&%(Z-Fw'	( r[   c                 :    | j                   | j                         v S r^   )rQ   r   r   s    rY   can_insert_in_graphz#BuiltinVariable.can_insert_in_graph  s    ww$22444r[   c                 2    t        |   di | || _        y )N )super__init__rQ   )r   rQ   kwargsr  s      rY   rH  zBuiltinVariable.__init__  s    "6"r[   c                     | j                   d}n| j                   j                  }| j                  j                   d| dS )NNone())rQ   r  r  )r   names     rY   __repr__zBuiltinVariable.__repr__  s=    77?D77##D..))*!D633r[   c                     | j                   S r^   r   r   s    rY   r  z"BuiltinVariable.as_python_constant  s    wwr[   c                     t         t        j                   t        t        j                  t        t        j
                  i}| j                  |v r|| j                     S t        | !         S r^   )	rj   r/  rp   int64rn   float64rQ   rG  as_proxy)r   DTYPEr  s     rY   rT  zBuiltinVariable.as_proxy  sO    %**5==

 77e>!w!!r[   c                     | j                   j                  }| j                   j                  dk(  sJ ||j                  j                  vsJ d       |j                  |j                  |d             y )Nbuiltinszshadowed globalT)r   )rQ   r  
__module__r   	f_globalsappend_outputcreate_load_global)r   codegenrN  s      rY   reconstructzBuiltinVariable.reconstruct  se    wwww!!Z///7::///B1BB/g8848HIr[   c                     t        ||      S r^   )r"   r   argsrI  s      rY   constant_argszBuiltinVariable.constant_args  s    "400r[   c                     d}|D ]<  }t        |t        j                        r y|xs t        |t        j                        }> |S NF)r_   r   GetAttrVariablerI   )r   r`  
any_tensorargs       rY   tensor_argszBuiltinVariable.tensor_args  sJ    
 	QC#y889#Pz#y7O7O'PJ	Q r[   c                     d}|D ]<  }t        |t        j                        r y|xs t        |t        j                        }> |S rc  )r;  r   rd  rI   )r   	arg_typesre  arg_types       rY   tensor_args_typez BuiltinVariable.tensor_args_type  sJ    
! 	VH(I$=$=>#Uz(I<T<T'UJ	V r[   c                    g }g }t        j                  ||j                               D ]?  }t        |t        j
                        r|j                  |       /|j                  |       A t        d |D              xr  | j                  | S )Nc              3   b   K   | ]'  }|j                   t        |j                         nd ) y wrc  )rT   r    )rd   ts     rY   rf   zBBuiltinVariable.python_and_tensor_constant_only.<locals>.<genexpr>  s0      
 -.HH,@qxx(eK
s   -/)		itertoolschainr   r_   r   rI   r#  rh   ra  )r   r`  rI  rg  non_tensor_argsis         rY   python_and_tensor_constant_onlyz/BuiltinVariable.python_and_tensor_constant_only  s    v}}7 	*A!Y556""1%&&q)		*
  
 
 
 3 !d  /2	3r[   c                     | D cg c]  }|j                          c}|j                         D ci c]  \  }}||j                          c}}fS c c}w c c}}w r^   )r  r   )r`  rI  re   kvs        rY   unwrap_unspec_args_kwargsz)BuiltinVariable.unwrap_unspec_args_kwargs"  sV    0451$$&528,,.8
*.!QAq##%%8
 
 	
5 8
s
   AAc                 >    | j                         xr t        ||      S r^   )r   r$   r_  s      rY   has_constant_handlerz$BuiltinVariable.has_constant_handler(  s%    --/ 
4Q&5
 	
r[   ri  
has_kwargsc                    	
 ddl m t               g t        fdD              rfdS t	        j
                         r"t         t              s t        u r
	 	 d fd}|S j                         ri t        j                  u rt        d   t        j                        r:j                        rj                  S rj!                  j                         t#              dk(  rYsWt        j$                   g 

sn>t#        
      dk(  r
\  	j!                  	fd       nd
fd	}j!                  |       t'        d
 j(                   d       rd fd}j!                  |       j+                         r2t-        d D              r	sd fd}nd fd}j!                  |        fdt#              dk(  rfdS t#              dk(  r\  dfd}|S dfd}|S )Nr2   )LazyVariableTrackerc              3   6   K   | ]  }t        |        y wr^   )r;  )rd   rn  r|  s     rY   rf   z0BuiltinVariable._make_handler.<locals>.<genexpr>4  s     Eaz!01Es   c                 l    j                  | |D cg c]  }|j                          c}|      S c c}w r^   )r   realize)r   r`  rI  rv  objs       rY   r   z/BuiltinVariable._make_handler.<locals>.<lambda>5  s-    C,=,=$/QQYY[/- /s   1
c                     t         u r:t        d |D              s(t        dt        |      dg t        j
                         t        j                  |fi |S )Nc              3      K   | ]:  }t        |t        j                        xr t        |j                  t               < y wr^   )r_   r   r7   rX   rx   rc   s     rY   rf   zWBuiltinVariable._make_handler.<locals>.create_exception_class_object.<locals>.<genexpr>D  s?      4  q)"<"<= 1"177C014s   A Azassert with non-string messagez1Dynamo only supports asserts with string messagesgb_typecontextexplanationhints)AssertionErrorrh   r   rx   r   SUPPORTABLEr   r  )r   r`  rI  rQ   s      rY   create_exception_class_objectzDBuiltinVariable._make_handler.<locals>.create_exception_class_objectA  sc     ' 4 "4 1
 % @ #D	$W> 1 = =>	 !222tFvFFr[   r   r   c                      | g| S r^   rF  )r   r`  _binop_handlers      rY   r   z/BuiltinVariable._make_handler.<locals>.<lambda>g  s    M"4Lt4L r[   c                 2    D ]  } || g| }|s|c S  y r^   rF  )r   r`  r  rQ   rvbinop_handlerss        rY   call_binop_handlersz:BuiltinVariable._make_handler.<locals>.call_binop_handlersj  s'    , &]T]#%I&r[   call_c                    	  	| g|i |}||S y # t         $ r 	  t        j                  	      j                  | g|i |  # t         $ rq}j	                  ||      }|sRt
        j                  d	|       t        dd	 d| d| dj                   g t        j                         Y d }~Y y Y d }~Y y d }~ww xY wt        $ r/}j	                  ||      }|s |j                          Y d }~y d }~ww xY w)Nz1incorrect arg count %s %s and no constant handlerz"invalid call to builtin op handlerzinvalid args to z:  z/Encountered TypeError when trying to handle op r  )	TypeErrorinspect	signaturebindry  logwarningr   r  r   	DIFFICULTr   remove_from_stats)
r   r`  rI  r'  ery  excrQ   r  self_handlers
          rY   call_self_handlerz8BuiltinVariable._make_handler.<locals>.call_self_handleru  s+   ,)">t>v>F)% *  <)),7<<RQ$Q&Q   % /2/G/Gf/U,3KK S , !
 -(L*:<.4&PQRXQY(Z.]^`^i^i]j,k&D(9(C(C&D	   4  # ,+.+C+CD&+Q(/))++,sE    	C<)AC<	CA B=1C<7C<=CC<%C77C<c              3   <   K   | ]  }t        |t                y wr^   )r;  r7   rc   s     rY   rf   z0BuiltinVariable._make_handler.<locals>.<genexpr>  s     GJq"23G   c                    	  |D cg c]  }|j                          c} }t        j                  |       S c c}w # t        $ rL}t        t        |      | t	        t        t        j                  |j                                     Y d }~kd }~wt        $ r0}t        dd d| dg t        j                  |       Y d }~d }~ww xY w)Nr`  constant fold exceptionattempted to run function  with arguments 7Encountered exception when attempting to constant fold.r  r  r  r  from_exc)r  	Exceptionr   r`   listmapr7   r  r`  r3   r   r   
DYNAMO_BUGr5   r  )r   r`  rI  re   resr  rQ   s         rY   constant_fold_handlerz<BuiltinVariable._make_handler.<locals>.constant_fold_handler  s     >BCa224C" +00S99! D$ 0 I!%c*:*A*A388&L!M 
 ? ($=&@DTUYTZ$[(a"A$5$@$@"A%( s.   ? :? ? 	CABC&CCc                 (   t        ||      rk	  |D cg c]  }|j                          c}i |j                         D ci c]  \  }}||j                          c}}}t        j                   |       S y c c}w c c}}w # t        $ r0}t	        dd d| dg t
        j                  |       Y d }~Vd }~wt        $ rL}t        t        |      | t        t        t        j                  |j                                     Y d }~d }~ww xY w)Nr  r  r  r  r  r  )r$   r  r   r3   r   r   r  r  r   r`   r  r  r7   r  r`  r5   r  )	r   r`  rI  re   ru  rv  r  r  rQ   s	           rY   r  z<BuiltinVariable._make_handler.<locals>.constant_fold_handler  s   4T6B"$BF!GQ!"6"6"8!G# KQ,,.#"BF!QAq';';'=$=#"#C(  /44R==- C "H#"  C ,(A*DRDHXY]X^(_,e&E(9(D(D&E),   ) 4 $S	 "%)#.>.E.Esxx*P%Q s@   B A:B A?B :B 	D&B99DADDc                     | D cg c]  }|j                          }}t        ddj                   d d dj                   d| d ddj                   d| d	j                   d
ddg       y c c}w )Nz Failed to trace builtin operatorzbuiltin r  z4Dynamo does not know how to trace builtin operator `z` with argument types z (has_kwargs rM  zAvoid calling builtin `z?. Consider using an equivalent alternative function/method to `z`.zIf you are attempting to call a logging function (e.g. `print`), you can try adding it to `torch._dynamo.config.reorderable_logging_functions`.z"Please report an issue to PyTorch.r  )python_type_namer   r  )r`  rf  real_arg_typesri  rQ   rz  s      rY   call_unimplemented_v2z<BuiltinVariable._make_handler.<locals>.call_unimplemented_v2  s    @DEc224ENE:"2;;-q1ZLIRSUS^S^R_ `''5&6mJ<qR .bkk]:PQ_P` aTTVT_T_S``bde8 Fs   A7c                      |      S r^   rF  )r   r`  rI  r  s      rY   r   z/BuiltinVariable._make_handler.<locals>.<lambda>  s    ,A$,G r[   c                 2     | ||      }|r|S  |       y r^   rF  )r   r`  rI  r  r  r  s       rY   builtin_dispatchz7BuiltinVariable._make_handler.<locals>.builtin_dispatch  s!    Rv.I%d+r[   c                 D    D ]  } || ||      }|s|c S   |       y r^   rF  )r   r`  rI  rQ   r  r  r>  s        rY   r  z7BuiltinVariable._make_handler.<locals>.builtin_dispatch  s2    " "BBf-B!	" &d+r[   r!  )lazyr|  rP   ri   r  isclassr;  r  GeneratorExitrD  r{   r   r   rI   rk  _handle_insert_op_in_graphr#  rq   rB  ro   r  r   rh   )rQ   ri  rz  r  r  r  r  r  r|  r  r  r  r  r>  r  r  s   ```     @@@@@@@@rY   _make_handlerzBuiltinVariable._make_handler-  s   -b!+-E9EE  ??2r9% ]"G+G" 10""$("""y|Y-E-EF##I.555 > >? y>Qz,@@PiPN!^$)#1  LM&  34seBKK=$94@,B OO-.((*GYGG":0>4 OO12	  x=AGG]a!JW,  ,  r[   r   rN   c           
         ddl m}m} |r# | j                  g ||j	                          sy ddl m} ddlm}m}m	}	m
}
  |	|||      r|j                  sct        |d   t              s@| j                  |v r|| j                     }n|| j                     }|d   }|d   |d<   ||d<   n|| j                     }n| j                  }|j                  ||      } |
||||      S | j                  }	  | j                   |i |r(ddlm} ddlm}  ||| ||j*                        ||      S |t,        v r0t        |d   t.        j0                        rt,        |   |d   |d   g}}|t2        j4                  u rKt        |d   t6              r8t8        j:                  |d   t.        j0                  j                  d      |d   g}}t=        ||      r[t?        d	 |D              sI |j@                  jB                  d
tE        |      gtG        ||       } |t.        jH                  ||      S |t2        jJ                  u rEtM        |      dk(  r7t        |d   t.        j                        r|d   jO                  |d|dd  |      S  |j@                  jB                  d
|gtG        ||       }t?        d |D              r |tP        ||      S tS        ||      rb| jU                  ||      \  }} ||i |}t?        d tW        jX                  ||j	                               D              } |tZ        ||||      S t]        d |D              rt7        j                  ||d       S |t2        j^                  u r3t        |d   t.        jZ                        r|d   ja                         |d<    |||      S # tb        $ r9 te        dd|  d| d| d| j                   dg tf        jh                         Y y w xY w)Nr2   )r   wrap_fx_proxy_cls)SourcelessBuilder)BUILTIN_TO_TENSOR_FN_MAPBUILTIN_TO_TENSOR_RFN_MAPcan_dispatch_torch_functiondispatch_torch_functionr   r   )	unique_id)invoke_and_store_as_constantc              3   T   K   | ]   }t        |      t        j                  k(   " y wr^   )r`   r   rI   rd   rf  s     rY   rf   z=BuiltinVariable._handle_insert_op_in_graph.<locals>.<genexpr>D  s&      B:=S	Y555Bs   &(r   __eq__c              3   <   K   | ]  }t        |t                y wr^   r_   rF   r  s     rY   rf   z=BuiltinVariable._handle_insert_op_in_graph.<locals>.<genexpr>]  s     E:c#34Er  c              3   h   K   | ]*  }t        |t        j                        r|j                   , y wr^   r_   r   rJ   need_unwraprc   s     rY   rf   z=BuiltinVariable._handle_insert_op_in_graph.<locals>.<genexpr>g  ,      "!!Y%J%JK MM"   02)	raw_valuer  c              3   <   K   | ]  }t        |t                y wr^   r_   rH   rc   s     rY   rf   z=BuiltinVariable._handle_insert_op_in_graph.<locals>.<genexpr>t  s     BZ?3Br  z,unimplemented builtin op on tensor argumentszpartial tensor op: r  z3Dynamo does not know how to trace builtin operator z with tensor argumentsr  )5r   r   r  rg  r   r  torch_functionr  r  r  r  exportr_   rI   rQ   r  rs  bytecode_transformationr  r-  r  r  IN_PLACE_DESUGARING_MAPr   r7   r{   r   rH   r/  selectr#   ri   r   r   r.   r/   NumpyNdarrayVariabler   rq   r   rF   r%   rw  ro  rp  rJ   rh   r   r  NotImplementedErrorr   r   r  )r   r   r`  rI  r   r  r  r  r  r  r  functmpfn_varrQ   r  r  proxy_args_kwargsr  r  s                         rY   r  z*BuiltinVariable._handle_insert_op_in_graph  s   =*$**CDC6==?C 	/	
 	
 'r48 99!$q'>:ww";;8A7@q'C"1gDG!DG3DGG<Dww&--b$7F*2vtVDDWWe	3t33TDVD?C3Ibkk2D&  ,,Q332 326a$q'8JDX%%%*T!Wo*N
 LLQ!2299!<Q  (f5c BAEB ? /		..#*2. 'tV4 ))G)GUSS hkk!INtAw	(@(@A
 Aw**2xab6JJ*BII** #40E
 EEE($ 
 *$7!%!?!?f!Mw11	! "&__T6==?C"  )/' +  BTBB&--b%>> )))jGYBB/ #1g88:DG$R//" 	F-dV1TF!F8DQRVRYRYQZZpq6)556		s;   /9N) )C;N) %AN) <AN) A-N) 2(N) AN) )?O+*O+call_function_handler_cacher`  r5   rI  dict[str, VariableTracker]c           	         |rK|j                         D ci c]  \  }}||j                          }}}| j                  gd |D        d}n| j                  gd |D        }| j                  j	                  |      }|sL| j                  | j                  |D cg c]  }t        |       c}t        |            x| j                  |<   } ||||      S c c}}w c c}w )Nc              3   2   K   | ]  }t        |        y wr^   r`   rc   s     rY   rf   z0BuiltinVariable.call_function.<locals>.<genexpr>       4!d1g4   Tc              3   2   K   | ]  }t        |        y wr^   r  rc   s     rY   rf   z0BuiltinVariable.call_function.<locals>.<genexpr>  r  r  )r   r  rQ   r  r:  r  r`   rj   )	r   r   r`  rI  ru  rv  keyr  re   s	            rY   r   zBuiltinVariable.call_function  s     17@Aan@F@77;4t4;d;C7754t45C2266s;>B>P>P40a$q'0$v,? D,,S1G r4(( A 1s   CC
c                    | j                   t        u r|dk(  rt        |      dk(  sJ t        |      dk(  sJ |\  }}}|j                         }t	        |t
              rH|j                  j                  j                  |      r#|j                         r|j                  |||      S |dk(  r,| j                   t        u rKt        |      dk(  r=t        |      dk(  sJ |j                  j                  j                  | |d   |dd        S | j                   t        u rt        |      dk(  rs|sqt        i t        t                     }t	        |d   t              r|d   j                   t        u r|S |j                  j                  j                  | |d   |dd        S | j                   t         u rt        |      dk(  r|d   j#                  |      r|st	        |d   t              rH|d   j                   t         u r3|d   j%                  |      }	t'        j(                  |	t                     S |j                  j                  j                  | |d   |dd        S | j                   t*        u rlt-        g t                     }
t	        |d   t              r|d   j                   t*        u r|
S |j                  j                  j                  | |d   |dd        S | j                   t        u r|dk(  rt'        j.                  d       S | j                   t        u r#|d	k(  rt        j0                  |t        g|i |S | j                   t        u rt3        | j                   |      }|t4        v rxt	        |d   t&        j6                        r$|d   j8                  j;                  |||dd  |      S t	        |d   t&        j                        r|d   j;                  |||dd  |      S | j                   t<        u rYt        |      dk\  rKt3        | j                   |      }|t>        v r-t	        |d   t.              r|d   j;                  |||dd  |      S t@        | u  ||||      S )
N__setattr__   r   __new__r2   r   r   rH  fromkeys)!rQ   r%  rq   r  r_   rK   r   r   is_attribute_mutationis_python_constantmethod_setattr_standardtrack_new_user_defined_objectdictr:   r4   rP   tupler   r   r   rE   r  rB   r7   call_custom_dict_fromkeysro   r'   UserDefinedDictVariable_dict_vtr   rx   r0   rG  )r   r   rN  r`  rI  r  name_varvaldict_vt	init_argslist_vtresolved_fnr  s               rY   r   zBuiltinVariable.call_method  s    77f!6t9>!>v;!###!%C3++-C3 9:II**@@E//1222xEE9ww& SY!^6{a'''yy--KK$q'48  ww$3t9>&+BDTDVWd1g7DGJJ$<N"N yy--KKGH  5 ING33B7d1g7DGJJ%<O $Q ; ;B ?I$22!1A1C  yy--KKGH  ww$&r9I9KLd1g7DGJJ$<N"Nyy--KKGH  77f!3--d3377d?tz1"<<RWWPVWW77d?!$''40Kl*d1gy'H'HI7++77D$qr(FSSQ)D)DE7..r4ab6JJ77c>c$i1n!$''40Kk)d1g'787..r4ab6JJw"2tT6::r[   c           	      X   t        |t        t        j                  f      rt        |t        j                        r|j	                  |dg i       }n|}| j
                  t        u rt        nt        }ddl	m
}  |||j                  j                  d||j                         fi             S y )Nitemr   r   r   r   r  )r_   rH   r   rI   r   rQ   rp   r   r
   torch._dynamo.variables.builderr   r   r   rT  )r   r   rf  r   fn_r   s         rY   _call_int_floatzBuiltinVariable._call_int_float  s     cOY-E-EFG#y778r62r:!WW^'CE ii,,#]]_&	  Hr[   c                 *   t        |t              rt        |j                  t        j                        r|S t        |j                  t        j                  t        j                  f      sJ t        j                  ||j                         dk7        S y Nr   )
r_   rH   sym_numr/  SymBoolr-   SymIntSymFloatr  rT  )r   r   rf  s      rY   	call_boolzBuiltinVariable.call_bool  sm     c?+ #++u}}5

 #++enn'EFFF"))"clln.ABB ,r[   c                    t        |t        j                        r3t        j                  j	                  t        |j                              S t        |t        j                        r?t        |j                  d      r|j                  j                  }nUt        |j                  d      r|j                  j                  }n(t        dt        |      dg t        j                         t        |j                        j                  t         j                  u r&	 t        j                  j	                                S t%              r't        ddt        |j                         d	d
g       y |j&                  }	 t        j                  |      }|j/                  ||gi       S t        |t        j0                  f      rht3        |j4                        dk(  r|j6                   }n"dj9                  d |j4                  D              }t        j                  j	                  |      S y # t"        $ r Y y w xY w# t(        $ r }t*        j-                  d|       Y d }~y d }~ww xY w)N)rX   __str__rO  z+failed to call str() on user defined objectz5User defined object has no __str__ or __repr__ methodr  z0Attempted to a str() method implemented in C/C++ z5 has a C/C++ based str method. This is not supported.zWrite the str method in Pythonz)Failed to create UserFunctionVariable: %sr   , c              3   <   K   | ]  }|j                           y wr^   )r  )rd   r   s     rY   rf   z+BuiltinVariable.call_str.<locals>.<genexpr>`  s     !KQ!"6"6"8!Kr  )r_   r   r   r7   r  rx   rQ   rK   hasattrrX   r  rO  r   r   
USER_ERRORr`   r%  AttributeErrorr,   __func__r  r  r  r  r  rq   r`  r  join)r   r   rf  
str_methodbound_methoduser_func_variabler  rX   s           rY   call_strzBuiltinVariable.call_str,  s   cI::<--443svv;4GGiAACsyy), YY..
J/ YY//
 IH W9-889	 CII&&&..8$55<<:<<PP 1< N#'		?"33h i;<	  *22)2)G)G)U& 556H3%QSTTi99;<388}!<<.		!K#((!KK--4454AA =3 & $ & KK KQOs*   $H, ?H; ,	H87H8;	I$II$c                 "   t        |      dk(  r:|d   j                  |      r&|d   j                  |      }| j                  ||      S t        |      dk(  r| j	                  ||d   |d         S t        |      dkD  r| j                  ||      S y )Nr2   r   r   )rq   has_force_unpack_var_sequenceforce_unpack_var_sequence_call_min_max_seq_call_min_max_binary)r   r   r`  r   s       rY   _call_min_maxzBuiltinVariable._call_min_maxc  s    t9>d1gCCBGG55b9E))"e44Y!^,,Ra$q'BBY]))"d33 r[   c                     t        |      dkD  sJ t        |      dk(  r|d   S t        j                  t        j                  | j                  |      |      S Nr   r2   )rq   	functoolsreducepartialr  )r   r   r   s      rY   r  z!BuiltinVariable._call_min_max_seql  sM    5zA~~u:?8O	 1 1$2K2KR PRWXXr[   c                    ||y | j                  ||      r9t        |t        j                        s||}}t        |t        j                        sJ t        |t              r5t        j
                  t        j                        j                  ||gi       }t        |t              st        |t              rLddl
m}  |t        |      | |j                  j                  d| j                  gt!        ||gi              S |j#                         rt        |t        j$                        r$dd l}t        j(                  |j*                        }n#t        j
                  t        j,                        }| j                  t.        u rd|ind|i}|j                  ||g|      }nt        |t        j$                        rIdd l}t.        |j0                  t2        |j4                  i| j                     }	t        j(                  |	      }nLt.        t        j0                  t2        t        j4                  i| j                     }
t        j
                  |
      }|j                  |||gi       }t7        d ||fD              rt9        d	 ||fD              rt        j                  j;                  |      S |j#                         r|j=                         }n|j>                  }| j                  t.        u rt/        |j>                  |      }nt3        |j>                  |      }t9        d
 ||fD              }t        j@                  j;                  |||      S |S t        |t              st        |t              rs| j                  t.        u rt        jB                  nt        jD                  } |j                  j                  d|gt!        ||gi        }t        jF                  ||d       S t        |tH              rJt        |tH              r9| j                  |j=                         |j=                               }tI        |      S y y )Nr2   r  r   r  r   rs   rr   c              3   p   K   | ].  }t        |t        j                  t        j                  f       0 y wr^   )r_   r   rJ   r7   )rd   rr  s     rY   rf   z7BuiltinVariable._call_min_max_binary.<locals>.<genexpr>  s9      	  !==!22	s   46c              3   <   K   | ]  }t        |t                y wr^   r  )rd   r  s     rY   rf   z7BuiltinVariable._call_min_max_binary.<locals>.<genexpr>  s     KSz#'78Kr  c              3   h   K   | ]*  }t        |t        j                        r|j                   , y wr^   r  rc   s     rY   rf   z7BuiltinVariable._call_min_max_binary.<locals>.<genexpr>  r  r  )%rg  r_   r   rI   rF   TorchInGraphFunctionVariabler/  r   r   rH   r   r  r`   r   r   rQ   r/   r  r  numpyNumpyVariableclipclamprr   maximumrs   minimumrh   ri   from_tensor_variabler  r  rJ   sym_maxsym_minr  r7   )r   r   r   r   r  nprQ   rI  r'  np_fntorch_fnraw_braw_resr  py_fnr  rX   s                    rY   r  z$BuiltinVariable._call_min_max_binarys  s   9	 Aq!a!9!9:!1a!9!9::: !-.::5<<HVVR
 !_-A1O6(G0"))00' +Aq626  ##%a!?!?@&"009B"??LB(,3%eQZ))"qc6:a!?!?@& "**c2::>twwGE"007B #U]]CGPH"??IB))"q!fb9  	 Q	 	 KQFKK$55JJ6RR'')002EKKE77c>!!++u5G!!++u5G! "V" 
 !<<QQG[ 
 ?+z!_/M%)WW^EMME*BII**):Aq62)FE #))"eT::+,A?O1PGG$$&$$&E $E** 2Q,r[   rf  c                     t        t              j                  ||t        j                  d      gi       }|j                  |g i       S )N__abs__rP   ro   r   r7   r  )r   r   rf  
abs_methods       rY   call_abszBuiltinVariable.call_abs  F    $W-;;&--i892

 ''B33r[   c                     t        t              j                  ||t        j                  d      gi       }|j                  |g i       S )N__pos__r<  )r   r   rf  
pos_methods       rY   call_poszBuiltinVariable.call_pos  r?  r[   c                     t        |t        j                        rt        dddg        t	        |      }t        j                  |      }t        j                  j                  |      S )Nzunsupported index(Tensor)r  z;Dynamo does not support tracing builtin index() on a Tensorr  )	r_   r   rI   r   r*   r{   r   r7   r  )r   r   rf  constant_values       rY   
call_indexzBuiltinVariable.call_index  sW    c93343Y	 3!,))00@@r[   c                     t        t              j                  ||t        j                  d      gi       }|j                  |||      S )N	__round__r<  )r   r   rf  r`  rI  round_methods         rY   
call_roundzBuiltinVariable.call_round  sF    &w/==&--k:;R
 ))"dF;;r[   c                     t        |i       rt        j                  |      S  | j                  | r't	        d |D              }t        j                  |      S y )Nc              3   l   K   | ],  }t         j                  j                  t        |             . y wr^   )r   r7   r  r*   r  s     rY   rf   z-BuiltinVariable.call_range.<locals>.<genexpr>  s+      IL	**11,s2CD   24)r$   r   RangeVariable_dynamic_argsr  r   r   r`  s      rY   
call_rangezBuiltinVariable.call_range  sZ    (r2**400T& PT D **400r[   c                 j    t        d |D              xs  t        d |j                         D              S )Nc              3   <   K   | ]  }t        |t                y wr^   r  rc   s     rY   rf   z0BuiltinVariable._dynamic_args.<locals>.<genexpr>  s     @a:a1@r  c              3   <   K   | ]  }t        |t                y wr^   r  rc   s     rY   rf   z0BuiltinVariable._dynamic_args.<locals>.<genexpr>  s      H
/0Jq/*H
r  )ri   r   r_  s      rY   rO  zBuiltinVariable._dynamic_args  s7    @4@@ 
C H
4:MMOH
 E
 	
r[   c                 ,    t        j                  |      S r^   )r   SliceVariablerP  s      rY   
call_slicezBuiltinVariable.call_slice  s    &&t,,r[   c           
          ddl m}  || |j                  j                  d| j                  gt        ||             S r   )r   r   r   r   rQ   r/   )r   r   r`  rI  r   s        rY   
_dyn_proxyzBuiltinVariable._dyn_proxy  sA    *"BII""+<T6+J
 	
r[   c                 4   t        |t        j                        rJ  | j                  |i |r | j                  |g|i |S t        j
                  j                  | j                        }| |g t                     S |j                  |      r|j                  rNt        |j                        s8t        |t              r3t        |j                  j                  t        j                                nt#        |dd      rOt        |t$              r?t'        |t(              s/|j*                  j,                  j/                  |j                         t        |t        j0                        r3t        |j                  j                  t        j2                               nLt        |t        j4                        s2t        |j                  j                  t        j6                                |t9        |j;                  |            t                     S y )Nr   rT   F)r_   r   IteratorVariablerO  rY  r@   cls_forrQ   r4   r   rT   r    rD   r   rU   r   TUPLE_ITERATOR_LENro   r:   r-   r?   r   guard_on_key_orderr   MappingProxyVariableMAPPING_KEYS_CHECKUnspecializedNNModuleVariableSEQUENCE_LENGTHr  r   r   r   r  r`  rI  rW   s         rY   _call_iter_tuple_listz%BuiltinVariable._call_iter_tuple_list  s    c9#=#=>>>4t.v."4??27777((009;.0  ((,zz"4SZZ"@c#89!

--l.M.MN
  Xu5&s,=> &sK 8		4488D!#y'E'EF &JJ11,2Q2QR (Y-T-TU &JJ11,2N2NO S,,R01.0 7 -r[   c                     t         j                  j                  | j                        } |t	        |j                  |            t                     S r   )r   r@   r\  rQ   r  r  r4   rc  s         rY   _call_iter_tuple_generatorz*BuiltinVariable._call_iter_tuple_generatorG  sB    ((009..r23*,
 	
r[   c                 l   t        |t        j                        rSt        j                  j	                  | j
                        } |t        |j                  |            t                     S t        |t        j                        r | j                  ||g|i |S  | j                  ||g|i |S r   )r_   r   r[  r@   r\  rQ   r  r  r4   LocalGeneratorObjectVariablerf  rd  rc  s         rY   _call_tuple_listz BuiltinVariable._call_tuple_listN  s    c9556,,44TWW=CS22267.0  YCCD24222sLTLVLL-4--b#GGGGr[   c                     t        |t        j                        r|}n | j                  ||g|i |}||j	                  |d||      S |S )N__iter__)r_   r   r[  rd  r   )r   r   r  r`  rI  rets         rY   	call_iterzBuiltinVariable.call_iterZ  sX    c9556C -$,,RFtFvFC; ??2z4@@
r[   c           	         ddl m}m} ddlm} t        |t        j                  |||f      rt        j                  j                  d      S t        |t              r2t        j                  j                  t        |j                              S t        |t        t        t        t        t         t"        f      rt        j                  j                  d      S y )Nr2   )r   FunctoolsPartialVariabler   TF)r-  r   ro  r.  r   r_   r   r   r7   r  rL   rk   rX   rH   rI   rB   rE   rA   )r   r   rf  r   ro  r   s         rY   call_callablezBuiltinVariable.call_callablek  s    Q/22(( 	
 --44T::01--44Xcii5HII $

 --44U;;

r[   c                 V    t        |      dk(  r|d   S t        dd| d| ddg       y )	Nr   r2   zbad args to builtin cast()z	got args r  z0Dynamo expects exactly 2 args to builtin cast().z3Ensure your call to cast() has exactly 2 arguments.r  )rq   r   )r   r  r`  rI  s       rY   	call_castzBuiltinVariable.call_cast  s:    t9>7N0vQvh/JHI		
r[   c                 >    t        j                  |t        g|i |S r^   )rP   call_custom_dictr  r   r   r`  rI  s       rY   	call_dictzBuiltinVariable.call_dict  s    //DJ4J6JJr[   c                     | j                  t        j                  | t        j                        t        j                  | |      g||      S r^   )r  r5   r  r   construct_dict)r   user_clsr`  rI  s       rY   rt  z BuiltinVariable.call_custom_dict  sF    --!!"i&>&>?""2x0848
 	
r[   c                    |t         t        t        hv sJ |rB|t        u sJ t        |      dk(  rt        |      dk(  rd|v sJ g ||j	                  d      }t        |      dk(  rt        t        d      t        |      dk(  rg |t        j                  d       }t        |      dk(  sJ |\  }}|t        urt        nt        }t        |t               rW|j                         D cg c]  }t        j                  |       }} |t         j                  ||      |t                     S |j                  |       rJ|j!                  |       }t#        d |D              r' |t         j                  ||      |t                     S t%        d|j&                   d	| d
| d|j&                   dddg       y c c}w )Nr2   rX   r   z,fromkeys expected at least 1 argument, got 0r   r   c              3   2   K   | ]  }t        |        y wr^   )r>   )rd   rv  s     rY   rf   z<BuiltinVariable.call_custom_dict_fromkeys.<locals>.<genexpr>  s     0a;q>0r  zfailed to call dict.fromkeys()z.fromkeys(): r  zFailed to call zo.fromkeys() because arguments could not be automatically converted to a list, or some dict key is not hashable.z(Manually convert the argument to a list.zEnsure all keys are hashable.r  )r  r   r   rq   popr   r  r7   r  r:   r;   r_   keysr  r4   r  r  rh   r   r  )	r   ry  r`  rI  rf  rX   DictVariableTyperu  r}  s	            rY   r  z)BuiltinVariable.call_custom_dict_fromkeys  s    D+{;;;;{***t9>c&kQ&67f;LLL/T/6::g./Dt9>I'UVVt9>9T9+22489D4yA~~
U!)!<BU 	 c4 7:xxzB!#**1-BCB#c5)8CSCU  ..r2004D0400'MM$."2"4  	4(()tfAfXF)(*;*;)< =0 0 ;/
	
 Cs   +F=c           
      0   |rJ |st        g t                     S t        |      dk7  r3t        t        |t        j                  dt        |       d      g       |d   }t        |t        j                         r|j                  t                     S |j                  |      r&|j                  |      }t        |t                     S t        |t        j                        rt        |j                  t              rp|j                  |d      }t        |t        j                         rD|j#                  |||      }t        |t               r|S t%        t&              j)                  ||      S t        t        |t        j                  d      g       y )	Nr   r2   z&set() takes 1 positional argument but  were givenr  r   rk  z!failed to construct builtin set())r?   r4   rq   r   r  r7   r  r_   r   cloner  r  rK   rX   r   var_getattrUserMethodVariabler  rP   setcall_set)r   r   r`  rI  rf  r   iter_fnouts           rY   r  zBuiltinVariable.call_set  sW   zr1A1CDDt9>$$++@T;W 1gc900199+;+=9>>..r211"5Eu4D4FGGY@@AjIIxG
 oob*5G'9#?#?@44WdFKc;/J&s+44R== "))*MNO	
r[   c           
         |rJ |st        g       S t        |      dk7  r3t        t        |t	        j
                  dt        |       d      g       |d   }t        |t        j                         r-t        |j                  D cg c]  }|j                   c}      S |j                  |      r|j                  |      }t        |      S t        t        |t	        j
                  d      g       y c c}w )Nr2   z,frozenset() takes 1 positional argument but r  r  r   z'failed to construct builtin frozenset())r=   rq   r   r  r7   r  r_   r   	set_itemsvtr   r   )r   r   r`  rI  rf  re   r   s          rY   call_frozensetzBuiltinVariable.call_frozenset  s    z$R((t9>$$++Fs4ykQ\] 1gc9667$CMM%Bqadd%BCC((,++B/E$U++ "))*STU	
	 &Cs   C3c                     |rt        |      dk(  rd|v sJ |j                  dd      }|D cg c]&  }|j                  |      r|j                  |      n|( }}t	        j
                  ||t                     S c c}w )Nr2   strictF)r  r   )rq   r|  r   r   r   ZipVariabler4   )r   r   r`  rI  r  rf  s         rY   call_zipzBuiltinVariable.call_zip
  s    v;!#F(:::He, 
 ,/+F+Fr+JC##B'PSS
 
 $$/?/A
 	
	
s   +A:c                     	 |d   j                  |d|dd  |      S # t        $ r4}t        t        |      |t	        |j
                               Y d }~y d }~ww xY w)Nr   __len__r2   r  )r   r  r   r`   r  r`  )r   r   r`  rI  r  s        rY   call_lenzBuiltinVariable.call_len  sV    	E7&&r9d12hGG 	E$T!WbtAFF|DD	Es    	A*AAc                 6    |d   j                  |d|dd  |      S )Nr   __getitem__r2   r   ru  s       rY   call_getitemzBuiltinVariable.call_getitem  s#    Aw""2}d12hGGr[   c           	      4   	 j                         }|j                         }t        t        j                        r7j                  +fd}t        j                  j                   ||            S t        t        j                        rJt        j                  t        j                        r&t        dd d| dd	g t        j                          t        t        j                        r[d
|j"                  j$                  v rCt        j                  j                  |j"                  j'                  |j                              S t        t        j(                        rt        j                  t        |            S t        |t*              st-        t/        |d
d             r|f}nrt0        j2                  dk\  r't        |t        j4                        r|j6                  }n8t        |t8              rt;        d |D              r|}nt=        t>        |dg       	 tA              }t        j                  j                  |      S # t        $ r- t        dd d| dd g t        j                         Y pw xY w# t>        $ r v }Y gw xY w)Nz6builtin isinstance() cannot determine type of argumentzisinstance(r  rM  z=Dynamo doesn't have a rule to determine the type of argument r  c                 j    fdt        |      t        u rt        fd|D              S  |      S )Nc                 >   | t         vr~j                         j                  j                  d   }t	        |      r2| t
        j                  j                  j                  u rt        ||       S t        j                         |       S t         |    }j                  |v S )Nexample_value)r1   rT  nodemetar   r/  nn	parameter	Parameterr_   r;  python_typedtype)tyexample_valdtypesrf  s      rY   
check_typezOBuiltinVariable.call_isinstance.<locals>._tensor_isinstance.<locals>.check_type/  s    !44&)lln&9&9&>&>&O9+F "ehh&8&8&B&B B
 $.k2#>>#-coo.?#DD04F99..r[   c              3   .   K   | ]  } |        y wr^   rF  )rd   r  r  s     rY   rf   zNBuiltinVariable.call_isinstance.<locals>._tensor_isinstance.<locals>.<genexpr>A  s     D"z"~Ds   )r`   r  ri   )
tensor_vartensor_typer  rf  s     @rY   _tensor_isinstancez;BuiltinVariable.call_isinstance.<locals>._tensor_isinstance.  s3    /" $-DDDD%k22r[   z<isinstance() called on user defined object with C extensionszeUser-defined object with C extensions can have torch.Tensor attributes; intentionally graph breaking.__instancecheck__)r  
   c              3   l   K   | ],  }t        |t              xs t        t        |d d             . yw)r  N)r_   r`   rk   ro   )rd   tps     rY   rf   z2BuiltinVariable.call_isinstance.<locals>.<genexpr>j  s6      8
 r4 THWR9Ld-S$TT8
rM  z?isinstance() arg 2 must be a type, a tuple of types, or a unionr  )!r  r  r   r   r  r  r_   r   rI   r  r7   r  rK   rX   typesMemberDescriptorTyper  r  r   r  !UserDefinedExceptionClassVariabler`   rk   ro   sysversion_info	UnionType__args__r  rh   r   r  r;  )r   r   rf  isinstance_typerj  r  isinstance_type_tupler  s     `     rY   call_isinstancezBuiltinVariable.call_isinstance  ss   	(H *<<>c93349N3. --44"38 
 c9>>?JIIu11E
 V%cU"_,=Q?<6)556 sI??@#'@'@'I'II--44));;OSYYW  c9FFG#**:h+PQQ ot,O%8$?1
 &5$6!(ZU__.
 %4$<$<!/C 8
%8
 5
 %4!$U
	4 X'<=C ))0055C # 	P%cU"_,=Q?[\_[`a5)445	 	~  	433C	4s#   I #J 2JJJJc           	          	 |j                         }|j                         }t        j                  t                    S # t        $ r* t        dd| d| dddgt        j                         Y Qw xY w)z,Checks if first arg is subclass of right argz(issubclass() with non-constant argumentszissubclass(r  rM  z7issubclass() with non-constant arguments not supported.z#Make sure your arguments are types.r  )r  r  r   r   r  r   r7   r;  )r   r   left_tyright_ty
left_ty_pyright_ty_pys         rY   call_issubclasszBuiltinVariable.call_issubclass  s    	 335J"557K ))*Z*MNN # 		B%gYb
!<U9&11			s    A 0A43A4c                 .    t        j                  ||      S r^   )r   SuperVariabler   r   r   r   s       rY   
call_superzBuiltinVariable.call_super  s    &&q!,,r[   c                     	 |j                  |      S # t        $ rD}t        |t        j                        r$|j                          |j                  d   cY d }~S  d }~ww xY wr  )next_variabler   r_   r   r@   r  r   )r   r   rf  exs       rY   	call_nextzBuiltinVariable.call_next  sU    	$$R(( 	#y99:$$&yy|#		s     	A 8AA AA c                     |j                         re|j                         }t        |t        j                        r)t        j
                  t        |j                  |            S |j                  ||      S y r^   )	r  r  r_   r   rP   r7   r  rQ   call_obj_hasattr)r   r   r  attrrN  s        rY   call_hasattrzBuiltinVariable.call_hasattr  s`    ""$**,D#y889 11'#&&$2GHH''D11	 %r[   c                     |D cg c]&  }|j                  |      r|j                  |      n|( }}t        j                  ||t	                     S c c}w r   )r   r   r   MapVariabler4   )r   r   rQ   seqsr   s        rY   call_mapzBuiltinVariable.call_map  s_     
 ,/+F+Fr+JC##B'PSS
 
 $$R=M=OPP	
s   +Ac                     |j                  |      r|j                  |      n|}t        j                  ||t	                     S r   )r   r   r   FilterVariabler4   )r   r   rQ   r   s       rY   call_filterzBuiltinVariable.call_filter  s;    -0-H-H-Lc%%b)RU''C?O?QRRr[   r  r  c                    |j                         st        dd| d| d| dddg       |j                         }t        |t              r|dk(  rd	}|j
                  j                  j                  |      rht        |t        j                        rN|d
v rJ|j                  r>|j
                  j                  j                  |      rt        dd| d| d| ddg        |j
                  j                  j                  ||      r&|j
                  j                  j                  ||      S |9| j                  |||      }|j                         dv sJ |j                         s|S |j                  xr t!        |j                  |      }|dv r	 |j                         }t        |t"              r|dk(  rat%        |j&                        D 	
cg c]*  \  }	}
t)        j*                  ||
|xr t-        ||	            , }}	}
t        j.                  ||      S |dk(  r!t)        j*                  ||j0                  |      S |dk(  rt3        j4                  |j6                        S t        |t        j:                        r|j=                  ||      S t        |t        j                  t        j>                  t        j2                  t        j@                  t        jB                  t        jD                  f      rt        |t        jD                        r]tG        |jH                  jJ                  tL        jN                        r/tP        jR                  r|dv rt        dd| d| dd| dg       t        |t              r|jT                  jV                  jX                  d   }t        |tZ        j\                        rFt_        |      r;|j`                  rtP        jb                  st        dddg td        jf                         	 |j=                  ||      S t        |t        jj                        rtm        |jH                  |      }t        |tZ        jn                  jp                  tZ        jn                  jr                  f      r@tZ        jt                  jv                  jy                  |      rt        jj                  ||      S |tz        v rt        jh                  |||      S y t        |t|              r|j~                  s||jH                  j                  vrtm        |jH                  |      }n|jH                  j                  |   }tP        j                  r'|j                  j                  |jH                  ||       t)        j*                  |||      S t        |t        j                        r-|dv r)t3        j4                  tm        |j                  |            S 	 |j=                  ||      S c c}
}	w # t8        $ r Y w xY w# t8        $ r t        jh                  |||      cY S w xY w# t8        $ r t        jh                  |||      cY S w xY w)Nz)getattr() with non-constant name argumentzgetattr(r  rM  z:getattr() with non-constant name argument is not supportedz1Ensure the name argument of getattr() is a stringr  _gradgrad)named_parameters
parametersnamed_buffersbuffersnamed_modulesmodulesz,getattr() on nn.Module with pending mutationzPIntentionally graph breaking on getattr() on a nn.Module with a pending mutation)TF>   __base__	__bases__	__flags__r  rS   r  r  )assertRaisesRegexassertNotWarnsassertWarnsRegexassertDictEqualassertSequenceEqualassertWarnszFailed to trace unittest methodzfunction: unittest.TestCase.z3Dynamo does not know how to trace unittest method `z` zAvoid calling `TestCase.z%`. Please report an issue to PyTorch.r  zAttempted to wrap sparse Tensorr  z-torch.compile does not support sparse Tensors)r  rX  )Gr  r   r  r_   rI   r   r   r  r   ra  is_state_mutatedhas_pending_mutationhas_pending_mutation_of_attr	load_attrr  rT   r   r`   	enumerater  r5   r  r   rE   r  r7   r  r  r  r   r  NamedTupleVariableDistributedVariabler   rK   r;  rX   r  unittestTestCaser   enable_trace_unittestr  r  r  r/  Tensorr   r  capture_sparse_computer   r  rd  r*  ro   _opsOpOverloadPacket
OpOverload_dynamotrace_rulesis_aten_op_or_tensor_methodr&   r   is_torchr   replay_record_enabledexec_recorderrecord_module_accessr-   r   rQ   )r   r   r  r  defaultrN  hasattr_varrT   rX   rr  r   
tuple_argsfake_valmembers                 rY   call_getattrzBuiltinVariable.call_getattr  s    **,C"3%r(2gYa@XJK	 **, c>*twD99!!77<#yFFG ,,		..CCCH$ N"*3%r$r'! D%2  99!!>>sDI99))33C>>++BX>K113}DDD113<
3::t <99..0eT*{*
 )2%//(B	& !%1 ,11 "Av'J-2J&
 &  )66z&QQz).44RPP{*/66uGG c9556??2t,,((,,**--2233

 3	 C CDsyy22H4E4EF00 !=:4&A"UVZU[[] ^24& 9= =	 #~.99>>..?x6%h/YYf.K.K$ A "$S> 1 = =>	Kr400 YCCDSYY-F44ejj6K6KL--++GGO ==fVTT// 00d6JJ 0[)||t399+=+== D1++D1++  55ciivN"((VV<<C778T F
 >
 $**73664+@AAKr400& ' n ' K 00d6JJK< ' K 00d6JJKsT   =W0 /W*;W0 %W0 ;#W0 =X  X' *W0 0	W=<W= !X$#X$'!Y
Yr  c                    t        |t        j                  t        j                  t        j                  t        j
                  t        j                  f      r|j                  |d||gi       S |j                  j                  j                  |      r9|j                         r(|j                         }t        |t        j                        rddlm} |dk(  r+t!        dd| d| d| dd	g t"        j$                  
       n|dk(  rh|j&                  t!        dd| d| d| dddg
       |j                  j(                  D cg c]  }|j&                  |j&                  k(  s|  }}|D ]'  }|j                  j(                  j+                  |       ) t-        |      5  t/        j0                         5   || |j                  j2                  dt.        j4                  j6                  gt9        ||gi              }	d d d        d d d        d }
|j                  j3                  d|
	j;                         fi         |
|j;                         j<                  j>                  d          |	S |dv rd}n)tA        |      rt!        dd| d| d| ddd| dg
       |j                  j                  jC                  |||       |S t        |t        jD                        r0|j                  jG                         stI        d      |j                         rt        |t        j                        rtK        |j;                         j<                  |      }	 |jM                  ||j                               }t        |t        j                        rptK        |j;                         j<                  |      }tS        jT                  |jV                  d      }||u r(|t.        jX                  jZ                  j\                  u r|S |j_                  |       y y c c}w # 1 sw Y   xY w# 1 sw Y    xY w# tN        tP        f$ r d }Y w xY w)Nr  r2   r   requires_gradz!setattr() on Tensor.requires_gradzsetattr(r  rM  zsetattr() on Tensor.requires_grad not supported. Mutating requires_grad can introduce a new leaf from non-leaf or vice versa in the middle of the graph, which AOTAutograd does not currently know how to handle.r  dataz&Failed to mutate tensor data attributezVDyanmo only supports mutating `.data` of tensor created outside `torch.compile` regionzWDon't mutate `.data` on this tensor, or move the mutation out of `torch.compile` regionr   c                     | j                   }|dkD  r|dz
  }t        j                  j                  j	                  | f|f       | S r!  )_versionr/  _C	_autograd_unsafe_set_version_counter)re   versions     rY   _lower_version_count_by_1z?BuiltinVariable.call_setattr.<locals>._lower_version_count_by_1  s>    "#**"Q;&-kG**FFtgZX r[   r  )r  r  r  zFailed to set tensor attributez6Dyanmo doesn't support setting these tensor attributeszDon't mutate attribute 'z@' on tensors, or move the mutation out of `torch.compile` regionz?Can't inplace modify module params/buffers inside HigherOrderOp)0r_   r   PlacementVariabler  rK   NestedUserFunctionVariabler  r   r   r   r  r  r  rI   r   r   r   r   r  rT   tracked_fakesremovedynamo_disable_gradr/  no_gradr   r  set_r/   rT  r  r  r+   
store_attrr   is_root_tracerr   r)   r  r  r   r  getattr_staticmodule_typer  Moduler  convert_to_unspecialized)r   r   r  r  r  rN  r   tf	to_remover  r  assigning_fake_valgetattr_varexisting_fake_attrmod_setattrs                  rY   call_setattrzBuiltinVariable.call_setattrU  s	    ++,,3344++	
 ??2}xorJJII""88=++-..0D#y7782 ?*$ C"*3%r$r#a @%l ? 1 = => V^ zz)($L&.se2dV2cU!$D)P!M#	" &(YY%<%<!!		SZZ@W!I ! ( ;		//66r:; -R0 	%--/ 	+2BII22 / % 1 1 "3C:r!B	 	! II**'1)	 .clln.A.A.F.F.WX J.. "D06 % @"*3%r$r#a @$\6tf =N N	 II""--c4=JY77899++-,U  **,Y--2 &4CLLN4G4G%L"'"%//"h6Q6Q6S"TK k9+C+CD)78L8L8N8S8SUW)X& #*"8"8-"XK*.@@'588??+F+FF**((,7 9}!	 	 	 	F '(>? '"&K'sC   
P)P&P+;A
PP+ P8 P(	#P++P58QQc                 ,    |j                  |d|gi       S )N__delattr__r   )r   r   r  r  s       rY   call_delattrzBuiltinVariable.call_delattr  s     r=8*bAAr[   c                    	 |j                         }|j                  xr t        |j                        }|2t        |t        j                        r|j                  r|j                  }|t        j                  u r5|j                  j                  dt              }t!        t#        |      d      }t%        j&                  |||      S # t        $ r+}t        t        j                  t        |      d      d d }~ww xY w)Nunknown_python_type)	case_namer  r  )r  r  r   r   INVALID_INPUTrx   rT   r!   r_   r   rK   
cls_sourcer/  r  r   install_global_by_idr   r   r5   r  )r   r   r  py_typeerrorrT   rN  s          rY   	call_typezBuiltinVariable.call_type  s    	oo'G 6
3:: 6N3	 C CD^^Fell"9911"e<DT 2H=F$$R&99' # 	++E
/ 		s   C 	C;&C66C;c                     |j                  |      r8t        t        |j                  |                  }t	        j
                  |      S y r^   )r   r  reversedr   r   rE   )r   r   r  r   s       rY   call_reversedzBuiltinVariable.call_reversed		  s@    &&r*#"9"9""=>?E**511 +r[   c                     |j                  |      r_t        |t        j                        sDt        j                  |j                  |      t                     }|j                  |dg |       |S y y )Nr   sort)r  r_   r   rI   rB   r  r4   r   )r   r   r  rI  list_vars        rY   call_sortedzBuiltinVariable.call_sorted	  sm     ,,R0)):
 !----b1.0H   VR8O:
0r[   c                     t        |t              r9t        j                  |t        j                  |j                               d       S y )Nr  )r_   rH   r  r{   r}   rT  r   r   r   s      rY   call_negzBuiltinVariable.call_neg	  s<    a)"))qzz|,  r[   c                 z    |j                         }t        |      }t        j                  j	                  |||      S r^   )r  rx   r   StringFormatVariabler  )r   r   _format_stringr`  rI  format_strings         rY   call_formatzBuiltinVariable.call_format)	  s5    &99;M*--44]D&QQr[   c                    t        |      dkD  rot        |d   t        j                        rR|d   }|j                  j                  |j                        }t        j                  j                  t        |            S t        |      dk(  rt        |d   t        j                  t        j                  f      r{|d   j                  r5t        |d   j                  j                  t        j                                t        |d   j"                        }t        j                  j                  |      S t        |      dk(  r)t        |d   t$              r|d   }|j'                  |      S t)        |d   t        j*                        r5t        j                  j                  t        |d   j,                              S t)        |d   t        j.                        r5t        j                  j                  t        |d   j"                              S t)        |d   t        j0                        r5t        j                  j                  t        |d   j2                              S t5        dt7        |      d| dgt8        j:                         y )Nr   r2   zid() with unsupported argsz5Dynamo doesn't know how to trace id() call with args zkSupported args are Tensors, and functions/nn.Modules/user-defined objects from outside the compiled region.r  )rq   r_   r   r   r   r  r  r7   r  idr   rK   rT   r   rU   r   ID_MATCHrX   rI   call_idr-   r   rQ   SkipFunctionVariablero  
fake_valuer   rx   r   r  )r   r   r`  nn_mod_variabler   constant_resulttensor_variables          rY   r;  zBuiltinVariable.call_id.	  s   t9q=ZQ1K1KL"1gO))))/*D*DEC--44RW==Y!^
G//1T1TU!
 Aw~~d1gnn778M8MNO a/O--44_EEY!^
47N C"1gO"**2..DGY;;<--44RQ

^DDDGY;;<--44RQ5FGGDGY??@--44RQ8J8J5KLL4D	STXSYZ8 '22		r[   c                 L    t        dd| dddgt        j                         y )Nzcopy.deepcopy()zcopy.deepcopy(rM  z'Dynamo does not support copy.deepcopy()zAvoid calling copy.deepcopy()r  )r   r   r  )r   r   re   s      rY   call_deepcopyzBuiltinVariable.call_deepcopyP	  s2    %$QCq)A/"..		
r[   c                    ddl m} ddlm} | j                  }|t
        j                  t
        j                  fv rt        |t              xrk t        |t              xrY t        t        |j                         j                              t        t        |j                         j                              k(  }|t
        j                  u rt        j                  |      S t        j                  |       S ||vrEt!        d|j"                   d| d| dd|j"                   d	| d| g t$        j&                  
       t        |t              rnt        |t              r^|j(                  xr |j(                  D|j(                  |j(                  k7  r+	 t+        j,                  |j(                  |j(                         t        |t              r|n|}|j2                  j5                  d||j                         |j                         fi       }	 |t7        |      ||	      S # t.        $ rI t!        d|j"                   d| d| dd| d| d|j"                   dg t$        j0                  
       Y w xY w)Nr2   r&  %supported_tensor_comparison_op_valuesz unsupported Tensor comparison oprL  r  rM  *Dynamo does not support the comparison op z with Tensor arguments r  z8failed to broadcast when attempting Tensor comparison opz.Dynamo was unable to broad cast the arguments z, when attempting to trace the comparison op .r   )r   r  r   rE  rQ   r{   r  is_notr_   rI   r9  r(   rT  r  r7   r  r   r  r   r  sizer/  broadcast_shapesRuntimeErrorr  r   r   r`   )
r   r   r  r  r  rE  r
  	is_result
tensor_clsr  s
             rY   r&  z'BuiltinVariable._comparison_with_tensor[	  s9   .AWW(,,0040 Iun5I1$--/2F2FGH01A1F1FGHI  X\\!'..y99'..9}==:::;;-qbq9H V))-b96)556 t^,5.1)uzz6		UZZ'
&&tyy%**= (n=T5
		&&R$--/5>>3C!Db
 !
 	
    V!{{m1TF"UG1="PQUPVVXY^X_ `BBD++a!Q9-889s   *H AI10I1c           
         ddl m} | j                  }||vrEt        d|j                   d| d| dd|j                   d| d| g t
        j                  	       t        |t        j                        r$t        j                   |t               d             S |j                  j                  d
||j                         |j                         fi       }t        j                   ||d       S )Nr2   rD  z!unsupported SymNode comparison oprL  r  rM  rF  z with SymNode arguments r  r   r0  )r   rE  rQ   r   r  r   r  r_   r   r   r7   r%  r   r   rT  rH   r  )r   r   r  r  rE  r
  r  s          rY   r"  z(BuiltinVariable._comparison_with_symnode	  s    AWW::;;;-qbq9H V**.r%:6)556 eY??@--b4.@AA		&&R$--/5>>3C!Db
 %%
 	
r[   c           
         t        |t              rt        |t              ry t        |t        t        f      rdt        |t        t        f      rNt        j                  | |j                  j
                  dt        j                  gt        ||gi        d       S t        |d      r8t        |d      r+t        t        |j                  |j                  z              S y y )Nr   r0  r  )r_   r7   rH   r  r   r   r{   r   r/   r  r?   r  r  r  s       rY   	call_and_zBuiltinVariable.call_and_	  s    a)*z!=M/Na/+;<=*!12C
 #))&		&&#X]]5F1vr5R   1k"wq+'>tAKK!++$=>?? (?"r[   c           
         t        |t              rt        |t              ry t        |t        t        f      rdt        |t        t        f      rNt        j                  | |j                  j
                  dt        j                  gt        ||gi        d       S t        |d      r7t        |d      r+t        t        |j                  |j                  z              S t        |t              r|j                  |d|gi       S y )Nr   r0  r  __or__)r`  rI  )r_   r7   rH   r  r   r   r{   r   r/   r  r?   r  r  r:   r   r  s       rY   call_or_zBuiltinVariable.call_or_	  s    a)*z!=M/Na/+;<=*!12C
 #))&		&&#X\\4Eq!fb4Q   1k"wq+'>tAKK!++$=>??a*+==XQC=CCr[   c           
      x   t        |t              rMt        j                  | |j                  j                  dt
        j                  gt        |gi        d       S t        |t              r|j                  }t        |t        t        f      r+t        j                  t        |j                        dk(        S y )Nr   r0  r   )r_   rH   r  r   r   r{   r~   r/   r<   dv_dictrB   r:   r7   rq   r   r1  s      rY   	call_not_zBuiltinVariable.call_not_	  s    a)"))&		&&#X]]5FsB5O   a)*		Aa,(9:;#**3qww<1+<==r[   r   r   c                 ,    |j                  |d|gi       S )N__contains__r   r  s       rY   call_containszBuiltinVariable.call_contains	  s     }}R!b99r[   )r   N)r\  rM   r!  )r`  zlist[VariableTracker]rI  r  r   r5   )r   rN   rf  r5   r^   )ir  rX  __qualname____doc__r%  	_SENTINELr5   _nonvar_fieldsclassmethodrZ   staticmethodr"  cacher   r   r   r  r   r  r  rx   r   r8  rB  rD  rH  rO  r  rT  r]  ra  rg  rk  rs  rw  ry  r`   rj   r  r  r  r   __annotations__r   r   r  call_int
call_floatr  r  r  r  r  call_mincall_maxr>  rC  rF  rJ  rQ  rO  rW  rY  rd  rf  ri  rm  
call_tuple	call_listrp  rr  rv  rt  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r'  r*  r.  r2  r7  r;  rB  r&  r"  rP  	call_iandrS  call_iorrV  rY  __classcell__)r  s   @rY   rP   rP      s    I		'	'N
 ) ) __?  ?B: __*  *X __#TfuT#Yf0E%EFF #  #J __J  JX 	 	54# 4"J13 
 



 H T$Z H T H  H TMr 	  fck')S/)*
 	
	
" 
)#) ()) -	)
 
)(Y; &	Y;
 -Y; 
Y;v* H JC$5Bn4Ya+F HH44A<	

-
 04,),\

H "J I<:	
K 
 
 +
#+
 +
Z"
H
4

EHd6LO(-3 / 2QS \K#\K \K "	\K|R-#R- R- "	R-
 R-hB#B B "	B:3 :/ :02 7 2o 2
#  "	"R
 D	
3
j
6@$ I, H$:):.=:BQ:r[   rP   c              #      K   ddl m} |j                  | d      }	 |j                  |        d  |j	                  |        y # |j	                  |        w xY ww)Nr2   )GradModeVariableF)r  rl  r  enterexit)r   rl  gmvs      rY   r  r  	  sD     "

!
!"e
,C		"s   AA AAA)r[  
contextlibr"  r  ro  loggingra   r{   r  r  typingr  collectionsr   r   collections.abcr   r   r   r   r	   r/  r
   r   torch._subclasses.meta_utilsr   torch.utils._python_dispatchr   r  r   r   r   r   r  r   r   r   r   r   r   r   guardsr   r   replay_recordr   rT   r   r   r   r    r!   utilsr"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   baser3   r4   r5   constantr7   ctx_managerr8   r9   dictsr:   r;   r<   r=   r>   r?   listsr@   rA   rB   rC   rD   rE   r   rF   rG   rH   rI   rJ   r0  rK   rL   torch._dynamo.codegenrM   torch._dynamo.symbolic_convertrN   	getLoggerr  r  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ru   r   r   r   r   r   r   r  Any_HandlerCallbackr`   r  _TrackersTyper   cmp_eqr   cmp_ner   cmp_ltr   cmp_ler   cmp_gtr   cmp_ger  rP   contextmanagerr  rF  r[   rY   <module>r     sm  *        
    0 . 1 1  $ 6 F > >   1 '     $ Y X & 6    I /Dg! MM8<<MM8<<MM8<<))x''MM8<<h&&hoohooMM8<<MM8==LL(,,MM8<< " fjj&**5F  d?+U43H#3M-NNOKK!!KK!!KK!!KK!!KK!!KK!! W%:o W%:tJ  r[   