
    ȅi#                        % S SK r S SKJrJr  S SKJr  S SKrS SKJr  S SK	J
r
Jr  S SKJrJr  S SKJr  SS	KJr  SS
KJr  / r\\   \S'   \\\\   \S-  \4   r\\\\   \S-  \\4   r\ R8                  4S jr   SS\S\\\R>                  R@                  4   S\\\4   S\\\4   S\\   S-  S\\!   S-  S\\   S-  S\\\4   4S jjr"g)    N)CallableIterable)Any)
QConfigAny)MatchAllNodePattern)GraphNode)type_before_parametrizations   )_is_observed_standalone_module)QuantizeHandler__all__c                   ^  [        U[        5      (       a)  UtpEU[        L a  [        U5      S:w  a  [	        S5      e/ nOUn/ n[        U[
        5      (       a  [        U[        5      (       a  gX:X  a  g[        U[        5      (       a  [        UR                  5      U:  a  g[        U[
        5      (       aX  [        U[        R                  R                  5      (       a/  UR                  S:w  a  g[        T UR                     5      U:w  a  gO[!        U5      (       aK  UR                  S:w  d  UR                  ULa  gUR                  [        L a  UR"                  S   US   :w  a  gOH[        U[$        5      (       a"  UR                  S:w  d  UR                  U:w  a  gOUR                  U:w  a  gU(       d  g[        U5      [        UR"                  5      :w  a  g['        U 4S	 j[)        UR"                  U5       5       5      $ )
z&Matches a node in fx against a pattern   z.Expecting getattr pattern to have two elementsTFcall_modulecall_functionr   call_methodc              3   >   >#    U  H  u  p[        TXS S9v   M     g7f)r   )max_usesN)	_is_match).0node	arg_matchmoduless      ^/home/james-whalen/.local/lib/python3.13/site-packages/torch/ao/quantization/fx/match_utils.py	<genexpr>_is_match.<locals>.<genexpr>K   s#      :OD 	'4Q7:s   )
isinstancetuplegetattrlenAssertionErrortype
issubclassr   r
   userstorchnnModuleopr   targetcallableargsstrallzip)r   r   patternr   
self_matcharg_matchess   `     r   r   r      s   '5!!#* 
 7|q $%UVVK
*d##
:|(L(LdD!!S_x%?*d##
:uxx(O(O77m#'(<=K L	*		77o%J)F[[G#yy|wqz)	J	$	$77m#t{{j'@ (A	
	"
;3tyy>) "499k:      graphr   patternsroot_node_getter_mappingstandalone_module_namesstandalone_module_classescustom_module_classesreturnc           
        ^^^^ Uc  / nTc  / mTc  / m0 n[        5       nU4S jmU4S jm[        U R                  5       H  n	U	R                  U;  d  M  U	R                  U;  d  M'  UR	                  5        H`  u  pUR                  U
5      n[        XU
5      (       d  M)  U	R                  U;  d  M;  / nT" XXU5        U" XU5      nU	nT" UUUUU
U5          M     M     Uc  [        S5      eU R                   HL  n	U	R                  S:X  d  M  [        XR                     5      U;   d  M2  U	U	S[        XSS94XyR                  '   MN     S[        S	[        [        [        R                  R                   4   4UU4S
 jjnU R                   He  n	U	R                  S:X  d  M  U" U	R                  U5      (       d  [#        XR                     5      (       d  MK  U	U	S[        XSS94XyR                  '   Mg     U$ )a  
Matches the nodes in the input graph to quantization patterns, and
outputs the information needed to quantize them in future steps.

Inputs:
  - graph: an fx.Graph object
  - modules: a mapping of fully qualified module name to instance,
      for example, {'foo': ModuleFoo, ...}
  - patterns: a mapping from a tuple of nodes in reverse order to
      uninitialized QuantizeHandler subclass.

Outputs a map of
  node_name ->
    (node, matched_values, matched_pattern, QuantizeHandler instance,
     qconfig)

For example, {
  'relu_1': (relu_1, [relu_1], torch.nn.functional.relu,
             <CopyNodeQuantizeHandler instance>, QConfig(...)),
  ...
}
Nc           	         > [        U[        5      (       a  U UUU4XR                  '   g [        U[        5      (       d  g U H  nT" XXcXE5        M     g )N)r   r
   namer   )	last_node	match_mapnode_patternmatched_node_patternr1   match_valuen#_recursive_record_node_in_match_maps          r   rE   :_find_matches.<locals>._recursive_record_node_in_match_map|   sY     lD))$	,I''( L(33!3!7 "r4   c                   > [        U [        5      (       a  U tpV[        U5      S:H  n/ nT" XQX#U5        U S   [        La(  [	        XaR
                  5       H  u  pT" XXU5        M     [        U5      S:  a=  U(       a  UR                  [        U5      5        g UR                  [        U5      5        g UR                  US   5        g UR                  U5        g )Nr   r   )	r   r    r"   r!   r0   r-   appendextendlist)r1   r   r?   rB   r@   sr-   is_single_argcurrent_node_pattern
subpatternargrecord_matchs              r   rP   #_find_matches.<locals>.record_match   s    gu%%HAINM/1 )9Mqz('*4';OJ $iX (<'(1, !(//6J0KL(//5I0JK$++,@,CD ''-r4   modules must not be Noner   T)is_custom_modulenode_targetr   c                 X   > Uc  [        S5      eU T;   =(       d    [        X   5      T;   $ )NrR   )r#   r$   )rT   r   r9   r8   s     r   is_standalone_module+_find_matches.<locals>.is_standalone_module   s:    ? !;<<22 )G()()	
r4   )rV   )setreversednodesr>   itemsgetr   r#   r*   r$   r+   r   r.   dictr'   r(   r)   r   )r5   r   r6   r7   r8   r9   r:   r@   all_matchedr   r1   quantize_handler_clsroot_node_getterrB   quantize_handlerr?   rV   rE   rP   s       ``           @@r   _find_matchesrb   Q   s   > $ " ($&!&"$)+IEK&.4 %99I%$));*F191A-#;#?#?#H WG44)9S79( IV';,7G($ !%I7!!,,(	 ) 2B &2 788GG}$W[[)*.CC E	$Iii  
# 
S%((//=Q8R 
 
 77m# g66-gkk.BCC DI	$Iii   r4   )NNN)#syscollections.abcr   r   typingr   r'   torch.ao.quantization.qconfigr   torch.ao.quantization.utilsr   r   torch.fx.graphr	   r
   torch.nn.utils.parametrizer   graph_moduler   ra   r   r   rJ   r.   __annotations__r    _MatchResult_MatchResultWithQConfigmaxsizer   r]   r(   r)   r$   rb    r4   r   <module>rp      s0   
 .   4 = & C 8 - c  T4:w~FG$t*gnozA  03{{ /n 1537.2VV#uxx&'V 7O+,V #7H#45	V
 "#Y-V  $DzD0V  9t+V 
#|
Vr4   