
    ȅi                       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        W/home/james-whalen/.local/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                 ^   [        [        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   ra   keysremover"   rR   
startswithr)   )r   all_preservable_cia_opsr   r   op_nameks         rX   ,_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()`
r2   r\   r[   rX   rH   rH   ?  s     r[   eprE   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R0                  R2                  [4        5      (       d   eUR0                  R2                  R6                  R8                  nUc   eUR:                  [<        [>        4;  a  [@        RB                  " U/5      n[5        [E        UURF                  U5      5      UR0                  l        URI                  5         [K        U RL                  U RN                  U5        [Q        XRR                  U RL                  RT                  5      n[W        UU5      n[Y        U5      nSSK-J.nJ/n  / nUR0                  R`                   H  nURb                  S:X  d  M  [/        URd                  S   [f        5      (       ay  S nURd                  S   Rh                  c'  U RN                  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RF                  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%RN                  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 RL                  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 RR                  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+  [/        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(                  R0                  R`                   Vs/ s H  nURb                  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      n2U2c  [        R                  " 5       OU2n3U(       a  [        R                  OUn4U	" 5          U3   [s        U5         U4" 5          U" U R(                  U/UUS LUb  UOS S9u  n(n5U(R0                  R                  5         S S S 5        S S S 5        S S S 5        S S S 5        S n6W(R0                  R`                   Vs/ s H  nURb                  S:X  d  M  UPM     n7n[?        U(R0                  R                  5       R                  S   5      n8[        U75      [        U.5      :X  d   e[        U.U75       H  u  n9n:U9Rj                  =U:l5        U:lT        M      0 n;[        [        5      n<[        5       n=U7 H3  n>U>Rj                  U;U>Rj                  '   [        U>Rj                  U<U=5        M5     U(R0                  R`                   H=  nURb                  S:X  a  M  [        U;U<U=URj                  URj                  5      Ul5        M?     [        U(5        SSK[J\n?J]n@  SSK^J_nA  [        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(RI                  5         [        U8WA" U(5      5       H  u  nDn+U+c  M  U+WDl5        M     [        U RL                  R                  5       VEVFs0 s HK  u  nEnF[/        UFR                  [        5      (       a  M'  WFR                  Rj                  U7WE   Rj                  _MM     nGnEnF[        U RL                  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      nKUKU8S [        UK5        Vs/ s H  nURj                  PM     sn:X  d   eU5R                  R}                  5        H  u  nLnMWJUM   nEU RL                  R                  UE   nNUNR                  [        R                  [        R                  4;   d   eWNR                  [        R                  :X  a  [        R                  O[        R                  nOWNR                  [        R                  :X  a  WNR                  OWNR                  Rj                  nPWIRo                  [        WO[        WLS9UPS95        M     [        U RL                  R                  5       H  u  nEnFWIRo                  [        UEU:X  a  [        R                  OWFR                  U6" WFR                  U8[        WK5      WE-      5      WGR                  UFR                  UFR                  5      5      5        M     UGb  U5R                  c   eU5R                  R                  nQ[        U5R                  5      [        U RL                  R                  5      :X  d   e[        U RL                  R                  5       VEVFs0 s H7  u  nEnF[/        UFR                  [        5      (       d  M'  U5R                  WE   WF_M9     nRnEnFU8[        WI5      S   H  nWQURj                     nSWRUS   nFUFR                  [        R                  :X  a  [        GR                   nTWFR                  nPOKWFR                  [        R                  :X  a  [        GR                  nTWSnPOG[        SWFR                   35      eWIRo                  [        WT[        URj                  S9WP5      5        M     [        U75      [        U.5      :X  d   eG[        WHWIS9n)[        U.U75       H  u  nUnV[/        UURd                  S   [        GR                  5      (       d  WURd                  S   WVRd                  S'   WVR                  U)GR
                  ;   d  WVR                  U)GR                  ;   d  M  WURd                  R}                  5        H  u  nWnXUXWVRd                  UW'   M     M     U(U)U RR                  4$ s  sn'n&f ! , (       d  f       G
Na= f! , (       d  f       G
Nk= f! , (       d  f       G
Nu= 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 ! , (       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export)&_enable_graph_inputs_of_type_nn_module_fakify_script_objectsplaceholdervalr7   )r   _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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_argZ  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_trace)metadataz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_specr   graph_codegenr   pytree_info	orig_argsr   ra   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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_INPUTAssertionErrorr;   Tensorinputs_to_parametersinputs_to_buffers)Yr   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output_name
input_name
input_specoutput_kindr   	gradientsspecssourcer   old_noderU   r   vsY                                                                                            rX   2_decompose_and_get_gm_with_new_signature_constantsrU  H  s    Y?  ?
 r44iik"
3'''?@"
3$$e$<="

	
 	*#.$
3'''?@$
3$$e$<=$
  .boo>	&DII ==#)),,n====++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););<<<<~%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 	$$& 	. 	; 	 	"$N *,T477m;ST-22883G3G3I3N3Nq3Q-RK  C(8$9999.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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 	 

  L 1 34Dtyy)F=DyyI///!77i222!88$';DII;%GHH"		2 5&  C(8$9999.l ""24DE((--.==#+==#7HMM%  OO2GGG"5"G"GG ++-1#$a  . F "BMM11K	27  K FE  ID$ @M  	.- 	;: 	 	"!> UP *" XWJ
s;  {- {3{	?Az7	1z%6*z A+z%z7	{	{#{-;{?{?+|||
|=} |9|'9|	|'|9}} };#}" &}4*(}47A}:!~ (~&~-~z%%
z4/z7	7
{{		
{{
{*	%{--
{<
|$|''
|61|99
}	}
}"
}1r   r6  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.
rG  call_functionr7   N)_set_replace_hookget_replace_hookr   r   r   rc   tree_flattenrm   r   r   fxNoderR   buffers_to_mutateparameters_to_mutater   opsr   r   defaultrY   
erase_noder   )r   r6  r+  rm   r;  outs         rX   r   r     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)NrW  .)rX  rY  modulesr   r   r[  GraphModulera   r   r   r   r   operatorgetitemrm   rY   rj   ra  rR   )r   r   module_call_graphr   node_idgetitemsr+  rR  idxnew_identrys              rX    _common_getitem_elimination_passro  )  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                   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                   ;  $ rQ   )input_tokens)xold_graph_params_buffersrq  s    rX   <lambda>0_get_updated_module_call_graph.<locals>.<lambda>d  s$    a77 :,999:r[   	from_noder7   zparametrizations.rd  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 tensorsrW  )"r   deepcopyr   r   rR   r   r!  r   r   ra   filterr   r  ru  r   re   r   r   r   joinsplitr   rj   rK   rL   
ValueErrorr   r_  r   todtype_layoutdevicedtyperm   )rp  rq  r   r   rr  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_targetrn  rj   rv  rS  rw  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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_constraintsri  r   r   )rU  r  r   r   ri  r   r   _get_updated_range_constraintsr  rE   r   r   r   )r   r   r   r   r   r   r6  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]ri  r   r   r  c	                r   [         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         [-        U R                  5      U l        g )Nc              3   B   #    U  H  n[        U[        5      v   M     g 7frQ   )r{   r+   ).0rT  s     rX   	<genexpr>+ExportedProgram.__init__.<locals>.<genexpr><  s     >Iq:a**Is   )r   r[  r   CodeGenr   _create_graph_module_for_exportr  r   rf  r   r   ro  r  r  r  r  r  r  r+   allr  validate_convert_guards_to_coder  )
rS   r  r   r   r   r  ri  r   r   r  s
             rX   __init__ExportedProgram.__init__  s     //1<TIdEHH0011##**4995(	
 7F+5CT ,,,9J-#/r+(	>I>>>>>#3D4F4FGr[   F)is_backward_compatiblec                     U R                   $ rQ   )r  rS   s    rX   r   ExportedProgram.graph_moduleC  s     !!!r[   c                     [        S5      e)Nz7Unable to set ExportedProgram's graph_module attribute.r   rS   values     rX   r   r  H  s     TUUr[   c                 .    U R                   R                  $ rQ   )r   r   r  s    rX   r   ExportedProgram.graphM  s       &&&r[   c                     [        S5      e)Nz0Unable to set ExportedProgram's graph attribute.r  r  s     rX   r   r  R  s     MNNr[   c                     U R                   $ rQ   )r  r  s    rX   r   ExportedProgram.graph_signatureW  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_dicta  s     r[   c                     [        S5      e)Nz5Unable to set ExportedProgram's state_dict attribute.r  r  s     rX   r   r  f  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.parametersk  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_parameterss  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   ri  !ExportedProgram.module_call_graph  r  r[   c                     [        S5      e)Nz<Unable to set ExportedProgram's module_call_graph attribute.r  r  s     rX   ri  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                 0    " 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$ )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    )r	   r  ri  ri   rj   rM   rN   )rS   r  s     rX   r  ExportedProgram.call_spec  s    	-z 	- 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     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                 R    U R                   c   eU R                   S   R                  $ 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.constants  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  rv  s     rX   r  <ExportedProgram._get_flat_args_with_check.<locals>.<genexpr>&  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_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  )rS   rm   rn   s      rX   __call__ExportedProgram.__call__W  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>._trainy  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.modulej  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                 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_gmry   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{  rG  r   z.Number of outputs changed after transformationr   )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  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  ri  r   r   r  )r6   ra   r   r   r   modifiedr;   r   r[  rf  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  sh   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m '&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.utilsrP  r   r   r   r  r   r   r   r<   r  r  )rS   r  rP  r7  placeholdersr1  input_placeholderss          rX   r  (ExportedProgram._check_input_constraints2  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.validate?  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)rS   rT  s     rX   rV  ExportedProgram._validateD  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	$ )NrG  )
rE   r   r   r   r|  r  r  r   r   r  )rS   r   r   r   r   r  s         rX   _updateExportedProgram._updateM  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[  rf  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  ri  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N %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\X \:K \|
 %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%  rT  s         rX   r  r  c  s     HHNN"D99==% 			%" 	 
 / &I"""a&&66### s
   !B1B1old_range_constraintszdict[sympy.Symbol, Any] | Noner  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 rQ   )r  r   r   replacementsvar_to_range)r   rj  r   r  r   rT  s         rX   r  r  s  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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[  rf  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  rR  ConstantSource)r  rR  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   rx  )_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   rg  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[  rf  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	  rU  r   ro  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)-XE2E2 

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

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