
    3j]                        % S SK r S SKrS SKrS SKrS SKrS SKrS SKJr  S SKJrJ	r	J
r
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  \(       a  SS	KJr  / S
Qr\" SS9 " S S\5      5       r0 r\\S\4   \\R>                     4   \ S'   S\\R>                     4S jr!\!" 5       \\RD                  '    " S S5      r#\RH                  \RJ                  \RL                  \RN                  \RP                  RR                  \ RT                  \RV                  \#" 5       \," S5      \RZ                  \R\                  " S5      \S.r/\0" \5       H  r1\2" \\15      \/\1'   M     SSS\4S jr3S\Rh                  Rj                  S\R>                  4S jr60 r7\\8\9\94   \R>                  4   \ S'   S\Rh                  Rj                  S\R>                  4S jr:\" SS9S\S\4   S\8S    S!\\9S"4   SS4S# j5       r;\S$\S\4   S%\
S&   S\8\\R>                     S-  \\Rh                  Rj                     S-  4   4S' j5       r<\ S8S$\S\4   S%\
S   S\\R>                     S-  4S( jj5       r<\" SS9 S9S$\S\4   S%\=S\\R>                     \8\\R>                     S-  \\Rh                  Rj                     S-  4   -  S-  4S) jj5       r<\" SS9S*\>S\>4S+ j5       r?\" SS9S,\S-\S\=4S. j5       r@\" SS9    S:S\S\4   S\8\S4   S!\\9\4   S-  S/\8\   S-  S0\\9\4   S-  S1\=S\4S2 jj5       rA\" SS9    S:S\S\4   S\8\S4   S!\\9\4   S-  S/\8\   S-  S0\\9\4   S-  S1\=S\S-  4S3 jj5       rB\" SS9  S;S4\R                  R                  S\9S\8\   S!\\9\4   S-  S1\=S\S-  4S5 jj5       rES6\R>                  S\8\S4   S!\\9\4   S1\=S\S-  4
S7 jrFg)<    N)Callable)AnycastLiteral
NamedTupleoverloadTYPE_CHECKING)boolean_dispatched)
OpOverloadOpOverloadPacket)
_fast_bind   )compatibility)Argument)ArgsKwargsPaircheck_for_mutable_operationget_signature_for_torch_opcreate_type_hinttype_matchesnormalize_functionnormalize_moduleF)is_backward_compatiblec                   B    \ rS rSr% Sr\\S4   \S'   \\	\4   \S'   Sr
g)r       z4
Simple named tuple for wrapping args/kwargs pairs.
.argskwargs N)__name__
__module____qualname____firstlineno____doc__tupler   __annotations__dictstr__static_attributes__r       S/home/wildlama/miniconda3/lib/python3.13/site-packages/torch/fx/operator_schemas.pyr   r       s%     S/cNr(   r   ._manual_overridesreturnc                     / n S[         R                  SS 4S jnU R                  [        R                  " U5      5        S[         R                  S[
        SS 4S jnU R                  [        R                  " U5      5        U $ )Nselfr+   c                     g Nr   )r-   s    r)   nonzero!_nonzero_schemas.<locals>.nonzero0       r(   as_tuplec                    g r/   r   )r-   r3   s     r)   r0   r1   5   r2   r(   )torchTensorappendinspect	signaturebool)
signaturesr0   s     r)   _nonzero_schemasr<   -   sx    Jell t  g''01ell  $  g''01r(   c                   :    \ rS rSrS\S\R                  4S jrSrg)_FakeGlobalNamespace@   namer+   c                 0    US:X  a  [         $ [        S5      e)Nr5   z!Expected a torch namespace lookup)r5   RuntimeError)r-   r@   s     r)   __getattr__ _FakeGlobalNamespace.__getattr__A   s    7?L>??r(   r   N)	r   r   r    r!   r&   types
ModuleTyperC   r'   r   r(   r)   r>   r>   @   s    @ @(8(8 @r(   r>   t)r6   DeviceLayoutnumberFutureAnyEnumTypeQScheme	__torch__NoneTypeStoragerG   PyObjectts_typeztorch._C.JitTypec                 6    [        U R                  [        5      $ )z
Convert a TorchScript type to a Python type (including subtypes) via
eval'ing the annotation_str. _type_eval_globals sets up expressions
like "List" and "Future" to map to actual types (typing.List and jit.Future)
)evalannotation_str_type_eval_globals)rR   s    r)    _torchscript_type_to_python_typerW   Y   s     &&(:;;r(   	ts_schemac           
         SSK Jn  / nU R                   GHX  n[        UR                  5      nUR                  5       (       a  UR                  OUR                  nUR                  S:w  a  UR                  OSnUR                  (       a  UR                  OUR                  nUS:X  a  XqR                  :w  a  [        SU 35      eUR                  n[        U5       Hw  u  pU	R                  UR                  :w  a%  [        SU	R                   SU	R                   35      eU" U	R                  UR                  U	R                   U	R"                  S	9X('   My     UR%                  U" XgXTS	95        GM[     U R&                   V
s/ s H  n
[        U
R                  5      PM     nn
[)        U5      S:X  a  S nO [)        U5      S
:X  a  US   nO[+        U5      n[         R,                  " X,S9$ s  sn
f )Nr   )	Parameterr-   inputfromz$Expected POSITIONAL_OR_KEYWORD, got z)Expected POSITIONAL_OR_KEYWORD for param z, got )r@   kinddefault
annotationr   )return_annotation)r8   rZ   	argumentsrW   typehas_default_valuedefault_valueemptyr@   
kwarg_onlyKEYWORD_ONLYPOSITIONAL_OR_KEYWORDAssertionErrorPOSITIONAL_ONLY	enumerater]   r^   r_   r7   returnslenr#   	Signature)rX   rZ   
parametersargarg_typer^   r@   r]   idxpretreturn_typesreturn_types                r)   %_torchscript_schema_to_signature_implrw   b   s    ""$J""3CHH='*'<'<'>'>###IOO 88v-sxx7 ~~ ""00 	 6>666$'KD6%RSS ,,D $J/66Y<<<(CAFF86RSRXRXQYZ  #,"22II ||	#
 0 	4GQ	
G #N ?H>O>O>Os(2>O   <A	\	a	"1oL)ZGGs    G'_SCHEMA_TO_SIGNATURE_CACHEc                     U R                   U R                  4n[        R                  U5      nUb  U$ [	        U 5      nU[        U'   U$ r/   )r@   overload_namerx   getrw   )rX   	cache_key	cache_valress       r)    _torchscript_schema_to_signaturer      sN     	 7 77I*..y9I
/	
:C,/y)Jr(   targetr   )r   .r   r   c                 n   [        U SS9u  p4U(       a  U(       a  / n[        X45       H'  u  pg [        U/UQ70 UD6  UR                  Xg45        M)     S[
        R                  R                  SS 4S jn[        U5      S:X  a  g [        U5      S:X  a  US   u  pU" U
5        g g g g ! [         a     M  f = f)NT)return_schemasschemar+   c                 D    U R                   (       a  [        SU  S35      eg )Nz!Tried to trace mutable operation z|. FX only supports functional code, so operations that mutate operands in-place (e.g. via `out` arguments) are not supported)
is_mutablerB   )r   s    r)   throw_if_mutable5check_for_mutable_operation.<locals>.throw_if_mutable   s/      "7x @( )  !r(   r   r   )	r   zipr   r7   	TypeErrorr5   _CFunctionSchemarm   )r   r   r   r;   schemasmatched_schemascandidate_signaturer   r   _schema_to_checks              r)   r   r      s     5VDQJgSU
 ,/z+C'.@@@&&(;'DE ,D	UXX%<%< 	 	 1$!Q&!0!3A_- ? z  s   !B&&
B43B4opr   Tc                     g r/   r   r   r   s     r)   r   r      s	     SVr(   c                     g r/   r   r   s     r)   r   r      s     &)r(   c                 :   [        U [        5      (       a  U R                  /nO[        U [        5      (       a4  U R	                  5        Vs/ s H  n[        X5      R                  PM     nnO[        R                  U 5      nU(       a  U(       a  US4$ S$ [        R                  R                  R                  U 5      nUc  U(       a  S$ S$ [        R                  R                  U5      nU Vs/ s H  n[        U5      PM     nnU(       a  Xr4$ U$ s  snf s  snf )aX  
Given an operator on the `torch` namespace, return a list of `inspect.Signature`
objects corresponding to the overloads of that op.. May return `None` if a signature
could not be retrieved.

Args:
    op (Callable): An operator on the `torch` namespace to look up a signature for

Returns:
    Optional[List[inspect.Signature]]: A list of signatures for the overloads of this
        operator, or None if the operator signatures could not be retrieved. If
        return_schemas=True, returns a tuple containing the optional Python signatures
        and the optional TorchScript Function signature
N)NN)
isinstancer   _schemar   	overloadsgetattrr*   r{   r5   jit	_builtins_find_builtinr   _jit_get_schemas_for_operatorr   )r   r   r   r   overrideaten_fnr   r;   s           r)   r   r      s    , "j!!::,	B(	)	)ACPX72(00P$((,'5Hd#?4?))%%33B7?#1<;t;((88AIPQv26:JQ$2J B
B Q Rs   D0Dxc                     [        U [        [        45      (       a  [        U [        5      (       a  S[        S[        4S jnOS[        S[        4S jn[	        U 5      S:X  a  U" [        5      $ U S   nU  H5  n[        X25      (       a  M  [        X#5      (       a  UnM)  U" [        5      s  $    U" U5      $  U $ ! [         a    [        R                  " SU  35         U $ f = f)a  
Produces a type hint for the given argument.

The :func:`create_type_hint` looks for a type hint compatible with the input argument `x`.

If `x` is a `list` or `tuple`, it looks for an object in the list whose type is a superclass
of the rest, and uses that as `base_type` for the `List` or `Tuple` to be returned.
If no such object is found, it defaults to `List[Any]`.

If `x` is neither a `list` nor a `tuple`, it returns `x`.
r   r+   c                     [         U    $ r/   )listr   s    r)   ret_type"create_type_hint.<locals>.ret_type  s    7Nr(   c                     [         U S4   $ )N.)r#   r   s    r)   r   r   "  s     C=(r(   r   z@We were not able to successfully create type hint from the type )	r   r   r#   r   rm   
issubclass	Exceptionwarningswarn)r   r   	base_typerG   s       r)   r   r     s    
a$''!T""# # #
) ) ) 1v{}$!Ia++	-- !I#C=(  I&&- (8 H  
NqcR	
 H
s   A-B; 0=B; .	B; ;#C"!C"signature_typeargument_typec                   ^^ [        U SU 5      nU TL a  gU[        R                  L a'  U T:w  a!  U R                  n[	        U4S jU 5       5      $ [        U SS 5      [
        L a  U R                  S   mT[        L a
  T[        L a  g[        R                  " T5      (       d  [        R                  " SU  S35        g[        TSS 5      [
        L a  [        TR                  S   T5      $ S[        S	[        4U4S
 jjnU" T5      $ U [        L a  T[        R                  L a  gU [         R"                  L a  T[        [$        1;   a  g[        R                  " T5      (       a'  [        R                  " U 5      (       a  [        TU 5      $ g)N
__origin__Tc              3   <   >#    U  H  n[        UT5      v   M     g 7fr/   )r   ).0cr   s     r)   	<genexpr>type_matches.<locals>.<genexpr>C  s     I=a<=11=s   r   z.Does not support nested parametric types, got z. Please file a bug.FrG   r+   c                    > [         R                  " U 5      [        La  g[         R                  " U 5      nUS:X  a  g[	        U4S jU 5       5      $ )NF)r   Tc              3   X   >#    U  H  o[         L =(       d    [        UT5      v   M!     g 7fr/   )Ellipsisr   )r   r   sig_el_types     r)   r   =type_matches.<locals>.is_homogeneous_tuple.<locals>.<genexpr>Z  s"     XiXD*Q*DDis   '*)typing
get_originr#   get_argsall)rG   	containedr   s     r)   is_homogeneous_tuple*type_matches.<locals>.is_homogeneous_tupleT  sC      #50*IE!XiXXXr(   )r   r   Union__args__anyr   intr8   isclassr   r   r   objectr:   r5   dtypenumbersNumberfloat)r   r   sig_origin_typesig_containedr   r   s    `   @r)   r   r   8  s[   nlNKO& &,,&>]+J&//I=III~|T2d:$--a0 CK3$6{++MM@@PPde =,5=m44Q7EE	YF 	Yt 	Y $M22 %++!='Mc5\,I}%%'//.*I*I-88r(   	arg_typeskwarg_typesnormalize_to_only_use_kwargsc                 N    [        XX#XE5      nUc  [        SU  SU SU 35      eU$ )zV
Wrapper around normalize_function that never returns None, but
loudly errors instead
zFailed to normalize function z with args z and kwargs )r   rB   )r   r   r   r   r   r   r~   s          r)   _normalize_function_or_errorr   k  sH     fC {+F8;tfLQWPXY
 	
 
r(   c                 `   Uc  0 nSn[        U [        R                  5      (       d8  [        U [        [        45      (       d  [        U S5      (       a  U R                  n [        U [        R                  5      (       d  [        U [        [        45      (       d  U nU [        ;   aw  [        U [        5      (       a  [        S5      e[        U    nUS   US   p[        R                  " U	5      R                  [        R                  " U
5      R                  :w  a  gU	n[        U5      (       d  [        S[        U5       35      e[        R                  " [        R                  " U5      5      n[!        XX%5      nU$ [        U 5      (       d  [        S[        U 5       35      e[#        U 5      n/ nU(       GaS  U H$  n [%        U/UQ70 UD6  UR'                  U5        M&     [+        U5      S:X  a   U$ [+        U5      S	:X  a  [!        US   XU5      nU$ Uc  Ub  U(       a  UO[-        [.        [0           S
5      nU(       a  UO0 nU H  nSn [%        U/UQ70 UD6nUR2                  R5                  5        H4  u  nnUR                  U   nU=(       a    [7        UR8                  U5      nM6     U(       d  Mp  [!        UUUU5      n  U$     U$ SR;                  S U 5       5      n[=        S[>        R@                  " U 5       SU 35      eU$ ! [(         a     GMa  f = f! [(         a    Sn N~f = f)a  
Returns normalized arguments to PyTorch functions. This means that
`args/kwargs` will be matched up to the functional's
signature and return exclusively kwargs in positional order if
`normalize_to_only_use_kwargs` is True.
Also populates default values. Does not support positional-only
parameters or varargs parameters (*args, **kwargs). Does not support modules.

May require `arg_types` and `kwarg_types` in order to disambiguate overloads.

Args:
    target (Callable): Function that we are normalizing
    args (Tuple[Any]): Tuple of args to the function
    kwargs (Optional[Dict[str, Any]]): Dict of kwargs to the function
    arg_types (Optional[Tuple[Any]]): Tuple of arg types for the args
    kwarg_types (Optional[Dict[str, Any]]): Dict of arg types for the kwargs
    normalize_to_only_use_kwargs (bool): Whether to normalize to only use kwargs.

Returns:

    Returns normalized_args_and_kwargs, or `None` if not successful.
N_opz"target should not be a string hereif_trueif_falsez*target_for_analysis must be callable, got ztarget must be callable, got r   r   r   TF
c              3   8   #    U  H  n[        U5      v   M     g 7fr/   )r&   )r   r   s     r)   r   %normalize_function.<locals>.<genexpr>  s      12AF/s   z Tried to normalize arguments to zy but the schema match was ambiguous! Please provide argument types to the normalize_arguments() call. Available schemas:
)!r   rE   BuiltinFunctionTyper   r   hasattrr   r
   r&   ri   r8   r9   ro   callablerb   unwrap&_args_kwargs_to_normalized_args_kwargsr   r   r7   r   rm   r   r#   r   ra   itemsr   r_   joinrB   r5   typename)r   r   r   r   r   r   new_args_and_kwargstarget_for_analysis
dispatchedr   r   sigtorch_op_schemasr   r   sig_matchesbound_typesarg_namerq   paramschema_printoutss                        r)   r   r     st   > ~vu8899F%5z$BCCFE""  fe77886,j9::$''
 &#&&$%IJJ+F3J *9 5z*7MX!!'*55$$X.99: ")+,, <TBU=V<WX  /B CDDv
D }  #@f!OPP5f=35 (8#2DTDVD#**+>? (8 ?#q(Z Y _%*&L#A&6R'#T M (K,C-6	DsR<PI1<+"K/?+&*
0*4 3+6?+CN+K 7B6K6K6Q6Q6S 2((;(F(Fx(P.9 /"l$)$4$4h?" 7T '; F$7$($*$@	!" 0 " G 0@F  (,yy 12A1 ($ ':5>>&;Q:R SOO_N`b  e ! 4  ) 0*/K0s%   = LA!L
LLL-,L-rootc                     U R                  U5      n[        UR                  S5      (       a  UR                  R
                  n[        [        R                  US5      UR                  :X  aG  [        R                  " [        R                  " UR                  5      5      nUc  0 n[        XX45      n	U	$ g! [         a  n[        SU S35      UeSnAff = f)a  
Returns normalized arguments to PyTorch modules. This means that
`args/kwargs` will be matched up to the functional's
signature and return exclusively kwargs in positional order if
`normalize_to_only_use_kwargs` is True.
Also populates default values. Does not support positional-only
parameters or varargs parameters (*args, **kwargs).

Args:
    root (nn.Module): root module upon which we query modules
    target (Callable): Function that we are normalizing
    args (Tuple[Any]): Tuple of args to the function
    kwargs (Optional[Dict[str, Any]]): Dict of kwargs to the function
    normalize_to_only_use_kwargs (bool): Whether to normalize to only use kwargs.

Returns:

    Returns normalized_args_and_kwargs, or `None` if not successful.
z$Tried to normalize node with target z# but root did not have that target!Nr   )get_submoduleAttributeErrorrB   r   	__class__r   r   r5   nnr8   r9   r   forwardr   )
r   r   r   r   r   submode	classnamer   r   s
             r)   r   r     s    6##F+ v,,$$--	588Y-1A1AA##GNN6>>$BCC~"H6# '&  26( ;  !
 	s   B5 5
C?CCr   c                 ^  ^	 [         R                  R                  [         R                  R                  1m	[	        U	4S jU R
                  R                  5        5       5      (       a*  [        U R
                  R                  5       5      / SQ:w  a  g[        U /UQ70 UD6nUR                  5         0 n/ n[        U R
                  5       HL  u  pxU(       d/  U[        U5      :  a   UR                  UR                  U   5        M;  UR                  U   XX'   MN     [        [!        U5      U5      $ )aU  
Given a call target, args, and kwargs, return the arguments normalized into
an ArgsKwargsPair, or None if the type signature is not supported by
this normalization.

Args:

    sig (inspect.Signature): Signature object for the target
    args (Tuple): Arguments that appear at the callsite for `target`
    kwargs (Dict): Keyword arguments that appear at the callsite for `target`
    normalize_to_only_use_kwargs (bool): Whether to normalize to only use kwargs.

Returns:

    Optional[ArgsKwargsPair]: Normalized args and kwargs for `target`, or `None` if
        this target is not supported.
c              3   @   >#    U  H  oR                   T;  v   M     g 7fr/   )r]   )r   rs   supported_parameter_typess     r)   r   9_args_kwargs_to_normalized_args_kwargs.<locals>.<genexpr>\  s     
T<Sq6622<Ss   )r[   r\   to	generatorN)r8   rZ   rh   rg   r   ro   valuesr   keysr   apply_defaultsrk   rm   r7   ra   r   r#   )
r   r   r   r   
bound_args
new_kwargsnew_argsir   r   s
            @r)   r   r   >  s    6 	//&&! 
TCNN<Q<Q<S
TTT
 ##%&*NNC1$1&1J!#JHcnn-+CIOOJ0078 * 4 4U ;J	 . %/:66r(   ).)F)NNNF)NF)Genumr8   r   rE   r   r   collections.abcr   r   r   r   r   r   r	   r5   torch._jit_internalr
   
torch._opsr   r   torch.utils._inspectr   _compatibilityr   noder   __all__r   r*   r%   r   rn   r$   r<   r0   r>   r6   devicelayoutr   r   rK   Enumqschemerb   UntypedStorageTypeVarrV   dirkr   rW   r   r   rw   rx   r#   r&   r   r   r   r:   r   r   r   r   r   r   Moduler   r   r   r(   r)   <module>r     s         $ J J  2 3 + )  e,Z  - HJ 4c*D1B1B,CCD I$w001   $4#5 %--  @ @ llllllnnii99}}%'T
##		  
VA#FA.q 
<.@ <S <6Hxx&&6H6Hr HJ DsCx'2C2C!CD Ixx&& e,&S#X&

 & j!& 
	& -&R 
VcV,3DMV
4!!"T)40G0G+H4+OOPV 
V
 
=@)c),3EN)	'

t#) 
)
 e,38%Cc%C,0%C 			D""#d*D1H1H,ID,PPQR
%C -%CP e,) )6 ) -)X e,/ /S /T / -/d e, %)#')-).S#X
S/ cNT! SzD 	
 c3h$& #'  -. e, %)#')-).HS#XH
S/H cNT!H SzD 	H
 c3h$&H #'H dH -HV e,
 %)).+
((//++ *+ cNT!	+
 #'+ d+ -+\17			17
S/17 cN17 #'	17
 d17r(   