
    [Th#                         S SK Jr  S SKJr  S SKJr  S SKJr  S SKJ	r	  / SQr
\" SS9 " S	 S
\	5      5       r\" SS9  SS\S\S\S\S\\\\\4   4   4
S jj5       r\" SS9S\S\S\4S j5       rg)    )compatibility)Graph)GraphModule)SubgraphMatcher)Module)HolderModulelift_subgraph_as_modulecompare_graphsF)is_backward_compatiblec                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )r      zm
HolderModule is used to copy all the attributes from original module to submodules
that uses the attributes
c                 v   > [         TU ]  5         UR                  5        H  u  p#U R                  X#5        M     g )N)super__init__items
add_module)selfdkv	__class__s       T/var/www/auris/envauris/lib/python3.13/site-packages/torch/fx/passes/utils/common.pyr   HolderModule.__init__   s,    GGIDAOOA!      )__name__
__module____qualname____firstlineno____doc__r   __static_attributes____classcell__)r   s   @r   r   r      s    
" "r   r   gmsubgraph	comp_name
class_namereturnc                    [        0 5      n0 nUR                   H  nUR                  S;  a  M  UR                  n[	        U[
        5      (       d   eUR                  S5      nUn	U n
USS  HD  n[        X5      (       d  U	R                  U[        0 5      5        [        X5      n	[        X5      n
MF     US   n[        X5      nU SU 3XW'   [        XU5        M     [        XAU5      U4$ )a[  
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	      s    6 R I02^^4422&#&&&&"LL-%cr*D4&&l2&674&Dg,G + +2.G4	/8k6(,C!)i0- 0 yJ79RRRr   leftrightc                 V    [        U SSS9nUR                  U5      n[        U5      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
   R   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   r1   tupledictr	   boolr
   r   r   r   <module>rR      s    2   - ?  H e,	"6 	" -	" e, #	4S4S4S 4S 	4S
 ;S#X&'4S -4Sn e, u   -r   