
    shQ                     H   % S SK r 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\r\" 5       r\\
\4   \S'   S	 rS
\\
\4   4S jr\" 5       r\\
\4   \S'   0 r\\
\4   \S'   0 r\\
\4   \S'   SS jrS
\\
\4   4S jrS
\\
\4   4S jrS\\
\4   S
\\
\4   4S jrg)    N)OrderedDict)Any)FixedQParamsFakeQuantize)ObserverBase)Pattern)get_default_fusion_patternsget_default_quant_patterns.get_default_output_activation_post_process_map_DEFAULT_FUSION_PATTERNSc                    ^  U 4S jnU$ )Nc                    > U [         T'   U $ N)r   )fnpatterns    z/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/torch/ao/quantization/fx/pattern_utils.pyinsert(_register_fusion_pattern.<locals>.insert   s    ,. )	     )r   r   s   ` r   _register_fusion_patternr      s     Mr   returnc                  6    [         R                   " [        5      $ r   )copyr   r   r   r   r   r       s    99-..r   _DEFAULT_QUANTIZATION_PATTERNS!_DEFAULT_OUTPUT_FAKE_QUANTIZE_MAP_DEFAULT_OUTPUT_OBSERVER_MAPc                    ^ ^ UU 4S jnU$ )Nc                 h   > U [         T'   Tb$  [        R                  " TS9[        T'   T[        T'   U $ )N)observer)r   r   	with_argsr   r   )r   fixed_qparams_observerr   s    r   r   '_register_quant_pattern.<locals>.insert/   sE    24&w/!- )22<RS . 5K(1	r   r   )r   r!   r   s   `` r   _register_quant_patternr#   .   s     Mr   c                  6    [         R                   " [        5      $ r   )r   r   r   r   r   r	   r	   <   s    99344r   c                 x    U (       a  [         R                   " [        5      $ [         R                   " [        5      $ r   )r   r   r   )is_trainings    r   r
   r
   B   s'     yy:;;yy566r   patterns_dictc                 Z   ^ U4S jm[        [        U R                  5       U4S jS95      $ )a
  
Return a sorted version of the patterns dictionary such that longer patterns are matched first,
e.g. match (F.relu, F.linear) before F.relu.
This works for current use cases, but we may need to have a more clever way to sort
things to address more complex patterns
c                 l   > Sn[        U [        5      (       a  U  H  nUT" U5      -  nM     U$ US-  nU$ )zthis will calculate the length of the pattern by counting all the entries
in the pattern.
this will make sure (nn.ReLU, (nn.BatchNorm, nn.Conv2d)) comes before
(nn.BatchNorm, nn.Conv2d) so that we can match the former first
r      
isinstancetuple)r   lenitemget_lens      r   r0   &_sorted_patterns_dict.<locals>.get_len]   sF     gu%%wt}$   
 1HC
r   c                 P   > [        U S   [        5      (       a  T" U S   5      * $ S$ )Nr   r*   r+   )kvr0   s    r   <lambda>'_sorted_patterns_dict.<locals>.<lambda>n   s'    jA.F.FGBqEN?MAMr   )key)r   sorteditems)r'   r0   s    @r   _sorted_patterns_dictr9   S   s.     !M	
 r   r   )r   collectionsr   typingr   #torch.ao.quantization.fake_quantizer   torch.ao.quantization.observerr   torch.ao.quantization.utilsr   __all__QuantizeHandlerr   dict__annotations__r   r   r   r   r   r#   r	   r
   r9   r   r   r   <module>rC      s     #  H 7 /  <G= $w78 H/T'?*B%C / BM Wo%= > N
 EG !4(@#A F?A d7O#;< A
5D/)A$B 57	'<
 7"01	'?
"#r   