
    9iCR                         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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\	R>                  R@                  SS4S jr!S\	R>                  R@                  SS4S jr"S\	R>                  R@                  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)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       V/var/www/html/land-doc-ocr/venv/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      $ 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   all)valr+   r,   r-   r2   s    r   r2   &_check_val.<locals>._check_correct_val+   s    ;c4e455%%%u{{ELL%,,O
 
 *ell+
 
 fh899.//X&&:c:::r   c                 r    [        U [        5      (       d  g[        U R                  R                  5      S:H  $ )NFr   )r5   r   lenr"   returnsr$   s    r   _no_returns_check_val.<locals>._no_returns@   s,    "j))2::%%&!++r   rA   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&   rF   rA   r+   r,   r-   r2   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      rI   z has invalid torch_fn field )rK   getr   rM   r5   tupler8   )r&   rO   s     r   _check_torch_fnrS   O   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)_VerifierMeta_   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)SyntaxErrorr5   r8   type__new__rX   )metaclsrM   basesattrsrets        r   r`   _VerifierMeta.__new__b   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   rX   dictr8   r_   __annotations__r`   r   r   r   r   rU   rU   _   s     -/ItCj))*/r   rU   objrL   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)rh   rL   target_atomsattr_itriatoms         r   getattr_recursiveru   r   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)rW   ~   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   rZ   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r0   ts     r   r3   OVerifier._check_graph_module.<locals>._allowed_getattr_types.<locals>.<genexpr>   s     41;   )r   r   any)is_toplevel_gmrd   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)r0   r   s     r   r3   fVerifier._check_graph_module.<locals>._check_valid_op.<locals>._allowed_builtin_ops.<locals>.<genexpr>   s     ?3R7,,R003s   #%)r   r@   rd   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   r3   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)*listrR   r_   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_decompositionsr5   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' rH   get_attrz/Expected get_attr target to be string, but got c                 2   > [        [        TU S 5      U5      $ r!   )r5   rp   )rM   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)rR   r_   r   modulesr5   r:   r   r   graphlintnodesr   r   rL   r(   r8   ru   r   Moduler   rm   rp   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   rR   r_   r   r   r   r   r   r   r   r   rZ   r:   r   r[   r   r   r   r   rW   rW   ~   s    G
T 
:1%S	3"7 1DuT#Y^'< D
tCy#~1F 
; 4 
 / /
 K"ehh&:&: K"t K" K"r   rW   )	metaclassc                       \ rS rSrSrSrg)TrainingIRVerifieriJ  r   r   N)r   r   r   r   r\   r   r   r   r   r  r  J  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	  rM   	signatureinputsr   outputs)exported_programr  r&   r	  entryargs         r   r   r   N  s    (::#3#9#9#?#?@#?4YY#?E@"??&--888 5, 
*GH  .
 ..888 5,!#((+HI  / # As   Dc           
      V   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.  [        S[        U5       S[        UR                  5       S35      e[        UR                  U5       GH  u  pB[        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XPR(                  ;  a  [        SU S35      e[        U R(                  U   [*        R,                  R.                  5      (       d  [        SU S35      eGM  UR                  [         R0                  :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R2                  c  [        SU S35      eUR2                  SL a  X`R(                  ;  a  [        SU S35      eUR2                  SL a!  X`R(                  ;   a  [        SU S35      eGM  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XpR6                  ;  a  [        SU S35      eGMV  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XR6                  ;  a  [        SU S35      eGM  UR                  [         R<                  :X  aH  [        UR                  [>        5      (       d&  [        SUR                   SUR                   S	35      eGMr  [        SUR                   S35      e   [A        U R                  R                  5      S   n	U	R                  S:X  d   eU	RB                  S    V
s/ s H:  n
[        U
[*        RD                  RF                  5      (       a  U
R                  OU
PM<     nn
[        U5      [        URH                  5      :w  aD  [        S[        U5       S[        URJ                  5       S [        URL                  5       S!35      e[        URN                  5      n[        URJ                  5      [        URP                  5      -   [        URR                  5      -   U-   nXU nXU[        URL                  5      -    nU GH2  nUURJ                  ;   aH  URJ                  U   URT                  ;  a)  [        S"U S#URJ                   S$URT                   S%35      eM\  UURP                  ;   aH  URP                  U   URV                  ;  a)  [        S&U S'URP                   S(URV                   S%35      eM  UURR                  ;   aI  URR                  U   URX                  ;  a)  [        S)U S*URR                   S+URX                   S%35      eGM  [        S,U S-URJ                   S.URR                   35      e   [        XRL                  5       H(  u  nnUU:w  d  M  [        S/U S0URL                   S135      e   g s  snf s  sn
f )2Nr  zNumber of graph inputs (z:) does not match number of inputs in the graph signature ()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 rj   outputr   zNumber of output nodes zg is different Than the number of outputs specified by the graph signature: 
Number of mutated buffers: z. 
Number of user outputs: z. 
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. )-graph_signaturer  r	  r   rM   rD   input_specsr   zipr5   r  r   r   r   r   kindr   
USER_INPUT	PARAMETERrL   
state_dictr:   r   r   BUFFER
persistentCONSTANT_TENSOR	constants
CUSTOM_OBJr
   TOKENr   r   argsr   Nodeoutput_specsbuffers_to_mutateuser_outputsoutput_tokensparameters_to_mutateuser_inputs_to_mutatebuffers
parametersuser_inputs)r  gsr&   input_node_names
input_specparambuffertensor_const
custom_objoutput_noder  output_nodes
num_tokensendmutate_nodesuser_output_nodesmutation_nodeuser_output_nodeuser_output_names                      r   r   r   _  sW   		)	)B /44:::dgg>V			:   BNN 33 &s+;'<&= >GGJ2>>GZF[[\^
 	

  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 %c,&7%8 9**-b.B.B*C)D E''*2??';&<DB
 	
 R%%&JB  !
b%%
&	'
b&&
'	( 	  +c:L$3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 /22C__.U**//$/0 188:7HL  /VAZs   `!`!A`&r\   c                     U S:X  d  U S:X  a$  [         R                  R                  U [        5      $ [         R                  U    $ )Nr]    )rU   rX   rQ   rW   )r\   s    r   load_verifierrF    s:    &GrM&&**7H==""7++r   r  )-r   r   ry   collections.abcr   typingr   r   r   r:   
torch._opsr   r   torch._subclasses.fake_tensorr	   torch.export.graph_signaturer
   r   r   r   r   r   r   torch.fxr   torch.export.exported_programr   	Exceptionr   r7   r%   r   r*  r)   r(   rS   r_   rU   r8   ru   rW   r  r   r   rF  r   r   r   <module>rO     s      $ , ,  6 4   ! =	 	%j %T % 4 
$WUXX]] $Wt $WN
%((-- 
D 
 D &	3 	 	 	I" I"X "k\,3 ,4> ,r   