Ë
    g^(h�  ã                  óŒ   — d dl mZ d dlZd dlZd dlmc mZ d dlm	Z	 d dl
mZmZmZ d dlmZmZmZ ddgZd
d„Z G d	„ de«      Zy)é    )ÚannotationsN)ÚPerChannelMinMaxObserver)ÚQuantizationAnnotationÚQuantizationSpecÚ	Quantizer)ÚOperatorConfigÚOperatorPatternTypeÚQuantizationConfigÚget_embedding_operators_configÚEmbeddingQuantizerc                 óX  — t        t        j                  t        j                  dt	        j
                  d¬«      ¬«      } t        d d | d «      }t        j                  j                  gg}|j                  t        j                  g«       t        ||¬«      }t        j                  |«      S )Nr   g      0?)Úeps)ÚdtypeÚqschemeÚch_axisÚobserver_or_fake_quant_ctr)ÚconfigÚ	operators)r   ÚtorchÚuint8Ú per_channel_affine_float_qparamsr   Ú	with_argsr
   ÚnnÚ	EmbeddingÚappendÚFÚ	embeddingr   ÚcopyÚdeepcopy)Úweight_quantization_specÚquantization_configÚopsÚsupported_config_and_operatorss       úq/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/torch/ao/quantization/quantizer/embedding_quantizer.pyr   r      sŒ   € Ü/Ü�k‰kÜ×6Ñ6ØÜ#;×#EÑ#EÈ&Ô#Qô	 Ðô -¨T°4Ð9QÐSWÓXÐÜ',§x¡x×'9Ñ'9Ð&:Ð%;€CØ‡J�J”—‘ˆ}ÔÜ%3Ø"¨cô&Ð"ô �=‰=Ð7Ó8Ð8ó    c                  óv   ‡ — e Zd Zdˆ fd„Zed	d„«       Ze	 	 	 	 d
d„«       Zdd„Zdd„Zdd„Z	edd„«       Z
ˆ xZS )r   c                ó"   •— t         ‰| �  «        y ©N)ÚsuperÚ__init__)ÚselfÚ	__class__s    €r$   r*   zEmbeddingQuantizer.__init__,   s   ø€ Ü‰ÑÕr%   c                óh   — | j                  «       D ��ch c]  \  }}|’Œ	 }}}t        |«      S c c}}w r(   )Úget_supported_operatorsÚlist)ÚclsÚspecÚ_Ú
op_configss       r$   Ú"get_supported_quantization_configsz5EmbeddingQuantizer.get_supported_quantization_configs/   s=   € ð !$× ;Ñ ;Ó =÷/
Ù�T˜1ŠDð/
ˆ
ñ /
ô �JÓÐùó/
s   ”.c                óH   — | j                  «       D ]  \  }}||k(  sŒ|c S  g S r(   )r.   )r0   r!   r   r"   s       r$   Ú.get_supported_operator_for_quantization_configzAEmbeddingQuantizer.get_supported_operator_for_quantization_config6   s7   € ð ×6Ñ6Ó8ò 	‰KˆF�Cð Ð,Ó,Ø’
ð	ð ˆ	r%   c                ó<   — | j                  |j                  «       |S )z!just handling global spec for now)Ú_annotate_embedding_opsÚgraph©r+   Úmodels     r$   ÚannotatezEmbeddingQuantizer.annotateD   s   € à×$Ñ$ U§[¡[Ô1Øˆr%   c                óŒ  — t        «       }|j                  D ]«  }|j                  dk(  sŒ|j                  t        j
                  j                  j                  j                  k(  sŒO|j                  j                  €t        d«      ‚t        |j                  d   |j                  j                  i¬«      |j                  d<   Œ­ y )NÚcall_functionz<Embedding config must have a valid weight quantization spec.r   )Úinput_qspec_mapÚquantization_annotation)r   ÚnodesÚopÚtargetr   r"   Úatenr   Údefaultr   ÚweightÚ
ValueErrorr   ÚargsÚmeta)r+   r9   Úembedding_configÚnodes       r$   r8   z*EmbeddingQuantizer._annotate_embedding_opsI   s¤   € Ü+IÓ+KÐØ—K‘Kò 	ˆDð —‘˜?Ó*Ø—K‘K¤5§9¡9§>¡>×#;Ñ#;×#CÑ#CÓCà#×*Ñ*×1Ñ1Ð9Ü$ØVóð ô 8NàŸ	™	 !™Ð&6×&=Ñ&=×&DÑ&Dð%ô8�—	‘	Ð3Ò4ñ	r%   c                 ó   — y r(   © r:   s     r$   ÚvalidatezEmbeddingQuantizer.validate\   s   € Ør%   c                ó   — t        «       gS r(   )r   )r0   s    r$   r.   z*EmbeddingQuantizer.get_supported_operators_   s   € ä.Ó0Ð1Ð1r%   )ÚreturnÚNone)rP   zlist[QuantizationConfig])r!   r
   rP   zlist[OperatorPatternType])r;   útorch.fx.GraphModulerP   rR   )r9   ztorch.fx.GraphrP   rQ   )r;   rR   rP   rQ   )rP   zlist[OperatorConfig])Ú__name__Ú
__module__Ú__qualname__r*   Úclassmethodr4   r6   r<   r8   rN   r.   Ú__classcell__)r,   s   @r$   r   r   +   sc   ø„ õð ò ó ð ð ðØ"4ðà	"òó ðóó
ó&ð ò2ó ô2r%   )rP   r   )Ú
__future__r   r   r   Útorch.nn.functionalr   Ú
functionalr   Útorch.ao.quantization.observerr   Ú)torch.ao.quantization.quantizer.quantizerr   r   r   Ú7torch.ao.quantization.quantizer.xnnpack_quantizer_utilsr   r	   r
   Ú__all__r   r   rM   r%   r$   ú<module>r_      sK   ðå "ã ã ß Ð Ý C÷ñ ÷
ñ ð %Øð€ó9ô 62˜õ 62r%   