
    Vh                     &   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlmZ d dl	m
Z
 d dl mZ d dlmZmZmZmZmZmZ d dlmZ d dlmZ d dlmZmZmZ d d	lmZ d d
lmZ d dlm Z m!Z! d dl"m#Z#m$Z$ d dl%m&Z& er
d dl'Z'd dl(m)Z) d dl*Z*d dl+m,c m-Z. d dl/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z> d dl?m@Z@ d dlAmBZB d dlmCZC d dlDmEZEmFZF d dlGmHZH d dlImJZJ d dlKmLZL d dlMmNZN ddlOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\ g dZ]ee*j                  j                  geeL   f   Z`ej                   G d d             Zbej                   G d d             Zcd Zdd eee   d!e.j                  d"eee   d#e.j                  d$egf
d%Zhe*j                  j                  j                  e*j                  j                  j                  e*j                  j                  j                  e*j                  j                  j                  e*j                  j                  j                  e*j                  j                  j                  e*j                  j                  j                  e*j                  j                  j                  e*j                  j                  j                  e*j                  j                  j                  e*j                  j                  j                  e*j                  j                  j                  gZwe*j                  j                  j                  e*j                  j                  j                  e*j                  j                  j                  e*j                  j                  j                  e*j                  j                  j                  e*j                  j                  j                  e*j                  j                  j                  e*j                  j                  j                  e*j                  j                  j                   g	Zed@d&       Zed'        Zd(ee*j
                  j                  ef   d$eee*j
                  j                  ef   d)f   fd*ZdAd+Zd,ee*j
                  j                  ef   d-ee*j
                  j                  ef   d.ee   fd/Zd0e*j                  j                  d1eSd$ee*j                  j                  eSf   fd2Zd0e*j                  j                  fd3Zd0e*j                  j                  d4eec   fd5Zd,ee*j
                  j                  ef   d-ee*j
                  j                  ef   d.ee   d6egfd7Z G d8 d9      Zd: Z	 dBd0e*j                  j                  d;d<d$d=fd>Zd? Zy)C    N)
namedtuple)Iterator)contextmanager)AnyCallablefinalOptionalTYPE_CHECKINGUnion)autograd_not_implemented)FakeScriptObject)_deregister_op_impl_is_op_registered_to_fake_ruleregister_op_impl)FakeTensorMode)#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                       e Zd ZU ee   ed<   ee   ed<   ej                  ed<   ej                  ed<   dZe	ee
      ed<   d Zy)rD   inputsoutputsin_specout_specNforward_arg_namesc                     | j                   D ]-  }|j                  |j                  k(  s|j                  |_        / | j                  D ]-  }|j                  |j                  k(  s|j                  |_        / y N)rG   namerH   )selforiginal_nodenew_nodeios        M/home/dcms/DCMS/lib/python3.12/site-packages/torch/export/exported_program.pyreplace_all_uses_withz)ModuleCallSignature.replace_all_uses_withf   sd     	'Avv+++!	'  	'Avv+++!	'    )__name__
__module____qualname__listr5   __annotations__pytreeTreeSpecrK   r	   strrU    rV   rT   rD   rD   ^   sE    ,__oo-1xS	*1'rV   rD   c                   ,    e Zd ZU eed<   dZee   ed<   y)rC   fqnN	signature)rW   rX   rY   r^   r[   rb   r	   rD   r_   rV   rT   rC   rC   o   s    	H/3Ix+,3rV   rC   c                 B     t        j                          fd       }|S )Nc                  T    t               5   | i |cd d d        S # 1 sw Y   y xY wrM   r+   )argskwargsfns     rT   wrapperz/_disable_prexisiting_fake_mode.<locals>.wrapperv   s+    #% 	't&v&	' 	' 	's   ')	functoolswraps)rg   rh   s   ` rT   _disable_prexisiting_fake_moderk   u   s%    __R' ' NrV   
spec1_typespec1_context
spec2_typespec2_contextreturnc                     | || |u xr ||k(  S t        | t        t        f      rt        |t        t        f      r||k(  S t        | t        t        f      rt        |t        t        f      r||k(  S | |u xr ||k(  S )zeTreat containers and their immutable variants as the same type. Otherwise
    compare as normal.
    )
issubclassdictr   rZ   r   )rl   rm   rn   ro   s       rT   _fx_collection_equivalence_fnrt   ~   s     Z/Z'JM],JJ*t^45*T>*; --*t^45*T>*; --#F(FFrV   c              #     K   i }t               }| j                         D ]z  \  }}|j                  j                         ||<   |j	                  |       t
        D ]3  }||j                  vs |j                  |      t        |d             5 t        |      }t        j                  j                  j                  |j                  v r/|j                  t        j                  j                  j                  = |r9 |j                  t        j                  j                  j                        |       d }t        |      s& t        |      t        j                   ||             t"        D ](  }	|	|j                  vs |j                  |	      |       * } 	 d  |D ]_  }
|
j                  j%                          |
j                  j'                  ||
          |
j(                  j%                          t+        |
       a y # |D ]_  }
|
j                  j%                          |
j                  j'                  ||
          |
j(                  j%                          t+        |
       a w xY ww)NT)deferred_errorc                 R    |d   }|d= | 5   ||i |cd d d        S # 1 sw Y   y xY w)Noriginal_callabler_   )fake_tensor_modeopre   rf   orig_cia_callables        rT   $_force_dispatch_to_orig_cia_callablezQ_override_composite_implicit_decomp.<locals>._force_dispatch_to_orig_cia_callable   s<     &': ;*+! :($9&9: : :s   &)rx   )setitems
py_kernelscopyadd(_AUTOGRAD_ALIAS_BACKEND_KEYS_TO_OVERRIDEpy_implr   r   torch_CDispatchKeyCompositeImplicitAutogradr   r   ri   partial_BACKEND_KEYS_TO_OVERRIDEclearupdate_dispatch_cacher   )cia_ops_to_callablesafesaved_tablespatched_opsop_overloaddecomp_callableoverride_dispatch_keyr{   r|   keyrz   s              rT   #_override_composite_implicit_decompr      s      L%K(;(A(A(C ><$_$/$:$:$?$?$A[!$%M 	!$K,B,BB:##$9:,[N	 0<8899[=S=SS&&uxx';';'U'UVOK 4 4 N NO	: .k:)[)!!8&7 - 	<C+000  )##C():;#	<[><@$ 	$BMM!MM  b!12$$&#		$+ 	$BMM!MM  b!12$$&#		$s-   A)I0,DI0I0H "A%I0A&I--I0c               #      K   t        t        j                  j                  j                  j
                  t        t        j                  j                  j                  j                  t        id      5  d  d d d        y # 1 sw Y   y xY ww)NF)r   )r   r   opsatentodtype_layoutr&   dtyper_   rV   rT   !_override_decomp_aten_to_variantsr     sg     
 
-IINN**,GIINN##%@	
 
  	  s   A2B4B9	BBBdecomp_table.c                 J   t        t                     }i }t        | j                               D ]_  }||v r| |   ||<   |j	                  |       | |= $t        |      s0|j                         }|j                  d      rJ d       | |   ||<   a |D ]  }t        ||<    || fS )Nr   zThis should be a custom op)	r}   r   rZ   keysremover   rN   
startswithr&   )r   all_preservable_cia_opsr   rz   op_nameks         rT   ,_split_decomp_table_to_cia_and_python_decompr   '  s     ""<">?<$$&' 7$ ((&22&6##**2.R  $B'ggiG))&1O3OO1&22&6#97@ % =!<A= ,,rV   c                      t               S )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()`
    r/   r_   rV   rT   rE   rE   S  s     rV   cia_to_decomppython_decomp_tablejoint_loss_indexc                   ddl m} ddlm} ddlm}m}m}	m}
m	}m
} ddlm} d } || |      s| j                         }i t        |j                  d            t        |j!                  d            }dd	lm}  ||       i t        |j                  d            t        |j!                  d            }t'        | j(                        }|t+         |       d
      }|j,                  }|j.                  j0                  j2                  j4                  }|j6                  t8        t:        fvrt=        j>                  t:        d |g      }tA        tC        ||jD                  |            |j.                  _        |jG                          tI        | jJ                  | jL                  |       tO        || jP                  | jJ                  jR                        }tU        ||      }tW        |      }ddl,m-}m.} g }|j.                  j^                  D ]  }|j`                  dk(  stc        |jd                  d   tf              rwd }|jd                  d   jh                  '| jL                  |jd                  d   jj                     }n#|jd                  d   jh                  jl                  }|jo                  |       |jo                  |jd                  d           |5  tq               5  ts        |      5   || jt                        5  t=        jv                  ||jD                        } ||g |d   |d   jy                         i |      5 \  }} }!}"}# ||| |!||"|dd|	      }$|$jL                  j{                         D %&ci c]  \  }%}&|%tc        |&t|              r|#|&   n|& c}&}%|$_&        |$j~                  }'|$j                  }(t        |(|      }(t        ||'|(       t        | jJ                  |(      }( ||'|(|"      })t        |'|(|| |!||)       d d d        d d d        d d d        d d d        d d d         |
'        ||'        ||'(       t        |'|(      \  }'}(|j{                         D ]  \  }*}+|*|vs|+| jP                  |*<    |j{                         D ]h  \  }*}+|*| jP                  vr&tc        |+t        j                  j                        rJ |*| jP                  v sI|*|vsN| jP                  j                  |*       j |'|(| jP                  fS | j(                  j.                  j^                  D cg c]  }|j`                  dk(  s| },}|,D cg c]  }|jd                  d    }-}| j(                  j!                         D *.cg c]  \  }*}.|*	 }/}*}.|/D ]  }*t        | j(                  |*        t        |-      }|t        j                         n|}|rt        j                  n|}0 |	       5  |5  ts        |      5   |0       5   || j(                  |-||d
nd||nd       \  }'}1|'j.                  j                          d d d        d d d        d d d        d d d        d }2'j.                  j^                  D cg c]  }|j`                  dk(  s| }3}t9        |'j.                  j^                        d   j                  d   }4t        |3      t        |,      k(  sJ t        |,|3      D ]  \  }5}6|5jj                  x|6_5        |6_R         |3D 7ci c]  }7|7jj                  |7jj                   }8}7|'j.                  j^                  D ]8  }|j`                  dk(  rt        |8|jj                  |jj                        |_5        : t        |'       ddlUmV}9mW}: ddlXmY}; t        j                  j                  j                  s[d}<t        |'      }=|=L |:|'t        j                  |9|<            5  t        |'|=dt        |'j.                         d
       d d d        |'jG                          t         |;|'            D ]7  \  }>}*tc        |4|>   t        j                  j                        s.|*|4|>   _5        9 t        | jJ                  j                        D >?ci c]C  \  }>}?tc        |?j                  t              s$|?j                  jj                  |3|>   jj                  E }@}>}?t        | jJ                  j                        D >?cg c]E  \  }>}?t        |?j                   |2|?j                  |3|>         |?j                  |?j                        G }A}>}?g }Bt        1j                        D >*ci c]  \  }>}*|*|>
 }C}>}*t9        |1j                  j                               }D|D|4d t        |D       D cg c]  }|jj                   c}k(  sJ |1j                  j{                         D ]  \  }E}FC|F   }>| jJ                  j                  |>   }G|Gj                  t        j                  t        j                  fv sJ Gj                  t        j                  k(  rt        j                  nt        j                  }HGj                  t        j                  k(  rGj                  nGj                  jj                  }IBjo                  t        Ht        E      |I              t        | jJ                  j                        D ]  \  }>}?Bjo                  t        |>|k(  rt        j                  n|?j                   |2|?j                  |4t        D      |>z            @j                  |?j                  |?j                                      ||1j                  J |1j                  j                  }Jt        |1j                        t        | jJ                  j                        k(  sJ t        | jJ                  j                        D >?ci c]/  \  }>}?tc        |?j                  t              r|1j                  |>   |?1 }K}>}?t        |4t        B      d        D ]  \  }>}J|jj                     }LK|L   }?|?j                  t        j                  k(  rt        j                  }M|?j                  }InH|?j                  t        j                  k(  rt        j                  }ML}Int        d|?j                         Bjo                  t        Mt        |jj                        I              t        |3      t        |,      k(  sJ t        AB      }(t        |,|3      D ]  \  }N}Otc        |Njd                  d   t        j                         sNjd                  d   Ojd                  d<   Oj                  |(j                  v sOj                  |(j                  v s}Njd                  j{                         D ]  \  }P}Q|QOjd                  |P<     |'|(| jP                  fS c c}&}%w # 1 sw Y   
xY w# 1 sw Y   
xY w# 1 sw Y   
xY w# 1 sw Y   
xY w# 1 sw Y   
 xY wc c}w c c}w c c}.}*w # 1 sw Y   #xY w# 1 sw Y   (xY w# 1 sw Y   -xY w# 1 sw Y   2xY wc c}w c c}7w # 1 sw Y   xY wc c}?}>w c c}?}>w c c}*}>w c c}w c c}?}>w )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                 >    |d uxs | j                   j                  d uS rM   )graph_signaturebackward_signature)epr   s     rT   _is_joint_ir_decompzO_decompose_and_get_gm_with_new_signature_constants.<locals>._is_joint_ir_decompp  s)    D( A!!44D@	
rV   F)remove_duplicate)!unwrap_tensor_subclass_parametersT)	shape_envexport)&_enable_graph_inputs_of_type_nn_module_fakify_script_objectsplaceholdervalr4   )r   _check_autograd_state_prettify_placeholder_namesdecompose_custom_triton_ops)decompositionstrace_jointoutput_loss_indexc                    t        | t              r| S t        | t              rt        |j                        S t        | t              rt	        |j                        S t        | t
              rt        |j                        S t        | t              rt        |j                        S t        dt        |              )NrN   zType of old_arg not supported: )	
isinstancer6   r@   rN   r?   r>   r=   RuntimeErrortype)old_argnew_phs     rT   
update_argzF_decompose_and_get_gm_with_new_signature_constants.<locals>.update_argb  s    g/0N0!v{{330!v{{33!12#551"44<T']OLMMrV   )_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   modulers   named_parametersnamed_buffers7torch._functorch._aot_autograd.subclass_parametrizationr   r   graph_moduler   	_out_specgraph_codegenpytree_info	orig_argsr   rZ   tupler\   r]   r   r   _in_spec	recompiler   r   	constantsr$   
state_dictnon_persistent_buffersr   r   torch._export.non_strict_utilsr   r   nodesrz   r   metar7   fake_valrN   real_objappendr   r   example_inputstree_unflattenvaluesr~   r   gmsigr!   r#   r"   r'   !_remove_unneccessary_copy_op_passr   nn	Parameterpopdelattrr*   
contextlibnullcontexteliminate_dead_codere   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_envri   r   r   r   	enumeratefxNoder   r   r6   r:   r   
persistentuser_inputsuser_inputs_to_mutater   r9   
USER_INPUTBUFFERr;   BUFFER_MUTATIONUSER_INPUT_MUTATIONr<   r@   r   LOSS_OUTPUTgetr   gradients_to_user_inputs	PARAMETERGRADIENT_TO_PARAMETERGRADIENT_TO_USER_INPUTAssertionErrorr8   Tensorinputs_to_parametersinputs_to_buffers)Rr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   modwrapped_params_buffersr   unwrapped_params_buffers	fake_moderJ   orig_arg_namestemp_registered_constantsfake_params_buffersparams_buffers_to_node_metar   r   retracing_argsnodereal_script_objretracing_args_unwrappedpatched_modnew_fake_argsnew_fake_kwargsnew_fake_constant_attrsmap_fake_to_realaten_export_artifactra   objr   new_graph_signaturer   rN   p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   rR   specold_new_placeholder_mapr   r   user_inputs_indexmutation_namesoutput_name
input_name
input_specoutput_kindr   	gradientsspecssourcer   old_noderQ   r   vsR                                                                                     rT   2_decompose_and_get_gm_with_new_signature_constantsrI  \  s    Y?  ?
 r#3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#
	

 IIOO 
	<Dww-'dii.0AB&*Oyy'008*,,,tyy7G7L7L*M*.))E*:*C*C*L*L"))/:"))$))E*:;
	< P	,.P	0S1
P	 2
	P	 (.'<'<($ (-a0-a0779  E' '9!#'+!4*/050K
($& %9$B$B$H$H$J2 !S %c+;< )- !2$. *,,&:&>&>#
 L+-F $ :/5H
 'V&&(;'# <+-D	 ('!#'{EP	 P	 P	 P	d 	 #B!"&9:"C##
 0557 	(GD!11&'d#	( .335 	,GD!2==(%a););<<<r}}$77MM%%d+	, &55 ..44=8P  /??d5!?I?-/__-J-J-LM'$MM! '&' !+I,5,=
&&(9I ' 	? (
 
!	" 'I '/R0 '*,' 0OO. 0 <%$4$@ d
O 	$$&' ' ' ' N *,T477m;STTrxx~~&r*//2K  C(8$9999.0@A 2&,kk1fm2 ,<<R <H< O77m#.xDIIN	O $B' Y==;;1 	 #2&	 (I%%&9{S  0()LRXX)V(WX	 LLN045 '4k!nehhmm4"&KN' !!3!3!?!?@At$(($45 	'*///  !!3!3!?!?@ At 	IItxx!1!!45KKOO		
K  L 1:/:U:U0VWWQqWW/??DDFGNK@U#nBU4VWDdii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	

. 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
4$((N3 ''*D0
 

 !S->-@!AB 	GAttyy)F=DyyI///!77i222!88$';DII;%GHH"		2	&  C(8$9999.l ""24DE 	%((--.=#+==#7HMM%  OO2GGG"5"G"GG ++- %1#$a %	% "BMM11g29E EP	 P	 P	 P	 P	 P	 P	 P	` @M' ' ' ' ' ' ' ': U =0 $" XWJ
s*  y'x>3x1Ax$	5x "x"A+xx$	x1x>%y5y
yy	y"3z6zy5
=y(	y5zzzzz!0&z&Az3A
z9/z?3{4{
xx!x$	$x.)x11x;6x>>y	yy(y2-y55y?:zz	zz&z0r   r0  c                    | j                  |j                               5  | j                  j                  D ]  }|j                  dk(  st        j                  |j                        \  }}|D ]  }t        |t        j                  j                        s(|j                  |j                  v sA|j                  dk(  sQ|j                  t        j                  j                   j"                  j$                  k(  s|j'                  |j                  d          | j                  j)                  |         | j+                          ddd       | |fS # 1 sw Y   | |fS xY w)zQ
    Removes redundant copy_ node that was introduced due to mutated buffer.
    outputcall_functionr4   N)_set_replace_hookget_replace_hookr   r   rz   r\   tree_flattenre   r   r   r
  r  rN   buffers_to_mutater   r   r   r   defaultrU   
erase_noder   )r   r0  r&  re   r4  outs         rT   r   r     s    
		1BBD	E HHNN 	5Dww(" --dii8a 
5C"36HH(;(M(MM  FFo5 #

eiinn.A.A.I.I I55chhqkBHH//4
5	5 	  """!  """s+   )E
AEE/E?;E;AEE!c           	         | j                  |j                               5  | j                         D ]  }t        |t        j
                  j                        s)i }i }t        |j                  j                        D ]  }|j                  dk(  r|j                  t        j                  k(  r|j                  \  }}||    d| }	|	|v rc|j                  ||	          |D ].  }
|
j                   |
j                   j                  |||	          0 |j                  j#                  |       |||	<   |	||<   |j$                  ||<     	 d d d        y # 1 sw Y   y xY w)NrL  .)rM  rN  modulesr   r   r
  GraphModulerZ   r   r   rz   r   operatorgetitemre   rU   rb   rR  rN   )r   r   module_call_graphr   node_idgetitemsr&  rF  idxnew_identrys              rT    _common_getitem_elimination_passr`  '  sG    
		o>>@	A .jjl 	.Ffehh&:&:;02G13HV\\//0 .77o-$++AQAQ2Q"&))KFC '0#7F)228F3CD%6 "E$: % E E$((6*:!""
 //5+/((.$(IIGDM!.	.. . .s   CE/AEEold_module_call_graphc                    t        j                  |      }i }| j                  j                  D ]=  }|j                  j                  dg       x}s"|j                  ||d   j                  <   ? |D ][  }|j                  }|g |j                  |j                  D ]-  }|j                  |j                  |j                        |_        / ] |S )N	from_noder   )
r   deepcopyr   r   r   r  rN   rb   rG   rH   )	r   ra  new_module_call_graph
provenancer&  historyr_  rb   xs	            rT   _get_updated_module_call_graphri  D  s     !MM*?@ "$J 5iimmK4474+/99Jwr{''(5
 ' 4OO	89##8i&7&78 	4A^^AFFAFF3AF	4	4 ! rV   r   c          
      F   t        | ||||      \  }}}t        || j                        }|j                  j	                  | j
                  j                         t        || j                        }	t        ||j                  |||	|| j                  | j                        }
|
S )Nr   r   r   r   )rootr   r   r   range_constraintsrZ  r   r   )rI  ri  rZ  r   r   r   _get_updated_range_constraintsrm  rB   r   r   r   )r   r   r   r   r   r   r0  r   re  new_range_constraintsexported_programs              rT   _decompose_exported_programrq  \  s     	;
#/)$?		
 ;

 GGNN2??''(:


 'hh+//((,,	 rV   c                   	   e Zd ZdZ	 	 dDdddeej                  j                  ee	e
f   f   dej                  j                  dedee	eej                  ej                  j                  f   f   dd	d
ee   deeee
df   ee	e
f   f      deee	eej                  eej*                  j,                  f   f      deeee         fdZe ed      d               Zej:                   ed      d               Ze ed      d               Zej:                   ed      d               Ze ed      d               Zej:                   ed      d               Ze ed      d               Z e j:                   ed      d               Z  ed      de!ej                  j                     fd       Z" ed      de!ee	ej                  j                  f      fd       Z# ed      de!ej                     fd       Z$ ed      de!ee	ej                  f      fd       Z%e ed      d               Z&e&j:                   ed      d                Z&e ed      d!               Z'e'j:                   ed      d"               Z'e ed      d#               Z(e(j:                   ed      d$               Z(e ed      d%               Z)e)j:                   ed      d&               Z)e ed      de
fd'              Z*e*j:                   ed      d(               Z*e ed      de	fd)              Z+e+j:                   ed      d*               Z+e ed      d+               Z,e,j:                   ed      d,               Z,e ed      d-               Z-e-j:                   ed      d.               Z-e ed      d/               Z.e.j:                   ed      d0               Z.d1 Z/d2e
d3e
de
fd4Z0d2e
d3e
de
fd5Z1d6 Z2de	fd7Z3dej                  j                  fd8Z4d9 Z5e6	 	 dEd:eeejn                  jp                  e9f      d;e:dd fd<       Z;d=e<dd fd>Z=d? Z> ed      d@        Z?e@dA        ZAddddB	 dFdCZBy)GrB   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)	verifiersrl  r   r   r   rm  dict[sympy.Symbol, Any]rZ  r   .r   rs  c	                $   t         j                  j                  j                         |_        t        ||      | _        t        |t         j                  j                        r/| j                  j                  j                  |j                         t        | j                  ||       || _        || _        || _        |J || _        || _        |xs i | _        |	xs t$        g}	t'        d |	D              sJ |	| _        | j+                          y )Nc              3   <   K   | ]  }t        |t                y wrM   )rr   r(   ).0rH  s     rT   	<genexpr>z+ExportedProgram.__init__.<locals>.<genexpr>  s     >q:a*>s   )r   r
  r   CodeGenr   _create_graph_module_for_export_graph_moduler   rW  r   r   r`  _graph_signature_state_dict_range_constraints_module_call_graph_example_inputs
_constantsr(   all
_verifiersvalidate)
rO   rl  r   r   r   rm  rZ  r   r   rs  s
             rT   __init__zExportedProgram.__init__  s      //1<T5IdEHH001##**4995(1B	
 7F+5CT ,,,9J-#/r+(	>I>>>>#rV   F)is_backward_compatiblec                     | j                   S rM   )r{  rO   s    rT   r   zExportedProgram.graph_module  s     !!!rV   c                     t        d      )Nz7Unable to set ExportedProgram's graph_module attribute.r   rO   values     rT   r   zExportedProgram.graph_module  s     TUUrV   c                 .    | j                   j                  S rM   )r   r   r  s    rT   r   zExportedProgram.graph  s       &&&rV   c                     t        d      )Nz0Unable to set ExportedProgram's graph attribute.r  r  s     rT   r   zExportedProgram.graph  s     MNNrV   c                     | j                   S rM   )r|  r  s    rT   r   zExportedProgram.graph_signature  s     $$$rV   c                     t        d      )Nz:Unable to set ExportedProgram's graph_signature attribute.r  r  s     rT   r   zExportedProgram.graph_signature  s     WXXrV   c                     | j                   S rM   )r}  r  s    rT   r   zExportedProgram.state_dict  s     rV   c                     t        d      )Nz5Unable to set ExportedProgram's state_dict attribute.r  r  s     rT   r   zExportedProgram.state_dict  s     RSSrV   rp   c              #   D   K   | j                         D ]	  \  }}|  yw)zH
        Returns an iterator over original module's parameters.
        N)r   )rO   r4  params      rT   
parameterszExportedProgram.parameters  s)     
 --/ 	HAuK	    c              #   h   K   | j                   j                  D ]  }|| j                  |   f  yw)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   )rO   
param_names     rT   r   z ExportedProgram.named_parameters  s7      ..99 	:Jdooj999	:s   02c              #   D   K   | j                         D ]	  \  }}|  yw)zC
        Returns an iterator over original module buffers.
        N)r   )rO   r4  bufs      rT   bufferszExportedProgram.buffers   s)     
 ((* 	FAsI	r  c              #      K   t        | j                  j                        }| j                  j                  D ]-  }||v r|| j                  |   f || j
                  |   f / yw)z
        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   )rO   r   buffer_names      rT   r   zExportedProgram.named_buffers  sm      "%T%9%9%P%P!Q//77 	@K44!4>>+#>>>!4??;#???		@s   A'A)c                     | j                   S rM   )r~  r  s    rT   rm  z!ExportedProgram.range_constraints       &&&rV   c                     t        d      )Nz<Unable to set ExportedProgram's range_constraints attribute.r  r  s     rT   rm  z!ExportedProgram.range_constraints       J
 	
rV   c                     | j                   S rM   )r  r  s    rT   rZ  z!ExportedProgram.module_call_graph!  r  rV   c                     t        d      )Nz<Unable to set ExportedProgram's module_call_graph attribute.r  r  s     rT   rZ  z!ExportedProgram.module_call_graph&  r  rV   c                     | j                   S rM   )r  r  s    rT   r   zExportedProgram.example_inputs-  s     ###rV   c                    ||| _         y t        |t              r4t        |      dk(  r&t        |d   t              rt        |d   t              st        d      |\  }}ddlm}  |||| j                  j                         || _         y )N   r   r4   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  rs   
ValueError_unliftr  	call_specrI   )rO   r  re   rf   r  s        rT   r   zExportedProgram.example_inputs2  s    
 =#(D  ue$E
a58U+58T*B 
 f0D&$..*@*@A$rV   c                 6   t        dddg      }t        | j                        dk(  r
 |d d       S | j                  d   j                  dk(  sJ  || j                  d   j                  j
                  | j                  d   j                  j                        S )NCallSpecrI   rJ   r   )rI   rJ    )r   r  rZ  ra   rb   rI   rJ   )rO   r  s     rT   r  zExportedProgram.call_specM  s     j9j*ABt%%&!+D488%%a(,,222**1-77??++A.88AA
 	
rV   c                     t        d      )Nz4Unable to set ExportedProgram's call_spec attribute.r  r  s     rT   r  zExportedProgram.call_specZ       QRRrV   c                      | j                   d   S Nr   r  r  s    rT   verifierzExportedProgram.verifier_  s     q!!rV   c                     t        d      )Nz3Unable to set ExportedProgram's verifier attribute.r  r  s     rT   r  zExportedProgram.verifierd  s     PQQrV   c                 P    | j                   J | j                   d   j                  S r  )r  dialectr  s    rT   r  zExportedProgram.dialecti  s)     ***q!)))rV   c                     t        d      )Nz2Unable to set ExportedProgram's dialect attribute.r  r  s     rT   r  zExportedProgram.dialecto  s     OPPrV   c                     | j                   S rM   r  r  s    rT   rs  zExportedProgram.verifierst       rV   c                     t        d      )Nz4Unable to set ExportedProgram's verifiers attribute.r  r  s     rT   rs  zExportedProgram.verifiersy  r  rV   c                     | j                   S rM   r  r  s    rT   tensor_constantsz ExportedProgram.tensor_constants~  r  rV   c                     t        d      )Nz;Unable to set ExportedProgram's tensor_constants attribute.r  r  s     rT   r  z ExportedProgram.tensor_constants  s     I
 	
rV   c                     | j                   S rM   r  r  s    rT   r   zExportedProgram.constants  r  rV   c                     t        d      )Nz4Unable to set ExportedProgram's constants attribute.r  r  s     rT   r   zExportedProgram.constants  r  rV   c                     | j                   j                  }|t        ||      }t        j                  ||f      \  }}| j                  |       t        d |D              }||fS )a  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   &   K   | ]	  }|d      yw)r4   Nr_   )rw  rh  s     rT   rx  z<ExportedProgram._get_flat_args_with_check.<locals>.<genexpr>  s     <1!A$<s   )r  rI   r.   r\   tree_flatten_with_path_check_input_constraintsr   )rO   re   rf   rI   flat_args_with_pathreceived_spec	flat_argss          rT   _get_flat_args_with_checkz)ExportedProgram._get_flat_args_with_check  so     ..((#FG4F-3-J-J6N.
*] 	%%&9:<(;<<	-''rV   re   rf   c                    | j                   j                  }| j                  ||      \  }}|"t        ||t              st        d| d|       g }| j                  j                  D ]  }|j                  t        j                  k(  r"|j                  t        j                  t        j                  fv r`|j                  du r)|j                  | j                  |j                             |j                  | j"                  |j                             |j                  t        j$                  t        j&                  fv s|j                  | j                  |j                              t)        |      }||z   S )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  rI   r  r-   rt   r  r   r   r   r9   r  r  r  r  r   r   r   r   CONSTANT_TENSOR
CUSTOM_OBJr   )rO   re   rf   rI   r  r  additional_inputsinput_s           rT   _graph_module_flat_inputsz)ExportedProgram._graph_module_flat_inputs  sf    ..((#'#A#A$#O 	=}7$A(
 Q) @ /#  **66 	HF{{i222##  !  $$- &,,T^^FMM-JK%,,T__V]]-KL))$$!  "(()FG#	H$ ""34 !9,,rV   c                     t        d      )Nz\Unable to call ExportedProgram directly. You should use `exported_program.module()` instead.r  )rO   re   rf   s      rT   __call__zExportedProgram.__call__  s    B
 	
rV   c           	      :   ddl mc m} | j                  ||      \  }}| j                  j
                  | j                  j                  }| j                  j                  }t        |      t        |      z   }	|d|	 }
| j                  j                  }|'t        t        |j                                     }|d| }||	d }	 t        j                  || j                  j
                        }	 | j                  j&                  D cg c]!  }|j(                  t*        j,                  k(  r|# }}t/        |
      D ]  \  }}| j                  j0                  |   j(                  t2        j4                  k(  r(j6                  J || j8                  j6                  <   dj(                  t2        j:                  k(  r@j6                  J t        fdt/        |      D              }||   j=                  |       t?        dj(                          |S |S # t         $ rD t        j"                  |      \  }}|j%                  d| j                  j
                   d|       w xY wc c}w # | j                  j&                  D cg c]!  }|j(                  t*        j,                  k(  r|# nc c}w }}t/        |
      D ]  \  }}| j                  j0                  |   j(                  t2        j4                  k(  r(j6                  J || j8                  j6                  <   dj(                  t2        j:                  k(  r@j6                  J t        fdt/        |      D              }||   j=                  |       t?        dj(                          w xY w)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   n   K   | ],  \  }}|j                   j                  j                  k(  r| . y wrM   )r   rN   r   )rw  rR   r<  output_specs      rT   rx  zDExportedProgram._postprocess_graph_module_outputs.<locals>.<genexpr>  s3      % '4#xx}}0B0BB %s   25zUnexpected kind: ) torch._export.error_exporterrorr  r  rJ   r   rP  r  r  assertion_dep_tokennextiterr   r\   r   	ExceptionrO  InternalErrorr   r   r9   r  r	  r   r;   r  r   r   r  copy_r  )rO   resr   orig_kwargsr  r  r4  buffer_mutationuser_input_mutationnum_mutatedmutated_valuesr  assertion_dep_token_indexr  r<  r  rR   r  indexr  s                      @rT   !_postprocess_graph_module_outputsz1ExportedProgram._postprocess_graph_module_outputs  s    	,+55iM	1>>""."22DDO"&"6"6"L"Lo.5H1IIK +.N #'"6"6"J"J".,06I6N6N6P1Q,R)445kl#CU++C1H1HI !% 4 4 @ @yyI$8$88  
 !*. 9 UHAu"&"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U 
s
;  #)#6#6s#; =))W~~../ 0E$o'  $ 4 4 @ @yyI$8$88   
 !*. 9 UHAu"&"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Us,   *H &I(AI%%I- -N&J-,C.Nc                     | j                   j                  dd      j                  dd      }d| d| j                   d| j                   d}|S )NF)print_outputcolored
z
    zExportedProgram:
    z
Graph signature: z
Range constraints: )r   print_readablereplacer   rm  )rO   r   strings      rT   __str__zExportedProgram.__str__  sp    ((77 8 

'$
! 	. !  $ 4 45 6""&"8"8!9= 	 rV   c                     ddl m}  ||       }ddt        fd}ddt        fd}t        j                  ||      |_        t        j                  ||      |_        |S )z_
        Returns a self contained GraphModule with all the parameters/buffers inlined.
        r4   )&_unlift_exported_program_lifted_statesmodec                     t        d      )Nz%Calling train() is not supported yet.NotImplementedErrorrO   r  s     rT   _trainz&ExportedProgram.module.<locals>._train*  s    %&MNNrV   c                     t        d      )Nz$Calling eval() is not supported yet.r  r  s     rT   _evalz%ExportedProgram.module.<locals>._eval-  s    %&LMMrV   T)r  r  booltypes
MethodTypetraineval)rO   r  r   r  r  s        rT   r   zExportedProgram.module"  s]     	D7=	Ot 	O	Nd 	N ''7&&uf5rV   c                     t        d t        | j                  j                        D        t	        | j                  j                              S )Nc              3   `   K   | ]&  \  }}|j                   t        j                  k(  r| ( y wrM   )r   r9   r  )rw  rR   ss      rT   rx  z=ExportedProgram._num_lifted_params_buffers.<locals>.<genexpr>6  s.      Aq66Y111 s   ,.)r  r	  r|  r   r  r  s    rT   _num_lifted_params_buffersz*ExportedProgram._num_lifted_params_buffers4  sC    %d&;&;&G&GH
 %%112
 	
rV   r   r   c                     |
t               n
t        |      }t        |t              r|j	                         }t        |      \  }}t        | ||d|      S )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)
        Nrk  )rE   rs   r   r0   materializer   rq  )rO   r   r   _decomp_tabler   r   s         rT   run_decompositionsz"ExportedProgram.run_decompositions>  sk    P )5(<"$$|BT 	 m%67)557M" 9G	
 +' 3!(C
 	
rV   passesc                 T   t        t        |            }ddlm}  |       5   || j                        }d d d        |j                  n| j                  }|J || j                  u r|j
                  s| S dt        dt        j                  j                  dt        fd}t        ||j                   || j                  |      | j                  t        || j                        t!        j"                  | j$                        | j&                  | j(                  | j*                  	      }|j                  j,                  j/                  | j                  j,                         |j                  j,                  j/                  |j                  j,                         |S # 1 sw Y   jxY w)Nr   )r   old_signaturenew_gmrp   c           	         g }t        |j                  j                        D ]  \  }}|j                  dk7  r n|t	        | j
                        k  sJ d       | j
                  |   }t        |j                  t        t        f      r|j                  n$ t        |j                        |j                        }|j                  t        |j                  ||j                  |j                                 t#        |j                  j                        d   }|j                  dk(  sJ g }t        |j$                  d         D ]  \  }}|t	        | j&                        k  sJ d       | j&                  |   }	t        |	j                  t        t        f      r|	j                  n$ t        |	j                        |j                        }|j                  t)        |	j                  ||	j                                t+        ||      }
|
S )zO
            Update the graph signature's user_input/user_outputs.
            r   z-Number of inputs changed after transformationr   rK  r   z.Number of outputs changed after transformationr   )r	  r   r   rz   r  r   r   r   r6   r7   r   rN   r   r:   r   r   r  rZ   re   r   r<   r8   )r  r	  new_input_specsrR   r&  old_input_specr   output_nodenew_output_specsold_output_specnew_signatures              rT   _get_updated_graph_signaturezKExportedProgram._transform_do_not_use.<locals>._get_updated_graph_signature  s    !O$V\\%7%78 477m+3!--  CBC  "/!:!:1!= "&**-=?P,Q #&& 2n001$))<   &&&++&--&11	0 v||11226K>>X---!$[%5%5a%89 43!..  DCD  #0"<"<Q"? "'++.>@Q-R $'' 3o112499=  !''33S/:P:PQ  1+:JM ! rV   	rl  r   r   r   rm  rZ  r   r   rs  )r3   rZ   r   r   r   modifiedr8   r   r
  rW  rB   r   r   r   rn  rm  r   rd  r  r   r   rs  r   r   )rO   r  pmr   r  transformed_gmr  transformed_eps           rT   _transform_do_not_usez%ExportedProgram._transform_do_not_use  so   f& 	@$& 	(T&&'C	(-0_))$BSBS)))T...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F'c                 R   ddl m} | j                  j                  D cg c]  }|j                  dk(  s| }}t        || j                  j                        D cg c]$  \  }}|j                  t        j                  k(  r|& }}} |||| j                         y c c}w c c}}w )Nr   )"_check_input_constraints_for_graphr   )torch._export.utilsr  r   r   rz   r  r   r   r   r9   r  rm  )rO   r  r  r1  placeholdersr   input_placeholderss          rT   r  z(ExportedProgram._check_input_constraints  s    J#'::#3#3Maqtt}7LMM L$*>*>*J*JK
1vv--- 
 

 	+ 3T5K5K	
 N
s   BB)B#c                 $    | j                          y rM   )	_validater  s    rT   r  zExportedProgram.validate  s    rV   c                     t        | j                        dkD  sJ d       | j                  D ]  } |       j                  |         y )Nr   z0ExportedProgram must have at least one verifier.)r  rs  check)rO   rH  s     rT   r  zExportedProgram._validate  sE     !#	>=	># 	ACIIdO	rV   )r   r   rs  c                $   t        ||j                  |||n| j                  t        j                  | j
                        t        j                  | j                        | j                  ||n| j                  ||	      S | j                  	      S )Nr  )
rB   r   r   r   rd  rm  r  r   r   rs  )rO   r   r   r   r   rs  s         rT   _updatezExportedProgram._update  s     $$+%/%;z"mmD,B,BC"mmD,C,CD..#,#8idnn#,#8i

 
	
 ?Cnn

 
	
rV   )NN)NF)rp   rB   )CrW   rX   rY   __doc__r   r   r   Modulers   r^   r   r
  Graphr8   r  r   rZ   rC   r	   r   r   r   ScriptObjectr   r(   r  propertyr1   r   setterr   r   r   r   r  r   r  r   rm  rZ  r   r  r  r  rs  r  r   r  r  r  r  r  r   r  rk   _opsOperatorBaser   r  r  PassTyper  r  r  r   r  r"  r_   rV   rT   rB   rB     s   . LP % 59%EHHOOT#s(^34% xx~~% .	%
 eELL%((2D2D$DEEF% 5%  0% !uS#XS#X'F!GH% eELL*:EHH<Q<QQRRS
% Dh01%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 
5n
 
 $
 $ KO,1D
tEJJ$;$;X$EFGD
 &*D
 
	D
 $D
LZX Z:K Zx
 %0 1   
 

rV   rB   c                 P   | j                   j                  D cg c]-  }|j                  j                  dd       |j                  d   / }}ddlm}  ||      }||j                  S |D ]4  }t        |t        j                        s|j                  j                  c S  y c c}w )Nr   r   r)   )r   r   r   r  torch._guardsr*   r   r   r   SymIntr&  )r   r&  valsr*   r   rH  s         rT   r  r    s     HHNN99==%1 			%D 
 / &I""" $a&66###$s   2B#old_range_constraintsz!Optional[dict[sympy.Symbol, Any]]rt  c                 <   |J t        |       }|i S t        j                  |      }|j                         D ci c]  \  }}||j                  vs|| }}}|j                  j                         D ]  \  }}||j                  vs||vs|||<     |S c c}}w rM   )r  r   r~   replacementsvar_to_range)r   r0  r   rm  r   rH  s         rT   rn  rn  "  s     !,,,r"I			"78*002Aay?U?U6U1  &&,,. %1I***q8I/I#$a % s   BBc                    	 t         j                  j                  | |      }|S # t        $ r\ t	        j
                  d       t         j                  j                  | t         j                  j                               }||_        Y |S w xY w)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
  rW  SyntaxErrorwarningswarnr%  _graph)rl  r   r   s      rT   rz  rz  9  sx    XX!!$.  I   	G	
 XX!!$(89	Is    $ A!B	B	r  )rp   r0   rM   )r   r   dataclassesri   rX  r  r6  collectionsr   collections.abcr   r   typingr   r   r   r	   r
   r   torch._higher_order_ops.utilsr   "torch._library.fake_class_registryr   torch._subclasses.fake_implsr   r   r   torch._subclasses.fake_tensorr   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_pytreer\   r  r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   torch._export.verifierr(   r-  r*   r,   torch.export._tree_utilsr-   r.   torch.export.decomp_utilsr0   torch.fx._compatibilityr1   torch.fx.passes.infra.pass_baser2   "torch.fx.passes.infra.pass_managerr3   r   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   __all__r
  rW  r+  	dataclassrD   rC   rk   r   Contextr  rt   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   rs   r)  r*  r   r   rE   intrI  r   r`  rZ   ri  rq  rB   r  rn  rz  r_   rV   rT   <module>ri     s          " $ % G G 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
  X$ X$v  )-uzz..89)-
4

''12C78)-Xo2 

//9:o2 ejj55x?@	o2
 smo2d##3G#
588!556#2..:!!0!01 

//9:1 ejj55x?@	1
 sm1 "&1h	
 	
D$$ BF> .rV   