
    N j                        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  S SK	J
r
Jr  S SK Jr  S SKJrJrJrJr  S SKJrJr  S SKJr  S SKJr  S S	KJrJrJr  S S
KJr  S SKJ r   S SK!J"r"  S SK#J$r$J%r%  S SK&J'r'J(r(  S SK)J*r*  \(       a
  S SK+r+S SK,J-r-  S SK.r.S SK/J0s  J1r2  S SK3J4r4J5r5J6r6J7r7J8r8J9r9J:r:J;r;J<r<J=r=J>r>J?r?J@r@JArAJBrBJCrC  S SKDJErE  S SKJFrF  S SKJGrG  S SKHJIrIJJrJ  S SKKJLrL  S SKMJNrN  S SKOJPrP  S SKQJRrR  SSKSJTrTJUrUJVrVJWrWJXrXJYrYJZrZJ[r[J\r\J]r]J^r^J_r_J`r`  / SQra\
\.R                  R                  /\PS-  4   rd\R                   " S S5      5       rf\R                   " S S 5      5       rgS! rhS"\iS-  S#\2R                  S$\iS-  S%\2R                  S&\k4
S' jrl\.R                  R                  R                  \.R                  R                  R                  \.R                  R                  R                  \.R                  R                  R                  \.R                  R                  R                  \.R                  R                  R                  \.R                  R                  R                  \.R                  R                  R                  \.R                  R                  R                  \.R                  R                  R                  \.R                  R                  R                  \.R                  R                  R                  /r{\.R                  R                  R                  \.R                  R                  R                  \.R                  R                  R                  \.R                  R                  R                  \.R                  R                  GR                   \.R                  R                  GR                  \.R                  R                  GR                  \.R                  R                  GR                  \.R                  R                  GR                  /	r\S( 5       rS)\\.GR                  GR                  \
4   S&\\\.GR                  GR                  \
4   S*4   4S+ jrSFS, jrS-S.S/\\.GR                  GR                  \
4   S0\\.GR                  GR                  \
4   S1\S-  4S2 jrS3\.R                  R                  S4\WS&\\.R                  R                  \W4   4S5 jrS3\.R                  R                  4S6 jrS7\.R                  R                  S8\WS3\.R                  R                  S9\WS:\\g   4
S; jrS/\\.GR                  GR                  \
4   S0\\.GR                  GR                  \
4   S1\S-  S<\k4S= jr " S> S.5      rS? r SGS3\.R                  R                  S@SAS&SB4SC jjrSD rSE rg)H    N)defaultdict)CallableIterator)contextmanager)Anyfinal
NamedTupleTYPE_CHECKING)tracingTracingContext)autograd_not_implemented)FakeScriptObject)_deregister_op_impl_is_op_registered_to_fake_ruleregister_op_impl)FakeTensorMode)_ConstantAttributeType)#first_call_function_nn_module_stack)_PyTreeCodeGen_PyTreeInfo)immutable_dictimmutable_list)insert_deferred_runtime_asserts)ValueRanges)_build_cache_collect_all_valid_cia_ops_collect_and_set_constant_attrs_collect_param_buffer_metadata_detect_fake_mode_from_gm_fakify_params_buffers_get_decomp_for_cia_is_preservable_cia_op_name_hoo_subgraph_placeholders7_override_graph_signature_for_temp_registered_constants/_overwrite_signature_for_non_persistent_buffers)_populate_param_buffer_metadata_to_new_gm_register_constants_as_buffers_rename_without_collisions_special_op_to_preserve_ciaplaceholder_naming_pass)Verifierdetect_fake_modeunset_fake_temporarily)is_equivalentreorder_kwargsCustomDecompTable)compatibility)
PassResult)PassManager   )ArgumentSpecConstantArgumentCustomObjArgumentExportGraphSignature	InputKind	InputSpec
OutputKind
OutputSpecSymBoolArgumentSymFloatArgumentSymIntArgumentTensorArgumentTokenArgument)ExportedProgramModuleCallEntryModuleCallSignaturedefault_decompositionsc                       \ rS rSr% \\   \S'   \\   \S'   \R                  \S'   \R                  \S'   Sr	\\
   S-  \S'   S rS	rg)
rG   a   inputsoutputsin_specout_specNforward_arg_namesc                    U R                    H0  nUR                  UR                  :X  d  M  UR                  Ul        M2     U R                   H0  nUR                  UR                  :X  d  M  UR                  Ul        M2     g N)rK   namerL   )selforiginal_nodenew_nodeios        n/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/torch/export/exported_program.pyreplace_all_uses_with)ModuleCallSignature.replace_all_uses_withi   sZ    Avv+++!  Avv+++!      )__name__
__module____qualname____firstlineno__listr8   __annotations__pytreeTreeSpecrO   strrY   __static_attributes__r\   r[   rX   rG   rG   a   sE    ,__oo*.tCy4'.'r[   rG   c                   4    \ rS rSr% \\S'   Sr\S-  \S'   Srg)rF   r   fqnN	signaturer\   )	r]   r^   r_   r`   re   rb   rj   rG   rf   r\   r[   rX   rF   rF   r   s    	H,0I"T)0r[   rF   c                 F   ^  [         R                  " T 5      U 4S j5       nU$ )Nc                  ^   > [        5          T" U 0 UD6sS S S 5        $ ! , (       d  f       g = frQ   r.   )argskwargsfns     rX   wrapper/_disable_prexisiting_fake_mode.<locals>.wrappery   s"    #%t&v& &%%s   
,)	functoolswraps)ro   rp   s   ` rX   _disable_prexisiting_fake_modert   x   s%    __R' ' Nr[   
spec1_typespec1_context
spec2_typespec2_contextreturnc                 .   U b  Uc  XL =(       a    X:H  $ [        U [        [        45      (       a  [        U[        [        45      (       a  X:H  $ [        U [        [        45      (       a  [        U[        [        45      (       a  X:H  $ XL =(       a    X:H  $ )z]Treat containers and their immutable variants as the same type. Otherwise
compare as normal.
)
issubclassdictr   ra   r   )ru   rv   rw   rx   s       rX   _fx_collection_equivalence_fnr}      s     Z/'JM,JJ*t^455*T>*; ; --*t^455*T>*; ; --#F(FFr[   c           	   #     #    0 n[        5       nU R                  5        GH  u  p4UR                  R                  5       X'   UR	                  U5        [
         H3  nXSR                  ;  d  M  UR                  U5      " [        USS95        M5     [        U5      n[        R                  R                  R                  UR                  ;   a/  UR                  [        R                  R                  R                  	 UR                  [        R                  R                  R                  5      " U5        S n[        U5      (       d$  [        U5      " [        R                   " UUS95        ["         H+  nXR                  ;  d  M  UR                  U5      " U5        M-     GM      S v   U H_  n	U	R                  R%                  5         U	R                  R'                  X   5        U	R(                  R%                  5         [+        U	5        Ma     g ! U H_  n	U	R                  R%                  5         U	R                  R'                  X   5        U	R(                  R%                  5         [+        U	5        Ma     f = f7f)NT)deferred_errorc                 \    US   nUS	 U    U" U0 UD6sS S S 5        $ ! , (       d  f       g = f)Noriginal_callabler\   )fake_tensor_modeoprm   rn   orig_cia_callables        rX   $_force_dispatch_to_orig_cia_callableQ_override_composite_implicit_decomp.<locals>._force_dispatch_to_orig_cia_callable   s3     &': ;*+!($9&9 "!!s   
+)r   )setitems
py_kernelscopyadd(_AUTOGRAD_ALIAS_BACKEND_KEYS_TO_OVERRIDEpy_implr   r!   torch_CDispatchKeyCompositeImplicitAutogradr   r   rr   partial_BACKEND_KEYS_TO_OVERRIDEclearupdate_dispatch_cacher   )
cia_ops_to_callablesaved_tablespatched_opsop_overloaddecomp_callableoverride_dispatch_keyr   r   keyr   s
             rX   #_override_composite_implicit_decompr      s     L%K(;(A(A(C$$/$:$:$?$?$A!$%M!$,B,BB##$9:,[N &N 0<8899[=S=SS&&uxx';';'U'UVEHH00JJK	
	: .k::[)!!8&7 -C000  ##C():;# -Y )D~$BMM!MM  !12$$&#	 +BMM!MM  !12$$&#	 s-   A&I:,DI: I:&H *A&I:A'I77I:decomp_table.c                 l   [        [        5       5      n0 n[        U R                  5       5       Ho  nX1;   a  X   X#'   UR	                  U5        X	 M#  [        U5      (       d  M5  UR                  5       nUR                  S5      (       a  [        SU 35      eX   X#'   Mq     U H  n[        X%'   M     X 4$ )Natenz)This should be a custom op, got aten op: )
r   r   ra   keysremover"   rR   
startswithAssertionErrorr)   )r   all_preservable_cia_opsr   r   op_nameks         rX   ,_split_decomp_table_to_cia_and_python_decompr     s     ""<">?<$$&'$ (&2&6##**2.  $B''ggiG!!&))$?yI  '3&6#? (F %!< % ,,r[   c                      [        5       $ )z
This is the default decomposition table which contains decomposition of
all ATEN operators to core aten opset. Use this API together with
:func:`run_decompositions()`
r2   r\   r[   rX   rH   rH   B  s     r[   eprE   cia_to_decomppython_decomp_tablejoint_loss_indexc                b!   SSK Jn  SSKJn  SSKJnJnJn	Jn
J	nJ
n  SSKJn  S nU" X5      (       GdU  U R                  5       n0 [        UR                  SS95      E[        UR!                  SS95      EnSS	KJn  U" U5        0 [        UR                  SS95      E[        UR!                  SS95      En['        U R(                  5      nUc  [+        U" 5       S
S9nUR,                  n[/        UR0                  R2                  [4        5      (       d+  [7        S[9        UR0                  R2                  5       35      eUR0                  R2                  R:                  R<                  nUc  [7        S5      eUR8                  [>        [@        4;  a  [B        RD                  " U/5      n[5        [G        UURH                  U5      5      UR0                  l        URK                  5         [M        U RN                  U RP                  U5        [S        XRT                  U RN                  RV                  5      n[Y        UU5      n[[        U5      nSSK.J/nJ0n  / nUR0                  Rb                   H  nURd                  S:X  d  M  [/        URf                  S   [h        5      (       ay  S nURf                  S   Rj                  c'  U RP                  URf                  S   Rl                     nO#URf                  S   Rj                  Rn                  nURq                  U5        M  URq                  URf                  S   5        M     [s        U5      nU   [u        U5         U" U Rv                  5         [y        U5         [B        Rz                  " UURH                  5      nU" U/ US   QUS   R}                  5       Q70 U5       u  n n!n"n#n$U" U U!U"UU#USUS9n%U%RP                  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(        U%R                  n(U%R                  n)[        U)U5      n)[        UU(U)5        [        U RN                  U)5      n)U" U(U)U#5      n*[        U(U)U U!U"UU*5        S S S 5        S S S 5        S S S 5        S S S 5        S S S 5        U
" W(5        U" U(5        U" U(W)5        [        U(U)5      u  n(n)0 U RT                  EUR                  5        V+V,s0 s H  u  n+n,U+U;  d  M  U+U,_M     sn,n+En-UR                  5        Hf  u  n+n,U+U-;  a9  [/        U,[        R                  R                  5      (       a  [7        SU+< S35      eU+U-;   d  MM  U+U;  d  MU  U-R                  U+5        Mh     U(U)U-4$ U R(                  R0                  Rb                   Vs/ s H  nURd                  S:X  d  M  UPM     n.nU. Vs/ s H  nURf                  S   PM     n/nU R(                  R!                  5        V+V0s/ s H  u  n+n0U+PM
     n1n+n0U1 H  n+[        U R(                  U+5        M     [        U/5      n2U2c  [        R                  " 5       OU2n3U(       a  [        R                  OUn4U	" 5          U3   [u        U5         U4" 5          U" U R(                  U/UUS LUb  UOS S9u  n(n5[/        U([        R                  R                  5      (       d   eU(R0                  R                  5         S S S 5        S S S 5        S S S 5        S S S 5        S n6W(R0                  Rb                   Vs/ s H  nURd                  S:X  d  M  UPM     n7n[A        U(R0                  R                  5       R                  S   5      n8[        U75      [        U.5      :w  a#  [7        S[        U75       S[        U.5       35      e[        U.U75       H  u  n9n:U9Rl                  =U:l6        U:lW        M      0 n;[        [        5      n<[        5       n=U7 H3  n>U>Rl                  U;U>Rl                  '   [        U>Rl                  U<U=5        M5     U(R0                  Rb                   H=  nURd                  S:X  a  M  [        U;U<U=URl                  URl                  5      Ul6        M?     [        U(5        SSK^J_n?J`n@  SSKaJbnA  [        R                  R                  R                  (       dY  SnB[        U(5      nCUCbI  W@" U([        R                  " U?SWB0S95         [        U(WCS[        U(R0                  5       3S
S9  S S S 5        U(RK                  5         [        U8WA" U(5      5       H  u  nDn+U+c  M  U+WDl6        M     [        U RN                  R                  5       VEVFs0 s HK  u  nEnF[/        UFR                  [        5      (       a  M'  WFR                  Rl                  U7WE   Rl                  _MM     nGnEnF[        U RN                  R                  5       VEVFs/ s HF  u  nEnF[        UFR                  U6" UFR                  U7UE   5      UFR                  UFR                  5      PMH     nHnEnF/ nI[        W5R                  5       VEV+s0 s H	  u  nEn+U+UE_M     nJnEn+[?        U5R                  R                  5       5      nKU8S [        UK5        Vs/ s H  nURl                  PM     nLnWKUL:w  a  [7        S WK S!WL 35      eU5R                  R                  5        GH
  u  nMnNWJUN   nEU RN                  R                  UE   nOUOR                  [        R                  [        R                  4;  a  [7        S"WOR                   35      eWOR                  [        R                  :X  a  [        R                  O[        R                  nPWOR                  [        R                  :X  a  WOR                  OWOR                  Rl                  nQWIRq                  [        WP[        WMS#9UQS$95        GM     [        U RN                  R                  5       H  u  nEnFWIRq                  [        UEU:X  a  [        R                  OWFR                  U6" WFR                  U8[        WK5      WE-      5      WGR                  UFR                  UFR                  5      5      5        M     UGb  U5GR                   c  [7        S%5      eU5GR                   GR                  nR[        U5R                  5      [        U RN                  R                  5      :w  aA  [7        S&[        U5R                  5       S'[        U RN                  R                  5       35      e[        U RN                  R                  5       VEVFs0 s H7  u  nEnF[/        UFR                  [        5      (       d  M'  U5R                  WE   WF_M9     nSnEnFU8[        WI5      S   H  nWRURl                     nTWSUT   nFUFR                  [        GR                  :X  a  [        GR                  nUWFR                  nQOJWFR                  [        R                  :X  a  [        GR                  nUWTnQO[7        S(WFR                   35      eWIRq                  [        WU[        URl                  S#9WQ5      5        M     [        U75      [        U.5      :w  a#  [7        S[        U75       S[        U.5       35      eG[        WHWIS)9n)[        U.U75       H  u  nVnW[/        UVRf                  S   [        GR                  5      (       d  WVRf                  S   WWRf                  S'   WWR                  U)GR                  ;   d  WWR                  U)GR                  ;   d  M  WVRf                  R                  5        H  u  nXnYUYWWRf                  UX'   M     M     U(U)U RT                  4$ s  sn'n&f ! , (       d  f       GNO= f! , (       d  f       GNY= f! , (       d  f       GNc= f! , (       d  f       GNm= f! , (       d  f       GNw= fs  sn,n+f s  snf s  snf s  sn0n+f ! , (       d  f       G	ND= f! , (       d  f       G	NN= f! , (       d  f       G	NX= f! , (       d  f       G	Nb= fs  snf ! , (       d  f       GN_= fs  snFnEf s  snFnEf s  sn+nEf s  snf s  snFnEf )*Nr   )_materialize_and_lift_constants)aot_export_module)2_disable_custom_triton_op_functional_decomposition_export_to_aten_ir_ignore_backend_decomps_verify_nn_module_stack_verify_placeholder_names_verify_stack_trace)ShapeEnvc                 H    US L=(       d    U R                   R                  S L$ rQ   )graph_signaturebackward_signature)r   r   s     rX   _is_joint_ir_decompO_decompose_and_get_gm_with_new_signature_constants.<locals>._is_joint_ir_decomp_  s)    D( A!!44D@	
r[   F)remove_duplicate)!unwrap_tensor_subclass_parametersT)	shape_envexportz6expected mod.graph._codegen to be _PyTreeCodeGen, got zout_spec must not be None)&_enable_graph_inputs_of_type_nn_module_fakify_script_objectsplaceholdervalr7   )r   _prettify_placeholder_namesdecompose_custom_triton_opsz	expected z6 not to be a torch.nn.Parameter when not in state_dict)decompositionstrace_jointoutput_loss_indexc                    [        U [        5      (       a  U $ [        U [        5      (       a  [        UR                  S9$ [        U [        5      (       a  [	        UR                  S9$ [        U [
        5      (       a  [        UR                  S9$ [        U [        5      (       a  [        UR                  S9$ [        S[        U 5       35      e)NrR   zType of old_arg not supported: )	
isinstancer9   rC   rR   rB   rA   r@   RuntimeErrortype)old_argnew_phs     rX   
update_argF_decompose_and_get_gm_with_new_signature_constants.<locals>.update_argf  s    g/00N00!v{{3300!v{{33!122#5511"44<T']OLMMr[   znew_placeholders length z( does not match old_placeholders length )_node_metadata_hook_set_node_metadata_hook)_graph_output_nameszUFile "torch/fx/passes/runtime_assert.py", line 24, in insert_deferred_runtime_assertsstack_trace)metadatazexported program: )r   zmutation_names z does not match expected z9expected input_spec.kind to be USER_INPUT or BUFFER, got r   )kindargtargetzPgraph_signature.backward_signature must not be None when joint_loss_index is setz#graph_signature.user_inputs length z# does not match input_specs length zUnknown input kind: input_specsoutput_specs)(torch._export.passes.lift_constants_passr   torch._functorch.aot_autogradr   torch.export._tracer   r   r   r   r   r   %torch.fx.experimental.symbolic_shapesr   moduler|   named_parametersnamed_buffers7torch._functorch._aot_autograd.subclass_parametrizationr   r   graph_moduler   	_out_specr   graph_codegenr   r   r   pytree_info	orig_argsra   tuplerc   treespec_tupler   _in_spec	recompiler   r   	constantsr'   
state_dictnon_persistent_buffersr    r   torch._export.non_strict_utilsr   r   nodesr   metar:   fake_valrR   real_objappendr   r   example_inputsr   tree_unflattenvaluesr   r   gmsigr$   r&   r%   r*    _remove_unnecessary_copy_op_passr   nn	Parameterpopdelattrr-   
contextlibnullcontextfxGraphModuleeliminate_dead_codeoutput_noderm   lenzipr   r   intr   r   r(   r#   (torch._export.passes._node_metadata_hookr   r   4torch._functorch._aot_autograd.input_output_analysisr   _dynamoconfigdo_not_emit_runtime_asserts_get_shape_envrr   r   r   r   	enumerater   r   r9   r=   r   
persistentuser_inputsuser_inputs_to_mutater   r<   
USER_INPUTBUFFERr>   BUFFER_MUTATIONUSER_INPUT_MUTATIONr?   rC   r   LOSS_OUTPUTgetr   gradients_to_user_inputs	PARAMETERGRADIENT_TO_PARAMETERGRADIENT_TO_USER_INPUTr;   Tensorinputs_to_parametersinputs_to_buffers)Zr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   modwrapped_params_buffersr   unwrapped_params_buffers	fake_moderN   orig_arg_namestemp_registered_constantsfake_params_buffersparams_buffers_to_node_metar   r   retracing_argsnodereal_script_objtxretracing_args_unwrappedpatched_modnew_fake_argsnew_fake_kwargsnew_fake_constant_attrsmap_fake_to_realaten_export_artifactri   objr   new_graph_signaturer   rR   pnew_state_dictold_placeholders	fake_args_buffers_to_removefake_mode_detfake_mode_ctx#custom_triton_ops_decomposition_ctxr   r   new_placeholdersnew_outputsold_phr   name_mapfind_available
used_namesphr   r   r   r   r   outputrV   specold_new_placeholder_mapr   r   user_inputs_indexmutation_namesexpected_namesoutput_name
input_name
input_specoutput_kindr   	gradientsspecssourcer   old_noderU   r   vsZ                                                                                             rX   2_decompose_and_get_gm_with_new_signature_constantsrX  K  s,    Y?  ?
 r44iik"
3'''?@"
3$$e$<="

	
 	*#.$
3'''?@$
3$$e$<=$
  .boo>	&DII ==#)),,n== HciiN`N`IaHbc  ++77AA  !<====u-,,hZ8H+
		 	
 	((:(:BLL#N %C 2 2 I I%
!
 5YD&DS&I#
	

 IIOODww-'dii.0ABB&*Oyy'008*,,,tyy7G7L7L*M*.))E*:*C*C*L*L"))/:"))$))E*:; $ I& / 323D3DEBK'-'<'<($ (-a0-a0779 ' '9!#'+!4050K	($$ %9$B$B$H$H$J2 %KS %c+;<< )- !
 %K2$. *,,&:&>&>#
 L+-F $ :/5H
 'V&&(;'# <+-D	 ('!#'y  F b 	 #B!"&9:"B##

mm
  8==??GD!55 a?
 .335GD!>)a!3!344(#D8+ab  ~%77"&&t, 6 &66 ..444=8P4   /??.>d5!.>I?-/__-J-J-LM-L'$-LM!& " %Y/M0=0EJ**,=M ' 	? ( 	 !+M:+-/OO.(4$4$@ d	
O "ehh223333
$$& 	. 	; 	 	"(N *,T477m;ST-22883G3G3I3N3Nq3Q-RK $4 55&s+;'<&==efijzf{e|}
 	
 .0@A&,kk1fm B H%0%5N5JGGRWWnj9  77m#.nj$))TYY
	  $B' Y==;;1 	 #2&	 (!!'=+2N 0()LRXX)V(WX	 LLNK)<R)@AFK B !!3!3!?!?@@GAt$(($45 	0'*///@   !!3!3!?!?@ AGAt 	IItxx!1!!45KKOO		
 A   L 1:/:U:U0VW0VWQq0VW/??DDFGN,78M#n:M,NO,NDdii,NNO'n--F~FVW
 	
 $3#H#H#N#N#PZj)''33A6
??9#7#79I9I"JJ KJOOK\] 
 )"2"22 &&// 	 )"2"22 $$ 	
 	 "4	
# $Q4 R//<<=4*+/?*?
&&TYY488[^1Dq1H%IJ'++DKKE	
 > #--5 b  $66OO	**+s23E3E3Q3Q/RR 5c/:U:U6V5W X&&)"*<*<*H*H&I%JL  %R%7%7%C%CD
D4$((N3 1O''*D0D 	 

  L 1 34Dtyy)F=DyyI///!77i222!88$';DII;%GHH"		2 5& $4 55&s+;'<&==efijzf{e|}
 	
 /l ""24DE((--.==#+==#7HMM%  OO2GGG"5"G"GG ++-1#$a  . F "BMM11}	27  K FE  ID* @M  	.- 	;: 	 	"!B UV *" XOf
sj  A@;%)1A	71(*~?A+=	);A@-A@>A@+A@%A@%A@*A@/=AA+ AAAAA$A@5	8AA AAAA+3AA=AA=#AB&AB6(ABAAB-AB 3AB&&AB+,AB+?
	
&!))
83;;
A@
	@A@@
A@@5
AA@?AAA
AAAAAA
AA(	A#AA+A+
AA:B
ABr   r8  c                 (   U R                  UR                  5       5         U R                  R                   GH*  nUR                  S:X  d  M  [
        R                  " UR                  5      u  p4U H  n[        U[        R                  R                  5      (       d  M.  UR                  UR                  ;   d  UR                  UR                  ;   d  Md  UR                  S:X  d  Mv  UR                  [        R                   R"                  R$                  R&                  L d  M  UR)                  UR                  S   5        U R                  R+                  U5        M     GM-     U R-                  5         SSS5        X4$ ! , (       d  f       X4$ = f)zI
Removes redundant copy_ node that was introduced due to mutated buffer.
rI  call_functionr7   N)_set_replace_hookget_replace_hookr   r   r   rc   tree_flattenrm   r   r   r  NoderR   buffers_to_mutateparameters_to_mutater   opsr   r   defaultrY   
erase_noder   )r   r8  r-  rm   r=  outs         rX   r   r   0  s    
		1BBD	EHHNNDww(" --dii8C!#uxx}}55$7$I$II88':'O'OO  FFo5 #

eiinn.A.A.I.I I55chhqkBHH//4   # 	 
F  ""! 
F	E  ""s+   )FAF2FF'9F$AF
Fc           	         U R                  UR                  5       5         U R                  5        GH   n[        U[        R
                  R                  5      (       d  M/  0 n0 n[        UR                  R                  5       H  nUR                  S:X  a  UR                  [        R                  L a  UR                  u  pxXG    SU 3n	X;   af  UR                  XY   5        U H0  n
U
R                   c  M  U
R                   R                  XeU	   5        M2     UR                  R#                  U5        M  XeU	'   XU'   M  UR$                  XF'   M     GM#     S S S 5        g ! , (       d  f       g = f)NrZ  .)r[  r\  modulesr   r   r  r  ra   r   r   r   r   operatorgetitemrm   rY   rj   rc  rR   )r   r   module_call_graphr   node_idgetitemsr-  rU  idxnew_identrys              rX    _common_getitem_elimination_passrp  I  s#    
		o>>@	AjjlFfehh&:&:;;02G13HV\\//077o-$++AQAQ2Q"&))KF '0#7F)2283CD%6E$: % E E$(6*:!" &7
 //5+/((.$(IIGM! 1 # 
B	A	As   CE6A E
E-old_gmold_graph_signaturer   old_module_call_graphc                   ^^ [         R                  " U5      nU R                  R                   Vs0 s H  ofR                  U_M     nn0 TR
                  ETR                  Em0 UR
                  EUR                  En0 n	Sn
U R                  R                   Vs/ s H   ofR                  S:X  d  M  UR                  PM"     nn[        [        UU4S jU5      5      nUR                  R                   Vs/ s H   ofR                  S:X  d  M  UR                  PM"     nnUR                  R                   GH  nUR                  R                  S/ 5      =n(       a  UR                  XS   R                  '   MD  UR                  S:X  d  MV  UR                  U;   a  Mh  UR                  UR                  ;   a  M  UR                  U;   d  M  [        UR                  [        5      (       d!  [!        S[#        UR                  5       35      eX   n[        U[        5      (       d  [!        S[#        U5       35      eUR                  X'   U
S-  n
GM     [%        [        5      nUR'                  5        Hb  u  nnUR)                  S	5      (       d  UT;   a  UU	U'   M)  M+  S
R+                  UR-                  S
5      SS 5      nUU   R/                  U5        Md     U GH  nUR0                  nUc  M  / UR2                  QUR4                  Q GHX  nUR                  U;   a  [7        SUR                   S35      eUR                  U	;   a  U	UR                     Ul        MS  UR                  U;   d  Me  UUR                     nUR                  S:X  d  M  UR                  [8        R:                  R<                  R>                  R@                  [8        R:                  R<                  R>                  RB                  [8        R:                  R<                  R>                  RD                  4;   d  GM   URF                  S   R                  nUU	;  a  [7        SU S35      eU	U   Ul        GM[     GM     U$ s  snf s  snf s  snf )Nr   r   c                 :   > U T;  =(       a    U TR                   ;  $ rQ   )input_tokens)xold_graph_params_buffersrr  s    rX   <lambda>0_get_updated_module_call_graph.<locals>.<lambda>  s$    a77 :,999:r[   	from_nodez"expected node.name to be str, got z!expected old_name to be str, got r7   zparametrizations.rf  zIt looks like z is a tensor subclass. Preserving submodule that takes subclass parameter is not supported in inference IR because we desugar them, resulting in more tensorsrZ  )$r   deepcopyr   r   rR   r"  r#  r   r   ra   filterr   r  rv  r   re   r   r   r   r   r   joinsplitr   rj   rK   rL   
ValueErrorr   ra  r   todtype_layoutdevicedtyperm   )rq  rr  r   r   rs  new_module_call_graphr-  	old_nodesnew_graph_params_buffers
provenanceuser_input_counterold_user_input_namesnew_user_input_nameshistoryold_nameold_param_to_desugaredrR   r   
old_targetro  rj   rw  rV  rx  s    `                     @rX   _get_updated_module_call_graphr  f  s    !MM*?@-3\\-?-?@-?TD-?I@ 

2
2 

/
/  

.
. 

+
+  "$J & 2 2 2gg6N 2    : 	
 !# .'']2J   iimmK4474+/99Jr{''(
 WW%77;;/">">>;;"66%dii55,@dii@QR   4GH%h44,?X?OP  ,099J(&!+&/ 8 ).0668f  !455//#'
4  0 &,,s"3Ab"9:J":.55d; 9 'OO	89##8i&7&78A vv// $QVVH -Z [  vv##AFF+ 9$$QVV,;;/1hooIINN%%22IINN%%,,IINN%%++J 7
 "*q!1!6!6J!3(,ZL 9b c  (
3AFG 9	 'R ! _ A s   Q+Q00Q04Q5Q5r   c                h   [        U UUUUS9u  nnn[        U R                  U R                  UUU R                  5      nUR
                  R                  U R                  R
                  5        [        UU R                  5      n	[        UUR                  UUU	UU R                  U R                  S9n
U
$ )Nr   r   r   r   )rootr   r   r   range_constraintsrj  r   r   )rX  r  r   r   rj  r   r   _get_updated_range_constraintsr  rE   r   r   r   )r   r   r   r   r   r   r8  r   r  new_range_constraintsexported_programs              rX   _decompose_exported_programr    s     	;
#/)$?		
 ;



 GGNN2??''(:


 'hh+//((,,	 r[   c                   	   \ rS rSr% Sr\R                  R                  \S'    \	\S'    \
\\4   \S'    S\S'    \\   \S'    \\\S	4   \
\\4   4   S
-  \S'    \
\\4   \S'    \\\      \S'    \\   \S'     SOS
S.S\R&                  R(                  \
\\4   -  S\R                  R*                  S\	S\
\\R,                  \R&                  R.                  -  4   SSS\\   S\\\S	4   \
\\4   4   S
-  S\
\\4   S
-  S\\\      S
-  4S jjjr\\" SS9S 5       5       r\R8                  \" SS9S 5       5       r\\" SS9S 5       5       r\R8                  \" SS9S  5       5       r\\" SS9S! 5       5       r\R8                  \" SS9S" 5       5       r\\" SS9S# 5       5       r\R8                  \" SS9S$ 5       5       r\" SS9S%\ \R&                  R.                     4S& j5       r!\" SS9S%\ \\\R&                  R.                  4      4S' j5       r"\" SS9S%\ \R,                     4S( j5       r#\" SS9S%\ \\\R,                  4      4S) j5       r$\\" SS9S* 5       5       r%\%R8                  \" SS9S+ 5       5       r%\\" SS9S, 5       5       r&\&R8                  \" SS9S- 5       5       r&\\" SS9S. 5       5       r'\'R8                  \" SS9S/ 5       5       r'\\" SS9S0 5       5       r(\(R8                  \" SS9S1 5       5       r(\\" SS9S%\4S2 j5       5       r)\)R8                  \" SS9S3 5       5       r)\\" SS9S%\4S4 j5       5       r*\*R8                  \" SS9S5 5       5       r*\\" SS9S6 5       5       r+\+R8                  \" SS9S7 5       5       r+\\" SS9S8 5       5       r,\,R8                  \" SS9S9 5       5       r,\\" SS9S: 5       5       r-\-R8                  \" SS9S; 5       5       r-S< r.S=\S>\S%\4S? jr/S=\S>\S%\4S@ jr0S%\4SA jr1SPS%\R                  R                  4SB jjr2SC r3\4  SQSD\
\Rj                  Rl                  \74   S
-  SE\8S%S 4SF jj5       r9SG\:S%S 4SH jr;SI r<\" SS9SJ 5       r=\>SK 5       r?S
S
S
SL. SRSM jjr@SNrAg
)SrE   i  a  
Package of a program from :func:`export`. It contains
an :class:`torch.fx.Graph` that represents Tensor computation, a state_dict containing
tensor values of all lifted parameters and buffers, and various metadata.

You can call an ExportedProgram like the original callable traced by
:func:`export` with the same calling convention.

To perform transformations on the graph, use ``.module`` property to access
an :class:`torch.fx.GraphModule`. You can then use
`FX transformation <https://pytorch.org/docs/stable/fx.html#writing-transformations>`_
to rewrite the graph. Afterwards, you can simply use :func:`export`
again to construct a correct ExportedProgram.
_graph_module_graph_signature_state_dictzdict[sympy.Symbol, ValueRanges]_range_constraints_module_call_graph.N_example_inputs
_constants
_verifiers_guards_code)	verifiersr  r   r   r   r  dict[sympy.Symbol, Any]rj  r   r   r  c	                   [         R                  R                  R                  5       Ul        [        X5      U l        [        U[         R                  R                  5      (       a/  U R                  R                  R                  UR                  5        [        U R                  X65        X0l        X@l        XPl        Uc  [        S5      eX`l        Xpl        U=(       d    0 U l        U	=(       d    [&        /n	[)        S U	 5       5      (       d  [        SU	 35      eXl        U R-                  5         [/        U R                  5      U l        g )Nz"module_call_graph must not be Nonec              3   B   #    U  H  n[        U[        5      v   M     g 7frQ   )r{   r+   ).0rW  s     rX   	<genexpr>+ExportedProgram.__init__.<locals>.<genexpr>c  s     >Iq:a**Is   z2all verifiers must be subclasses of Verifier, got )r   r  r   CodeGenr   _create_graph_module_for_exportr  r   r  r   r   rp  r  r  r  r   r  r  r  r+   allr  validate_convert_guards_to_coder  )
rS   r  r   r   r   r  rj  r   r   r  s
             rX   __init__ExportedProgram.__init__B  s    //1<TIdEHH0011##**4995(	
 7F+5CT$ !EFF9J-#/r+(	>I>>> DYKP  $3D4F4FGr[   F)is_backward_compatiblec                     U R                   $ rQ   )r  rS   s    rX   r   ExportedProgram.graph_modulem  s     !!!r[   c                     [        S5      e)Nz7Unable to set ExportedProgram's graph_module attribute.r   rS   values     rX   r   r  r  s     TUUr[   c                 .    U R                   R                  $ rQ   )r   r   r  s    rX   r   ExportedProgram.graphw  s       &&&r[   c                     [        S5      e)Nz0Unable to set ExportedProgram's graph attribute.r  r  s     rX   r   r  |  s     MNNr[   c                     U R                   $ rQ   )r  r  s    rX   r   ExportedProgram.graph_signature  s     $$$r[   c                     [        S5      e)Nz:Unable to set ExportedProgram's graph_signature attribute.r  r  s     rX   r   r    s     WXXr[   c                     U R                   $ rQ   )r  r  s    rX   r   ExportedProgram.state_dict  s     r[   c                     [        S5      e)Nz5Unable to set ExportedProgram's state_dict attribute.r  r  s     rX   r   r    s     RSSr[   ry   c              #   F   #    U R                  5        H	  u  pUv   M     g7f)z8
Returns an iterator over original module's parameters.
N)r   )rS   r=  params      rX   
parametersExportedProgram.parameters  s!     
 --/HAK 0   !c              #   j   #    U R                   R                   H  nXR                  U   4v   M     g7f)z
Returns an iterator over original module parameters, yielding
both the name of the parameter as well as the parameter itself.
N)r   r  r   )rS   
param_names     rX   r    ExportedProgram.named_parameters  s/      ..99Jooj999 :s   13c              #   F   #    U R                  5        H	  u  pUv   M     g7f)z3
Returns an iterator over original module buffers.
N)r   )rS   r=  bufs      rX   buffersExportedProgram.buffers  s!     
 ((*FAI +r  c              #      #    [        U R                  R                  5      nU R                  R                   H.  nX!;   a  X R                  U   4v   M  X R
                  U   4v   M0     g7f)zv
Returns an iterator over original module buffers, yielding
both the name of the buffer as well as the buffer itself.
N)r   r   r   r  r   r   )rS   r   buffer_names      rX   r   ExportedProgram.named_buffers  s^      "%T%9%9%P%P!Q//77K4!>>+#>>>!??;#???	 8s   A)A+c                     U R                   $ rQ   )r  r  s    rX   r  !ExportedProgram.range_constraints       &&&r[   c                     [        S5      e)Nz<Unable to set ExportedProgram's range_constraints attribute.r  r  s     rX   r  r         J
 	
r[   c                     U R                   $ rQ   )r  r  s    rX   rj  !ExportedProgram.module_call_graph  r  r[   c                     [        S5      e)Nz<Unable to set ExportedProgram's module_call_graph attribute.r  r  s     rX   rj  r    r  r[   c                     U R                   $ rQ   )r  r  s    rX   r   ExportedProgram.example_inputs  s     ###r[   c                 0   Uc  Xl         g [        U[        5      (       a?  [        U5      S:X  a0  [        US   [        5      (       a  [        US   [        5      (       d  [        S5      eUu  p#SSKJn  U" X#U R                  R                  5        Xl         g )N   r   r7   zqExample inputs should be a tuple containing example arguments (as a tuple), and example kwargs (as a dictionary).)_check_inputs_match)
r  r   r   r
  r|   r  _unliftr  	call_specrM   )rS   r  rm   rn   r  s        rX   r   r    s    
 =#(  ue$$E
a58U++58T**B 
 0D$..*@*@A$r[   c                 x    " S S[         5      n[        U R                  5      S:X  a  U" S S S9$ U R                  S   R                  S:w  a&  [	        SU R                  S   R                  < 35      eU" U R                  S   R
                  R                  U R                  S   R
                  R                  S9$ )Nc                   ^    \ rS rSr% \R
                  S-  \S'   \R
                  S-  \S'   Srg)+ExportedProgram.call_spec.<locals>.CallSpeci  NrM   rN   r\   )r]   r^   r_   r`   rc   rd   rb   rf   r\   r[   rX   CallSpecr    s     __t++oo,,r[   r  r   )rM   rN    z=expected first module_call_graph fqn to be empty string, got )r	   r
  rj  ri   r   rj   rM   rN   )rS   r  s     rX   r  ExportedProgram.call_spec  s    	-z 	- t%%&!+D488!!!$((B. OPTPfPfghPiPmPmOpq  **1-77??++A.88AA
 	
r[   c                     [        S5      e)Nz4Unable to set ExportedProgram's call_spec attribute.r  r  s     rX   r  r         QRRr[   c                      U R                   S   $ )Nr   r  r  s    rX   verifierExportedProgram.verifier
  s     q!!r[   c                     [        S5      e)Nz3Unable to set ExportedProgram's verifier attribute.r  r  s     rX   r  r    s     PQQr[   c                 d    U R                   c  [        S5      eU R                   S   R                  $ )Nz_verifiers must not be Noner   )r  r   dialectr  s    rX   r  ExportedProgram.dialect  s/     ??" !>??q!)))r[   c                     [        S5      e)Nz2Unable to set ExportedProgram's dialect attribute.r  r  s     rX   r  r    s     OPPr[   c                     U R                   $ rQ   r  r  s    rX   r  ExportedProgram.verifiers        r[   c                     [        S5      e)Nz4Unable to set ExportedProgram's verifiers attribute.r  r  s     rX   r  r  %  r  r[   c                     U R                   $ rQ   r  r  s    rX   tensor_constants ExportedProgram.tensor_constants*  r  r[   c                     [        S5      e)Nz;Unable to set ExportedProgram's tensor_constants attribute.r  r  s     rX   r  r  /  s     I
 	
r[   c                     U R                   $ rQ   r  r  s    rX   r   ExportedProgram.constants6  r  r[   c                     [        S5      e)Nz4Unable to set ExportedProgram's constants attribute.r  r  s     rX   r   r  ;  r  r[   c                     U R                   R                  nUb  [        X#5      n[        R                  " X45      u  pEU R                  U5        [        S U 5       5      nXe4$ )ag  Flatten args, kwargs using pytree, then, check specs.

Args:
    args: List[Any] original args passed to __call__
    kwargs: Dict[str, Any] original kwargs passed to __call

Returns:
    A tuple of (flat_args, received_spec)
    flat_args is flattened args / kwargs
    received_spec is the pytree spec produced while flattening the
    tuple (args, kwargs)
c              3   *   #    U  H	  oS    v   M     g7f)r7   Nr\   )r  rw  s     rX   r  <ExportedProgram._get_flat_args_with_check.<locals>.<genexpr>T  s     <(;1A$(;s   )r  rM   r1   rc   tree_flatten_with_path_check_input_constraintsr   )rS   rm   rn   rM   flat_args_with_pathreceived_spec	flat_argss          rX   _get_flat_args_with_check)ExportedProgram._get_flat_args_with_check@  sg     ..((#F4F-3-J-JN.
* 	%%&9:<(;<<	''r[   rm   rn   c                    U R                   R                  nU R                  X5      u  pEUb&  [        XS[        5      (       d  [        SU SU 35      e/ nU R                  R                   GH  nUR                  [        R                  :X  a  M$  UR                  [        R                  [        R                  4;   ac  UR                  SL a*  UR                  U R                  UR                      5        M  UR                  U R"                  UR                      5        M  UR                  [        R$                  [        R&                  4;   d  M  UR                  U R                  UR                      5        GM     [)        U5      nXd-   $ )a  Transform args, kwargs of __call__ to args for graph_module.

self.graph_module takes stuff from state dict as inputs.
The invariant is for ep: ExportedProgram is
ep(args, kwargs) ==
  ep.postprocess(ep.graph_module(ep.graph_module_flat_inputs(args, kwargs)))
z>Trying to flatten user inputs with exported input tree spec: 
z-
but actually got inputs with tree spec of: 
F)r  rM   r  r0   r}   r  r   r   r   r<   r  r  r  r  r   r   r   r   CONSTANT_TENSOR
CUSTOM_OBJr   )rS   rm   rn   rM   r  r  additional_inputsinput_s           rX   _graph_module_flat_inputs)ExportedProgram._graph_module_flat_inputsW  s\    ..((#'#A#A$#O 	}$A(
 (
 Q) @ /#  **66F{{i222##  !  $$- &,,T^^FMM-JK%,,T__V]]-KL))$$!  "(()FG# 7$ ""34 !,,r[   c                     [        S5      e)Nz\Unable to call ExportedProgram directly. You should use `exported_program.module()` instead.r  )rS   rm   rn   s      rX   __call__ExportedProgram.__call__  s    B
 	
r[   c                     U R                   R                  SSS9R                  SS5      n[        U R                  5      R                  SS5      nSU SU SU R
                   S3nU$ )NF)print_outputcolored
z
    zExportedProgram:
    z
Graph signature: z
Range constraints: )r   print_readablereplacere   r   r  )rS   r   r   strings       rX   __str__ExportedProgram.__str__  s    ((77 8 

'$
! 	 d223;;D(K. !  /0 1""&"8"8!9= 	 r[   c                     SSK Jn  U" XS9nSS[        4S jjnSS[        4S jjn[        R                  " XC5      Ul        [        R                  " XS5      Ul        U$ )a  
Returns a self contained GraphModule with all the parameters/buffers inlined.

- When `check_guards=True` (default), a `_guards_fn` submodule is generated
  and a call to a `_guards_fn` submodule is inserted right after placeholders
  in the graph. This module checks guards on inputs.
- When `check_guards=False`, a subset of these checks are performed by a
  forward pre-hook on the graph module. No `_guards_fn` submodule is generated.

r7   )&_unlift_exported_program_lifted_states)check_guardsmodec                     [        S5      e)Nz%Calling train() is not supported yet.NotImplementedErrorrS   r  s     rX   _train&ExportedProgram.module.<locals>._train  s    %&MNNr[   c                     [        S5      e)Nz$Calling eval() is not supported yet.r   r"  s     rX   _eval%ExportedProgram.module.<locals>._eval  s    %&LMMr[   T)r  r  booltypes
MethodTypetraineval)rS   r  r  r   r#  r&  s         rX   r   ExportedProgram.module  sY     	D7X	Ot 	O	Nd 	N ''7&&u5r[   c                     [        S [        U R                  R                  5       5       [	        U R                  R                  5      5      $ )Nc              3   j   #    U  H)  u  pUR                   [        R                  :X  d  M%  Uv   M+     g 7frQ   )r   r<   r  )r  rV   ss      rX   r  =ExportedProgram._num_lifted_params_buffers.<locals>.<genexpr>  s-      HDA66Y111 Hs   $3	3)nextr  r  r   r
  r  s    rX   _num_lifted_params_buffers*ExportedProgram._num_lifted_params_buffers  sC    %d&;&;&G&GH
 %%112
 	
r[   r   r   c                     Uc
  [        5       O
[        U5      n[        U[        5      (       a  UR	                  5       n[        U5      u  nn[        U UUSUS9$ )a  
Run a set of decompositions on the exported program and returns a new
exported program. By default we will run the Core ATen decompositions to
get operators in the
`Core ATen Operator Set <https://pytorch.org/docs/stable/torch.compiler_ir.html>`_.

For now, we do not decompose joint graphs.

Args:
    decomp_table:
     An optional argument that specifies decomp behaviour for Aten ops
     (1) If None, we decompose to core aten decompositions
     (2) If empty, we don't decompose any operator


Some examples:

If you don't want to decompose anything

.. code-block:: python

    ep = torch.export.export(model, ...)
    ep = ep.run_decompositions(decomp_table={})

If you want to get a core aten operator set except for certain operator, you can do following:

.. code-block:: python

    ep = torch.export.export(model, ...)
    decomp_table = torch.export.default_decompositions()
    decomp_table[your_op] = your_custom_decomp
    ep = ep.run_decompositions(decomp_table=decomp_table)
Nr  )rH   r|   r   r3   materializer   r  )rS   r   r   _decomp_tabler   r   s         rX   run_decompositions"ExportedProgram.run_decompositions  sn    P )5(<"$$|BT 	 m%677)557M" 9G	
 +' 3!(C
 	
r[   passesc                 |   [        [        U5      5      nSSKJn  U" 5          U" U R                  5      nS S S 5        Wb  UR                  OU R                  nUc  [        S5      eXPR                  L a  UR                  (       d  U $ S[        S[        R                  R                  S[        4S jn[        UUR                  U" U R                  U5      U R                  [        UU R                   5      ["        R$                  " U R&                  5      U R(                  U R*                  U R,                  S9	nUR                  R.                  R1                  U R                  R.                  5        UR                  R.                  R1                  UR                  R.                  5        U$ ! , (       d  f       GN~= f)	Nr   )r   ztransformed_gm must not be Noneold_signaturenew_gmry   c           	         / n[        UR                  R                  5       H  u  p4UR                  S:w  a    OU[	        U R
                  5      :  a%  [        SU S[	        U R
                  5       S35      eU R
                  U   n[        UR                  [        [        45      (       a  UR                  O$[        UR                  5      " UR                  5      nUR                  [        UR                  UUR                   UR"                  5      5        M     [%        UR                  R                  5      S   nUR                  S:w  a  [        SUR                  < 35      e/ n[        UR&                  S   5       H  u  p4U[	        U R(                  5      :  a%  [        S	U S[	        U R(                  5       S
35      eU R(                  U   n	[        U	R                  [        [        45      (       a  U	R                  O$[        U	R                  5      " UR                  5      nUR                  [+        U	R                  XiR                   5      5        M     [-        X(S9n
U
$ )z7
Update the graph signature's user_input/user_outputs.
r   z9Number of inputs changed after transformation: got index z
 but only z input_specsr|  rI  z,expected last node to have op='output', got r   z:Number of outputs changed after transformation: got index z output_specsr   )r  r   r   r   r
  r   r   r   r   r9   r:   r   rR   r   r=   r   r   r  ra   rm   r   r?   r;   )r=  r>  new_input_specsrV   r-  old_input_specr   r	  new_output_specsold_output_specnew_signatures              rX   _get_updated_graph_signatureKExportedProgram._transform_do_not_use.<locals>._get_updated_graph_signature  sU    !O$V\\%7%7877m+M5566(STUSV W$$'(A(A$B#C<Q  "/!:!:1!= "&**-=?P,Q  #&& n001$))<   &&&++&--&11	# 94 v||11226K~~)$B;>>BTU   "$[%5%5a%89M6677(TUVTW X$$'(B(B$C#DMS  #0"<"<Q"? "'++.>@Q-R  $'' o112499=  !''33S:P:PQ :$ 1+M ! r[   	r  r   r   r   r  rj  r   r   r  )r6   ra   r   r   r   r   modifiedr;   r   r  r  rE   r   r   r   r  r  r   r}  r  r   r   r  r   r   )rS   r;  pmr   restransformed_gmrE  transformed_eps           rX   _transform_do_not_use%ExportedProgram._transform_do_not_use  sn   f& 	@$&T&&'C '-0_))$BSBS! !BCC ...s||K>	!/>	!HH((>	! ">	!@ ) &&8$$n <&& #mmD,C,CD..nnnn
  	##((//0A0A0F0FG##((//0@0@0E0EF} '&s   F,,
F;c                 `   SSK Jn  U R                  R                   Vs/ s H  o3R                  S:X  d  M  UPM     nn[        X@R                  R                  5       VVs/ s H'  u  p5UR                  [        R                  :X  d  M%  UPM)     nnnU" XaU R                  5        g s  snf s  snnf )Nr   )"_check_input_constraints_for_graphr   )torch._export.utilsrP  r   r   r   r  r   r   r   r<   r  r  )rS   r  rP  r9  placeholdersr1  input_placeholderss          rX   r  (ExportedProgram._check_input_constraintsh  s    J#'::#3#3M#3att}7L#3M L*>*>*J*JK
Kvv--- K 	 

 	+T5K5K	
 N
s   B%B% $B*B*c                 $    U R                  5         g rQ   )	_validater  s    rX   r  ExportedProgram.validateu  s    r[   c                     [        U R                  5      S:X  a  [        S5      eU R                   H  nU" 5       R                  U 5        M     g )Nr   z0ExportedProgram must have at least one verifier.)r
  r  r   check)rS   rW  s     rX   rV  ExportedProgram._validatez  s:    t~~!# !STTACIIdO  r[   )r   r   r  c                "   [        UUR                  UUb  UOU R                  [        R                  " U R
                  5      [        R                  " U R                  5      U R                  Ub  UOU R                  Ub  US9	$ U R                  S9	$ )NrG  )
rE   r   r   r   r}  r  r  r   r   r  )rS   r   r   r   r   r  s         rX   _updateExportedProgram._update  s     $$+%/%;z"mmD,B,BC"mmD,C,CD..#,#8idnn#,#8i

 
	
 ?Cnn

 
	
r[   )	r  r  r  r  r  r  r  r  r  )NNr(  )NF)ry   rE   )Br]   r^   r_   r`   __doc__r   r  r  rb   r;   r|   re   r   ra   rF   r   r   r   r+   r   ModuleGraphr!  r  r  propertyr4   r   setterr   r   r   r   r  r   r  r   r  rj  r   r  r  r  r  r  r   r  r  r  r  r   r4  rt   _opsOperatorBaser   r)  r9  PassTyperM  r  r  r   rV  r\  rf   r\   r[   rX   rE   rE     sJ    88'''O**Mc3hU99E_--J5c?DcN:;dBBLS0011:T(^$$Is) IM>B)H 26)HhhooS#X.)H xx~~)H .	)H
 ellUXX-?-???@)H 5)H  0)H eCHotCH~=>E)H 334t;)H X'$.)HV %0" 1 " %0V 1 V %0' 1 ' \\%0O 1 O %0% 1 % %0Y 1 Y %0  1   %0T 1 T %0HUXX%7%78  1 %0:(5ehh6H6H1H+I"J : 1: %0%,,/  1 %0
@xc5<<.?(@A 
@ 1
@ %0' 1 ' %0
 1 

 %0' 1 ' %0
 1 

 %0$ 1 $ %0% 1 %2 %0
 1 
  %0S 1 S %0"# " 1 " __%0R 1 R %0* * 1 *
 ^^%0Q 1 Q %0 1  %0S 1 S %0 1  %0
 1 

 %0 1  %0S 1 S(.,-c ,-3 ,-3 ,-\
c 
S 
S 
 588+?+? 2
 $ HL,1D
5::22H<=DD
 &*D
 
	D
 $D
LdX d:K dL
 %0 1   
 

 
r[   c                 l   U R                   R                   Vs/ s H1  nUR                  R                  SS 5      c  M"  UR                  S   PM3     nnSSKJn  U" U5      nUb  UR                  $ U H:  n[        U[        R                  5      (       d  M$  UR                  R                  s  $    g s  snf )Nr   r   r,   )r   r   r   r  torch._guardsr-   r   r   r   SymIntr-  )r   r-  valsr-   r'  rW  s         rX   r  r    s     HHNN"D99==% 			%" 	 
 / &I"""a&&66### s
   !B1B1old_range_constraintszdict[sympy.Symbol, Any] | Noner  c                 b   Uc  [        S5      e[        U 5      nUc  0 $ [        R                  " U5      nUR                  5        VVs0 s H  u  pEXBR                  ;  d  M  XE_M     nnnUR
                  R                  5        H!  u  pEXBR                  ;  d  M  XC;  d  M  XSU'   M#     U$ s  snnf )Nz&old_range_constraints must not be None)r   r  r   r   replacementsvar_to_range)r   rj  r   r  r   rW  s         rX   r  r    s     $EFFr"I			"78*0022a?U?U6U2   &&,,.***q/I#$a  / s   B+!B+c                     [         R                  R                  X5      nU$ ! [         a[    [        R
                  " SSS9  [         R                  R                  U [         R                  R                  5       5      nXl         U$ f = f)NzUnable to execute the generated python source code from the graph. The graph module will no longer be directly callable, but you can still run the ExportedProgram, and if needed, you can run the graph module eagerly using torch.fx.Interpreter.r  )
stacklevel)r   r  r  SyntaxErrorwarningswarnr`  _graph)r  r   r   s      rX   r  r    sy    XX!!$." I!   	G 	
 XX!!$(89	I!s   # A!BBc                 \   [        U 5      nUc  / $ UR                  R                  5        VVs1 s H   u  p#[        S U 5       5      (       d  M  UiM"     nnn[        R
                  R                  R                  R                  UR                  S UR                  5      nUR                   Vs/ s HJ  nUR                  R                  R                  U5      (       d  M/  UR                  UR                  5      PML     nnU Vs/ s H  nSU;  d  M  UPM     sn$ s  snnf s  snf s  snf )Nc              3      #    U  H8  n[        U[        R                  R                  R                  5      (       + v   M:     g 7frQ   )r   r   r  rU  ConstantSource)r  rU  s     rX   r  *_convert_guards_to_code.<locals>.<genexpr>  s4      
! 65==#7#7#F#FGGG!s   A Ac                     U R                   $ rQ   r   )r1  s    rX   ry  )_convert_guards_to_code.<locals>.<lambda>  s    AFFr[   z	L['self'])r  var_to_sourcesr   r  r   r  experimentalsymbolic_shapesShapeGuardPythonPrinterguardsexprfree_symbolsissubsetdoprint)r   r   varsources
local_vars
py_printerguardrets           rX   r  r    s   |,I	 &44::<<LC 
!
 
 	<   &&66NN  "2I4L4LJ
 %%%E::""++J7 	'
5::&%    #?sek&>Es??% @s#   DD0.D$"D$
D)D))ry   r3   rQ   )r  r   dataclassesrr   rh  r*  rq  collectionsr   collections.abcr   r   r   typingr   r   r	   r
   rg  r   r   torch._higher_order_ops.utilsr   "torch._library.fake_class_registryr   torch._subclasses.fake_implsr   r   r   torch._subclasses.fake_tensorr   torch.fx._symbolic_tracer   torch.fx._utilsr   torch.fx.graphr   r   torch.fx.immutable_collectionsr   r   torch.fx.passes.runtime_assertr   sympytorch.utils._sympy.value_rangesr   r   torch.utils._pytreeutils_pytreerc   rQ  r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   torch._export.verifierr+   r-   r/   torch.export._tree_utilsr0   r1   torch.export.decomp_utilsr3   torch.fx._compatibilityr4   torch.fx.passes.infra.pass_baser5   "torch.fx.passes.infra.pass_managerr6   r   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   __all__r  r  re  	dataclassrG   rF   rt   r   Contextr)  r}   r   r   AutogradCPUAutogradCUDAAutogradMetaAutogradXLAAutogradLazyAutogradIPUAutogradXPUAutogradMPSAutogradHPUAutogradPrivateUse1AutogradPrivateUse2AutogradPrivateUse3r   CPUCUDAMetaXLALazyIPUXPUMPSHPUr   r   r|   rc  rd  r   r   rH   r  rX  r   rp  ra   r  r  rE   r  r  r  r  r\   r[   rX   <module>r     s          # . % 8 8 1 B ? 
 9 ; ? 6 I J 
 ;  $ $    $ , * @ B 7 1 6 :   " UXX))*J,==> ' ' '  1 1 1
GtG>>G tG >>	G
 
G: 
HH$$	HH%%	HH%%	HH$$	HH%%	HH$$	HH$$	HH$$	HH$$	HH,,	HH,,	HH,,, (, 
HH	HH	HH	HH	HH	HH	HH	HH	HH
  P$ P$f,-uzz..89,-
4

''12C78,-^b2b2 

//9:b2 ejj55x?@	b2
 Djb2J##3G#
588!556#2..:x!HH  x!-x! 	x! *	x!
  0x!v4 

//9:4 ejj55x?@	4
 Dj4 "&4n}	
 }	
@$$ ?C; 0,@r[   