
    8hX                       % S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SKJ	r	J
r
  S SKJrJrJrJr  S SKrS SKrS SKrS SKJs  Jr  S SKJr  S SKJrJr  S SKJrJr  S SKJ r J!r!J"r"J#r#J$r$J%r%J&r&J'r'  S SK(J)r)  S S	K*J+r+J,r,  S S
K-J.r.J/r/J0r0J1r1J2r2J3r3J4r4J5r5  S SK6J7r7  S SK8J9r9  S SK:J;r;J<r<  S SK=J>r>  S SK?J@r@  S SKAJBrB  S SKCJDrDJErE  S SKFJGrGJHrH  S SKIJJrJJKrKJLrL  S SKMJNrN  S SKOJPrP  S SKQJRrR  S SKSJTrT  S SKUJVrV  S SKWJXrXJYrYJZrZJ[r[J\r\  S SK]J^r^  S SK_J`r`  S SKaJbrbJcrcJdrdJere  S SKfJgrgJhrhJiriJjrj  S SKkJlrlJmrm  S SKJnrn  S S KoJprp  S!S"KqJrrr  S!S#KsJtrt  S!S$KuJvrvJwrwJxrxJyryJzrz  S!S%K{J|r|J}r}  \R                  " \5      r\ GR                   " S& S'5      5       r\ GR                   " S( S)5      5       r\ GR                  " S*S+9 " S, S-5      5       r\" 5       r\GR                  \GR                  \GR                  \GR                  \GR                  \GR                   \GR                  \\GR                  1	\l        \	S. 5       r\	S/ 5       rS0 rS1 rS2 rS3\GR(                  GR*                  4S4 jrSS5\4S6 jjrS7 rS8 rS9 rS: rS;\GR8                  GR:                  S<\GR8                  GR:                  S=\\\4   4S> jrS3\GR(                  GR*                  S?\}S@\\\GRB                  4   SA\\\`4   SB\\   4
SC jrSD\,SE\}SA\\\`4   S=S4SF jrS3\GR(                  GR*                  S=S4SG jrS*SH.S3\GR(                  GR*                  S=\4SI jjrS3\GR(                  GR*                  SE\}S=S4SJ jrS;\GR8                  GR:                  S<\GR(                  GR*                  S=S4SK jrSL\GR8                  GR:                  S=\\\4   4SM jr SSN\nSO\nSP\\\z4   SQ\\\      S=\\y   4
SR jjr  SSSSTSTS*S*S*SU.SV\SW\\SX4   SY\\\\4      SZ\\\\\4   \\   \\   4      S[\\SX4   S\\S]\S^\S_\S`\S=\GR(                  GR*                  4Sa jjjr SSb STSS*STS*STSc.SL\GR8                  GR:                  Sd\,Se\Sf\Sg\Sh\S=\4Si jjjr SSL\GR8                  GR:                  SW\\SX4   SY\\\\4      S=\\   4Sj jjrSL\GR8                  GR:                  S=\\   4Sk jrSl\\GRB                     Sm\\\GRB                  4   SE\}SA\\\`4   S=S4
Sn jrSo\GR8                  GR:                  SE\}SA\\\`4   S=S4Sp jrSq\GR(                  GR*                  S=S4Sr jrSq\GR(                  GR*                  S=S4Ss jrS3\GR(                  GR*                  S?\}S=S4St jrSu\wS=\\\4   4Sv jrSq\\\      \Sw'   Sq\\\\4      \Sx'   Sy rSz rSL\GR8                  GR:                  S=\\\4   4S{ jrS| r SS}\S[\\SX4   S~\SQ\\\      S=\\GR(                  GR*                  \\y   4   4
S jjr SSL\GR8                  GR:                  S}\4S jjrS\R4S jr\	S\GR8                  GR:                  4S j5       r\	S 5       rSS jrSL\GR8                  GR:                  SW\\SX4   SY\\\4   SZ\\\\\4   \\   \\   4      S[\\SX4   S\nS]\Sf\S\S=\4S jrSS 4SL\GR8                  GR:                  Sd\,S=\4S jjrS rS3\GR(                  GR*                  S\S=\GR(                  GR                  4S jrSL\GR8                  GR:                  SW\\SX4   SY\\\4   SZ\\\\\4   \\   \\   4      S[\\SX4   S\nS]\Sf\S\S=\4S jr\\v  SS*SSS.SL\GR8                  GR:                  SW\\SX4   SY\\\\4      SZ\\\\\4   \\   \\   4      S\S[\\SX4   S=\w4S jjj5       5       r\\v  SS*SSSTSTSTS.SL\GR8                  GR:                  SW\\SX4   SY\\\\4      SZ\\\\\4   \\   \\   4      S\S[\\SX4   S\S]\Sf\S=\w4S jjj5       5       rg)    N)contextmanagernullcontext)AnyCallableOptionalUnion)enable_python_dispatcher)	UserErrorUserErrorType)exportdb_error_messageget_class_if_classified_error)_fakify_module_inputs_fakify_script_objects_gather_constant_attrs_NonStrictTorchFunctionHandler_override_builtin_opsmake_constraintsmake_fake_inputs$produce_guards_and_solve_constraints)CollectTracepointsPass)_materialize_and_lift_constantsConstantAttrMap)_collect_param_buffer_metadata_compiling_state_context_fakify_params_buffers)_populate_param_buffer_metadata_to_new_gm_update_gm_meta_if_possibleapply_runtime_assertion_passplaceholder_naming_passplaceholder_prefixes)SpecViolationError)_wrap_submodules)_graph_input_names_graph_output_names)GraphSignature)get_subclass_typing_container)create_functional_call)create_tree_flattened_fnregister_buffer_assignment_hook)_detect_attribute_assignmentaot_export_module)detect_fake_modetracingTracingContext)FakeScriptObject)dtrace_structured)FakeTensorMode)log_export_usage)!_check_input_constraints_pre_hook)_check_dynamic_shapes_combine_args_DimHintType_IntWrapper_process_dynamic_shapes)
OutputKind)_ConstantAttributeType)get_proxy_slotmake_fxPreDispatchTorchFunctionModetrack_tensor_tree)ConstraintViolationErrorfree_unbacked_symbolsGuardOnDataDependentSymNodeShapeEnv)_PyTreeCodeGen_PyTreeInfo)TreeSpec)ValueRangeError   )AutogradStateOpsFailSafeguard)_WrapperModule)_disable_prexisiting_fake_modeExportedProgram	InputKindModuleCallEntryModuleCallSignature)"_convert_to_export_graph_signatureExportGraphSignaturec                       \ rS rSr% SrSr\\S'   \R                  " \
S9r\
\   \S'   Sr\\S'   Sr\\S'   Sr\\S	'   S
r\\S'   S
r\\S'   Sr\\S'   Sr\\S'   S
r\\S'   Srg)ExportDynamoConfigr   z2
Manage Export-specific configurations of Dynamo.
T	allow_rnn)default_factoryreorderable_logging_functionsdo_not_emit_runtime_assertsspecialize_intspecialize_floatFassume_static_by_defaultautomatic_dynamic_shapes capture_dynamic_output_shape_opscapture_scalar_outputs+prefer_deferred_runtime_asserts_over_guards N)__name__
__module____qualname____firstlineno____doc__rT   bool__annotations__dataclassesfieldsetrV   r   rW   rX   rY   rZ   r[   r\   r]   r^   __static_attributes__r_       M/var/www/fran/franai/venv/lib/python3.13/site-packages/torch/export/_trace.pyrR   rR   r   s     It3>3D3D4!3x=  )-,ND!d!%*d*%*d*-1$d1#'D'8=/=rk   rR   c                   f    \ rS rSr% \R
                  R                  \S'   \\S'   \	\
\4   \S'   Srg)ATenExportArtifact   gmsig	constantsr_   N)r`   ra   rb   rc   torchfxGraphModulerf   rP   dictstrr:   rj   r_   rk   rl   rn   rn      s)    	C//00rk   rn   T)frozenc                   p    \ rS rSr% \\S'   \\S'   \\S'   \\S'   \\	\\	\
R                  4   4   \S'   Srg)	ExportArtifact   atenin_specout_spec	fake_modemodule_call_specsr_   N)r`   ra   rb   rc   rn   rf   rE   r1   rv   rw   pytreerj   r_   rk   rl   rz   rz      s8    
Cc6??&:!;;<<rk   rz   c               #     #    [         R                  R                  R                  S5      n [         R                  R                  R                  S5      n S v   [         R                  R                  R                  " U 6   [         R                  R                  R                  " U6   g ! [         R                  R                  R                  " U 6   [         R                  R                  R                  " U6   f = f7fNF)rs   backendsmkldnn	set_flagsnnpack)orig_mkldnn_flagorig_nnpack_flags     rl   _ignore_backend_decompsr      s     ~~,,66u=~~,,66u=;'')9:'')9: 	'')9:'')9:s    AC<B) AC<)AC99C<c               #   f  #    [         R                  R                  R                  n  S[         R                  R                  l        [         R                  R                  R                  v   U [         R                  R                  l        g ! U [         R                  R                  l        f = f7fr   rs   
_functorchconfigdecompose_custom_triton_ops)olds    rl   2_disable_custom_triton_op_functional_decompositionr      sv     



!
!
=
=CB>C;%%AAA>A;c;s   %B1AB - B1!B..B1c                  T    [         R                  R                  R                  (       + $ Nr   r_   rk   rl   (custom_triton_ops_decomposition_disabledr      s    &&BBBBrk   c                     S[        U 5      -   $ )N	L__self__)_strip_rootxs    rl   
_fixup_keyr      s    Q''rk   c                     [        U [        5      (       a5  U R                  S5      (       a  U [        S5      S  nUR	                  S5      $ U $ )N_export_root.)
isinstancerw   
startswithlenremoveprefix)r   strippeds     rl   r   r      sE    !Sall>::S(*+$$S))Hrk   rp   c           
         U R                   R                   GH  nUR                  [        R                  R
                  R                  :X  d  M8  SUR                  ;   d  MJ  [        UR                  S   5      nU R                   R                  U5         U R                   R                  S[        R                  R
                  R                  UR                  UUR                  S   S.S9nUR                  Ul        UR                  U5        U R                   R                  U5        SSS5        GM     g! , (       d  f       GM1  = f)z
In-place modifiy input graph module by replacing the export tracepoint with a new node
that has the same target and args, but with the _export_root stripped from path.
pathcall_functionkind)r   r   )argskwargsN)graphnodestargetrs   opshigher_order_export_tracepointr   r   inserting_beforecreate_noder   metareplace_all_uses_with
erase_node)rp   noder   new_nodes       rl   _rewrite_tracepoint_noder      s    
 ;;%))00CCC$"4;;v#67XX..t4!xx33'		..AA!YY$($(KK$7 	  4  H %)IIHM..x8HH''- 54	  54s   BD88
E	inputsc                    / n[        U 5       HN  u  p#[        U[        R                  5      (       d  M&  UR	                  UR
                  R                  SU45        MP     U(       a\  US   u  pEnUSS   HI  u  pxn	XGL a  M   SU SU SU SU SU SU	 SU SU S	UR                   S
U SU	 S	UR                   35       e   U$ g )Nzsymint inputr   rG   zshape env (z) from  z doesn't match mode (z

shape env from z allocated at:
z
shape env from )	enumerater   rs   SymIntappendr   	shape_envstack)
r   
shape_envsi
flat_inputr   desc1i1mdesc2i2s
             rl   detect_shape_envr      s    J"6*j%,,//z88.!LM + )!}	"&qrNLAb> i[wat;PQRPSSZ[`Zaabcebf g""'"-=ioo=N O""'"-=aggYH> + rk   c                 R  ^^ / m/ nU R                   R                   Hi  nUR                  S:X  a,  TR                  UR                  R                  S5      5        M?  UR                  UR                  R                  S5      5        Mk     [        TU-   5      n[        TU-   5      nU(       a  U(       a  XeR                  L d   S5       eUnO$U(       a  [        USS9nO[        [        5       SS9nSmUU4S jn[        R                  " X5      n	[        R                  " X5      n
XU4$ )	z
Given a graph module, extract fakified input tensors from the metadata of
its placeholders, and map them to the structure of given args and kwargs.
Also return the fake mode used to fakify those inputs.
placeholdervalexample_valuez7Detected shape env does not match fake mode's shape envT)r   exportr   c                 j   > [        U [        [        R                  45      (       a  TT   OU nTS-  mU$ )NrG   )r   intrs   Tensor)r   r   count	fake_inpss     rl   lookup_fake)_extract_fake_inputs.<locals>.lookup_fake  s2    ",Qell0C"D"Di!

rk   )r   r   opr   r   getr,   r   r   r1   rB   r   tree_map)rp   r   r   	fake_valsr   detected_fake_modedetected_shape_envr   r   	fake_argsfake_kwargsr   r   s              @@rl   _extract_fake_inputsr      s     II77m#TYY]]512TYY]]?;<	  *)i*?@))i*?@%)E)EE IE '		"-?M	"XZE	E 2I//+6K9,,rk   c                 \   UR                    HF  nUR                  [        R                  [        R                  4;   d  M3  XR
                     Ul        MH     UR                   HF  nUR                  [        R                  [        R                  4;   d  M3  XR
                     Ul        MH     g r   )
input_specsr   rL   	PARAMETERBUFFERr   output_specsr9   BUFFER_MUTATIONGRADIENT_TO_PARAMETER)param_buffer_tablerq   specs      rl   _replace_param_buffer_namesr   &  s    99
 
 -[[9DK     99&&,,
 
 -[[9DK !rk   c           	          [        U 5      [        U5      [        U5      -   :X  d,   S[        U 5       S[        U5       S[        U5       S35       eU [        U5      S   Vs/ s H  o2U   PM	     nn/ UQUQ7$ s  snf )Nz,Total number of arg names is expected to be z	 but got z positional args, z kwargs.)r   )orig_arg_namesr   r   kw_namereordered_kwargss        rl   _convert_to_positional_argsr   5  s    ~#d)c&k"99 
6s>7J6K Lt9+/F}H	F9 8Fc$ik7RS7RGw7RS		  Ts   !A8c                 h   Sn[         R                  " SSU5      nU R                  5        GH|  n[        U[        R
                  R                  5      (       d  M/  UR                  R                   GH2  nUR                  S;   a  M  SnUR                  R                  S0 5      =n(       a  [        [        UR                  5       5      5      u  p[        R                   " U	5      (       a5  [#        U	[        R$                  R&                  5      (       a  X:X  a  XL a  SnO[        U	[(        5      (       d   eU(       d  M  S n
X2UR*                  S	-   UR,                  -   40UEnUR/                  5        VVV	s0 s H  u  nu  pX" U5      U	4_M     sn	nnUR                  S'   GM5     GM     g s  sn	nnf )
Nz	L['self']z[^a-zA-Z0-9]_r   outputTnn_module_stackFc                    ^  / m " U4S jS5      n[        U SSU" 5       005        SR                  T5      $ ! [         a    U s $ f = f)Nc                   .   > \ rS rSrU 4S jrU 4S jrSrg)@_normalize_nn_module_stack.<locals>.normalize_path.<locals>.Pathi\  c                 6   > US:w  a  TR                  U5        U $ )N_modules)r   )selfnamepartss     rl   __getattr__L_normalize_nn_module_stack.<locals>.normalize_path.<locals>.Path.__getattr__]  s    #':#5$)LL$6'+rk   c                 <   > TR                  [        U5      5        U $ r   )r   rw   )r   idxr   s     rl   __getitem__L_normalize_nn_module_stack.<locals>.normalize_path.<locals>.Path.__getitem__b  s     %SX 6'+rk   r_   N)r`   ra   rb   rc   r   r   rj   )r   s   rl   Pathr   \  s    ,
, ,rk   r   Lr   r   )evaljoin	Exception)r   r   r   s     @rl   normalize_path2_normalize_nn_module_stack.<locals>.normalize_pathX  sQ    $ ", , TC&$&)9#:;"xx.$ $#$s   48 AAr   )resubmodulesr   rs   rt   ru   r   r   r   r   r   nextitervaluesinspectisclass
issubclassnnModulerw   ra   rb   items)gm_torch_levelroot_clsrootroot_keyrp   r   add_rootr   r   tyr  keys               rl   _normalize_nn_module_stackr  A  sp   DvvosD1H$$&"ehh2233HHNNDww33H"&))--0A2"FFF_%;%;%= >? ??2&&:b%((//+J+J|#(%b#....x$( X%8%83%>AVAV%VW#%# ,;+@+@+B0+BZd ..33+B0		+,O # 'T0s   7F-original_moduletraced_modulereturnc                    0 n0 nU R                  SS9 H  u  pEXB[        U5      '   M     U R                  SS9 H  u  pFXC[        U5      '   M     0 nUR                  SS9 H-  u  pX;  d   e[        U	5      U;   d  M  U[        U	5         Xx'   M/     UR                  SS9 H-  u  pX;  d   e[        U
5      U;   d  M  U[        U
5         Xx'   M/     U$ )z
Returns a mapping of parameter/buffer names from the new module to the
original model. This is to help with restoring the FQN for parameter/buffers
of a traced module to what the original module contains.
Fremove_duplicate)named_parametersidnamed_buffers)r  r  param_lookupbuffer_lookupr   parambufferr   dynamo_namedynamo_paramdynamo_buffers              rl   _get_param_buffer_mappingr*  u  s    $&L$&M&777O"&RY P'55u5M$(bj! N *,%2%C%C &D &! 444l|+.:2l;K.L+& '4&A&A 'B '" 444m-.;B}<M.N+' rk   rq   fake_params_buffersrr   flat_fake_argsc                    U R                   R                   Vs/ s H  oUR                  S:X  d  M  UPM     nn[        UR                  5      [        U5      :X  d   eSn[        XaR                  5       GH  u  pXUR                  [        R                  [        R                  4;   a<  UR                  c   eUUR                     R                  UR                  S   l        Mp  UR                  [        R                  :X  aH  XG   n	[        U	[        R                   5      (       a  U	R                  UR                  S   l        US-  nM  UR                  [        R"                  :X  a  UR                  c   eX8R                     n
[        U
[        R                   5      (       ak  UR                  S   R$                  (       a!  U
R                  UR                  S   l        GMo  UR                  S   R                  U
R                  :X  d   eGM  GM  UR                  [        R&                  [        R(                  4;   a  GM  [+        UR                  5      e   g s  snf )Nr   r   r   rG   )r   r   r   r   r   zipr   rL   r   r   r   requires_gradr   
USER_INPUTr   rs   r   CONSTANT_TENSORis_leaf
CUSTOM_OBJTOKENAssertionError)rp   rq   r+  rr   r,  r   placeholdersr   r   fake_argconstants              rl   _preserve_requires_grad_passr9    s    &(XX^^P^Tww-7OD^LPs3|#4444	A,8
99
 
 ;;***-@.m IIe* YY)...%(H(ELL11191G1G		% .FAYY)333;;*** -H(ELL1199U#++5=5K5KDIIe$299U+99X=S=SSSS 2 YY9//AA ++5 9 Qs
   IIorig_constant_attrsgraph_signaturec                 Z   0 nUR                  5        H  u  pEXP;   d  M  X   X4'   M     UR                   Hs  nUR                  [        R                  [        R
                  4;   d  M3  UR                  nUc   eUR                  Xw/5      nUS   Ul        X'   n	X'	 U H  n
XU
'   M	     Mu     g)zXRewrite the graph signature and constants table to use the FQN from the original module.Nr   )r  r   r   rL   r1  r3  r   r   )r:  r;  rr   remap_tabler   valuer   orig_targettargetsr8  r   s              rl   _remap_constantsrA    s     )+K (' 3 :K )  ++99%%  
 
 ++K***!ook=AG!!*DK -H&!$,&! " ,rk   c           	         SSK Jn  SSKJn  SSKJnJn  U" U 5      =nc  gUR                   Vs1 s H;  nU" XdR                  UR                  45      (       d  M(  XeR                  ;  d  M9  UiM=     nnU R                  R                   H`  nUR                  R                  SS5        UR                  R                  S5      =n	c  M?  U" U	SUUS	S
9=n
(       d  MR  XR                  S'   Mb     gs  snf )a  
When we run an interpreter-based pass over a GraphModule, execution of data-dependent operators
will produce example values with new unbacked symbols. To track that the new/old symbols are equivalent,
we used to rely on the unbacked_renamings mapping. This led to problematic metadata where the unbacked_bindings
keys mapped new symbols (u2) to paths containing old symbols (u0) in the example values, or worse, backed symbols
or constants (e.g. if the original unbacked was replaced/specialized). Additionally this created problems with
de/serialized programs, since we didn't comprehensively serialize ShapeEnv/unbacked renamings/node bindings.

This pass attempts a simpler way of handling these for export, by throwing away the previously computed bindings, and re-running
the pattern match used in compute_unbacked_bindings. This ensures we keep the original symbols contained in the example values,
or delete bindings if they've been replaced/specialized.
r   )_get_shape_env_from_gm) _free_unbacked_symbols_with_path)symbol_is_typeSymTNunbacked_bindingsr   r_   T)r   pendingsimplify)torch._export.utilsrC  %torch.fx.experimental.symbolic_shapesrD  torch.utils._sympy.symbolrE  rF  var_to_rangeUNBACKED_INTUNBACKED_FLOATunbacked_renamingsr   r   r   popr   )rp   rC  rD  rE  rF  r   symbolbase_unbacked_symbolsr   r   rG  s              rl   _replace_unbacked_bindingsrT    s     ;V>+B//	8  ,,,F&#4#4d6I6I"JK 	 666 	,   		)4099==''C4!A#-"   .?II)* s   'C.C.+C.)_prettify_placeholder_namesc        	   	      J   [         R                  " XV45      n	[        X5      u  p[        U 5        [	        UR
                  5      [	        UR                  5      -   [	        UR                  5      -   n
[        X	U
5        [        X0[        U5      5      n[        XU5      nU(       a   SSKJn  SSKJn  U" X5      u  pU" X5      u  pU R!                  5        H  n[#        U[$        R&                  R(                  5      (       d  M.  UR*                  R,                   HM  nUR.                  S;   d  M  UR0                  R3                  SS5        UR0                  R3                  SS5        MO     M     Uc   eU(       a  [5        U UUUUUU5        [7        XX|U	5        [9        U UU5      $ )a  
This is a helper function that is shared between export_to_aten_ir and export_to_aten_ir_make_fx
to produce the aten artifact. (export compatible graph module + signature)

It does:
1. Applies runtime assertion pass
2. Recompute unbacked_bindings pass
3. Populate meta val when missing
4. Lift constants as placeholders
5. Replace raw autograd and autocast ops with HOPs
6. Prettify names for placeholders
7. Preserve requires_grad value on node meta val
r   )replace_autocast_with_hop_pass)replace_set_grad_with_hop_passr   r   Nstack_trace)r   tree_leavesr   rT  r   
parametersbuffersinput_tokensset_missing_meta_valsrO   _get_non_persistent_buffersr   3torch._export.passes.replace_autocast_with_hop_passrW  3torch._export.passes.replace_set_grad_with_hop_passrX  r  r   rs   rt   ru   r   r   r   r   rQ  r   r9  rn   )rp   modconstant_attrsr;  pre_dispatchr   r   r+  rU  r,  total_non_user_inputsexport_graph_signaturerr   rW  rX  _modr   s                    rl   _produce_aten_artifactrh    s   6 ''(@AN6rKB
 r" 	O&&'
o%%
&	'
o**
+	, 
 ".CD @8= 0
NI 	
	
 &D&
" &D&
"
 

$ 4 455JJ$$Dww33		/6		mT2 %  "---""	
 !
$7N 
 rk   c                   ^
 U R                   R                   Vs1 s H  o"R                  iM     snm
U
4S jn[        [        R
                     n[        [        R                     n0 nUR                   H  nUR                  [        R                  :X  d  M#  UR                  R                  R                  U5      (       a  MO  UR                  R                  R                  U5      (       a+  U" XWR                  R                  [        U5      S -   5      nOU" XWR                  R                  -   5      nXUR                  R                  '   XR                  l        M     UR                   HF  nUR                  R                  U;   d  M  XgR                  R                     UR                  l        MH     U R                  5        H  n	[        U	[        R                   R"                  5      (       d  M.  U	R                   R                   H/  nUR                  U;   d  M  XbR                     =Ul        Ul        M1     U	R'                  5         M     gs  snf )zT
For strict mode, rename constants nodes that were previously annotated as buffers.
c                    > U T;   a%  SnU  SU 3=nT;   a  US-  nU  SU 3=nT;   a  M  Un TR                  U 5        U $ )NrG   r   )add)r   ndup_name
node_namess      rl   rename_constant0_rename_constants_nodes.<locals>.rename_constantw  s_    :A"&q},8;Q #'q},8;Dtrk   N)r   r   r   r    rL   r   r1  r   r   argr   r   r   r  r   rs   rt   ru   r   	recompile)rp   r;  r   ro  buffer_prefixconst_prefixbuffer_to_constantr   c_namerb  rn  s             @rl   _rename_constants_nodesrw  m  s    )+7))7J ))9)9:M'	(A(ABL++99	111$((--:R:R;
 ;
 xx}}''66( 88==]1C1E#FF ))EF06txx}}-"HHM ,  ,,88==...xx}}=DHHM -
 zz|#uxx3344IIOODyy..*<YY*GG	DK $ 	 A 8s   Ic                 x   [        X5      nUR                  5        H  u  p4UR                  SS5      X#'   M     UR                  5        H  u  p4[        X5      (       d  M  [	        X5      n[        U[        R                  5      (       a;  [        U[        R                  R                  5      (       d  UR                  XE5        O[        XU5        [        X5        M     UR                  R                   H1  nUR                  S:X  d  M  UR                   nXr;   d  M(  X'   Ul        M3     UR#                  5         g)zN
Restores the state dict of the traced module to that of the original module.
r   r   get_attrN)r*  r  replacehasattrgetattrr   rs   r   r  	Parameterregister_buffersetattrdelattrr   r   r   r   rr  )r  r  r   r   fqnattrr   	attr_names           rl   _restore_state_dictr    s     3?R
 (--/	#&;;sC#8  0 (--/	}++}+dELL))*T588CUCU2V2V))#4M-$ 0 ##))77j I.0;	 * rk   rb  c                 ~    U R                  SS9 VVs0 s H  u  pU[        U5      R                  _M     snn$ s  snnf NFr  )named_modulestyper`   )rb  r   r   s      rl   _get_module_hierarchyr    sD    .1.?.?QV.?.W.W74d1g.W  s   "9r}   r~   module_call_signaturesforward_arg_namesc           	      >   [          Vs/ s H  n[        XBR                  U5      S9PM     nnUS   R                  S:X  d   e[	        / / U UUS9US   l        UR                  5        VVs/ s H  u  pFU[         ;  d  M  [        XFS9PM     nnn/ UQUQ$ s  snf s  snnf )N)r  	signaturer    r   outputsr}   r~   r  )_EXPORT_MODULE_HIERARCHYrM   r   r  rN   r  r  )r}   r~   r  r  r  originalr  
additionals           rl   _make_module_call_graphr    s     ,+C 	C+E+Ec+JK+   A;??b   /+HQK 5::<<NC.. 	6C5<  
 $X#
###s   "B*B>Br_   F)preserve_module_call_signaturedisable_constraint_solver'allow_complex_guards_as_runtime_assertsrestore_fqn_log_export_usagesame_signaturefr   .r   dynamic_shapesr  r  r  r  r  r  c                   U(       a  [        SS1S9  [        U[        5      (       d&  [        [        R
                  S[        U5       35      eU=(       d    0 n[        R                  " [        [        X45      u  p[        XU5      n
[        X5        [        X5      n[        R                  " [        S X45      u  p[        R                  R                   R#                  [$        R&                  " [(        5      5          0 n[+        5       n[        U [        R,                  R.                  5      (       d  [1        XU5      nU   [3        5          [        R                  R5                  U UUSSUSUUU	S9
" U0 UD6u  pS	S	S	5        S	S	S	5        S	S	S	5        WWRB                  S'   [        U [        RD                  RF                  5      (       a  U(       a  [I        X5        U$ ! , (       d  f       Nj= f! , (       d  f       Ns= f! [6        [8        4 a(  n[        [        R:                  [=        U5      5      eS	nAf[>         a*  n[        [        R@                  S
[=        U5       3SS9eS	nAff = f! , (       d  f       N= f)z
Traces either an nn.Module's forward function or just a callable with PyTorch
operations inside and produce a torch.fx.GraphModule in torch IR.
zexport.private_api_export_to_torch_ireventflagsAExpecting `args` to be a tuple of example positional inputs, got c                     U R                   b(  U R                   R                  [        R                  :X  a  U R                  $ U $ r   )dynamismr  r6   STATICr   )as    rl   <lambda>%_export_to_torch_ir.<locals>.<lambda>  s7    ::L4G4G!G %% rk   Tsymbolic)	r  constraintsrZ   tracing_moder  r^   r  r  r  Nz5Consider annotating your code using torch._check*(). constrain_as_size_example)	case_namer   )%r2   r   tupler
   r   INVALID_INPUTr  r   tree_map_onlyr   r7   r5   r4   r8   rs   _dynamor   patchrg   asdictDEFAULT_EXPORT_DYNAMO_CONFIGr   rt   ru   r"   r   r   r?   rF   CONSTRAINT_VIOLATIONrw   rA   ANTI_PATTERNr   r  r  r  )r  r   r   r  r  r  r  r  r  r  combined_argsr  r   ctxr  r   es                    rl   r  r    s*   $ 3<Q;RSdE""''OPTUYPZ|\
 	

 \rF ''[4.ILD!!62M-8)-HK ''	 
LD 
			#	#K$6$67S$T	U 	GI-Ca!5!566&7H -/$)MM$8$8#1 +-1!+.G AE<c&7#1 %9 % % %! 0 
VF 0AN+,!UXX__%%+A.A 0/$ )/: 	HM>>AGG* 	**GAxP5 	9 
V	Uss   ?I1AHG3/G">G3H"
G0,G33
H	=H I1HI.#H77I.%I))I..I11
I?c                     U $ r   r_   r   s    rl   r  r  G      rk   )	transformrd  decomp_table_check_autograd_state_is_torch_jit_tracerU  r   rc  r  r  rU  r   c                ^   [         R                  R                  5       n[        5       nU	(       a  U(       d  U(       a
  [	        5       nU(       a  [        O[
        n[         R                  R                  R                  R                  U USSSS9   U   [        5          [        5          U" 5          U" [        5      " U USUUUS9u  nnS S S 5        S S S 5        S S S 5        S S S 5        S S S 5        S nU" U W5        U(       a	   U" U5        ['        UU UWUUUUUS9	$ ! , (       d  f       N[= f! , (       d  f       Nd= f! , (       d  f       Nm= f! , (       d  f       Nv= f! , (       d  f       N= f! [        [        4 a(  n[        [         R"                  [%        U5      5      eS nAff = f)NTtie_weightsstrictstack_weightsF)trace_jointrd  decompositionsr   c                    [        U [        R                  R                  5      (       a  [	        U S5      (       a%  UR
                  R                  U R
                  5        [        U R                  R                  5      S   n[        UR                  R                  5      S   nUR                  S:X  a  UR                  S:X  d   e[        UR
                  5      S:X  d   eUR
                  R                  UR
                  5        g g )Nr   r   r   )r   rs   rt   ru   r{  r   updatelistr   r   r   r   )old_gmnew_gmold_output_nodenew_output_nodes       rl   $_maybe_fixup_gm_and_output_node_meta@_export_to_aten_ir.<locals>._maybe_fixup_gm_and_output_node_metay  s    fehh2233vv&&""6;;/"6<<#5#56r:O"6<<#5#56r:O"%%1o6H6HH6TTT++,111  ''(<(<= 4rk   )	rp   rb  rc  r;  rd  r   r   r+  rU  )rs   _Cis_grad_enabledr   rH   r   r  utils	stateless_reparametrize_moduler   r   r+   r?   rF   r
   r   r  rw   rh  )rb  r   r   r+  rc  produce_guards_callbackr  rd  r  r  r  rU  r   r  grad_safe_guard#custom_triton_ops_decomposition_ctxrp   r;  r  r  s                       rl   _export_to_aten_irr  ?  sw   & hh..0O!mO ;=O ' 	? ( 	  66 	7 	
 	! "+-'(9:%'
O 	. 	# 	" 		
*	> )b1 	H#B' "%'!/$?
 
O 	.- 	#" 	"! 		
 	
\ )/: 	HM>>AGG	Hs   E#EE)D0	1D
D0	EE"E#E4 
D-)D0	0
D>:E
EE
E 	E##
E14F,#F''F,c           
      4   [         R                  " U R                  5      nUR                  " U6 R                  n/ nUR                  5        H  u  pgUR                  U   R                  [         R                  R                  :X  a6  UR                  [        U5       VV	s/ s H  u  pU SU 3PM     sn	n5        Mp  UR                  U5        M     U(       a4  UR                  UR                  5        V
V	s/ s H  u  pU
PM	     sn	n
5        U$ s  sn	nf s  sn	n
f )a  
Gets the argument names to forward that are used, for restoring the
original signature when unlifting the exported program module.
- Positional args: retain the original argument names, and enumerate
    *args as args_0, args_1, ...
- Keyword args: retain the original kwarg names in the order specified
    by the user. This order seems to matter for the current state of
    export lifted modules.
r   )r  r  forwardbind_partial	argumentsr  r[  r   _ParameterKindVAR_POSITIONALextendr   r   )rb  r   r   rq   _argsnamesr   r>  r   r   kwargs              rl   _get_forward_arg_namesr    s     

CKK
(Cd#--EE{{}>>$$$(>(>(M(MMLLIe4DE4DDATF!A3-4DEFLL % FLLN;NeN;<L F
 <s   D6D
c                    ^ [        5       nU R                  SS9 HO  u  mnT(       a'  UR                  U4S jUR                   5       5        M4  UR                  UR                  5        MQ     U$ )zG
Returns set of non-persistent buffers in a module and its submodules.
Fr  c              3   2   >#    U  H  nT S U 3v   M     g7f)r   Nr_   ).0br   s     rl   	<genexpr>._get_non_persistent_buffers.<locals>.<genexpr>  s     O1NATF!A3-1Ns   )ri   r  r  _non_persistent_buffers_set)rb  resultr   r   s      @rl   r_  r_    s\     uF$$e$<aMMO1N1NOOMM!778	 =
 Mrk   orig_mod_bufferstraced_mod_buffersc                     UR                    Hj  nUR                  [        R                  :X  d  M#  UR                  c   eXR                     nXP;  d  MG  [        R
                  Ul        XSUR                  '   Ml     g)zh
Dynamo erroneously marks tensor attributes on modules as buffers.
Rewrite them to be tensor constants.
N)r   r   rL   r   r   r1  )r  r  r;  rr   r   r>  s         rl    _rewrite_dynamo_tensor_constantsr    sc      ++99	(((;;***&{{3E, &55	).$++& ,rk   orig_modc                     UR                    H~  nUR                  [        R                  :X  d  M#  UR                  (       a  M6  UR
                  c   eUR
                  U;  d   eU R                  UR
                  5      X#R
                  '   M     g)z3
Moves non-persistent buffers to tensor constants.
N)r   r   rL   r   
persistentr   
get_buffer)r  r;  rr   r   s       rl   0_move_non_persistent_buffers_to_tensor_constantsr    sk      ++99	(((;;***;;i///%-%8%8%EIkk"	 ,rk   graph_modulec           
         [        U /[        U R                  5       5      -   5       GH6  u  p[        U[        R
                  R                  5      (       d  M1  UR                  R                   H  nUR                  S;   a  US:X  a  UR                  R                  SS5      =n c  [        SU SUR                   S35      e[        S UR                  5        5       5      (       d  [        SU SUR                   S	U 35      eM  M  UR                  S
;   d  M  UR                  R                  SS5      (       d  M  [        SU SUR                   S35      e   GM9     g)af  
Perform nn_module_stack checks on the graph.
Current constraints:
    For the top level graph:
    - populated for 'call_function', 'get_attr'
    - None for 'placeholder', 'output'
    For submodule graphs:
    - None for 'placeholder', output'

TODO(pianpwk): make this a consistent node-level check once nn_module_stack is populated for cond submodules.
r   ry  r   r   NNode 	 of type z$ is missing nn_module_stack metadatac              3      #    U  H\  u  p[        U[        5      =(       a>    [        U[        5      =(       a'    [        U5      S :H  =(       a    [	        S U 5       5      v   M^     g7f)   c              3   B   #    U  H  n[        U[        5      v   M     g 7fr   )r   rw   )r  r   s     rl   r  4_verify_nn_module_stack.<locals>.<genexpr>.<genexpr>  s     >Aq
1c 2 2As   N)r   rw   r  r   all)r  kvs      rl   r  *_verify_nn_module_stack.<locals>.<genexpr>  s]      
 %<DA	 #1c* ?&q%0?FaK?  >A>>? %<s   A$A&z[ has incorrect nn_module_stack metadata formatexpected Dict[str, Tuple[str, str]], but got r   z7 contains nn_module_stack metadata, this should be None)r   r  r  r   rs   rt   ru   r   r   r   r   r   r!   r  r  )r  r   rb  r   r   s        rl   _verify_nn_module_stackr    s]    \NT,2F2F2H-IIJ#uxx3344IIOODww776+/99==9JD+QQ 1#D6477);_`   
 %4$9$9$;   1#D6477) <LL[K\^  $ 5599==!2D99,vYtwwi7no - $ Krk   c           
         U /U R                  5       Q H  n[        U[        R                  R                  5      (       d  M.  U R
                  R                   H  nUR                  R                  SS5      nUR                  S;   a:  Ub5  [        U[        5      (       d  [        SU SUR                   SU 35      eMg  Mi  UR                  S;   d  M{  U(       d  M  [        SU SUR                   SU 35      e   M     g)	z
Perform stack trace checks on the graph.
Constraints:
    - None or non-empty str for 'call_function', 'get_attr'
    - None for 'placeholder', 'output'
rY  Nr  r  r  zP has invalid stack_trace metadata, expected a string or None but instead found: r   zA contains stack_trace metadata, expected None but instead found: )r  r   rs   rt   ru   r   r   r   r   r   rw   r!   )r  rb  r   rY  s       rl   _verify_stack_tracer    s     6|3356#uxx3344 &&,,D))--t<Kww77#+z+s/K/K,vYtwwi 8HHS}V  0L+
 55;,vYtwwi 8<<G=J  - 7rk   c           
      2   UR                    Vs0 s H#  o"R                  R                  UR                  _M%     nnU R	                  5        H  n[        U[        R                  R                  5      (       d  M.  UR                  R                   H|  nUR                  S:X  d  M  UR                  U;  a  M'  X5R                     n[        U   nUR                  R                  U5      (       a  M`  [        SUR                   SU SU 35      e   M     gs  snf )z
Performs a sanity check on the placeholder node names.
- User input nodes: no restrictions, should match the original forward() signature
- Params/buffers/constants/custom_obj/token nodes: should start with prefixes defined in <placeholder_prefixes>
r   zPlaceholder node name z does not follow spec for z, name should have prefix: N)r   rq  r   r   r  r   rs   rt   ru   r   r   r   r    r   r!   )rp   rq   r   name_to_kindrb  r   	node_kindprefixs           rl   _verify_placeholder_namesr
  8  s     :=IHHMM499,LIzz|#uxx3344IIOODww-'99L0(3	-i8yy++F33,0;UV_U``{  }C  |D  E  $  Js   *Depc                    Sn[        5       nU R                  R                  5        H  n[        U[        R
                  R                  5      (       d  M.  UR                  R                   H  nUR                  S:w  a  M  US-  n[        UR                  S5      (       d   e[        UR                  S5      (       d   eUR                  UR                  R                   SUR                  R                   35        M     M     XS.$ )Nr   r   rG   ra   r`   r   )op_countop_set)ri   r  r  r   rs   rt   ru   r   r   r   r{  r   rk  ra   r`   )r  r  r  r   r   s        rl   get_ep_statsr  P  s    HUF__$$&!UXX1122GGMMDww/)MH4;;55554;;
3333JJ$++0014;;3G3G2HIJ " ' !33rk   _EXPORT_FLAGSr  c                 F   ^  [         R                  " T 5      U 4S j5       nU$ )Nc                  `  >  [         R                   " 5       nT	" U 0 UD6n[         R                   " 5       n[        S	SXB-
  [        S.[        U5      D6   S qS qU$ ! [         a  n[        U5      nUR                  S-   UR                  -   n[        U5      nUb8  [        R                  [        U5      5        [        SU[        U5      [        S9  O[        SU[        U5      [        S9  [        US5      (       a"  [        UR                  [         R"                  S9  UeS nAff = f! S qS qf = f)
Nzexport.time)r  metricsr  r   zexport.error.classified)r  r  messager  zexport.error.unclassifiedpartial_fx_graph)filer_   )timer2   r  r  r  r  ra   rb   r   logerrorr   rw   r{  printr  sysstderrr  )
r   r   startr  endr  t
error_typer  fns
            rl   wrapper$_log_export_wrapper.<locals>.wrappere  s*   '	,IIKET$V$B))+C ## r"	D !M'+$	?  	QA+ann<J5a8I$		0;< 3#F'	 !5#F'	 q,--&&
 G5	8 !M'+$s%   AA 
D$$B;DD$$D' 'D-)	functoolswraps)r!  r"  s   ` rl   _log_export_wrapperr&  d  s&    __R+ +Z Nrk   c                     [        U [        [        [        45      (       d  U 4n OL[        U [        5      (       a  [        U 5      n O+[        U [        R
                  [        45      (       a  Uc  U 4n Uc  0 nX4$ r   )r   r  r  rv   rs   r   )example_inputsexample_kwarg_inputss     rl   $_process_jit_trace_inputs_for_exportr*    sp    nudD&9::(*	ND	)	)~. 	>ELL$#788 ((*#!//rk   c                     [        U R                  SS95      n[        U R                  SS95      nX-  n[        U 5      nU H  nUR	                  US 5        M     U$ r  )rv   r   r"  r_  rQ  )rb  r   r"  original_state_dictnon_persistent_buffersr   s         rl   _get_original_state_dictr.    sk     C00%0HI**E*BCM*:8=#4( $ rk   c                    [        U[        5      (       d&  [        [        R                  S[        U5       35      eUb  UO0 n[        R                  " X45      u  pE[        U[        R                  R                  5      (       a  UR                  nUR                  XU5      nO>S n[        U[        R                  R                  5      (       a  UR                  XU5      nXXSU4$ )Nr  c                     g r   r_   r  s    rl   r  (_process_export_inputs.<locals>.<lambda>  s    drk   )r   r  r
   r   r  r  r   tree_flattenrs   r   AdditionalInputsverifyr  ShapesCollection)rb  r   r   r  r   original_in_specverify_additional_inputss          rl   _process_export_inputsr9    s    dE""''OPTUYPZ|\
 	
 )VrF --tn=A.%,,"?"?@@#1#8#8 '66s&I#2 nell&C&CDD+::3fMN);SSSrk   export_artifactstrict_mode_exportc           	         U R                   R                  nU R                   R                  nU R                  nU R                  nU R
                  n0 n	UR                  5        H.  u  pU(       d  [        U
5      OU
n[        / / US   US   SS9X'   M0     [        U5      S:  a4  U(       d  [        U5        [        X5      " U5      nUc   eUR                  n[        c   e[        UUU	U5      nXN4$ )zt
In-place modify the graph module in export_artifact, remove _export_tracepoint nodes and
return module_call_graph.
r}   r~   Nr  r   )r|   rp   rq   r   r}   r~   r  r   rN   r   r   r   r  r  r  )r:  r  r;  r  rp   rf  r   r}   r~   r  r  specsmod_fqnresmodule_call_graphs                  rl   _get_module_call_graphrA    s     /3366B3B3G3G3K3K))  (//G(11H >@'--/
*<+c"#*=)$:&"+
' 0 )*Q.!$R($%;TUWX#////	   rk   c                 z   UR                   R                  nUR                   R                  nUR                  n[	        S [        UR                  5       5       [        UR                  5      5      n	[        XX5S9n
U(       d)  0 nU
 H  nX;  d  M
  X   X'   M     U H	  nX=   X'   M     Un
[        UUU
UU	5      nU$ )Nc              3   j   #    U  H)  u  pUR                   [        R                  :X  d  M%  Uv   M+     g 7fr   )r   rL   r0  )r  r   ss      rl   r  )_get_range_constraints.<locals>.<genexpr>  s-      	
Evv--- AEs   $3	3r  )
r|   rp   rq   r   r	  r   r   r   r5   r   )rb  r:  r   r   r  r  rp   rf  r   
num_liftedr  combined_args_traced_orderrq  r  range_constraintss                  rl   _get_range_constraintsrJ    s      /3366B3B3G3G3K3K / 9 9I	
!"8"D"DE	

 	"../J "6M %'" C 2?2D*/ ! C.4k&+  3(
 rk   r   c                     U R                   c   eU R                   R                  R                  5        VVs0 s H  u  p[        U5      (       d  M  X_M     snn$ s  snnf r   )r   rM  r  r@   )r   r   r  s      rl   _get_inline_constraintsrL  )  s^    *** ''44::<<DA # 	<  s   AAobjc              #      #    U R                   nUR                  X R                  5      U l          Sv   X l         g! X l         f = f7f)zfHelper method to make it easier to cleanly torch.export() a method on a
module that is not `forward`.
N)r  __get__	__class__)rM  
new_methodoriginal_methods      rl   patch_forwardrS  2  s<      kkO $$S--8CK& &os   -A; AAAc               #     #    [         R                  R                  5       n [         R                  R                  S5         S v   [         R                  R                  U 5        g ! [         R                  R                  U 5        f = f7fr   )rs   r  _jit_texpr_fuser_enabled_jit_set_texpr_fuser_enabled)original_states    rl   _temp_disable_texpr_fuserrX  D  sU     XX668N	HH))%0>--n=--n=s   >B	A%  B	%!BB	c           
         [        5          SSKJn  [        X5      u  pE[	        X[
        R                  R                  45      (       a$  [        U UUSSS9R                  5       sS S S 5        $ [	        U [
        R                  5      (       a  [	        U R                  5       [
        R                  R                  [
        R                  R                  45      (       aV  [        U R                  5       U 5         [        U R                  5       UUSSS9R                  5       sS S S 5        sS S S 5        $ [        [        U 5      UUSSS9R                  5       sS S S 5        $ ! , (       d  f       O= f S S S 5        g ! , (       d  f       g = f)Nr   )TopLevelTracedModuleFT)r  r  )rX  torch.jit._tracerZ  r*  r   rs   r  ScriptModule_exportmoduleScriptMethodownerr  r  rS  rI   )traced_callabler   r   rZ  export_argsexport_kwargss         rl   "_convert_ts_to_export_experimentalrd  N  s;   	"	$9%I$%W"oehh>S>S'TUU$( fh 
%	$ ););<<!!#XX""EHHOO4B
 B
 446H#))+! (, &( IH% 
%	$8 /$( fhE 
%	$$ IHH% 
%	$	$s1   AE;-B
E;7)E  	E;3#E; 
E.	*E;;
F	orig_in_spec_to_aten_funcc	                 B   [        U UUUUSUSS9n	[        XU5      u  n
nn[        X5      nU	R                  R                   H  nUR
                  S:X  d  M  SUR                  ;  d  M'  [        XR                  5      n[        U[        R                  R                  5      (       a  Mg  Uc   S5       eUR                  USS9UR                  S'   M     [        U	R                  R                  [        R                  R                  R                   5      (       d   eU	R                  R                  R"                  R$                  =nnUc   eUc   eUR&                  [(        [*        4;  a  [,        R.                  " [*        SU/5      nU	R                  R                  R"                  R0                  n[!        [3        UU	R4                  U5      5      U	R                  l        U	R7                  5         [9        U	['        U 5      5        [;        U	5      n[=        U 5      n[?        X	5      n[A        U 5      nURC                  5        VVs0 s H	  u  nnUU_M     nnnU Vs1 s H  nUU;   d  M  UU   iM     snU	l"        [G        U5      nU   [I        U5         U" U	[K        UX5      0 UU5      nSSS5        SSS5        WRL                  nURN                  nURP                  n[S        UUU5        [U        [W        U RY                  5       5      [[        U	R]                  5       5      UUS	9  [_        UU5        [a        U UU5        [c        UUU5        [e        UU5        [g        UUUUU	R                  S
   S9$ s  snnf s  snf ! , (       d  f       N= f! , (       d  f       N= f)R
_to_aten_func can either be `_export_to_aten_ir_make_fx` or `_export_to_aten_ir`
F)r  r  r  r  ry  r   NzbCannot find dynamo_fake_mode. This could be due to the exported graph module have no placeholders.T)static_shapes)r  r  r;  rr   r   r|   r}   r~   r   r   )4r  r   r   r   r   r   r   r|  r   r   rs   r  r  from_tensor_codegenrt   rC   pytree_infor~   r  r  r  r   rE   	orig_argsrD   _in_specrr  r  r   r   r*  r_  r  r  r.   r-   r   rp   rq   rr   r   r  ri   r\  rv   r"  r   r  rA  rw  rz   ) rb  r   r   r  r  re  r  r  rf  r  r   r   dynamo_fake_moder+  r   r  r~   orig_out_specr   params_buffers_to_node_metarc  r   r-  tracedorigreverse_name_lookupr   txaten_export_artifactrp   rf  rr   s                                    rl   _strict_exportrx  t  s}    )'E0W	N  	^6:	 11AR $$**77j U$))%;>;;7DdEHHOO44'3 x3 $4#?#? $@ $		%  + n**33UXX^^5R5RSSSS
  .33<<HHQQQH} $$$ }}T5M)??5$
;#))22>>HHN$2##	
%N! ~tCy9"@"P ,C0N)B3)W
 9=<N<T<T<VW<VLFD4<<VW +2*D&& 	"D!*2N. 
(	)B	72;,'	O 
 '	 
	 	 B155$..I-#R)? %S[[]+ < < >?.	   24JK 5#Y
 ^%;YG B 67!"(--.AB e X2 ';		s6   M4
M:,	M:
NM?-N?
N		N
Nc                     U $ r   r_   r   s    rl   r  r    r  rk   c                    S n[         R                  R                  R                  R	                  U USSSS9   [        5          [        5          U" U5      " U USUS9u  pUR                  R                   HQ  n
U
R                  S:X  d  M  [        U
R                  5      S:X  d  M0  SU
R                  ;  d  MB  S U
R                  S'   MS     [        U [         R                  R                  5      (       a6  [!        U S	5      (       a%  UR                  R#                  U R                  5        S S S 5        S S S 5        S S S 5        U(       a	   U" W5        [1        WU UW	SUUUS
9$ ! , (       d  f       N>= f! , (       d  f       NG= f! , (       d  f       NP= f! [$        [&        4 a(  n[)        [*        R,                  [/        U5      5      eS nAff = f)Nc                 :  ^$^% U=(       d    0 n[        U R                  SS95      n[        U R                  SS95      n0 UEUEn[        R                  " U5      u  px[        U5      n[        U5      n	[        U5      n
[        U5      n[        XUSS9n/ nUR                  U5        UR                  U5        [        XU5      u  m%n[        R                  " X45      u  nn[        R                  " T%5      U%4S j5       n[        5          [        5       n[        U SS 5      nUb  [        U5      n0 n[!        UU5      nS m$["        U$4S j5       nU   U" U5         [%        USSS	9" U6 nS S S 5        S S S 5        UGb9  ['        W5      n[)        UR*                  R-                  5       5       VVVs0 s H  u  nu  nnUc  M  UUU	U-      _M     nnnn[/        UR0                  R2                  5      S
   nWR-                  5        H  u  nn[5        UUU   5      n[5        UU5      nUR0                  R7                  U5         UR0                  R9                  S[:        R<                  R>                  R@                  RB                  UU4S9n URD                  U l"        S S S 5        M     WRG                  5         S n!WR0                  RI                  U!5        S S S 5        ['        W5      n[K        U5      n"[M        [/        U5      [/        U5      UUS  U"[        [O        USU	 U5      5      [        [O        UXU
-    U5      5      0 0 UUS / / S9n#UU#4$ ! , (       d  f       GN= f! , (       d  f       GN= fs  snnnf ! , (       d  f       GM  = f! , (       d  f       N= f)NFr  T)store_orig_modc                      > [        T" U 6 5      $ r   )r  )r   flat_fns    rl   
wrapped_fnG_export_to_aten_ir_make_fx.<locals>._make_fx_helper.<locals>.wrapped_fn3  s    $((rk   r   c                   U" X5      nX;   a  [         R                  R                  5       (       a  [        U[         R                  5      (       a  [         R
                  R                  5       nU H  n[        U[        5      (       d  M  UR                  n[        X5      R                  nUR                  S[         R                  R                  R                  R                  X40 5      n	[!        XISUS9  M     U$ )z
The idea here is that we override subclass getattr methods to proxy
inner tensors and metadata. Because of infinite loop shenanigans, we have
to manually construct the getattr proxy nodes without relying on torch function
system.
r   N)r8  tracer)rs   r  _is_torch_function_mode_enabledr   r   	overrides _get_current_function_mode_stackr=   r  r;   proxycreate_proxyr   r   access_subclass_inner_tensordefaultr>   )
r   r  original_getattrattrs_to_proxyouttorch_function_mode_stackmoder  r  inner_proxys
             rl   custom_getattributeP_export_to_aten_ir_make_fx.<locals>._make_fx_helper.<locals>.custom_getattributeD  s     't2)xx??AA%c5<<88 !& P P R 6 )B#-d4P#Q#Q-1[[F,:4,H,N,NE282E2E(7(-		(8(8(U(U(](]).(*	3&K %6(+4PV%& )B 
rk   c              3   *  >#    0 nU  H  n[        U5      nU Hk  nXA;  d  M
  [        X4   5      S:  d   eX4   S   n[        [        U5      5      [        [        [        R
                  5      5      -
  nUR                  U4X'   Mm     M      UR                  5        H%  u  nu  nn[        R                  " TUUS9n	Xl        M'     Sv   UR                  5        H  u  nu  pXl        M     g! UR                  5        H  u  nu  pXl        M     f = f7f)z~
Context manager that temporarily monkey patches
tensor.__getattribute__ so that we can intercept it at
torch_function layer.
r   )r  r  N)
r&   r   ri   dirrs   r   __getattribute__r  r$  partialmethod)r   tensor_type_to_old_getattributerq  subclass_types_to_instancessubclass_typeinstancer  r   old_getattrcustomr   r  s              rl   $override_getattribute_for_subclassesa_export_to_aten_ir_make_fx.<locals>._make_fx_helper.<locals>.override_getattribute_for_subclassesh  s4      0  C 6c: 0 *E(O#&'B'Q#RUV#VV#V'B'QRS'TH-0X-?#c%,,FWBX-XN - > > .N;J *E	  9 9>>@ #&!*!8!8/-8+9"
 .4* A /N/T/T/V++K-8* 0W/N/T/T/V++K-8* 0Ws#   DA)D=C, 	#D,$DD)record_module_stackrd  r  r   )r   c                    U R                   S:X  a  U R                  [        R                  R                  R
                  R                  [        R                  R                  R                  R                  [        R                  R                  R                  R                  [        R                  R                  R                  R                  [        R                  R                  R                  R                  4;   a  gg)Nr   FT)r   r   rs   r   profiler_record_function_enterr  _record_function_enter_new_record_function_exit_RecordFunctionr|   detachr   r  )r   s    rl   
_is_impureG_export_to_aten_ir_make_fx.<locals>._make_fx_helper.<locals>._is_impure  s    77o-$++ II&&==EEII&&AAIIII&&<<LL IINN))11II$$AAIIB 3 !rk   r   )r[  r\  user_inputsuser_outputsinputs_to_parametersinputs_to_buffersbuffers_to_mutateuser_inputs_to_mutater}   r~   backward_signaturer]  output_tokens)(rv   r   r"  r   r3  r  r   r'   r  r(   r$  r%  r	   r   r|  r*   r)   r   r<   r#   r   _buffersr  r  r   r   
_find_noder   r   rs   r   r|   copy_r  r   removeeliminate_dead_coder$   r%   r.  )&rb  r   r   r  r   r"  params_and_buffersparams_and_buffers_flatparams_spec	param_len
buffer_len
params_lenfunctional_callparams_buffers_argsr~   	flat_argsr}   r  r  non_strict_rootassigned_buffershookr  rp   input_namesr   r   bufbuffer_input_namesoutput_nodebuf_node	name_noder   r  output_namesrq   r  r~  s&                                       @@rl   _make_fx_helper3_export_to_aten_ir_make_fx.<locals>._make_fx_helper  s   2 4 4e 4 LMS...FGB 0BMB/5/B/BCU/V,"'(?"@()	'
+,
0j
 *,""#:;""4(4&
 $002E1NO	7		!	) 
"	) &'-C%c>4@O*2?C 46 6#%5"H )9 )9V :9E(,!% 	 F *04 +4O4L4L4R4R4T*U&*U;D# 5D+i!m44*U # &
 #288>>226!1!7!7!9IC)".@.EFH *2t 4I22;?#%88#7#7+!IINN0088"*I!6 $8 $
 )2 @? ": & HH((4[ (` ),*2.,-'#JK0%!%c+a	*BDT&U!V"K	
,BC]S !"$#
" 3wM FE& @?a ('si   	AN	M M)M 1>N/M2
 M2
A2N?AM9:N
MM  
M/	*N9
N		N
NTr  F)r  r   r   r   r   r   )rp   rb  rc  r;  rd  r   r   r+  )rs   r  r  r  r  r   r   r   r   r   r   usersr   r   rt   ru   r{  r  r?   rF   r
   r   r  rw   rh  )rb  r   r   r+  rc  r  r  r  rp   r;  r   r  s               rl   _export_to_aten_ir_make_fxr    s   BP 	  66 	7 	
 	 ! "'8	
 HHNND?*

Oq(*#'		%  # c588//00WS&5I5IGGNN388$3 	# 	"	
H 	H#B' "%'/	 	E 	#" 	"!	
 	
N )/: 	HM>>AGG	Hsf   FE49E#E#'E#9A2E#+E43FF #
E1-E44
F	>F
FG&#G		Gc                     SnU R                   R                   HS  nUR                  S:X  d  M  X2:  a4  XU-
     n[        U[        R
                  5      (       d  XTR                  S'   US-  nMU     g )Nr   r   r   rG   )r   r   r   r   rs   r   r   )rp   r  num_params_buffersindexr   user_args         rl   r^  r^    sa     E77m#*$-?%?@!(ELL99'/IIe$QJE rk   r   c                 h   ^ [        [        U4S jU R                  R                   5       5      5      $ )Nc              3   J   >#    U  H  oR                   T:X  d  M  Uv   M     g 7fr   )r   )r  r   r   s     rl   r  _find_node.<locals>.<genexpr>(  s     Jnd		T8ITTns   #	#)r	  r
  r   r   )rp   r   s    `rl   r  r  '  s!    JbhhnnJJKKrk   c	                 N  ^^^^^^^^^ SmSm0 mUUUU4S jn	[        U UUTTUS9u  mn
nmmm[        TU 5      nUUUUU4S jn[        T5      n[        R                  " [
        5      nSUS'   T   [        5          [        U5         [        R                  R                  R                  U5         [        X
UT5       u  nnnnn[        XT5         [        5          U" UUUUUUU	S9nUR                  R!                  5        VVs0 s H#  u  nnU[#        U[$        5      (       a  UU   OU_M%     snnUl        SSS5        SSS5        SSS5        SSS5        SSS5        SSS5        SSS5        ['        U WR(                  UR                  5        Tc   eTc   e[+        UTTTTS9$ s  snnf ! , (       d  f       N|= f! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       N= f)	rh  Nc                 "   >^  SU UUUU4S jjnU$ )Nc                   > U=(       d    0 n " UU4S jS[         R                  R                  5      nU" U 5      nT Vs/ s H  nSU-   PM
     nn[        5       n[	        U [         R
                  R                  5      (       d  [        XWT5      nU   T" XQ4SU0UD6u  p[        R                  SU	5        S S S 5        [        R                  " [        W
R                  5      U
l        [        R                  " [        U
R                  5      U
l        [        R                  " [        U
R                  5      U
l        [        R                  " [        U
R                   5      U
l        [        R                  " [        U
R"                  5      U
l        W	R$                  R&                   Hy  nSUR(                  ;   d  M  UR(                  S   n[        R                  " [        U5      R+                  5        VVs0 s H  u  p[-        U5      U_M     snnUR(                  S'   M{     X4$ s  snf ! , (       d  f       GN|= fs  snnf )Nc                   8   >^  \ rS rSrU 4S jrUU4S jrSrU =r$ )]_non_strict_export.<locals>._tuplify_outputs.<locals>._aot_export_non_strict.<locals>.WrapperiC  c                 .   > [         TU ]  5         Xl        g r   )super__init__r   )r   rb  rP  s     rl   r  f_non_strict_export.<locals>._tuplify_outputs.<locals>._aot_export_non_strict.<locals>.Wrapper.__init__D  s    G$&(+%rk   c                 ^  > U R                   n[        R                  " X45      u  nm[        U[        R
                  R                  5      (       a  [        UR                  R                  5       ;   a  [        X1U5        [        R
                  R                  R                  5          / UQUR                  5       Q7n[        R
                  R                  U5      R                  " U6 nS S S 5        OU" U0 UD6n[        R                  " W5      u  nm[        U5      $ ! , (       d  f       N2= fr   )r   r   r3  r   rs   rt   ru   r3   _forward_pre_hooksr  	tracebackpreserve_node_metaInterpreterrunr  )	r   r   r   rb  r   tree_out	flat_outsr}   r~   s	          rl   r  e_non_strict_export.<locals>._tuplify_outputs.<locals>._aot_export_non_strict.<locals>.Wrapper.forwardH  s     ++C!'!4!4d^!DJAw!#uxx';';<< >"55<<>? >cP"XX//BBD#<T#<FMMO#<D',xx';';C'@'D'Dd'KH ED $'#7#7*0*=*=h*G'Ix ++ EDs   'AD
D,)r   )r`   ra   rb   rc   r  r  rj   __classcell__)rP  r}   r~   s   @rl   Wrapperr  C  s    ,, ,rk   r  z_export_root.r   z%Exported program from AOTAutograd:
%sr   )rs   r  r  r   r   rt   ru   r"   r  debugr   r   r   r[  r\  r  r  r  r   r   r   r  r   )rb  r   r   r  r  wrapped_modr   new_preserved_call_signaturesr  rp   rq   r   r   r  r   
aot_exportr}   r   r~   r  s                  rl   _aot_export_non_strictL_non_strict_export.<locals>._tuplify_outputs.<locals>._aot_export_non_strict@  s   \rF, ,%((// ,: "#,K .L--K!#-K * - -Cc588#7#788&@Q $[OvOO		BBG  $__[#..ICN //+s{{CCK$*OOKAVAV$WC!'-S55(C$ %+OOKAVAV$WC!$		1&*ii0A&BO )/')%')"4)"HC #3,)"4DII/0 ' 7N=- 4s    H&$H+6H=+
H:r   r_   )r  r  r}   r   r~   r  s   ` rl   _tuplify_outputs,_non_strict_export.<locals>._tuplify_outputs?  s    A	 A	F &%rk   )r  r  c           	          > [        TU TTTTS9$ )N)r   rp   r  equalities_inputsoriginal_signaturer  )r   )rp   r  r  r  r   r  s    rl   _produce_guards_callback4_non_strict_export.<locals>._produce_guards_callback  s"    3)/1 3
 	
rk   FrW   )r  r  rj  )r   r   r.   rg   r  r  r   r-   rs   r  r   r  r   r   r   rr   r  r   r/   r  rq   rz   )rb  r   r   r  r  re  r  r  rf  r  r   r   r+  r  rv  dynamo_configpatched_modnew_fake_argsnew_fake_kwargsnew_fake_constant_attrsmap_fake_to_realrw  r  rM  r  r   r}   r   r  r~   s      ``  `                @@@@@@rl   _non_strict_exportr  +  s(    $(H"&G?AD& D&Z 	/0W	 1C@
 
 
		"B  &&'CDM /0
 	&(""=1 #3;	J O' !))D!##0#'(@*$  !5 > > D D F. FHC j>N.O.O%c*UXX F. * $ E K 	2 	 	) 	> 5!%%';'E'E !+ . $# ED KJ 	21 	 	)( 		s   0H;H*G41G#	?GG*F0*F*1	F0:GG
G#	G4H"H*F00
F>:G
GG
G G#	#
G1-G44
H>H
H	H
H$r  r  r  c                h   [        U 5      q[        XX#5      u  nnnnn[        U 5      nU(       a  [        O[
        n	U	" U UUUUUSS[        S9	n
U
R                  R                  n[        XU5      n[        U
R                  5      nXR                  R                  R                  S'   [        U U
UUU5      n[        U
UUU5      u  nn[!        U5        [#        U5        [%        X5        ['        X5        SSKJn  [-        UUR.                  UUUUX4U
R                  R0                  U/S9	nU" U5        U$ )NF	rb  r   r   r  r  re  r  r  rf  inline_constraintsr   )TrainingIRVerifier	r  r   r;  
state_dictrI  r@  r(  rr   	verifiers)r  r  r9  r.  rx  r  r  r|   rq   r  rL  r   rp   r   rJ  rA  r  r  r
  r   torch._export.verifierr  rK   r   rr   )rb  r   r   r  r  r  re  r8  r,  export_funcr:  rf  r  r  rI  rp   r@  r  exported_programs                      rl   _export_for_trainingr    sf     5S9 	s&A  337 %+.0BK!%'E!05!0
O -1155.s&A01J1JK :L  !56. 3&	B Bb9(9&hh.&++~!&&00%&
 -.rk   )r  r  rd  r  r  rd  c                D  ^^ SSK Jn	  [        U 5      q[	        5       n
U
R                  U(       a  SOS5        U
R                  U(       a  SOS5        U
q[        S[        S9  [        S	S
 S9  U(       a*  U	" 5       (       a  [        U UUUUUS9m[        SU4S jS9  T$ [        XX#5      u  nnnnn[        U 5      nU(       a  [        O[        nU" U UUUUUUU[        R                  " [         UUS9S9	nUR"                  R$                  nU(       d  ['        XU5      OSn[)        UR*                  5      nUUR"                  R,                  R.                  S'   [1        U UUUUUS9n[3        UUUU5      u  nn[5        U5        [7        U5        U(       d  [9        UU5        [:        R<                  R>                  RA                  USS9  SSK!J"n  [G        UU 5        [I        UURJ                  UUUUX4UR"                  RL                  U/S9	m[        SU4S jS9  U" T5        T$ )a	  
Traces either an nn.Module's forward function or just a callable with PyTorch
operations inside and produce a ExportedProgram.

Args:
    mod: the `nn.Module` to trace.

    args: example positional inputs.

    kwargs: optional example keyword inputs.

    dynamic_shapes:
     An optional argument where the type should either be:
     1) a dict from argument names of ``f`` to their dynamic shape specifications,
     2) a tuple that specifies dynamic shape specifications for each input in original order.
     If you are specifying dynamism on keyword args, you will need to pass them in the order that
     is defined in the original function signature.

     The dynamic shape of a tensor argument can be specified as either
     (1) a dict from dynamic dimension indices to :func:`Dim` types, where it is
     not required to include static dimension indices in this dict, but when they are,
     they should be mapped to None; or (2) a tuple / list of :func:`Dim` types or None,
     where the :func:`Dim` types correspond to dynamic dimensions, and static dimensions
     are denoted by None. Arguments that are dicts or tuples / lists of tensors are
     recursively specified by using mappings or sequences of contained specifications.

    preserve_module_call_signature: A list of submodule paths for which the original
        calling conventions are preserved as metadata.

    allow_complex_guards_as_runtime_asserts:
     With the current dynamic shapes language for dims and derived dims, we can run into constraints
     that are not expressible with the language. For example, flattening a matrix and adding to a vector,
     both fully dynamic (i.e. x.reshape([-1]) + y) emits a guard s0 * s1 = s2, which is not expressible.
     By default, we either raise a constraint violation error or specialize to static values.
     If this flag is set to True, we avoid erroring out and instead allow complex constraints to exist as runtime
     assertions in the graph. The sympy interpreter (torch/utils/_sympy/interp.py) will produce the math ops
     required to compute and assert the value of the guard (e.g. sym_size_int, eq, _assert_scalar).
     Additionally, if TORCH_DYNAMO_DO_NOT_EMIT_RUNTIME_ASSERTS=1 is specified, we will allow complex constraints
     while not emitting runtime asserts, returning a cleaner graph with lesser guarantees around dynamic shapes.

Returns:
    An ExportedProgram containing the traced module.
r   ) export_training_ir_rollout_checkr  
non_strictrd  aot_dispatchzexport.enterr  r   c                      g)Nzstart!r_   r_   rk   rl   r  _export.<locals>.<lambda>v  s    8rk   )
payload_fnr  r  c                     > [        T 5      $ r   rw   r1  s   rl   r  r    s	    Rrk   )rd  r  r  Nr  rF  T)in_place)Verifierr   c                     > [        T 5      $ r   r  )r  s   rl   r  r    s    SAQ=Rrk   )'torch._utils_internalr  r  r  ri   rk  r  r2   r0   r  r9  r.  rx  r  r$  partialr  r|   rq   r  rL  r   rp   r   rJ  rA  r  r  r
  rs   r]  r  remove_proxy_from_state_dictr  r  r   rK   r   rr   )rb  r   r   r  r  r  rd  r  r  r  r  r7  r8  r,  r  r:  rf  r  r  rI  rp   r@  r  r  r  s                          @@rl   r]  r]  0  sF   t G  5S9EE	II&hl3	IIn.AM>?h+;< 8::!+I
 	,I	 	s&A  337 %+.0BK!%'E%0W/''% 3
O 4C3G3G3K3K :Ms&1RV  11J1JK :LO  !56./ 3&	B B!"&<= 
MM445HSW4X/C(&hh.&++~!&&00*
 (5RS-.rk   r   )NN)F)rg   r$  r  loggingr  r  r  warnings
contextlibr   r   typingr   r   r   r   rs   torch._dynamotorch.fxtorch.utils._pytreer  _pytreer   torch._dispatch.pythonr	   torch._dynamo.excr
   r   torch._export.db.loggingr   r   torch._export.non_strict_utilsr   r   r   r   r   r   r   r   -torch._export.passes.collect_tracepoints_passr   (torch._export.passes.lift_constants_passr   r   rJ  r   r   r   r   r   r   r   r    r  r!   torch._export.wrappersr"   4torch._functorch._aot_autograd.input_output_analysisr#   r$   &torch._functorch._aot_autograd.schemasr%   -torch._functorch._aot_autograd.subclass_utilsr&   9torch._functorch._aot_autograd.traced_function_transformsr'   $torch._functorch._aot_autograd.utilsr(   r)   torch._functorch.aot_autogradr*   r+   torch._guardsr,   r-   r.   "torch._library.fake_class_registryr/   torch._loggingr0   torch._subclasses.fake_tensorr1   r  r2   torch.export._unliftr3   torch.export.dynamic_shapesr4   r5   r6   r7   r8   torch.export.exported_programr9   torch.fx._symbolic_tracer:   "torch.fx.experimental.proxy_tensorr;   r<   r=   r>   rK  r?   r@   rA   rB   torch.fx.graphrC   rD   rE   torch.utils._sympy.value_rangesrF   
_safeguardrH   _wrapper_utilsrI   r  rJ   rK   rL   rM   rN   r;  rO   rP   	getLoggerr`   r  	dataclassrR   rn   rz   r  criticalr  r  	exceptioninfowarningr  warnrV   r   r   r   r   r   rt   ru   r   r   r   r   r   r  r  r  rv   rw   r*  r   r  r9  rA  rT  rh  rw  r  r  r  r  re   r  r  r  ri   r_  r  r  r  r  r
  r  r  rf   r  r&  r*  r.  r9  rA  rJ  rL  rS  rX  rd  rx  r  r^  Noder  r  r  r]  r_   rk   rl   <module>r@     s       	 
   2 1 1    $ $ ; 6	 	 	 Q	 	 	 6 3 B W D C ? , 8 2 B  5 ;   7 ( ; 5 *  V ! > > >. 1 1 1 d#= = $=  23 MMMMLLKKOO	MM
>  : ; ; B BC(.!5!5 .0S (+-\:	1h XX__ 88??  
#s(^ F$,$,	$, c5<</0$, C//0	$,
 I$,N-(-)- C//0- 
	-6%?588#7#7 %?D %?d !%hh hV..). 
.b!XX__!5:XX5I5I!	!Huxx 4S>  .2	$$$ !&9!9:$  S	*	$
 
/$: (,MQ	Z 79&+49"ZZ
S/Z T#s(^$Z U4S>5:tCy#HIJ	Z %*#s(OZ  $Z .2Z Z Z Z XXZF !` "& %(,(-`	`
 $`  ` ` "&` "&` `L (,	
S/ T#s(^$ 
#Y	>
UXX__ 
S 
/%,,'/S%,,.// */ C//0	/
 
/,FhhooF)F C//0F 
	F(%((*>*> (4 (Vehh&:&: t 4#7	04_ 4c3h 4  %)xC! (59 (4S>2 9/d0$%((// d38n T0 .2	,!#,!$)#s(O,! ,!  S	*	,!
 588o!667,!j -	-#-`~  &uxx & &" > >#LX	X
S/X cNX U4S>5:tCy#HIJ	X
 %*#s(OX X .2X X X XB !D	D
 $D DN"L588'' Ls Luxx}} Ll	l
S/l cNl U4S>5:tCy#HIJ	l
 %*#s(Ol l .2l l l l^  (,MQ	Q 68Q	Q
S/Q T#s(^$Q U4S>5:tCy#HIJ	Q Q %*#s(OQ Q   Qh  (,MQ	i 6849 %i	i
S/i T#s(^$i U4S>5:tCy#HIJ	i i %*#s(Oi i .2i i i   irk   