
    `i                        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dS )    )annotationsN)PerChannelMinMaxObserver)QuantizationAnnotationQuantizationSpec	Quantizer)OperatorConfigOperatorPatternTypeQuantizationConfigget_embedding_operators_configEmbeddingQuantizerreturnr   c                 J   t          t          j        t          j        dt	          j        d                    } t          d d | d           }t          j        j        gg}|	                    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       /home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/torch/ao/quantization/quantizer/embedding_quantizer.pyr   r      s    /k6#;#E&#Q#Q#Q	      -T49QSWXX',x'9&:%;CJJ}%3"c& & &" =7888    c                       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   r   Nonec                H    t                                                       d S N)super__init__)self	__class__s    r%   r,   zEmbeddingQuantizer.__init__,   s    r&   list[QuantizationConfig]c                \    d |                                  D             }t          |          S )Nc                    h | ]\  }}|S  r2   ).0spec_s      r%   	<setcomp>zHEmbeddingQuantizer.get_supported_quantization_configs.<locals>.<setcomp>1   s)     /
 /
 /
T1D/
 /
 /
r&   )get_supported_operatorslist)cls
op_configss     r%   "get_supported_quantization_configsz5EmbeddingQuantizer.get_supported_quantization_configs/   s<    /
 /
 # ; ; = =/
 /
 /

 Jr&   r"   r
   list[OperatorPatternType]c                N    |                                  D ]\  }}||k    r|c S g S r*   )r7   )r9   r"   r   r#   s       r%   .get_supported_operator_for_quantization_configzAEmbeddingQuantizer.get_supported_operator_for_quantization_config6   sD     6688 	 	KFC ,,,


 -	r&   modeltorch.fx.GraphModulec                :    |                      |j                   |S )z!just handling global spec for now)_annotate_embedding_opsgraphr-   r?   s     r%   annotatezEmbeddingQuantizer.annotateD   s    $$U[111r&   rC   torch.fx.Graphc                (   t                      }|j        D ]{}|j        dk    rn|j        t          j        j        j        j        k    rJ|j	        j
        t          d          t          |j        d         |j	        j
        i          |j        d<   |d S )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-   rC   embedding_confignodes       r%   rB   z*EmbeddingQuantizer._annotate_embedding_opsI   s    +I+K+KK 	 	D ?**K59>#;#CCC#*19$V   8N	!&6&=&D%8 8 8	34	 	r&   c                    d S r*   r2   rD   s     r%   validatezEmbeddingQuantizer.validate\   s    r&   list[OperatorConfig]c                     t                      gS r*   )r   )r9   s    r%   r7   z*EmbeddingQuantizer.get_supported_operators_   s    .0011r&   )r   r(   )r   r/   )r"   r
   r   r<   )r?   r@   r   r@   )rC   rF   r   r(   )r?   r@   r   r(   )r   rX   )__name__
__module____qualname__r,   classmethodr;   r>   rE   rB   rW   r7   __classcell__)r.   s   @r%   r   r   +   s                    [     [   
   &    2 2 2 [2 2 2 2 2r&   )r   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   r2   r&   r%   <module>rf      s   " " " " " "            C C C C C C         
          %9 9 9 9 62 62 62 62 62 62 62 62 62 62r&   