
    קgC                     8   d dl mZmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ g dZ ed	           G d
 de                      Z ed	          	 	 ddededededeeeeef         f         f
d            Z ed	          dededefd            ZdS )    )DictTuple)compatibility)Graph)GraphModule)SubgraphMatcher)Module)HolderModulelift_subgraph_as_modulecompare_graphsF)is_backward_compatiblec                   "     e Zd ZdZ fdZ xZS )r
   zy
    HolderModule is used to copy all the attributes from original module to submodules
    that uses the attributes
    c                     t                                                       |                                D ]\  }}|                     ||           d S )N)super__init__items
add_module)selfdkv	__class__s       X/var/www/html/ai-engine/env/lib/python3.11/site-packages/torch/fx/passes/utils/common.pyr   zHolderModule.__init__   sU    GGII 	" 	"DAqOOAq!!!!	" 	"    )__name__
__module____qualname____doc__r   __classcell__)r   s   @r   r
   r
      sB         
" " " " " " " " "r   r
    r   gmsubgraph	comp_name
class_namereturnc                    t          i           }i }|j        D ]}|j        dvr|j        }t	          |t
                    sJ |                    d          }|}	| }
|dd         D ]U}t          |	|          s#|	                    |t          i                      t          |	|          }	t          |
|          }
V|d         }t          |
|          }| d| ||<   t          |	||           t          |||          |fS )aw  
    Create a GraphModule for subgraph, which copies the necessary attributes from the original parent graph_module.

    Args:
        gm (GraphModule): parent graph module

        subgraph (Graph): a valid subgraph that contains copied nodes from the parent graph

        comp_name (str): name for the new component

        class_name (str): name for the submodule

    )call_moduleget_attr.N)r
   nodesoptarget
isinstancestrsplithasattrr   getattrsetattrr   )r!   r"   r#   r$   	submoduleorig_to_split_fqn_mappingnr-   target_name_partscurrorig_gmnameleaf_node_name	leaf_nodes                 r   r   r      s7   6 R  I02^ 1 14222&#&&&&&"LL--%crc* 	- 	-D4&& 8l2&6&67774&&Dgt,,GG*2.G^44	/8,C,C6,C,C!&)ni0000y(J779RRRr   leftrightc                 v    t          | dd          }|                    |          }t          |          dk    S )z
    Return True if two graphs are identical, i.e they
        - have the same number of outputs in the same order
        - have the same number of inputs in the same order
        - have the same set of nodes, and identical connectivity
    T)match_outputmatch_placeholderr   )r   matchlen)r=   r>   matchermatchess       r   r   r   T   s:     dNNNGmmE""Gw<<!r   N)r    r   )typingr   r   torch.fx._compatibilityr   torch.fx.graphr   torch.fx.graph_moduler   #torch.fx.passes.utils.matcher_utilsr   torch.nnr	   __all__r
   r/   r   boolr    r   r   <module>rO      s           1 1 1 1 1 1             - - - - - - ? ? ? ? ? ?       H
G
G e,,,	" 	" 	" 	" 	"6 	" 	" -,	" e,,, #	4S 4S4S4S 4S 	4S
 ;S#X&'4S 4S 4S -,4Sn e,,, u     -,  r   