
    ^j                         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y)    )compatibility)Graph)GraphModule)SubgraphMatcher)Module)HolderModulelift_subgraph_as_modulecompare_graphsF)is_backward_compatiblec                   <     e Zd ZdZdeeedz  f   ddf 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
    dNreturnc                 v    t         |           |j                         D ]  \  }}| j                  ||        y )N)super__init__items
add_module)selfr   kv	__class__s       g/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/torch/fx/passes/utils/common.pyr   zHolderModule.__init__   s5    GGI 	"DAqOOAq!	"    )	__name__
__module____qualname____doc__dictstrr   r   __classcell__)r   s   @r   r   r      s.    
"$sFTM12 "t " "r   r   gmsubgraph	comp_name
class_namer   c                    t        i       }i }|j                  D ]  }|j                  dvr|j                  }t	        |t
              st        dt        |             |j                  d      }|}	| }
|dd D ]A  }t        |	|      s|	j                  |t        i              t        |	|      }	t        |
|      }
C |d   }t        |
|      }| d| ||<   t        |	||        t        |||      |fS )a  
    Create a GraphModule for subgraph, which copies the necessary attributes
    from the original parent graph_module.

    Args:
        gm (GraphModule): parent graph module

        subgraph (:class:`torch.fx.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_attrzExpected str target, got .N)r   nodesoptarget
isinstancer   AssertionErrortype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	      s   : R I02^^ 14422&#& #<T&\N!KLL"LL-%cr* 	-D4&l2&674&Dgt,G	- +2.G^4	/8k6(,C!&)ni0/12 y(J79RRRr   leftrightc                 \    t        | dd      }|j                  |      }t        |      dkD  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
   S   s/     dNGmmE"Gw<!r   N) r   )torch.fx._compatibilityr   torch.fx.graphr   torch.fx.graph_moduler   #torch.fx.passes.utils.matcher_utilsr   torch.nnr   __all__r   r   tupler   r	   boolr
    r   r   <module>rP      s    1   - ?  H e,	"6 	" -	" e, #	7S7S7S 7S 	7S
 ;S#X&'7S -7St e, u   -r   