
    ȅiU                        S SK r S SKrS SKrS SKJr  S SKJrJrJ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JrJrJr  S SKJr  \(       a  S S	KJr   " S
 S\5      rS\S\4S jr S\	RB                  RD                  SS4S jr#S\	RB                  RD                  SS4S jr$S\	RB                  RD                  SS4S jr% " S S\&5      r'S\S\(S\4S jr) " S S\'S9r* " S S\*5      r+S!S jr,S!S jr-S\(S\&\*   4S  jr.g)"    N)Iterable)AnyfinalTYPE_CHECKING)is_opaque_type)HigherOrderOperator
OpOverload)
FakeTensor)CustomObjArgument	InputKindSymBoolArgumentSymFloatArgumentSymIntArgumentTensorArgumentTokenArgument)GraphModule)ExportedProgramc                       \ rS rSrSrg)SpecViolationError    N)__name__
__module____qualname____firstlineno____static_attributes__r       P/home/james-whalen/.local/lib/python3.13/site-packages/torch/_export/verifier.pyr   r      s    r   r   opreturnc                 8    U R                   R                  (       + $ N)_schema
is_mutabler   s    r   is_functionalr&       s    zz$$$$r   nodec                     [        U 5      $ r"   )
_check_val)r'   s    r   _check_has_fake_tensorr*   $   s    dr   c                 H  ^^^^ SSK JmJmJm  UUUU4S jmS nSU R                  ;  aA  U R
                  S:X  a  U" U R                  5      (       a  g [        SU R                   S35      eU R                  S   nT" U5      (       d  [        SU R                   S	U 35      eg )
Nr   )SymBoolSymFloatSymIntc                    > U c  g[        U [        [        [        [        45      (       a  g[        U [
        R                  [
        R                  [
        R                  [
        R                  45      (       a  g[        U [        [
        R                  45      (       a  g[        U TTT45      (       a  g[        U [        5      (       a  g[        U [        5      (       a  [        U4S jU  5       5      $ [        [!        U 5      5      (       a  gg)NTc              3   4   >#    U  H  nT" U5      v   M     g 7fr"   r   ).0x_check_correct_vals     r   	<genexpr>9_check_val.<locals>._check_correct_val.<locals>.<genexpr>>   s     :c)!,,cs   F)
isinstanceintboolstrfloattorchmemory_formatdtypedevicelayoutr
   Tensorr   r   allr   type)valr,   r-   r.   r3   s    r   r3   &_check_val.<locals>._check_correct_val,   s    ;c4e455%%%u{{ELL%,,O
 
 *ell+
 
 fh899.//X&&:c:::DI&&r   c                 r    [        U [        5      (       d  g[        U R                  R                  5      S:H  $ )NFr   )r6   r	   lenr#   returnsr%   s    r   _no_returns_check_val.<locals>._no_returnsC   s,    "j))2::%%&!++r   rC   call_function
Node.meta z is missing val field.z has invalid val field )	%torch.fx.experimental.symbolic_shapesr,   r-   r.   metar   targetr   name)r'   rH   rC   r,   r-   r.   r3   s      @@@@r   r)   r)   )   s    OO .,
 DII77o%+dkk*B*B :dii[8N!OPP
))E
Cc"" :dii[8OPSu!UVV #r   c                 4   U R                   R                  S5      nUc  [        SU R                   35      e[	        U[
        5      (       dM  [	        US   [        5      (       a4  [	        US   [        5      (       a  [        SU R                   SU 35      eg g g )Ntorch_fnz*Unable to find torch_fn metadata for node r      rK   z has invalid torch_fn field )rM   getr   rO   r6   tupler9   )r'   rQ   s     r   _check_torch_fnrU   R   s    yy}}Z(H 8D
 	
 x''x{C((x{C(( #?zJ
 	
 ) ) (r   c                   :    \ rS rSr% 0 r\\\S   4   \S'   S r	Sr
g)_VerifierMetab   Verifier	_registryc                    U(       a)  SU;   d  SU;   a  [        S5      eSU;   a	  US   S:w  d   eOSU;   d   eSU;   d   eUS   S:X  d   e[        US   [        5      (       d   e[        R	                  XX#5      nX@R
                  US   '   U$ )Ncheck_check_graph_modulez'Overriding method check is not allowed.dialectATEN)SyntaxErrorr6   r9   rB   __new__rZ   )metaclsrO   basesattrsrets        r   ra   _VerifierMeta.__new__e   s    %#8E#A!"KLL%%	*:f*DDD*De###(E111#v---%	*C0000ll7%7.1%	*+
r   r   N)r   r   r   r   rZ   dictr9   rB   __annotations__ra   r   r   r   r   rW   rW   b   s     -/ItCj))*/r   rW   objrN   c           	          UR                  S5      nU n[        U5       H@  u  pE[        X55      (       d   [        SSR	                  US U 5       35      e[        X55      nMB     U$ )N.z#Node referenced nonexistent target )split	enumeratehasattrRuntimeErrorjoingetattr)ri   rN   target_atomsattr_itriatoms         r   getattr_recursiverv   u   sl    <<$LH\*x&&5chh|BQ?O6P5QR  8* + Or   c                       \ rS rSrSrS\4S jrS\\\	   S4   4S jr
S\\\	   S4   4S jrS\\\	   S4   4S jrS	 rS
\SS4S jr\SS j5       r\S
\R&                  R                  SS4S j5       rSrg)rY      r_   r    c                    [         R                  [         R                  [         R                  [         R                  [         R
                  [         R                  [         R                  [         R                  [         R                  [         R                  [         R                  [         R                  [         R                  [         R                  [         R                  [         R                   [         R"                  [         R$                  [         R&                  [         R(                  [         R*                  [,        R.                  [,        R0                  [,        R2                  [4        /$ r"   )operatorgetitemaddmulsubtruedivgelegtlteqnefloordivmodand_or_not_pownegabslshiftrshiftmathceilfloortruncroundselfs    r   allowed_builtin_opsVerifier.allowed_builtin_ops   s    LLLLLLKKKKKKKKKKKKLLMMLLMMLLLLLLOOOOIIJJJJ3
 	
r   .c                     [         [        4$ r"   )r	   r   r   s    r   allowed_op_typesVerifier.allowed_op_types   s    /00r   c                 ~    [         R                  R                  [         R                  R                  R
                  4$ r"   )r;   fxr   utils_pytreeTreeSpecr   s    r   allowed_getattr_typesVerifier.allowed_getattr_types   s'    $$ekk&9&9&B&BCCr   c                     [         R                  R                  [         R                  R                  R
                  [         R                  [         R                  R                  R                  4$ r"   )
r;   r   r   nn	parameter	Parameterr@   r   r   r   r   s    r   allowed_getattr_types_for_subgm(Verifier.allowed_getattr_types_for_subgm   sH     HH  HH((LLKK((	
 	
r   c                     g r"   r   )r   r   s     r   check_valid_opVerifier.check_valid_op   s    r   gmNc                     g)z7
Additional checks that are specific to some dialects.
Nr   )r   r   s     r   check_additionalVerifier.check_additional   s    r   c                 f    U R                  UR                  5        [        U5        [        U5        g r"   )r]   graph_module*_verify_exported_program_module_call_graph"_verify_exported_program_signature)r   eps     r   r\   Verifier.check   s$      1226*2.r   c                   ^ ^ S[         [        [           S4   4U 4S jjnSU 4S jjnUR                  5        GH  nXAL n[	        U[
        R                  R                  5      (       d  M2  UR                  R                  5         UR                  R                   GH  nUR                  S;   a  [        SUR                   S35      eUR                  S:X  a  [        U5        U" UR                  5        M\  UR                  S	:X  Ga  [	        UR                  [        5      (       d!  [        S
[        UR                  5       35      e[!        XFR                  5      m[	        T[
        R"                  R$                  5      (       GaK  U4S jn[        T5      R&                  S:X  a  U" S[        5      (       a6  [)        TS5      (       a%  [)        TS5      (       a  [+        TSS 5      S:X  a  GMS  U" S[        5      (       a8  U" S[,        5      (       a&  U" S[.        5      (       a  [)        TS5      (       a  GM  [+        TSS 5      n[+        TSS 5      n	[+        TSS 5      n
[        S[        T5       S[        U5       S[        U	5       S[        U
5       35      e[        T5      R&                  S:X  a  GM  [        T5      R&                  S:X  a  GM7  [	        TU" U5      5      (       d-  [        S[        T5       SUR                   SU" U5       35      eGM~  UR                  S:X  d  GM  [        U5        GM     GM     T R1                  U5        g )Nr    .c                    > U (       a  TR                  5       nOTR                  5       n[        S U 5       5      (       a   eU$ )Nc              3   0   #    U  H  o[         L v   M     g 7fr"   objectr1   ts     r   r4   OVerifier._check_graph_module.<locals>._allowed_getattr_types.<locals>.<genexpr>   s     41;   )r   r   any)is_toplevel_gmre   r   s     r   _allowed_getattr_types<Verifier._check_graph_module.<locals>._allowed_getattr_types   s>    002::<444444Jr   c                   > S[         4U4S jjnS[        [        [           S4   4U4S jjn[        R
                  R                  R                  [        R                  [        R                  [        R                  [        R                  [        R                  [        R                  [        R                  [        R                  [        R                   R"                  R$                  [        R&                  R(                  [        R*                  R,                  R.                  [        R*                  R,                  R0                  [        R2                  R4                  R6                  R8                  [        R:                  R<                  R>                  [        R:                  R<                  R@                  [        R:                  R<                  RB                  [        R:                  R<                  RD                  [        R:                  R<                  RF                  4n[I        X" 5       5      (       d0  X" 5       ;  a&  X;  a!  [K        SU  SU" 5        SU" 5        SU 35      e[I        U [L        5      (       a/  TRN                  S	:w  a  [Q        U 5      (       d  [K        S
U  S35      eTRS                  U 5        g )Nr    c                  Z   > TR                  5       n [        S U  5       5      (       d   eU $ )Nc              3   N   #    U  H  n[         R                  " U5      v   M     g 7fr"   )inspect	isbuiltin)r1   r   s     r   r4   fVerifier._check_graph_module.<locals>._check_valid_op.<locals>._allowed_builtin_ops.<locals>.<genexpr>   s     ?3R7,,R003s   #%)r   rA   re   r   s    r   _allowed_builtin_opsSVerifier._check_graph_module.<locals>._check_valid_op.<locals>._allowed_builtin_ops   s-    ..0?3?????
r   .c                  Z   > TR                  5       n [        S U  5       5      (       a   eU $ )Nc              3   0   #    U  H  o[         L v   M     g 7fr"   r   r   s     r   r4   cVerifier._check_graph_module.<locals>._check_valid_op.<locals>._allowed_op_types.<locals>.<genexpr>   s     8CqF{Cr   )r   r   r   s    r   _allowed_op_typesPVerifier._check_graph_module.<locals>._check_valid_op.<locals>._allowed_op_types   s-    ++-8C88888
r   z
Operator 'z#' is not an allowed operator type: z
Valid builtin ops: zValid torch functions: TRAININGz
operator 'z' is not functional)*listrT   rB   r   r;   autograd	grad_modeset_grad_enabledsym_int	sym_floatsym_itesym_maxsym_minsym_notsym_sqrtsym_sumexport
custom_ops._call_custom_autograd_function_in_pre_dispatch_C_set_grad_enabledampautocast_mode_enter_autocast_exit_autocastr   experimentalsymbolic_shapes cast_symbool_to_symint_guardless
_functorchpredispatch_add_batch_dim_remove_batch_dim_vmap_increment_nesting_vmap_decrement_nestinglazy_load_decompositionsr6   r   r	   r^   r&   r   )r   r   r   _allowed_torch_functionsr   s       r   _check_valid_op5Verifier._check_graph_module.<locals>._check_valid_op   s   $ 
uT#Y^'<  ((99''VV **		''77		''66%%55VV  ,,;;  ,,>>  ,,DD  ,,DD  ,,EE-($2 b"3"566244:,$RD(KL]L_K` a..B.D-E12J1KM  "j)) <<:-mB6G6G,z"=P-QRR#r   >   call_methodcall_modulez'call_module is not valid: got a class 'z' rJ   get_attrz/Expected get_attr target to be string, but got c                 2   > [        [        TU S 5      U5      $ r"   )r6   rq   )rO   tyattrs     r   _is_type.Verifier._check_graph_module.<locals>._is_type  s    #-gdD$.G#LLr   LoweredBackendModule
backend_idoriginal_modulemodule_nameaotiprocessed_bytescompile_specszInvalid get_attr type z2. 
LoweredBackendModule fields: backend_id(str) : z, processed_bytes(bytes) : z, compile_specs(list) : AOTInductorEPModuleAOTInductorRunnerWrapperz on target z. 
Valid get_attr types: placeholderr    N)rT   rB   r   modulesr6   r;   r   r   graphlintnodesr   r   rN   r)   r9   rv   r   Moduler   rn   rq   bytesr   r   )r   r   r   r   r   r   r'   r   r   r  r  r   s   `          @r   r]   Verifier._check_graph_module   s   	eDIsN6K 	5	$n ::<C YNc588#7#788IINN		77<<,A$++bQ  WW/t$#DKK0WW
*%dkk3770MdSWS^S^N_M`a  -S++>D!$88M  :..2HH (s ; ;$+D2C$D$D$+D-$@$@$+D,$E$O ( (s ; ;$,->$F$F$,_d$C$C$+D2C$D$D (-4T<-N
29$@QSW2X07ot0T&8&<T$ZL I99=j9I8J K@@D_@U?V W==A-=P<Q	%S'" !" "$Z004II$!$Z004NN$%d,B>,RSS04T$ZLDKK= Y55KN5[4\^  T WW-t$ (  V 	b!r   r   )r   r   r    N)r   r   r   r   r^   r   r   rT   rB   r   r   r   r   r   r   r   r   r\   r;   r   r]   r   r   r   r   rY   rY      s    G
T 
:1%S	3"7 1DuT#Y^'< D
tCy#~1F 
; 4 
 / /
 K"ehh&:&: K"t K" K"r   rY   )	metaclassc                       \ rS rSrSrSrg)TrainingIRVerifieriM  r   r   N)r   r   r   r   r^   r   r   r   r   r  r  M  s    Gr   r  c                    U R                   nU R                  R                   Vs1 s H  o"R                  iM     nnU H  nUR                  c  M  UR                  R
                   H?  nUR                  (       d  M  UR                  U;  d  M(  [        SUR                   S35      e   UR                  R                   H?  nUR                  (       d  M  UR                  U;  d  M(  [        SUR                   S35      e   M     g s  snf )NzInput z does not exist in the graph.zOutput )module_call_graphr  r
  rO   	signatureinputsr   outputs)exported_programr  r'   r
  entryargs         r   r   r   Q  s    (::#3#9#9#?#?@#?4YY#?E@"??&--888 5, 
*GH  .
 ..888 5,!#((+HI  / # As   Dc           
      j   U R                   nU R                  R                   Vs/ s H   o"R                  S:X  d  M  UR                  PM"     nn[        U5      [        UR                  5      :w  a  UR                   Vs/ s H6  n[        UR                  S5      (       d  M   UR                  R                  PM8     nn[        U5      [        U5      -
  n[        U5      [        U5      -
  n[        S[        U5       S[        UR                  5       SU SU 35      e[        UR                  U5       GH  u  p[        UR                  [        [        [        [         45      (       a?  UR                  R                  U:w  a%  [        SUR                  R                   SU 35      eUR"                  [$        R&                  :X  a  M  UR"                  [$        R(                  :X  a  [        UR                  [        5      (       d&  [        S	UR                   S
UR                   S35      eUR*                  c  [        SUR                   S35      eUR*                  n	XR,                  ;  a  [        S	U	 S35      e[        U R,                  U	   [.        R0                  R2                  5      (       d  [        SU	 S35      eGM  UR"                  [$        R4                  :X  a  [        UR                  [        5      (       d&  [        SUR                   S
UR                   S35      eUR*                  c  [        SUR                   S35      eUR*                  n
UR6                  c  [        SU
 S35      eUR6                  SL a  XR,                  ;  a  [        SU
 S35      eUR6                  SL a!  XR,                  ;   a  [        SU
 S35      eGM  GM  UR"                  [$        R8                  :X  a  [        UR                  [        5      (       d&  [        SUR                   S
UR                   S35      eUR*                  c  [        SUR                   S35      eUR*                  nXR:                  ;  a  [        SU S35      eGMV  UR"                  [$        R<                  :X  a  [        UR                  [>        5      (       d&  [        SUR                   SUR                   S35      eUR*                  c  [        SUR                   S35      eUR*                  nXR:                  ;  a  [        SU S35      eGM  UR"                  [$        R@                  :X  aH  [        UR                  [B        5      (       d&  [        SUR                   S
UR                   S35      eGMr  [        SUR"                   S35      e   [E        U R                  R                  5      S   nUR                  S:X  d   eURF                  S    Vs/ s H:  n[        U[.        RH                  RJ                  5      (       a  UR                  OUPM<     nn[        U5      [        URL                  5      :w  a  URL                   Vs/ s HI  n[        UR                  S5      (       a  UR                  R                  O[O        UR                  5      PMK     nn[        U5      [        U5      -
  n[        U5      [        U5      -
  n[        S [        U5       S![        URL                  5       S"U S#U 35      e[        URP                  5      n[        URR                  5      [        URT                  5      -   [        URV                  5      -   U-   nUUU nUUU[        URX                  5      -    nU GH2  nUURR                  ;   aH  URR                  U   URZ                  ;  a)  [        S$U S%URR                   S&URZ                   S'35      eM\  UURT                  ;   aH  URT                  U   UR\                  ;  a)  [        S(U S)URT                   S*UR\                   S'35      eM  UURV                  ;   aI  URV                  U   UR^                  ;  a)  [        S+U S,URV                   S-UR^                   S'35      eGM  [        S.U S/URR                   S0URV                   35      e   [        UURX                  5       H(  u  nnUU:w  d  M  [        S1U S2URX                   S335      e   g s  snf s  snf s  snf s  snf )4Nr  rO   zNumber of graph inputs (z:) does not match number of inputs in the graph signature (z$)
Placeholders missing input_specs: z#
Input_specs missing placeholders: zInput spec name z does not match node name z
Parameter z! is not a tensor argument. Found z	 instead.zInputSpec for z has no target.z is not in the state dict.zState dict entry for parameter z* is not an instance of torch.nn.Parameter.zBuffer z is missing a persistence flagTFzNon-persistent buffer z( is in the state dict, it should not be.zConstant tensor z$ is not in the constants dictionary.zCustom object z( is not a custom object argument. Found zUnknown InputKind rk   outputr   zNumber of output nodes zK is different Than the number of outputs specified by the graph signature: z
Nodes missing output_specs: z
Output_specs missing nodes: zBuffer output zV does not point to a buffer that exists. 
Dict of buffers that are mutated, in order: z 
Buffer nodes available: z 
zParameter output z\ does not point to a parameter that exists. 
Dict of parameters that are mutated, in order: z 
Parameter nodes available: zUser input output z^ does not point to a user input that exists. 
Dict of user inputs that are mutated, in order: z 
User input nodes available: zMutation node z: is neither a buffer nor a user input. Buffers to mutate: z, User inputs to mutate: zUser output zY is not in the correct order or is not found in the exported program's user_output list: z. )0graph_signaturer  r
  r   rO   rF   input_specsrn   r  setr   zipr6   r   r   r   r   kindr   
USER_INPUT	PARAMETERrN   
state_dictr;   r   r   BUFFER
persistentCONSTANT_TENSOR	constants
CUSTOM_OBJr   TOKENr   r   argsr   Nodeoutput_specsr9   output_tokensbuffers_to_mutateparameters_to_mutateuser_inputs_to_mutateuser_outputsbuffers
parametersuser_inputs)r  gsr'   input_node_namesspecinput_spec_namesmissing_in_specsmissing_in_graph
input_specparambuffertensor_const
custom_objoutput_noder  output_nodesoutput_spec_namesmissing_out_specsmissing_out_graph
num_tokensendmutate_nodesuser_output_nodesmutation_nodeuser_output_nodeuser_output_names                             r   r   r   b  s]	   		)	)B /44:::dgg>V			:   BNN 33&(nn
&4d&8QMDHHMMn 	 
 /037G3HH/037G3HH &s+;'<&= >GGJ2>>GZF[ \11A0B C11A0BD
 	
  0@A
NN^-=O
 
 ~~""d*(&z~~':':&;;UVZU[\  ??i222__	 3 33jnnn==(  11RS]SaSaRbbkl    (($Z__$5_E  %%E777(:eW<V)WXX.99%@%((BTBTUU(5eW<fg  V
 __	 0 00jnnn==(joo..OPZP^P^O__hi    (($Z__$5_E   &&F$$,(fX%CD 
 %%-"="==(76(:T)UVV$$-&<W<W2W(,VH4\]  3X- __	 9 99jnnn==(&z&77XYcYgYgXhhqr    (($Z__$5_E  &,,L#=#==(&|n4XY  > __	 4 44jnn.?@@($Z__$55]^h^l^l]mmvw    (($Z__$5_E  $**J!;!;;($ZL0TU  < __	/jnnm<<(&z&77XYcYgYgXhhqr  =
 %'9*//9J!%LMM} BB '--334R8K>>X%%% ##A&&C sEHHMM22;&  
 <C00 
' %TXXv66DHHMMCMI' 	 
  -4E0FF 12S5FF %c,&7%8 9LLOPRP_P_L`Ka b++<*= >++<*=?
 	
 R%%&JB  !
b%%
&	'
b&&
'	( 	  +:c:L$S3R__1E+EF%B000##M2"**D($]O 4CCECWCWBX Y//1zzl#?  E b555&&}5R]]J(' 7FFHF]F]E^ _224--E  K b666''6bnnL(( 8GGIG_G_F` a335>>2B#G  M %  0&&(&:&:%;;TUWUmUmTnp / &8 /22CR__.U**//$/0 188:7HL  /V[

^
s$   d!d!>d&!d&Ad+9Ad0r^   c                     U S:X  d  U S:X  a$  [         R                  R                  U [        5      $ [         R                  U    $ )Nr_    )rW   rZ   rS   rY   )r^   s    r   load_verifierrN    s:    &GrM&&**7H==""7++r   r  )/r   r   rz   collections.abcr   typingr   r   r   r;   torch._library.opaque_objectr   
torch._opsr   r	   torch._subclasses.fake_tensorr
   torch.export.graph_signaturer   r   r   r   r   r   r   torch.fxr   torch.export.exported_programr   	Exceptionr   r8   r&   r   r+  r*   r)   rU   rB   rW   r9   rv   rY   r  r   r   rN  r   r   r   <module>rX     s      $ , ,  7 6 4   ! =	 	%j %T % 4 
&WUXX]] &Wt &WR
%((-- 
D 
 D &	3 	 	 	I" I"X "xv,3 ,4> ,r   