ó
    EñiT  ã                   ó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    €Úc/home/mande/repo/quber/.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   € Ü�9Š9Ô-Ó.Ð.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/   s@   ø€ Ø24Ô& wÑ/Ø!Ñ-ä(×2Ò2Ð<RÑSô .¨gÑ6ð 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   € Ü�9Š9Ô3Ó4Ð4r   c                 óx   • U (       a  [         R                   " [        5      $ [         R                   " [        5      $ r   )r   r   r   )Úis_trainings    r   r
   r
   B   s'   € ö Ü�yŠyÔ:Ó;Ð;ä�yŠyÔ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$ )zàthis 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   ø€ ð ˆÜ�gœu×%Ñ%Û�Ø‘w˜t“}Ñ$’ñ  ð ˆ
ð �1‰HˆCØˆ
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Ñ.F™G B q¡E›N˜?ÐMÈAÐ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ÃÐ   W¨oÐ%=Ñ >Ó Nð
 EGÐ ! 4¨°Ð(@Ñ#AÓ FØ?AÐ ˜d 7¨OÐ#;Ñ<Ó Aô
ð5 D¨°/Ð)AÑ$Bô 5ð7à	ˆ'�<Ð
Ñ ô7ð"Ø˜ Ð0Ñ1ðà	ˆ'�?Ð
"Ñ#õr   