o
    ‡ZŽhÉ
  ã                   @   s*   d dl Z d dlZdejjddfdd„ZdS )é    NÚgraphÚreturnc                 C   sŠ  | j D ]¿}|jtjkrÂ|j\}}|jsqt|jdƒr]|jj}|jjdkrIt	|ƒdkr9t
|d tdƒƒr9|d |_qt	|ƒ|ksAJ ‚|| }||_q|jjdkr\t	|ƒdksWJ ‚|d |_qt|jdƒr¦|jj}|jjtu r’t	|ƒdkr‚t
|d tdƒƒr‚|d |_qt	|ƒ|ksŠJ ‚|| }||_q|jjtu r¥t	|ƒdks J ‚|d |_qt|jd	ƒrÂ|jtjkr³q|jj}|jj| }|| |_qd
S )aà  
    Annotate the type of getitem nodes, inferred from the type of sequence node.
    If sequence node is not annotated with a type, do nothing.
    Currently support getitem nodes from tuple, list, and NamedTuple sequence node.

    This is helpful since annotations on local names within function are lost during FX transforms.
    Adding back known type annotation for getitem nodes to improve jit scriptability.

    Args:
        graph (Graph): The graph to be annotated
    Ú_nameÚTupleé   é   .r   ÚListÚ
__origin__Ú__annotations__N)ÚnodesÚtargetÚoperatorÚgetitemÚargsÚtypeÚhasattrÚ__args__r   ÚlenÚ
isinstancer	   ÚtupleÚlistÚtorchZTensorr
   Ú_fields)r   ÚnodeZsequence_nodeZ
index_nodeZparameterized_typesZ	node_typeZsequence_node_field_typesÚ
field_name© r   úU/var/www/auris/lib/python3.10/site-packages/torch/fx/passes/annotate_getitem_nodes.pyÚannotate_getitem_nodes   sR   

ÿ
€ÿ
€
€×r   )r   r   ZfxZGraphr   r   r   r   r   Ú<module>   s    