
    9ibd                       % 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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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/J0r0J1r1  S SK2J3r3J4r4J5r5J6r6J7r7J8r8J9r9J:r:  S SK;J<r<  S SK=J>r>  S SK?J@r@  S SKAJBrBJCrC  S SKDJErE  S SKFJGrG  S SKHJIrIJJrJ  S SKKJLrLJMrM  S SKNJOrOJPrPJQrQ  S SKRJSrS  S SKTJUrU  S SKVJWrW  S SKXJYrY  S SKZJ[r[  S SK\J]r]  S SK^J_r_J`r`JaraJbrbJcrc  S SKdJere  S SKfJgrg  S SKhJiriJjrjJkrkJlrl  S SKmJnrnJoroJprpJqrq  S S KrJsrsJtrt  S S!KJuru  S S"KvJwrw  S#S$KxJyryJzrzJ{r{J|r|J}r}  S#S%K~JrJr  \GR                  " \5      rS&r\\\\4   \\S'4   \\   4   r\\S('   \ GR                   " S) S*5      5       r\ GR                   " S+ S,5      5       r\ GR                  " S-S.9 " S/ S05      5       r\" 5       r\GR                   \GR"                  \GR$                  \GR&                  \GR(                  \GR                  \GR*                  \\	GR.                  1	\l        \S1 5       r\S2 5       rS3 rS4 rS5 rS6\GR<                  GR>                  4S7 jrSS8\4S9 jjrS: rS; rS< rS= rS>\GRL                  GRN                  S?\GRL                  GRN                  S@\\\4   4SA jrS6\GR<                  GR>                  SB\SC\\\GRR                  4   SD\\\g4   SE\\   4
SF jrSG\1SH\SD\\\g4   S@S4SI jrS6\GR<                  GR>                  S@S4SJ jrS-SK.S6\GR<                  GR>                  S@\4SL jjrS6\GR<                  GR>                  SH\S@S4SM jrS>\GRL                  GRN                  S?\GR<                  GR>                  S@S4SN jrSO\GRL                  GRN                  S@\\\4   4SP jr SSQ\uSR\uSS\\\}4   ST\\\      S@\\|   4
SU jjr " SV SW\5      r  SSXSYSYS-S-S-SZ.S[\S\\\S'4   S]\\\\4      S^\\\\\4   \\   \\   4      S_\\S'4   S`\Sa\Sb\Sc\Sd\S@\GR<                  GR>                  4Se jjjr SSf SYSS-SYSg.SO\GRL                  GRN                  Sh\1Si\Sj\S@\4
Sk jjjr SSO\GRL                  GRN                  S\\\S'4   S]\\\\4      S@\\   4Sl jjrSO\GRL                  GRN                  S@\\   4Sm jrSn\\GRR                     So\\\GRR                  4   SH\SD\\\g4   S@S4
Sp jrSq\GRL                  GRN                  SH\SD\\\g4   S@S4Sr jrSs\GR<                  GR>                  S@S4St jrSs\GR<                  GR>                  S@S4Su jrS6\GR<                  GR>                  SB\S@S4Sv jrSw\zS@\\\4   4Sx jrSq\\\      \Sy'   Sq\\\\4      \Sz'   S{ rS| rSO\GRL                  GRN                  S@\\\4   4S} jrSO\GRL                  GRN                  S\\\S'4   S]\\\\4      S^\\\\GR                  GR                  \GR                  GR                  4      S@\\\S'4   \\\4   \u\\   \\z/S4   4   4
S~ jr SS\S_\\S'4   S\ST\\\      S@\\GR<                  GR>                  \\|   4   4
S jjrSO\GRL                  GRN                  S\4S jrS\W4S jr\S\GRL                  GRN                  4S j5       r\S 5       rSO\GRL                  GRN                  S\\\S'4   S]\\\4   S^\\\\\4   \\   \\   4      S_\\S'4   S\uSa\S\S@\4S jrSS 4SO\GRL                  GRN                  Sh\1S@\4S jjrS rS6\GR<                  GR>                  S\S@\GR<                  GR                  4S jrSO\GRL                  GRN                  S\\\S'4   S]\\\4   S^\\\\\4   \\   \\   4      S_\\S'4   S\uSa\S\S@\4S jr\\y  SS-SXSYS.SO\GRL                  GRN                  S\\\S'4   S]\\\\4      S^\\\\\4   \\   \\   4      S\S_\\S'4   Sa\S@\z4S jjj5       5       r\\y  SS-SXSYSYS.SO\GRL                  GRN                  S\\\S'4   S]\\\\4      S^\\\\\4   \\   \\   4      S\S_\\S'4   S\Sa\S@\z4S jjj5       5       rg)    N)contextmanagernullcontext)AnyCallableOptionalUnion)	TypeAlias)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)create_functional_call)_graph_input_names_graph_output_names)GraphSignature)get_subclass_typing_container)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)find_legit_leaks_from_referrers)!_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   )_disable_prexisiting_fake_modeExportedProgram	InputKindModuleCallEntryModuleCallSignature)"_convert_to_export_graph_signatureExportGraphSignatureNONSTRICT_EXPORT_SANITIZE_TRACE._DynamicShapesSpecc                       \ 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)ExportDynamoConfigy   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__rV   bool__annotations__dataclassesfieldsetrX   r   rY   rZ   r[   r\   r]   r^   r_   r`   __static_attributes__ra       S/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/torch/export/_trace.pyrT   rT   y   s     It3>3D3D4!3x=  )-,ND!d!%*d*%*d*-1$d1#'D'8=/=rm   rT   c                   f    \ rS rSr% \R
                  R                  \S'   \\S'   \	\
\4   \S'   Srg)ATenExportArtifact   gmsig	constantsra   N)rb   rc   rd   re   torchfxGraphModulerh   rP   dictstrr<   rl   ra   rm   rn   rp   rp      s)    	C//00rm   rp   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_specsra   N)rb   rc   rd   re   rp   rh   rG   r2   rx   ry   pytreerl   ra   rm   rn   r|   r|      s8    
Cc6??&:!;;<<rm   r|   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)ru   backendsmkldnn	set_flagsnnpack)orig_mkldnn_flagorig_nnpack_flags     rn   _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   ru   
_functorchconfigdecompose_custom_triton_ops)olds    rn   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   ra   rm   rn   (custom_triton_ops_decomposition_disabledr      s    &&BBBBrm   c                     S[        U 5      -   $ )N	L__self__)_strip_rootxs    rn   
_fixup_keyr      s    Q''rm   c                     [        U [        5      (       a5  U R                  S5      (       a  U [        S5      S  nUR	                  S5      $ U $ )N_export_root.)
isinstancery   
startswithlenremoveprefix)r   strippeds     rn   r   r      sE    !Sall>::S(*+$$S))Hrm   rr   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 modify 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targetru   opshigher_order_export_tracepointr   r   inserting_beforecreate_noder   metareplace_all_uses_with
erase_node)rr   noder   new_nodes       rn   _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   rI   zshape env (z) from  z doesn't match mode (z

shape env from z allocated at:
z
shape env from )	enumerater   ru   SymIntappendr   	shape_envstack)
r   
shape_envsi
flat_inputr   desc1i1mdesc2i2s
             rn   detect_shape_envr      s    J"6*j%,,//z88.!LM + )!}	"&qrNLAb> i[wat;PQRPSSZ[`Zaabcebf g""'"-=ioo=N O""'"-=aggYH> + rm   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$ )NrI   )r   intru   Tensor)r   r   count	fake_inpss     rn   lookup_fake)_extract_fake_inputs.<locals>.lookup_fake!  s2    ",Qell0C"D"Di!

rm   )r   r   opr   r   getr-   r   r   r2   rD   r   tree_map)rr   r   r   	fake_valsr   detected_fake_modedetected_shape_envr   r   	fake_argsfake_kwargsr   r   s              @@rn   _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,,rm   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_specsr;   BUFFER_MUTATIONGRADIENT_TO_PARAMETER)param_buffer_tablers   specs      rn   _replace_param_buffer_namesr   -  s    99
 
 -[[9DK     99&&,,
 
 -[[9DK !rm   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        rn   _convert_to_positional_argsr   <  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>.Pathic  c                 6   > US:w  a  TR                  U5        U $ )N_modules)r   )selfnamepartss     rn   __getattr__L_normalize_nn_module_stack.<locals>.normalize_path.<locals>.Path.__getattr__d  s    #':#5$)LL$6'+rm   c                 <   > TR                  [        U5      5        U $ r   )r   ry   )r   idxr   s     rn   __getitem__L_normalize_nn_module_stack.<locals>.normalize_path.<locals>.Path.__getitem__i  s     %SX 6'+rm   ra   N)rb   rc   rd   re   r   r   rl   )r   s   rn   Pathr   c  s    ,
, ,rm   r  Lr   r   )evaljoin	Exception)r   r  r   s     @rn   normalize_path2_normalize_nn_module_stack.<locals>.normalize_path_  sQ    $ ", , TC&$&)9#:;"xx.$ $#$s   48 AAr   )resubmodulesr   ru   rv   rw   r   r   r   r   r   nextitervaluesinspectisclass
issubclassnnModulery   rc   rd   items)gm_torch_levelroot_clsrootroot_keyrr   r   add_rootr   r   tyr  keys               rn   _normalize_nn_module_stackr  H  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  pEUR                  [        U5      5      b  M"  XB[        U5      '   M1     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_parametersr   idnamed_buffers)r  r  param_lookupbuffer_lookupr   parambufferr   dynamo_namedynamo_paramdynamo_buffers              rn   _get_param_buffer_mappingr,  |  s#    $&L$&M&777OBuI&.&*E# 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+' rm   rs   fake_params_buffersrt   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   rI   )r   r   r   r   r   zipr   rL   r   r   r   requires_gradr   
USER_INPUTr   ru   r   CONSTANT_TENSORis_leaf
CUSTOM_OBJTOKENAssertionError)rr   rs   r-  rt   r.  r   placeholdersr   r   fake_argconstants              rn   _preserve_requires_grad_passr;    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   r3  r5  r   r   )r<  r=  rt   remap_tabler   valuer   orig_targettargetsr:  r   s              rn   _remap_constantsrC    s     )+K (' 3 :K )  ++99%%  
 
 ++K***!ook=AG!!*DK -H&!$,&! " ,rm   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   ra   T)r   pendingsimplify)torch._export.utilsrE  %torch.fx.experimental.symbolic_shapesrF  torch.utils._sympy.symbolrG  rH  var_to_rangeUNBACKED_INTUNBACKED_FLOATunbacked_renamingsr   r   r   popr   )rr   rE  rF  rG  rH  r   symbolbase_unbacked_symbolsr   r   rI  s              rn   _replace_unbacked_bindingsrV    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   rV  r   
parametersbuffersinput_tokensset_missing_meta_valsrO   _get_non_persistent_buffersr   3torch._export.passes.replace_autocast_with_hop_passrY  3torch._export.passes.replace_set_grad_with_hop_passrZ  r
  r   ru   rv   rw   r   r   r   r   rS  r    r;  rp   )rr   modconstant_attrsr=  pre_dispatchr   r   r-  rW  r.  total_non_user_inputsexport_graph_signaturert   rY  rZ  _modr   s                    rn   _produce_aten_artifactrj    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 
 rm   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 $ )NrI   r   )add)r   ndup_name
node_namess      rn   rename_constant0_rename_constants_nodes.<locals>.rename_constant  s_    :A"&q},8;Q #'q},8;Dtrm   N)r   r   r   r!   rL   r   r3  r   r   argr   r   r   r
  r   ru   rv   rw   r   	recompile)rr   r=  r   rq  buffer_prefixconst_prefixbuffer_to_constantr   c_namerd  rp  s             @rn   _rename_constants_nodesry  v  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   ru   r   r  	Parameterregister_buffersetattrdelattrr   r   r   r   rt  )r  r  r   r   fqnattrr   	attr_names           rn   _restore_state_dictr    s     3?R
 (--/	#&;;sC#8  0 (--/	}++}+dELL))*T588CUCU2V2V))#4M-$ 0 ##))77j I.0;	 * rm   rd  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typerb   )rd  r   r   s      rn   _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           rn   _make_module_call_graphr    s     ,+C 	C+E+Ec+JK+   A;??b   /+HQK 5::<<NC.. 	6C5<  
 $X#
###s   "B*B>Bc                       \ rS rSrSrg)_ExportModuleSpecTrackerDicti  ra   N)rb   rc   rd   re   rl   ra   rm   rn   r  r    s    rm   r  ra   F)preserve_module_call_signaturedisable_constraint_solverr`   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          [+        5       n[-        5       n[        U [        R.                  R0                  5      (       d  [3        XU5      nU   [5        5          [        R                  R7                  U UUSSU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RD                  S'   [        U [        RF                  RH                  5      (       a  U(       a  [K        X5        U$ ! , (       d  f       Nj= f! , (       d  f       Ns= f! [8        [:        4 a(  n[        [        R<                  [?        U5      5      eS	nAf[@         a*  n[        [        RB                  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  r8   STATICr   )as    rn   <lambda>%_export_to_torch_ir.<locals>.<lambda>  s7    ::L4G4G!G %% rm   Tsymbolic)r  constraintsr\   tracing_moder  r`   r  r  Nz5Consider annotating your code using torch._check*(). constrain_as_size_example)	case_namer   )&r3   r   tupler   r   INVALID_INPUTr  r   tree_map_onlyr   r9   r7   r6   r:   ru   _dynamor   patchri   asdictDEFAULT_EXPORT_DYNAMO_CONFIGr  r   rv   rw   r#   r   r   rA   rH   CONSTRAINT_VIOLATIONry   rC   ANTI_PATTERNr   r  r  r  )r  r   r   r  r  r  r`   r  r  r  combined_argsr  r   ctxr  r   es                    rn   r  r    s)   $ 3<Q;RSdE""''OPTUYPZ|\
 	

 \rF ''[4.ILD!!62M-8)-HK ''	 
LD 
			#	#K$6$67S$T	U	,.  -Ca!5!566&7H -/$)MM$8$8#1 +-1!+.G@k&7#1 %9 
% % %! 0 
VD 0AN+,!UXX__%%+A.; 0/ )/: 	HM>>AGG* 	**GAxP5 	7 
V	Uss   ?I8AHG:.G)G:H)
G73G::
H	HI8HI5#H>>I5%I00I55I88
Jc                     U $ r   ra   r   s    rn   r  r  S      rm   )	transformrf  decomp_tablerW  r   re  rW  r   c                   U
(       a  [         O[        n[        R                  R                  R
                  R                  U USSSS9   [        5          [        5          U" 5          U" [        5      " U USUUUS9u  pS 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       NS= f! , (       d  f       N\= f! , (       d  f       Ne= f! , (       d  f       Nn= f! [        [        4 a(  n[        [        R                  [        U5      5      eS nAff = f)NTtie_weightsstrictstack_weightsF)trace_jointrf  decompositionsr   c                 J   [        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SUR
                  ;   a  UR
                  S	 [        UR
                  5      S:X  d   eUR
                  R                  UR
                  5        g g )Nr   r   descr   )r   ru   rv   rw   r}  r   updatelistr   r   r   r   )old_gmnew_gmold_output_nodenew_output_nodes       rn   $_maybe_fixup_gm_and_output_node_meta@_export_to_aten_ir.<locals>._maybe_fixup_gm_and_output_node_metav  s    fehh2233vv&&""6;;/"6<<#5#56r:O"6<<#5#56r:O"%%1o6H6HH6TTT---#((0++,111  ''(<(<= 4rm   )	rr   rd  re  r=  rf  r   r   r-  rW  )r   r   ru   r  utils	stateless_reparametrize_moduler   r   r,   rA   rH   r   r   r  ry   rj  )rd  r   r   r-  re  produce_guards_callbackr  rf  r  rW  r   #custom_triton_ops_decomposition_ctxrr   r=  r  r  s                   rn   _export_to_aten_irr  K  s8     ' 	? ( 	  66 	7 	
 	 ! "+-'(9:%'
 	. 	# 	"	
(>  )b1 	H#B' "%'!/$?
 
S 	.- 	#" 	"!	
 	
^ )/: 	HM>>AGG	Hsl   	C?C.C'C	?CC.C?3D 
CC
C+'C..
C<	8C??
DE #EE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   )rd  r   r   rs   _argsnamesr   r@  r   r   kwargs              rn   _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   Nra   ).0br   s     rn   	<genexpr>._get_non_persistent_buffers.<locals>.<genexpr>  s     O1NATF!A3-1Ns   )rk   r  r  _non_persistent_buffers_set)rd  resultr   r   s      @rn   ra  ra    s\     uF$$e$<aMMO1N1NOOMM!778	 =
 Mrm   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   r3  )r  r  r=  rt   r   r@  s         rn    _rewrite_dynamo_tensor_constantsr    sc      ++99	(((;;***&{{3E, &55	).$++& ,rm   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=  rt   r   s       rn   0_move_non_persistent_buffers_to_tensor_constantsr    sk      ++99	(((;;***;;i///%-%8%8%EIkk"	 ,rm   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   r{  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   ry   )r  r   s     rn   r  4_verify_nn_module_stack.<locals>.<genexpr>.<genexpr>  s     >Aq
1c 2 2As   N)r   ry   r  r   all)r  kvs      rn   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   ru   rv   rw   r   r   r   r   r   r"   r  r  )r  r   rd  r   r   s        rn   _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rm   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'
r[  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   ru   rv   rw   r   r   r   r   r   ry   r"   )r  rd  r   r[  s       rn   _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  - 7rm   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   rs  r   r   r
  r   ru   rv   rw   r   r   r   r!   r   r"   )rr   rs   r   name_to_kindrd  r   	node_kindprefixs           rn   _verify_placeholder_namesr	  7  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   rI   rc   rb   r   )op_countop_set)rk   r  r
  r   ru   rv   rw   r   r   r   r}  r   rm  rc   rb   )r
  r  r  r   r   s        rn   get_ep_statsr  O  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3rm   _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)filera   )timer3   r  r  r  r  rc   rd   r   logerrorr   ry   r}  printr  sysstderrr  )
r   r   startr
  endr  t
error_typer  fns
            rn   wrapper$_log_export_wrapper.<locals>.wrapperd  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   ` rn   _log_export_wrapperr%  c  s&    __R+ +Z Nrm   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  rx   ru   r   )example_inputsexample_kwarg_inputss     rn   $_process_jit_trace_inputs_for_exportr)    sp    nudD&9::(*	ND	)	)~. 	>ELL$#788 ((*#!//rm   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  )rx   r"  r$  ra  rS  )rd  r"  r$  original_state_dictnon_persistent_buffersr  s         rn   _get_original_state_dictr-    sk     C00%0HI**E*BCM*:8=#4( $ rm   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OAS n[        U[        R                  R                  5      (       a  UR                  XU5      nOUnXXWU4$ )a  
Process and validate export inputs for the torch.export API.

This function validates the input arguments, normalizes kwargs, computes input tree specs,
and handles special dynamic shapes cases like AdditionalInputs and ShapesCollection.

Args:
    mod: The PyTorch module to be exported.
    args: Tuple of example positional inputs for the module.
    kwargs: Optional dictionary of example keyword inputs.
    dynamic_shapes: Optional specification for dynamic shapes. Can be:
        - dict mapping argument names to dynamic shape specifications
        - tuple/list specifying dynamic shapes for each input in order
        - torch.export.AdditionalInputs object with verification callback
        - torch.export.ShapesCollection object

Returns:
    A tuple containing:
    - args: Validated tuple of positional inputs
    - kwargs: Normalized dictionary of keyword inputs (empty dict if None was passed)
    - original_in_spec: TreeSpec representing the flattened input structure
    - dynamic_shapes: Processed dynamic shapes specification
    - verify_additional_inputs: Callback function for additional input verification

Raises:
    UserError: If args is not a tuple.
r  c                     g r   ra   r
  s    rn   r  (_process_export_inputs.<locals>.<lambda>  s    drm   )r   r  r   r   r  r  r   tree_flattenru   r   AdditionalInputsverifyr  ShapesCollection)rd  r   r   r  r   original_in_specverify_additional_inputsout_dynamic_shapess           rn   _process_export_inputsr9    s    Z dE""''OPTUYPZ|\
 	
 )VrF --tn=A .%,,"?"?@@#1#8#8 +::3fM#2 nell&C&CDD!/!>!>s&!Q!/)?WWWrm   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~   rr   rs   r   r   r   r  r   rN   r   r   r   r  r  r  )r:  r  r;  r  rr   rh  r   r   r   r  r  specsmod_fqnresmodule_call_graphs                  rn   _get_module_call_graphrA    s     /3366B3B3G3G3K3K))  (//G(11H >@'--/
*<+c"#*=)$:&"+
' 0 )*Q.!$R($%;TUWX#////	   rm   c                 p   UR                   R                  nUR                   R                  nUR                  n[	        S [        UR                  5       5       [        UR                  5      5      n[        XU5      n	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   r2  )r  r   ss      rn   r  )_get_range_constraints.<locals>.<genexpr>3  s-      	
Evv--- AEs   $3	3)
r~   rr   rs   r   r  r   r   r   r7   r   )rd  r:  r   r   r  rr   rh  r   
num_liftedr  combined_args_traced_orderrs  r  range_constraintss                 rn   _get_range_constraintsrI  (  s      /3366B3B3G3G3K3K / 9 9I	
!"8"D"DE	

 	"../J "#V4M "$.;.@&+  *0+"'  /M(
 rm   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   rO  r  rB   )r   r  r   s      rn   _get_inline_constraintsrK  T  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__)rL  
new_methodoriginal_methods      rn   patch_forwardrR  ]  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   )ru   _C_jit_texpr_fuser_enabled_jit_set_texpr_fuser_enabled)original_states    rn   _temp_disable_texpr_fuserrX  o  sU     XX668N	HH))%0>--n=--n=s   >B	A%  B	%!BB	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  r{  r   NzbCannot find dynamo_fake_mode. This could be due to the exported graph module have no placeholders.T)static_shapes)r  r  r=  rt   r   r~   r   r   r   r   )4r  r   r   r   r   r   r   r~  r   r   ru   r  r  from_tensor_codegenrv   rE   pytree_infor   r  r  r  r   rG   	orig_argsrF   _in_specrt  r  r   r   r,  ra  r  r  r/   r.   r   rr   rs   rt   r   r  rk   r^  rx   r$  r   r  rC  ry  r|   )rd  r   r   r  r  rY  r`   rZ  r  r   r   dynamo_fake_moder-  r   r  r   orig_out_specr   params_buffers_to_node_metare  r   r,  tracedorigreverse_name_lookupr   txaten_export_artifactrr   rh  rt   s                                  rn   _strict_exportrl  y  s}    )'E4_	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   ra   r   s    rn   r  r    r  rm   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["        S	 5       nU   U" U5         U" 5          [%        USSS
9" U6 nS S S 5        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        URJ                  c   S5       e['        W5      n[M        U5      n#[O        [/        U5      [/        U5      UUS  U#[        [Q        USU	 U5      5      [        [Q        UXU
-    U5      5      0 0 0 UURJ                  S / / S9n$UU$4$ ! , (       d  f       GN= f! , (       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    rn   
wrapped_fnG_export_to_aten_ir_make_fx.<locals>._make_fx_helper.<locals>.wrapped_fn7  s    $((rm   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)r:  tracer)ru   rT  _is_torch_function_mode_enabledr   r   	overrides _get_current_function_mode_stackr?   rv  r=   proxycreate_proxyr   r   access_subclass_inner_tensordefaultr@   )
r   r  original_getattrattrs_to_proxyouttorch_function_mode_stackmoderv  rz  inner_proxys
             rn   custom_getattributeP_export_to_aten_ir_make_fx.<locals>._make_fx_helper.<locals>.custom_getattributeH  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 
rm   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   rk   dirru   r   __getattribute__r  r#  partialmethod)r   tensor_type_to_old_getattributers  subclass_types_to_instancessubclass_typeinstancer  r  old_getattrcustomr   r  s              rn   $override_getattribute_for_subclassesa_export_to_aten_ir_make_fx.<locals>._make_fx_helper.<locals>.override_getattribute_for_subclassesl  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c               3      #    [         R                  " 5       n  Sv   [         R                  R                  U 5        g! [         R                  R                  U 5        f = f7f)z
When pre-dispatch export accidentally change grad state, we restore it back.
This can happen when we are calling torch._C._set_grad_enabled directly in the
forward.
N)ru   is_grad_enabledrT  _set_grad_enabled)	old_states    rn   _maybe_restore_grad_stateV_export_to_aten_ir_make_fx.<locals>._make_fx_helper.<locals>._maybe_restore_grad_state  sA      "113	:HH..y9EHH..y9s   A!=  A!!AA!)record_module_stackrf  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   ru   r   profiler_record_function_enterr}  _record_function_enter_new_record_function_exit_RecordFunctionr~   detachr   r|  )r   s    rn   
_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 !rm   zout_spec.spec is None!r   )r]  r^  user_inputsuser_outputsinputs_to_parametersinputs_to_buffersbuffers_to_mutateparameters_to_mutateuser_inputs_to_mutater   r   backward_signaturer_  output_tokens))rx   r"  r$  r   r2  r  r   r$   r  r)   r#  r$  r
   r   r~  r+   r*   r   r>   r%   r   _buffersr  r  r   r   
_find_noder   r   ru   r   r~   copy_r}  r   removeeliminate_dead_coder   r&   r'   r0  )'rd  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   rs  r  non_strict_rootassigned_buffershookr  r  rr   input_namesr   r   bufbuffer_input_namesoutput_nodebuf_node	name_noder   r  output_namesrs   r  rr  s'                                        @@rn   _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 
: 
: 4Y?)+(,!% 	 , @  *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} (B }}(B*BB((,*2.,-'#JK0%!%c+a	*BDT&U!V"K	
,BC]S !!#"$]]#!
$ 3wS ,+ @? & @?C ('s   	AO	N-&N.N		=NN->ON?
N?
)A2OAO6:O	
NN
N*%N--
N<	7O
O	O
O'Tr  F)r  r   r   r   r   r   )rr   rd  re  r=  rf  r   r   r-  )ru   r  r  r  r  r   r   r   r   r   r   usersr   r   rv   rw   r}  r  rA   rH   r   r   r  ry   rj  )rd  r   r   r-  re  r  r  r  rr   r=  r   r  s               rn   _export_to_aten_ir_make_fxr    s   Uv 	  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   rI   )r   r   r   r   ru   r   r   )rr   r  num_params_buffersindexr   user_args         rn   r`  r`  -  sa     E77m#*$-?%?@!(ELL99'/IIe$QJE rm   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     rn   r  _find_node.<locals>.<genexpr>?  s     Jnd		T8ITTns   #	#)r  r  r   r   )rr   r   s    `rn   r  r  >  s!    JbhhnnJJKKrm   c                 H  ^^^^^^^^ SmSm0 mUUUU4S jn[        U UUTUS9u  mn	n
mmm[        TU 5      n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)	r\  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        [        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>.WrapperiY  c                 .   > [         TU ]  5         Xl        g r   )super__init__r   )r   rd  rO  s     rn   r  f_non_strict_export.<locals>._tuplify_outputs.<locals>._aot_export_non_strict.<locals>.Wrapper.__init__Z  s    G$&(+%rm   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   r2  r   ru   rv   rw   r5   _forward_pre_hooksr  	tracebackpreserve_node_metaInterpreterrunr  )	r   r   r   rd  r   tree_out	flat_outsr   r   s	          rn   r  e_non_strict_export.<locals>._tuplify_outputs.<locals>._aot_export_non_strict.<locals>.Wrapper.forward^  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   )rb   rc   rd   re   r  r  rl   __classcell__)rO  r   r   s   @rn   Wrapperr  Y  s    ,, ,rm   r  z_export_root.r   z%Exported program from AOTAutograd:
%sr   )ru   r  r  r   r   rv   rw   r#   r  debugr   r   r   r]  r^  r  r  r  r  r   r   r   r  r   )rd  r   r   r  r  wrapped_modr   new_preserved_call_signaturesr  rr   rs   r   r   r  r   
aot_exportr   r   r   r  s                  rn   _aot_export_non_strictL_non_strict_export.<locals>._tuplify_outputs.<locals>._aot_export_non_strictV  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!'-S55(C$ $		1&*ii0A&BO )/')%')"4)"HC #3,)"4DII/0 ' 7NC- $4s    I$I I'
I$r   ra   )r  r  r   r   r   r  s   ` rn   _tuplify_outputs,_non_strict_export.<locals>._tuplify_outputsU  s    D	 D	L &%rm   )r`   c                    > [        TU TTTS9$ )N)r   rr   r  equalities_inputsoriginal_signature)r   )rr   r  r  r   r  s    rn   _produce_guards_callback4_non_strict_export.<locals>._produce_guards_callback  s    3)/1
 	
rm   FrY   )r  r  r^  )r   r   r/   ri   r  r  r   r.   ru   r  r   r  r   r   r   rt   r  r   r0   r  rs   r|   )rd  r   r   r  r  rY  r`   rZ  r  r   r   r-  r  rj  dynamo_configpatched_modnew_fake_argsnew_fake_kwargsnew_fake_constant_attrsmap_fake_to_realrk  r  rL  r  r   r   r   r  r   s      ``                  @@@@@@rn   _non_strict_exportr  B  s$    $(H"&G?AG& G&` 	4_	 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   -H8H*G1.G 	<GF>*F-*F'.	F-7F>?GG 	G1HH'F--
F;7F>>
GG
GG 	 
G.*G11
G?;H
H	H
H!r  r  r`   r  c                   [        U 5      q[        XX#5      u  nnnnn[        U 5      n	U(       a  [        O[
        n
/ nU(       d  [        R                  R                  [        S5      S:X  ax  [        R                  " 5         [        R                  " 5        Vs/ s HC  n[        U[        R                  R                   R"                  5      (       d  M8  [%        U5      PME     nnU
" U UUUUUU[&        S9nUR(                  R*                  n[-        XU5      n[/        UR0                  5      nUUR(                  R2                  R4                  S'   [7        U UUUU5      n[9        UUUU5      u  nn[;        U5        [=        U5        [?        UU5        [A        UU 5        SSK!J"n  [G        UURH                  UU	UUX4UR(                  RJ                  U/S9	nU" U5        U(       Gd  [        R                  R                  [        S5      S:X  Gam  SSK&J'n  [        R                  " 5        Vs/ s H:  n[        U[        R                  R                   R"                  5      (       d  M8  UPM<     nn[P        RR                  " 5       nU H%  n[%        U5      U;  d  M  URU                  U5        M'     AA[W        U5      n/ n[Y        U5      S:  a  U Hq  n[%        U5      U;   d  M  U[%        U5         R4                  R                  S	S
5      nSURZ                   SUR\                   3nSU SU 3nUR_                  U5        Ms     SRa                  U5      n [b        Rd                  " S[Y        U5       SU  S35        AU$ s  snf s  snf )N01rd  r   r   r  r  rY  r`   rZ  inline_constraintsr   )TrainingIRVerifier	r  r   r=  
state_dictrH  r@  r'  rt   	verifiers)'_FAKE_TENSOR_ID_TO_PROXY_MAP_FOR_EXPORTr[  z<unknown stack trace>zshape=z, dtype=zFakeTensor(z): z
  z	Detected z fake tensors that are still alive after export.
This is likely result of torch.export.export not being able to track side effects that is happening outside of model scope.

Leaked tensors:
  zU

Alternatively, please file a bug report to PyTorch team for further debugging help.)3r  r  r9  r-  rl  r  osenvironr   rQ   gccollectget_objectsr   ru   _subclassesfake_tensor
FakeTensorr#  r  r~   rs   r  rK  r   rr   r   rI  rA  r  r  r	  r   torch._export.verifierr  rK   r   rt   "torch.fx.experimental.proxy_tensorr   weakrefWeakSetrm  r4   r   shapedtyper   r  warningswarn)!rd  r   r   r  r  r  r`   rY  r7  r+  export_func"alive_fake_input_ids_before_exportr   r:  rh  r  r  rH  rr   r@  r  exported_programr   fakes_afteractive_fakesr  
legit_leakleak_sourcesfake_valr[  
shape_info	leak_infoleak_detailss!                                    rn   _export_for_trainingr    sh     5S9 	s&A  337 %+.0BK46&bjjnn%DcJcQ


 ^^%.
%!U..::EEF BqE% 	+ .
 "%'E!4_0	O -1155.s&A01J1JK :LO  !56. 3&	B Bb"89C(9&hh.&++~!&&00%&
 -.bjjnn%DcJcQ	
 ^^%G
%!U..::EEF % 	 G
 )0(9&K+&HH  - ' .&El&S
"$z?Q&h<#JJ"I8#d33}.EF  
 $*(..)9(..AQ!RJ"-j\[M JI ''	2 ' ";;|4LMMC
O, -& '3^ 4fg Y.
HG
s   7M=M=+7N&N)r  r  rf  r`   rf  c                $  ^^ 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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[        R                  " [         US9S9nUR"                  R$                  n['        XU5      n[)        UR*                  5      nUUR"                  R,                  R.                  S'   [1        U UUUU5      n[3        UUUU5      u  nn[5        U5        [7        U5        [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.

    prefer_deferred_runtime_asserts_over_guards:
     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_strictrf  aot_dispatchzexport.enterr  r   c                      g)Nzstart!ra   ra   rm   rn   r  _export.<locals>.<lambda>  s    8rm   )
payload_fnr  r  c                     > [        T 5      $ r   ry   r0  s   rn   r  r"    s	    Rrm   )rf  r  r  T)in_place)Verifierr  c                     > [        T 5      $ r   r%  )r  s   rn   r  r"  "	  s    SAQ=Rrm   )'torch._utils_internalr  r  r  rk   rm  r  r3   r1   r  r9  r-  rl  r  r#  partialr  r~   rs   r  rK  r   rr   r   rI  rA  r  r  r	  ru   _exportr  remove_proxy_from_state_dictr	  r'  r   rK   r   rt   )rd  r   r   r  r  r  rf  r`   r  r  r6  r7  r+  r  r:  rh  r  r  rH  rr   r@  r'  r
  r  s                         @@rn   r+  r+    s0   r G  5S9EE	II&hl3	IIn.AM>?h+;< 8::!+I8c
 	,I	 	s&A  337 %+.0BK!%'E%4_''%
O 4C3G3G3K3K.s&A01J1JK :LO  !56. 3&	B Bb"89 
MM445HSW4X/C(&hh.&++~!&&00*
 (5RS-.rm   r   )NN)ri   r#  r  r  loggingr  r  r  r  r  r  
contextlibr   r   typingr   r   r   r   typing_extensionsr	   ru   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   rL  r   r   r   r   r   r   r    r!   r	  r"   torch._export.wrappersr#   5torch._functorch._aot_autograd.graph_capture_wrappersr$   4torch._functorch._aot_autograd.input_output_analysisr%   r&   &torch._functorch._aot_autograd.schemasr'   -torch._functorch._aot_autograd.subclass_utilsr(   $torch._functorch._aot_autograd.utilsr)   r*   torch._functorch.aot_autogradr+   r,   torch._guardsr-   r.   r/   "torch._library.fake_class_registryr0   torch._loggingr1   torch._subclasses.fake_tensorr2   r)  r3   %torch.export._leakage_detection_utilsr4   torch.export._unliftr5   torch.export.dynamic_shapesr6   r7   r8   r9   r:   torch.export.exported_programr;   torch.fx._symbolic_tracer<   r
  r=   r>   r?   r@   rM  rA   rB   rC   rD   torch.fx.graphrE   rF   rG   torch.utils._sympy.value_rangesrH   r  rJ   rK   rL   rM   rN   r=  rO   rP   	getLoggerrb   r  rQ   rx   ry   r  r  rR   rh   	dataclassrT   rp   r|   r  criticalr  r  	exceptioninfowarningr  r  rX   r   r   r   r   r   rv   rw   r   r   r   r   r   r  r  r  r,  r   r;  rC  rV  rj  ry  r  r  r  r  rg   r  r  r  rk   ra  r  r  r  r  r	  r  r  r  r%  r)  r-  objectr   r3  r5  r9  rA  rI  rK  rR  rX  rl  r  r`  Noder  r  r  r+  ra   rm   rn   <module>rU     si     	   	 	 
    2 1 1 '    $ $ ; 6	 	 	 Q	 	 	 6 3 X B W D C ? , 8 2 Q B  5 ;   7 ( ;  V !"C  !&d38neCHotCy&P Q I Q > > >. 1 1 1 d#= = $=  23 MMMMLLKKOO	MM
>  : ; ; B BC(.!5!5 .0S (+-\:	1h"XX__"88??" 
#s(^"J$,$,	$, 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	*	$
 
/$4	4 	 (,MQ	Y 79&+8="YY
S/Y T#s(^$Y U4S>5:tCy#HIJ	Y %*#s(OY  $Y 26Y Y Y Y XXYD !S (,(-S	S
 $S "&S "&S Sr (,	
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 AX	AX

AX T#v+&'AX LL))LL))+	
	AX 	&#+f o$%	'AXP .2	,!#,!$)#s(O,! ,!  S	*	,!
 588o!667,!^)	)#)X~  &uxx & &" > >W	W
S/W cNW U4S>5:tCy#HIJ	W
 %*#s(OW W 26W W W@ !W	W
 $W Wt"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 26l l l^  (,MQ	J 688=J	J
S/J T#s(^$J U4S>5:tCy#HIJ	J J %*#s(OJ 26J J   JZ  (,MQ	c 688=c	c
S/c T#s(^$c U4S>5:tCy#HIJ	c c %*#s(Oc c 26c c   crm   