
    8h                       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  S SK Jr  S SKJrJr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K0r0S SK1J2s  J3r4  S SK5J6r6J7r7J8r8J9r9J:r:J;r;J<r<J=r=J>r>J?r?J@r@JArAJBrBJCrCJDrD  S SKEJFrF  S SKJGrG  S SKJHrH  S SKIJJrJJKrK  S SKLJMrM  S SKNJOrO  S SKPJQrQ  S SKRJSrS  SSKTJUrUJVrVJWrWJXrXJYrYJZrZJ[r[J\r\J]r]J^r^J_r_J`r`Jara  / SQrb\\0R                  R                  /\\Q   4   re\R                   " S S5      5       rg\R                   " S S 5      5       rhS! riS"\\j   S#\4R                  S$\\j   S%\4R                  S&\l4
S' jrm\0R                  R                  R                  \0R                  R                  R                  \0R                  R                  R                  \0R                  R                  R                  \0R                  R                  R                  \0R                  R                  R                  \0R                  R                  R                  \0R                  R                  R                  \0R                  R                  R                  \0R                  R                  R                  \0R                  R                  R                  \0R                  R                  R                  /r|\0R                  R                  R                  \0R                  R                  R                  \0R                  R                  R                  \0R                  R                  GR                   \0R                  R                  GR                  \0R                  R                  GR                  \0R                  R                  GR                  \0R                  R                  GR                  \0R                  R                  GR
                  /	r\S( 5       rS)\\0GR                  GR                  \4   S&\\\0GR                  GR                  \4   S*4   4S+ jrSDS, jrS-\\0GR                  GR                  \4   S.\\0GR                  GR                  \4   S/\\   4S0 jrS1\0R                  R                  S2\XS&\\0R                  R                  \X4   4S3 jrS1\0R                  R                  4S4 jrS5\0R                  R                  S6\XS1\0R                  R                  S7\XS8\\h   4
S9 jrS-\\0GR                  GR                  \4   S.\\0GR                  GR                  \4   S/\\   S:\l4S; jr " S< S=5      rS> r SES1\0R                  R                  S?S@S&SA4SB jjrSC rg)F    N)defaultdict
namedtuple)Iterator)contextmanager)AnyCallablefinalOptionalTYPE_CHECKINGUnion)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)_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 rS	rg)
rH   `   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)rL   namerM   )selforiginal_nodenew_nodeios        W/var/www/fran/franai/venv/lib/python3.13/site-packages/torch/export/exported_program.pyreplace_all_uses_with)ModuleCallSignature.replace_all_uses_withh   sZ    Avv+++!  Avv+++!      )__name__
__module____qualname____firstlineno__listr9   __annotations__pytreeTreeSpecrP   r
   strrZ   __static_attributes__r]   r\   rY   rH   rH   `   sE    ,__oo-1xS	*1'r\   rH   c                   4    \ rS rSr% \\S'   Sr\\   \S'   Sr	g)rG   q   fqnN	signaturer]   )
r^   r_   r`   ra   rf   rc   rk   r
   rH   rg   r]   r\   rY   rG   rG   q   s    	H/3Ix+,3r\   rG   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rR   r/   )argskwargsfns     rY   wrapper/_disable_prexisiting_fake_mode.<locals>.wrapperx   s"    #%t&v& &%%s   
,)	functoolswraps)rp   rq   s   ` rY   _disable_prexisiting_fake_moderu   w   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   rb   r   )rv   rw   rx   ry   s       rY   _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oprn   ro   orig_cia_callables        rY   $_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   rs   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
             rY   #_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                 ^   [        [        5       5      n0 n[        U R                  5       5       Hh  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5       eX   X#'   Mj     U H  n[        X%'   M     X 4$ )NatenzThis should be a custom op)	r   r   rb   keysremover#   rS   
startswithr*   )r   all_preservable_cia_opsr   r   op_nameks         rY   ,_split_decomp_table_to_cia_and_python_decompr     s     ""<">?<$$&'$ (&2&6##**2.  $B''ggiG))&11O3OO1&2&6#9 (@ %!< % ,,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()`
r3   r]   r\   rY   rI   rI   >  s     r\   cia_to_decomppython_decomp_tablejoint_loss_indexc                   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d  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R.                  R0                  R2                  R4                  nUR6                  [8        [:        4;  a  [<        R>                  " [:        S U/5      n[A        [C        UURD                  U5      5      UR.                  l        URG                  5         [I        U RJ                  U RL                  U5        [O        XRP                  U RJ                  RR                  5      n[U        UU5      n[W        U5      nSSK,J-nJ.n  / nUR.                  R^                   H  nUR`                  S:X  d  M  [c        URd                  S   [f        5      (       ay  S nURd                  S   Rh                  c'  U RL                  URd                  S   Rj                     nO#URd                  S   Rh                  Rl                  nURo                  U5        M  URo                  URd                  S   5        M     [q        U5      nU   [s        U5         U" U Rt                  5         [w        U5         [<        Rx                  " UURD                  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SUS9	n%U%RL                  R}                  5        V&V's0 s H#  u  n&n'U&[c        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 RJ                  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 RP                  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        HX  u  n+n,U+U-;  a+  [c        U,[        R                  R                  5      (       a   eU+U-;   d  M?  U+U;  d  MG  U-R                  U+5        MZ     U(U)U-4$ U R(                  R.                  R^                   Vs/ s H  nUR`                  S:X  d  M  UPM     n.nU. Vs/ s H  nURd                  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      nUc  [        R                  " 5       OUnU(       a  [        R                  OUn2U	" 5          U   [s        U5         U2" 5          U" U R(                  U/UUb  S
OSUb  UOS S9u  n(n3U(R.                  R                  5         S S S 5        S S S 5        S S S 5        S S S 5        S n4W(R.                  R^                   Vs/ s H  nUR`                  S:X  d  M  UPM     n5n[9        U(R.                  R^                  5      S   R                  S   n6[        U55      [        U.5      :X  d   e[        U.U55       H  u  n7n8U7Rj                  =U8l5        U8lS        M      U5 V9s0 s H  n9U9Rj                  U9Rj                  _M     n:n9U(R.                  R^                   H;  nUR`                  S:X  a  M  [        U:URj                  URj                  5      Ul5        M=     [        U(5        SSKVJWn;JXn<  SSKYJZn=  [        R                  R                  R                  (       dW  Sn>[        U(5      n?U?bG  U<" U([        R                  " U;U>S95         [        U(U?S[        U(R.                  5       3S
S9  S S S 5        U(RG                  5         [        U=" U(5      5       H>  u  n@n+[c        U6U@   [        R                  R                  5      (       d  M4  U+U6W@   l5        M@     [        U RJ                  R                  5       V@VAs0 s HK  u  n@nA[c        UAR                  [        5      (       a  M'  WAR                  Rj                  U5W@   Rj                  _MM     nBn@nA[        U RJ                  R                  5       V@VAs/ s HF  u  n@nA[        UAR                  U4" UAR                  U5U@   5      UAR                  UAR                  5      PMH     nCn@nA/ nD[        W3R                  5       V@V+s0 s H	  u  n@n+U+U@_M     nEn@n+[9        U3R                  R                  5       5      nFUFU6S [        UF5        Vs/ s H  nURj                  PM     sn:X  d   eU3R                  R}                  5        H  u  nGnHWEUH   n@U RJ                  R                  U@   nIUIR                  [        R                  [        R                  4;   d   eWIR                  [        R                  :X  a  [        R                  O[        R                  nJWIR                  [        R                  :X  a  WIR                  OWIR                  Rj                  nKWDRo                  [        WJ[        WGS9UKS95        M     [        U RJ                  R                  5       H  u  n@nAWDRo                  [        U@U:X  a  [        R                  OWAR                  U4" WAR                  U6[        WF5      W@-      5      WBR                  UAR                  UAR                  5      5      5        M     UGb  U3R                  c   eU3R                  R                  nL[        U3R                  5      [        U RJ                  R                  5      :X  d   e[        U RJ                  R                  5       V@VAs0 s H7  u  n@nA[c        UAR                  [        5      (       d  M'  U3R                  W@   WA_M9     nMn@nA[        U6[        WD5      S  5       H  u  n@nWLURj                     nNWMUN   nAUAR                  [        R                  :X  a  [        R                  nOWAR                  nKOIWAR                  [        R                  :X  a  [        R                  nOWNnKO[        SWAR                   35      eWDRo                  [        WO[        URj                  S9WK5      5        M     [        U55      [        U.5      :X  d   eG[        WCWDS9n)[        U.U55       H  u  nPnQ[c        UPRd                  S   [        GR                  5      (       d  WPRd                  S   WQRd                  S'   WQR                  U)GR                  ;   d  WQR                  U)GR                  ;   d  M  WPRd                  R}                  5        H  u  nRnSUSWQRd                  UR'   M     M     U(U)U RP                  4$ s  sn'n&f ! , (       d  f       G
Nf= f! , (       d  f       G
Np= f! , (       d  f       G
Nz= f! , (       d  f       G
N= f! , (       d  f       G
N= fs  sn,n+f s  snf s  snf s  sn0n+f ! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GN= fs  snf s  sn9f ! , (       d  f       GN= fs  snAn@f s  snAn@f s  sn+n@f s  snf s  snAn@f )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$ rR   )graph_signaturebackward_signature)epr   s     rY   _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export)&_enable_graph_inputs_of_type_nn_module_fakify_script_objectsplaceholdervalr8   )r   _check_autograd_state_prettify_placeholder_namesdecompose_custom_triton_ops)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rS   zType of old_arg not supported: )	
isinstancer:   rD   rS   rC   rB   rA   RuntimeErrortype)old_argnew_phs     rY   
update_argF_decompose_and_get_gm_with_new_signature_constants.<locals>.update_argX  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\   )_node_metadata_hook_set_node_metadata_hook)_graph_output_nameszUFile "torch/fx/passes/runtime_assert.py", line 24, in insert_deferred_runtime_asserts)stack_tracezexported program: )r   r   )kindargtargetz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_specgraph_codegenpytree_info	orig_argsr   rb   tuplerd   re   r   r   _in_spec	recompiler   r   	constantsr(   
state_dictnon_persistent_buffersr!   r   torch._export.non_strict_utilsr   r   nodesr   r   metar;   fake_valrS   real_objappendr   r   example_inputsr   tree_unflattenvaluesr   r   gmsigr%   r'   r&   r+   !_remove_unneccessary_copy_op_passr   nn	Parameterpopdelattrr.   
contextlibnullcontexteliminate_dead_codern   lenzipr   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_envrs   r   r   r   	enumeratefxNoder   r   r:   r>   r   
persistentuser_inputsuser_inputs_to_mutater   r=   
USER_INPUTBUFFERr?   BUFFER_MUTATIONUSER_INPUT_MUTATIONr@   rD   r   LOSS_OUTPUTgetr   gradients_to_user_inputs	PARAMETERGRADIENT_TO_PARAMETERGRADIENT_TO_USER_INPUTAssertionErrorr<   Tensorinputs_to_parametersinputs_to_buffers)Tr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   modwrapped_params_buffersr   unwrapped_params_buffers	fake_moderO   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_artifactrj   objr   new_graph_signaturer   rS   pnew_state_dictold_placeholders	fake_args_buffers_to_remove#custom_triton_ops_decomposition_ctxr   r   new_placeholdersnew_outputsold_phr   phname_mapr   r   r   r   r   rW   specold_new_placeholder_mapr   r   user_inputs_indexmutation_namesoutput_name
input_name
input_specoutput_kindr   	gradientsspecssourcer   old_noderV   r   vsT                                                                                       rY   2_decompose_and_get_gm_with_new_signature_constantsrQ  G  s    Y?  ?
 r44iik"
3'''?@"
3$$e$<="

	
 	*#.$
3'''?@$
3$$e$<=$
  .boo>	&DII ==++77AA ==u-udXJ?H+
		 	
 	((:(: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!#'+!4*/050K
($& %9$B$B$H$H$J2 %KS %c+;<< )- !
 %K2$. *,,&:&>&>#
 L+-F $ :/5H
 'V&&(;'# <+-D	 ('!#'{  F d 	 #B!"&9:"C##

mm
  8==??GD!55 a?
 .335GD!>)%a););<<<<~%77"&&t, 6 &66 ..444=8P4   /??.>d5!.>I?-/__-J-J-LM-L'$-LM!& " !+I,5,=
&&(9I ' 	? ( 	 !+M:+-/OO. 0 <%$4$@ d
O 	$$& 	. 	; 	 	"$N *,T477m;STrxx~~&r*//2K  C(8$9999.0@A&,kk1fm B ,<<+;R +;H<77m#.xDIIN	  $B' Y==;;1 	 #2&	 (I%%&9{S 0()LRXX)V(WX	 LLN0454k!nehhmm44"&KN 6 !!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K@U#nBU4VW4VDdii4VWWWW#2#H#H#N#N#PZj)''33A6
9#7#79I9I"JJJJ )"2"22 &&// 	 )"2"22 $$ 	
 	 "4	
 $Q. R//<<=4*+/?*?
&&TYY488[^1Dq1H%IJ'++DKKE	
 > #11===#66OO	?../3r7I7I7U7U3VVVV %R%7%7%C%CD
D4$((N3 1O''*D0D 	 

 !S->-@!ABGAttyy)F=DyyI///!77i222!88$';DII;%GHH"		2 C&  C(8$9999.l ""24DE((--.==#+==#7HMM%  OO2GGG"5"G"GG ++-1#$a  . F "BMM11w29  K FE  IF$ @M  	.- 	;: 		 	"!> U =0 $" XWJ
sA  *{	6z7	z%Az	2z*y;7A+z"z	*z%2z7:{	{#{{!{!&{&{+|'|#|+<{1	'|/|7|'"|9:|9=!|>##}&}=(}
A}4}!;}'&}, },;z
zz	
z"z%%
z4/z77
{	{		
{1
| ;|
||
|$	|''
|6
}r   r7  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  MJ  UR                  S:X  d  M\  UR                  [        R                  R                   R"                  R$                  :X  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.
outputcall_functionr8   N)_set_replace_hookget_replace_hookr   r   r   rd   tree_flattenrn   r   r   r  r  rS   buffers_to_mutater   opsr   r   defaultrZ   
erase_noder   )r   r7  r,  rn   r<  outs         rY   r   r     s	    
		1BBD	EHHNNDww(" --dii8C"366HH(;(M(MM  FFo5 #

eiinn.A.A.I.I I55chhqkBHH//4   # 	 
F  ""! 
F	E  ""s+   )E(AE(E(;E(:E(AE((
E8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                  :X  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)NrT  .)rU  rV  modulesr   r   r  GraphModulerb   r   r   r   r   operatorgetitemrn   rZ   rk   r[  rS   )r   r   module_call_graphr   node_idgetitemsr,  rN  idxnew_identrys              rY    _common_getitem_elimination_passri    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 7A 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                   H  nUR                  R                  S/ 5      =n(       a  UR                  XS   R                  '   MC  UR                  S:X  d  MU  UR                  U;   a  Mg  UR                  UR                  ;   a  M  UR                  U;   d  M  [        UR                  [        5      (       d   eX   n[        U[        5      (       d   eUR                  X'   U
S-  n
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R,                  nUc  M  / UR.                  QUR0                  Q GHX  nUR                  U;   a  [3        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                  [4        R6                  R8                  R:                  R<                  [4        R6                  R8                  R:                  R>                  [4        R6                  R8                  R:                  R@                  4;   d  GM   URB                  S   R                  nUU	;  a  [3        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                   ;  $ rR   )input_tokens)xold_graph_params_buffersrk  s    rY   <lambda>0_get_updated_module_call_graph.<locals>.<lambda>X  s$    a77 :,999:r\   	from_noder   r8   zparametrizations.r^  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 tensorsrT  )"r   deepcopyr   r   rS   r!  r"  r   r   rb   filterr   r  ro  r   rf   r   r   r   joinsplitr   rk   rL   rM   
ValueErrorr   rY  r   todtype_layoutdevicedtypern   )rj  rk  r   r   rl  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_desugaredrS   r   
old_targetrh  rk   rp  rO  rq  s    `                     @rY   _get_updated_module_call_graphr  :  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553GH%h4444+/99J(&!+&# , ).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 ! S A s   P5P:0P:4P?P?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_constraintsrc  r   r   )rQ  r  r   r   rc  r   r   _get_updated_range_constraintsr  rF   r   r   r   )r   r   r   r   r   r   r7  r   r~  new_range_constraintsexported_programs              rY   _decompose_exported_programr    s     	;
#/)$?		
 ;



 GGNN2??''(:


 'hh+//((,,	 r\   c                   <   \ rS rSrSr  SFSS.S\\R                  R                  \	\
\4   4   S\R                  R                  S\S\	\
\\R                  \R                  R                   4   4   S	S
S\\   S\\\\S4   \	\
\4   4      S\\	\
\4      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S& 5       5       r(\(R8                  \" SS9S' 5       5       r(\\" SS9S\4S( j5       5       r)\)R8                  \" SS9S) 5       5       r)\\" SS9S\
4S* j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-S2 r.S3\S4\S\4S5 jr/S3\S4\S\4S6 jr0S7 r1S\
4S8 jr2S\R                  R                  4S9 jr3S: r4\5  SGS;\\	\Rl                  Rn                  \84      S<\9SS 4S= jj5       r:S>\;SS 4S? jr<S@ r=\" SS9SA 5       r>\?SB 5       r@SSSSC. SHSD jjrASErBg)IrF   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.
N)	verifiersr  r   r   r   r  dict[sympy.Symbol, Any]rc  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   eX`l        Xpl        U=(       d    0 U l        U	=(       d    [$        /n	['        S U	 5       5      (       d   eXl        U R+                  5         g )Nc              3   B   #    U  H  n[        U[        5      v   M     g 7frR   )r|   r,   ).0rP  s     rY   	<genexpr>+ExportedProgram.__init__.<locals>.<genexpr>  s     >Iq:a**Is   )r   r  r   CodeGenr   _create_graph_module_for_export_graph_moduler   r`  r   r   ri  _graph_signature_state_dict_range_constraints_module_call_graph_example_inputs
_constantsr,   all
_verifiersvalidate)
rT   r  r   r   r   r  rc  r   r   r  s
             rY   __init__ExportedProgram.__init__  s     //1<TIdEHH0011##**4995(	
 7F+5CT ,,,9J-#/r+(	>I>>>>>#r\   F)is_backward_compatiblec                     U R                   $ rR   )r  rT   s    rY   r   ExportedProgram.graph_module  s     !!!r\   c                     [        S5      e)Nz7Unable to set ExportedProgram's graph_module attribute.r   rT   values     rY   r   r     s     TUUr\   c                 .    U R                   R                  $ rR   )r   r   r  s    rY   r   ExportedProgram.graph%  s       &&&r\   c                     [        S5      e)Nz0Unable to set ExportedProgram's graph attribute.r  r  s     rY   r   r  *  s     MNNr\   c                     U R                   $ rR   )r  r  s    rY   r   ExportedProgram.graph_signature/  s     $$$r\   c                     [        S5      e)Nz:Unable to set ExportedProgram's graph_signature attribute.r  r  s     rY   r   r  4  s     WXXr\   c                     U R                   $ rR   )r  r  s    rY   r   ExportedProgram.state_dict9  s     r\   c                     [        S5      e)Nz5Unable to set ExportedProgram's state_dict attribute.r  r  s     rY   r   r  >  s     RSSr\   rz   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   )rT   r<  params      rY   
parametersExportedProgram.parametersC  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   )rT   
param_names     rY   r    ExportedProgram.named_parametersK  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   )rT   r<  bufs      rY   buffersExportedProgram.buffersT  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   )rT   r   buffer_names      rY   r   ExportedProgram.named_buffers\  s^      "%T%9%9%P%P!Q//77K4!>>+#>>>!??;#???	 8s   A)A+c                     U R                   $ rR   )r  r  s    rY   r  !ExportedProgram.range_constraintsi       &&&r\   c                     [        S5      e)Nz<Unable to set ExportedProgram's range_constraints attribute.r  r  s     rY   r  r  n       J
 	
r\   c                     U R                   $ rR   )r  r  s    rY   rc  !ExportedProgram.module_call_graphu  r  r\   c                     [        S5      e)Nz<Unable to set ExportedProgram's module_call_graph attribute.r  r  s     rY   rc  r  z  r  r\   c                     U R                   $ rR   )r  r  s    rY   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   r8   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}   ry  _unliftr  	call_specrN   )rT   r  rn   ro   r  s        rY   r   r    s    
 =#(  ue$$E
a58U++58T**B 
 0D$..*@*@A$r\   c                 .   [        SSS/5      n[        U R                  5      S:X  a  U" S S S9$ U R                  S   R                  S:X  d   eU" U R                  S   R                  R
                  U R                  S   R                  R                  S9$ )NCallSpecrN   rO   r   )rN   rO    )r   r  rc  rj   rk   rN   rO   )rT   r  s     rY   r  ExportedProgram.call_spec  s     j9j*ABt%%&!+D488%%a(,,222**1-77??++A.88AA
 	
r\   c                     [        S5      e)Nz4Unable to set ExportedProgram's call_spec attribute.r  r  s     rY   r  r         QRRr\   c                      U R                   S   $ Nr   r  r  s    rY   verifierExportedProgram.verifier  s     q!!r\   c                     [        S5      e)Nz3Unable to set ExportedProgram's verifier attribute.r  r  s     rY   r  r    s     PQQr\   c                 R    U R                   c   eU R                   S   R                  $ r  )r  dialectr  s    rY   r  ExportedProgram.dialect  s)     ***q!)))r\   c                     [        S5      e)Nz2Unable to set ExportedProgram's dialect attribute.r  r  s     rY   r  r    s     OPPr\   c                     U R                   $ rR   r  r  s    rY   r  ExportedProgram.verifiers       r\   c                     [        S5      e)Nz4Unable to set ExportedProgram's verifiers attribute.r  r  s     rY   r  r    r  r\   c                     U R                   $ rR   r  r  s    rY   tensor_constants ExportedProgram.tensor_constants  r  r\   c                     [        S5      e)Nz;Unable to set ExportedProgram's tensor_constants attribute.r  r  s     rY   r  r    s     I
 	
r\   c                     U R                   $ rR   r  r  s    rY   r   ExportedProgram.constants  r  r\   c                     [        S5      e)Nz4Unable to set ExportedProgram's constants attribute.r  r  s     rY   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$ )af  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 flattend 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)r8   Nr]   )r  rp  s     rY   r  <ExportedProgram._get_flat_args_with_check.<locals>.<genexpr>  s     <(;1A$(;s   )r  rN   r2   rd   tree_flatten_with_path_check_input_constraintsr   )rT   rn   ro   rN   flat_args_with_pathreceived_spec	flat_argss          rY   _get_flat_args_with_check)ExportedProgram._get_flat_args_with_check  sg     ..((#F4F-3-J-JN.
* 	%%&9:<(;<<	''r\   rn   ro   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  rN   r  r1   r~   ry  r   r   r   r=   r  r  r  r  r   r   r   r   CONSTANT_TENSOR
CUSTOM_OBJr   )rT   rn   ro   rN   r  r  additional_inputsinput_s           rY   _graph_module_flat_inputs)ExportedProgram._graph_module_flat_inputs  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  )rT   rn   ro   s      rY   __call__ExportedProgram.__call__-  s    B
 	
r\   c           	      r  ^ SSK Js  Jn  U R                  X#5      u  pVU R                  R
                  Gb  U R                  R                  nU R                  R                  n[        U5      [        U5      -   n	USU	 n
U R                  R                  nUb'  [        [        UR                  5       5      5      nUSU nXS n [        R                  " XR                  R
                  5      n U R                  R&                   Vs/ s H%  nUR(                  [*        R,                  :X  d  M#  UPM'     nn[/        U
5       H  u  nnU R                  R0                  U   mTR(                  [2        R4                  :X  a*  TR6                  c   eUU R8                  TR6                  '   Mg  TR(                  [2        R:                  :X  aC  TR6                  c   e[        U4S j[/        U5       5       5      nUU   R=                  U5        M  [?        STR(                   35      e   U$ U$ ! [          aD    [        R"                  " U5      u  pmUR%                  SU R                  R
                   SU 35      ef = fs  snf ! U R                  R&                   Vs/ s H%  nUR(                  [*        R,                  :X  d  M#  UPM'     Os  snf nn[/        U
5       H  u  nnU R                  R0                  U   mTR(                  [2        R4                  :X  a*  TR6                  c   eUU R8                  TR6                  '   Mg  TR(                  [2        R:                  :X  aC  TR6                  c   e[        U4S j[/        U5       5       5      nUU   R=                  U5        M  [?        STR(                   35      e   f = f)zProcess potential mutations to the input.

Because self.graph_module is functional, so mutations has to be written
back after execution of graph_module.
r   Nz@Trying to flatten user outputs with exported output tree spec: 
z.
but actually got outputs with tree spec of: 
c              3   x   >#    U  H/  u  pUR                   R                  TR                  :X  d  M+  Uv   M1     g 7frR   )r   rS   r   )r  rW   rD  output_specs      rY   r  DExportedProgram._postprocess_graph_module_outputs.<locals>.<genexpr>`  s2      %+A#xx}}0B0BB A+As   *:	:zUnexpected kind: ) torch._export.error_exporterrorr  r  rO   r   rX  r  r  assertion_dep_tokennextiterr   rd   r   	ExceptionrW  InternalErrorr   r   r=   r  r  r   r?   r  r   r   r  copy_r  )rT   resr   orig_kwargsr  r  r<  buffer_mutationuser_input_mutationnum_mutatedmutated_valuesr  assertion_dep_token_indexr  rD  r  rW   r  indexr	  s                      @rY   !_postprocess_graph_module_outputs1ExportedProgram._postprocess_graph_module_outputs3  st    	,+55iM	>>""."22DDO"&"6"6"L"Lo.5H1IIK +.N #'"6"6"J"J".,06I6N6N6P1Q,R)445l#CU++C1H1HI !% 4 4 @ @ @yyI$8$88  @  
 !*. 9HAu"&"6"6"C"CA"FK"'':+E+EE*11===>C(:(:;$))Z-K-KK*11=== $ %+4[+A% !
 "%(..u5,/@AQAQ@R-STT !: 
s
;  #)#6#6s#; ))W~~../ 0E$o'  $ 4 4 @ @ @yyI$8$88  @ 
 !*. 9HAu"&"6"6"C"CA"FK"'':+E+EE*11===>C(:(:;$))Z-K-KK*11=== $ %+4[+A% !
 "%(..u5,/@AQAQ@R-STT !:s8   *H% "I6,I6%AI33I; ;N6"K:K C6N6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replacerf   r   r  )rT   r   r   strings       rY   __str__ExportedProgram.__str__j  s    ((77 8 

'$
! 	 d223;;D(K. !  /0 1""&"8"8!9= 	 r\   c                     SSK Jn  U" U 5      nSS[        4S jjnSS[        4S jjn[        R                  " X25      Ul        [        R                  " XB5      Ul        U$ )zO
Returns a self contained GraphModule with all the parameters/buffers inlined.
r8   )&_unlift_exported_program_lifted_statesmodec                     [        S5      e)Nz%Calling train() is not supported yet.NotImplementedErrorrT   r)  s     rY   _train&ExportedProgram.module.<locals>._train  s    %&MNNr\   c                     [        S5      e)Nz$Calling eval() is not supported yet.r+  r-  s     rY   _eval%ExportedProgram.module.<locals>._eval  s    %&LMMr\   )T)r  r(  booltypes
MethodTypetraineval)rT   r(  r   r.  r1  s        rY   r   ExportedProgram.modulew  sY     	D7=	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rR   )r   r=   r  )r  rW   ss      rY   r  =ExportedProgram._num_lifted_params_buffers.<locals>.<genexpr>  s-      HDA66Y111 Hs   $3	3)r  r  r  r   r  r  s    rY   _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  )rI   r}   r   r4   materializer   r  )rT   r   r   _decomp_tabler   r   s         rY   run_decompositions"ExportedProgram.run_decompositions  sn    P )5(<"$$|BT 	 m%677)557M" 9G	
 +' 3!(C
 	
r\   passesc                 j   [        [        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   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,                  R/                  U R                  R,                  5        UR                  R,                  R/                  UR                  R,                  5        U$ ! , (       d  f       GNu= f)Nr   )r   old_signaturenew_gmrz   c           	      &   / n[        UR                  R                  5       H  u  p4UR                  S:w  a    OU[	        U R
                  5      :  d   S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:X  d   e/ n[        UR$                  S   5       H  u  p4U[	        U R&                  5      :  d   S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   z-Number of inputs changed after transformationr   rS  r   z.Number of outputs changed after transformationr   )r  r   r   r   r  r   r   r   r:   r;   r   rS   r   r>   r   r   r  rb   rn   r   r@   r<   )rF  rG  new_input_specsrW   r,  old_input_specr   output_nodenew_output_specsold_output_specnew_signatures              rY   _get_updated_graph_signatureKExportedProgram._transform_do_not_use.<locals>._get_updated_graph_signature  s    !O$V\\%7%7877m+3}8899 C9 "/!:!:1!= "&**-=?P,Q  #&& n001$))<   &&&++&--&11	 90 v||11226K>>X---!$[%5%5a%893}99:: D: #0"<"<Q"? "'++.>@Q-R  $'' o112499=  !''33S:P:PQ :  1+M ! r\   	r  r   r   r   r  rc  r   r   r  )r7   rb   r   r   r   modifiedr<   r   r  r`  rF   r   r   r   r  r  r   ru  r  r   r   r  r   r   )rT   rD  pmr   r  transformed_gmrO  transformed_eps           rY   _transform_do_not_use%ExportedProgram._transform_do_not_use  sf   f& 	@$&T&&'C '-0_))$BSBS)))...s||K7	!/7	!HH((7	! "7	!r ) &&8$$n <&& #mmD,C,CD..nnnn
  	##((//0A0A0F0FG##((//0@0@0E0EFi '&s   F##
F2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.utilsrY  r   r   r   r  r   r   r   r=   r  r  )rT   r  rY  r8  placeholdersr;  input_placeholderss          rY   r  (ExportedProgram._check_input_constraints6  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 rR   )	_validater  s    rY   r  ExportedProgram.validateC  s    r\   c                     [        U R                  5      S:  d   S5       eU R                   H  nU" 5       R                  U 5        M     g )Nr   z0ExportedProgram must have at least one verifier.)r  r  check)rT   rP  s     rY   r_  ExportedProgram._validateH  s@    4>>"Q& 	
>	
& 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	$ )NrQ  )
rF   r   r   r   ru  r  r  r   r   r  )rT   r   r   r   r   r  s         rY   _updateExportedProgram._updateQ  s     $$+%/%;z"mmD,B,BC"mmD,C,CD..#,#8idnn#,#8i

 
	
 ?Cnn

 
	
r\   )r  r  r  r  r  r  r  r  )NN)NF)rz   rF   )Cr^   r_   r`   ra   __doc__r   r   r   Moduler}   rf   r   r  Graphr<   r   r  rb   rG   r
   r   r   r   r,   r  propertyr5   r   setterr   r   r   r   r  r   r  r   r  rc  r   r  r  r  r  r  r   r  r  r  r  r%  r   r=  ru   _opsOperatorBaser   r3  rB  PassTyperV  r  r  r	   r_  re  rg   r]   r\   rY   rF   rF     s   . LPAE# 59#EHHOOT#s(^34# xx~~# .	#
 eELL%((2D2D$DEEF# 5#  0# !uS#XS#X'F!GH# D&<!<=># Dh01#J %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 
5n  $
 $ KO,1D
tEJJ$;$;X$EFGD
 &*D
 
	D
 $D
LZX Z:K Zx
 %0 1   
 

 
r\   rF   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&  rP  s         rY   r  r  g  s     HHNN"D99==% 			%" 	 
 / &I"""a&&66### s
   !B1B1old_range_constraintsz!Optional[dict[sympy.Symbol, Any]]r  c                 P   Uc   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 rR   )r  r   r   replacementsvar_to_range)r   rs  r   r  r   rP  s         rY   r  r  w  s     !,,,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5        [         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   r  r`  SyntaxErrorwarningswarnri  _graph)r  r   r   s      rY   r  r    st    XX!!$.  I   	G	
 XX!!$(89	Is   # A"B	B	)rz   r4   rR   )r  r   dataclassesrs   ra  r4  ry  collectionsr   r   collections.abcr   r   typingr   r   r	   r
   r   r   rp  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_pytreerd   rZ  r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   torch._export.verifierr,   r.   r0   torch.export._tree_utilsr1   r2   torch.export.decomp_utilsr4   torch.fx._compatibilityr5   torch.fx.passes.infra.pass_baser6   "torch.fx.passes.infra.pass_managerr7   r   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   __all__r  r`  rn  	dataclassrH   rG   ru   r   Contextr3  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}   rl  rm  r   r   rI   intrQ  r   ri  rb   r  r  rF   r  r  r  r]   r\   rY   <module>r     s          / $ % G G 1 B ? 
 9 ; ? 6 I J 
 ;  $ $    " , * @ B 7 1 6 :   " UXX))*HZ,@@A ' ' '  4 4 4
GG>>G 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)-Xz2 

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

//9:4 ejj55x?@	4
 sm4 "&4n~	
 ~	
B$$ BF> .r\   