
    sh"                        % S SK r S SKJr  S SKJrJr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'   \\\\   \\   \4   r\\\\   \\   \\	4   r\ R:                  4S jr   SS\S\\\R@                  RB                  4   S\\\4   S\\\4   S\\\      S\\\"      S\\\      S\\\4   4S jjr#g)    N)Iterable)AnyCallableOptional)
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:X  d   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:X  d  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      x/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/torch/ao/quantization/fx/match_utils.py	<genexpr>_is_match.<locals>.<genexpr>J   s#      :OD 	'4Q7:s   )
isinstancetuplegetattrlen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!!#* 
 w<1$V&VV$K
*d##
:|(L(LdD!!S_x%?*d##
:uxx(O(O77m#+GDKK,@AZO P	*		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        Ha  u  pUR                  U
S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   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   rF   :_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@   rC   rA   sr-   is_single_argcurrent_node_pattern
subpatternargrecord_matchs              r   rQ   #_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   r   T)is_custom_modulenode_targetr   c                 F   > Uc   eU T;   =(       d    [        X   5      T;   $ r>   )r$   )rT   r   r9   r8   s     r   is_standalone_module+_find_matches.<locals>.is_standalone_module   s5    """22 )G()()	
r4   )rV   )setreversednodesr?   itemsgetr   r*   r$   r+   r   r.   dictr'   r(   r)   r   )r5   r   r6   r7   r8   r9   r:   rA   all_matchedr   r1   quantize_handler_clsroot_node_getterrC   quantize_handlerr@   rV   rF   rQ   s       ``           @@r   _find_matchesrb   P   s   > $ " ($&!&"$)+IEK&.4 %99I%$));*F191A-#;#?#?#N WG44)9S79( IV';,7G($ !%I7!!,,(	 ) 2B &2 GG}$W[[)*.CC E	$Iii  
# 
S%((//=Q8R 
 
 77m# g66-gkk.BCC DI	$Iii   r4   )NNN)$syscollections.abcr   typingr   r   r   r'   torch.ao.quantization.qconfigr   torch.ao.quantization.utilsr   r	   torch.fx.graphr
   r   torch.nn.utils.parametrizer   graph_moduler   ra   r   r   rK   r.   __annotations__r!   _MatchResult_MatchResultWithQConfigmaxsizer   r]   r(   r)   r$   rb    r4   r   <module>rp      s5   
 $ * *  4 = & C 8 - c  T4:x'8/IJ$t*hw'*D  03{{ .l 486:15TT#uxx&'T 7O+,T #7H#45	T
 &d3i0T  (T
3T $DI.T 
#|
Tr4   