
    [Tht                         S SK r S SKJrJrJr  S SKrS SKrS SKJr  S SKJrJ	r	  S SK
JrJrJrJr  S SKJrJrJr  SSKJr   " S S	\	5      r " S
 S\5      rg)    N)AnyCallableOptional)ProxyTransformer)Argumentmap_aggregateNodeTarget)create_type_hintnormalize_functionnormalize_module   )AnnotateTypesWithSchemac                     ^  \ rS rSrSr SS\R                  R                  S\4U 4S jjjr	S\
S\4U 4S jjr  SS	\S
\\S4   S\\\4   S\\\S4      S\\\\4      4
U 4S jjjrS	\S
\\S4   S\\\4   4U 4S jjrSrU =r$ )NormalizeArgs   aS  
Normalize arguments to Python targets. This means that
`args/kwargs` will be matched up to the module/functional's
signature and rewritten to 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).

If the nodes have 'type' metadata, it will use it to disambiguate
overloads. Otherwise, it will throw an error.

Example usage:
    m = torchvision.models.resnet18()
    traced = torch.fx.symbolic_trace(m)
    traced = NormalizeArgs(traced).transform()
modulenormalize_to_only_use_kwargsc                 >   > [         TU ]  U5        0 U l        X l        g N)super__init__node_mapr   )selfr   r   	__class__s      W/var/www/auris/envauris/lib/python3.13/site-packages/torch/fx/experimental/normalize.pyr   NormalizeArgs.__init__%   s     	 +-,H)    nreturnc                 n  >^ U R                  T5      u  p#U4S jn[        TR                  U5      n[        U[        5      (       d   e[	        U Vs/ s H  n[        U5      PM     sn5      nUR                  5        VVs0 s H  u  pxXt" U5      _M     n	nnTR                  S:X  a  U R                  TR                  X#XY5      n
O[        TU ]-  T5      n
TR                  S:w  aE  TU R                  U
'   TR                  U
R                  l        TR                  U
R                  l        U
$ s  snf s  snnf )Nc                    > [        U [        R                  5      (       a!  STR                  ;   a  TR                  S   $ S $ [	        U 5      $ )Ntype)
isinstancefxr
   metar$   )argr    s    r   get_type(NormalizeArgs.run_node.<locals>.get_type/   s<    #rww'')/166)9qvvf~CtC9r   call_functionoutput)fetch_args_kwargs_from_envr	   argsr%   tupler   itemsopr+   targetr   run_noder   r'   noder$   )r   r    r.   kwargsr)   	arg_typesikvkwarg_typesoutr   s    `         r   r3   NormalizeArgs.run_node,   s    66q9	
 "!&&(3	)U++++	B	1+A.	BC	28,,.A.$!q(1+~.A44?"$$QXXtYTC'"1%C448!"DMM#FFCHHMFFCHHM
 CAs   D,D1r2   r.   .r5   r6   r:   c                    > [        U5      (       d   e[        UUUUUU R                  5      nU(       a!  Uu  pxU R                  R	                  SXU5      $ [
        T	U ]  XU5      $ )Nr+   )callabler   r   tracercreate_proxyr   r+   )
r   r2   r.   r5   r6   r:   new_args_and_kwargsnew_args
new_kwargsr   s
            r   r+   NormalizeArgs.call_functionB   sx     0--
 #6 H;;++:  7(v>>r   c                    > [        U[        5      (       d   e[        U R                  UUUU R                  5      nU(       a  Uu  pV[
        TU ]  XU5      $ [
        TU ]  XU5      $ r   )r%   strr   r   r   r   call_module)r   r2   r.   r5   rA   rB   rC   r   s          r   rG   NormalizeArgs.call_module[   sm     &#&&&&.KK--
 #6 H7&vDD7&vV<<r   )r   r   )T)NN)__name__
__module____qualname____firstlineno____doc__torchr&   GraphModuleboolr   r
   r   r3   r   r/   r   dictrF   r   r+   rG   __static_attributes____classcell__r   s   @r   r   r      s    $ RVIhh**IJNI I$ 3 6 0404?? HcM"? S#X	?
 E#s(O,? d38n-? ?2==$)(C-$8=BFsCx.= =r   r   c                     ^  \ rS rSr% Sr\R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                   \R                   \R"                  \R"                  \R$                  \R$                  \R&                  \R&                  \R(                  \R(                  \R*                  \R*                  0r\\\\/\4   \\\/\4   4   \S'   S\S\\S4   S\\\4   4U 4S jjrS	r U =r!$ )
NormalizeOperatorsm   a  
Normalize callsites that are different ways of "spelling" the same
invocation into a single, canonical call. Currently supports:

1. Normalize operators (e.g. operator.add) to the `torch` ops they
   ultimately invoke (e.g. torch.add) when it is possible to statically
   reason that

Example usage:

    m = torchvision.models.resnet18()

    traced = torch.fx.symbolic_trace(m)

    traced = NormalizeOperators(traced).transform()
binary_magic_method_remapr2   r.   .r5   c                    > [        U5      (       d   eXR                  ;   a@  [        U5      S:w  a  [        TU ]  XU5      $ Uu  pE[        TU ]  U R                  U   XE40 S9$ [        TU ]  XU5      $ )N   )r2   r.   r5   )r>   rX   lenr   r+   )r   r2   r.   r5   lhsrhsr   s         r   r+    NormalizeOperators.call_function   s     3334yA~w,V6BBHC7(55f=Z )   w$V6::r    )"rI   rJ   rK   rL   rM   rN   addoperatormulsubdivtruedivfloor_dividefloordiv	remaindermodeqneltlegtgerX   rQ   r   r   __annotations__r   r/   r   rF   r+   rR   rS   rT   s   @r   rV   rV   m   s   ( 			8<<		8<<		8<<		8##H--(++(++(++(++(++(++	 t#sS!8S#JO#<<  ";;$)(C-$8;BFsCx.; ;r   rV   )ra   typingr   r   r   rN   torch.fxr&   r   r   torch.fx.noder   r	   r
   r   torch.fx.operator_schemasr   r   r   schema_type_annotationr   r   rV   r_   r   r   <module>rv      sK     * *    ' ? ?  <W=K W=t6;0 6;r   