
    PhH                     B   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
mZmZmZmZmZ d dlZd dlZg dZd Z e       Z ed	
      e G d d                    Z ed	
      	 ddedee   deeegef      de
eee   f   fd       Z ed	
      dededefd       Zy)    )	dataclassfield)Graph)Node)compatibility)DictListAnyTypeOptionalCallableN)get_source_partitionscheck_subgraphs_connectedSourcePartitionc                  |   t        j                  t              } t        j                  j                  dd      j                         }| j                  |       t        j                         }t        j                  d      }|j                  |       |j                  |       | j                  |       d| _        | S )NPYTORCH_MATCHER_LOGLEVELWARNINGz%(filename)s > %(message)sF)logging	getLogger__name__osenvirongetuppersetLevelStreamHandler	FormattersetFormatter
addHandler	propagate)loggerlevelconsole	formatters       uC:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\torch/fx/passes/utils/source_matcher_utils.py_init_loggerr&      s    x(FJJNN5yAGGIE
OOE##%G!!">?I#U
gFM    F)is_backward_compatiblec                       e Zd ZU ee   ed<   eed<    ee      Z	ee   ed<    ee      Z
ee   ed<    ee      Zee   ed<   y)r   nodessource)default_factoryinput_nodesoutput_nodesparamsN)r   
__module____qualname__r	   r   __annotations__r
   r   listr-   r.   r/    r'   r%   r   r      sT     : K $D9Kd9  %T:L$t*: t4FDJ4r'   r   graphwanted_sources	filter_fnreturnc                    i }| j                   D ]i  }|j                  j                  dd      x}"|d   }|d   |vr/|j                  |d   i       }|j                  |d   g       }|j	                  |       k dt
        t           dt        dt        fd	}	i }
|rYi }|j                         D ]B  \  }}|j                         D ci c]  \  }}t        t        ||            r|| }}}|||<   D |}|j                         D ]-  \  }}|j                         D cg c]  } |	||       c}|
|<   / |
S c c}}w c c}w )
a  
    Args:
        graph: The graph we want to partition
        wanted_sources: List of sources of nodes that were decomposed from this
            source. This can be a function (ex. torch.nn.functional.linear) or a
            leaf module type (ex. torch.nn.Linear).

    Returns:
        Dictionary mapping sources that were given to a list of SourcePartitions
        that correspond to the list of nodes that were decomposed from the given
        source.
    source_fn_stackN   r   r*   module_typer8   c           	         t               }t               }t               }| D ]  }|j                  D ])  }t        |t              s|| vs|j	                  |       + |j
                  dk(  r|j	                  |       |j                  j                         D ]  }|| vs|j	                  |         t        | |t        |      t        |      t        |            S )Nget_attr)
setargs
isinstancer   addopuserskeysr   r3   )r*   r=   r-   r.   r/   nodeargusers           r%   make_partitionz-get_source_partitions.<locals>.make_partitionW   s    euDyyc4(S-=OOC( ! ww*$

4 

)u$ $$T* *  L
 	
r'   )r*   metar   
setdefaultappendr	   r   r   r   itemsallmapvalues)r5   r6   r7   modulesrG   source_fn_st	source_fndiff_modules	partitionrJ   retfiltered_modulestpname_to_partitionnamefiltered_name_to_partitionkvs                     r%   r   r   2   sq   $ 24G !IIMM*;TBBLK $	Q<~-)))A,; ++IaL"=	 "
d4j 
t 
 
0 35C %,]]_!B! (9'>'>'@*'@OD)s9i01 i'@ ' *
 $>R  &5 #1@A
K
9.A.
KA   J* Ls   "D7D=	subgraph1	subgraph2c                     t        | j                        D ]2  }|j                  j                         D ]  }||j                  v s  y 4 y)z
    Given two subgraphs A and B (in the form of a list of nodes), checks if
    A has nodes connecting to at least one node in B -- aka there exists a node
    in B that uses a node in A (not the other way around).
    TF)reversedr*   rE   rF   )r_   r`   rG   rI   s       r%   r   r      s@     )JJOO%Dy& & * r'   )N)dataclassesr   r   torch.fx.graphr   torch.fx.noder   torch.fx._compatibilityr   typingr   r	   r
   r   r   r   r   r   __all__r&   r!   r   boolr   r   r4   r'   r%   <module>rj      s    (    1 < <  	 T 
 e,
5 5  -5$ e, 37NNIN $./N 
#tO$
$%	N -Nb e, _ Y]  -r'   