o
    Zh                     @  s   d dl mZ d dlZd dlZd dlm  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
dZG dd deZdS )    )annotationsN)PerChannelMinMaxObserver)QuantizationAnnotationQuantizationSpec	Quantizer)OperatorConfigOperatorPatternTypeQuantizationConfigget_embedding_operators_configEmbeddingQuantizerreturnr   c                  C  sZ   t tjtjdtjddd} td d | d }tjjgg}|	t
jg t||d}t|S )Nr   g      0?)Zeps)ZdtypeZqschemeZch_axisZobserver_or_fake_quant_ctr)config	operators)r   torchZuint8Z per_channel_affine_float_qparamsr   Z	with_argsr	   nnZ	EmbeddingappendF	embeddingr   copydeepcopy)Zweight_quantization_specquantization_configopsZsupported_config_and_operators r   b/var/www/auris/lib/python3.10/site-packages/torch/ao/quantization/quantizer/embedding_quantizer.pyr
      s   

c                      sf   e Zd Zd fddZedddZedddZdddZdddZdddZ	ed ddZ
  ZS )!r   r   Nonec                   s   t    d S N)super__init__)self	__class__r   r   r   ,   s   zEmbeddingQuantizer.__init__list[QuantizationConfig]c                 C  s   dd |   D }t|S )Nc                 S  s   h | ]\}}|qS r   r   ).0spec_r   r   r   	<setcomp>1   s    zHEmbeddingQuantizer.get_supported_quantization_configs.<locals>.<setcomp>)get_supported_operatorslist)clsZ
op_configsr   r   r   "get_supported_quantization_configs/   s   z5EmbeddingQuantizer.get_supported_quantization_configsr   r	   list[OperatorPatternType]c                 C  s&   |   D ]\}}||kr|  S qg S r   )r&   )r(   r   r   r   r   r   r   .get_supported_operator_for_quantization_config6   s
   zAEmbeddingQuantizer.get_supported_operator_for_quantization_configmodeltorch.fx.GraphModulec                 C  s   |  |j |S )z!just handling global spec for now)_annotate_embedding_opsgraphr   r,   r   r   r   annotateD   s   zEmbeddingQuantizer.annotater/   torch.fx.Graphc                 C  sd   t  }|jD ])}|jdkr/|jtjjjjkr/|j	j
d u r tdt|jd |j	j
id|jd< qd S )NZcall_functionz<Embedding config must have a valid weight quantization spec.r   )Zinput_qspec_mapZquantization_annotation)r
   nodesoptargetr   r   Zatenr   defaultr   weight
ValueErrorr   argsmeta)r   r/   Zembedding_confignoder   r   r   r.   I   s   

z*EmbeddingQuantizer._annotate_embedding_opsc                 C  s   d S r   r   r0   r   r   r   validate\   s   zEmbeddingQuantizer.validatelist[OperatorConfig]c                 C  s   t  gS r   )r
   )r(   r   r   r   r&   _   s   z*EmbeddingQuantizer.get_supported_operators)r   r   )r   r!   )r   r	   r   r*   )r,   r-   r   r-   )r/   r2   r   r   )r,   r-   r   r   )r   r=   )__name__
__module____qualname__r   classmethodr)   r+   r1   r.   r<   r&   __classcell__r   r   r   r   r   +   s    


)r   r   )
__future__r   r   r   Ztorch.nn.functionalr   Z
functionalr   Ztorch.ao.quantization.observerr   Z)torch.ao.quantization.quantizer.quantizerr   r   r   Z7torch.ao.quantization.quantizer.xnnpack_quantizer_utilsr   r   r	   __all__r
   r   r   r   r   r   <module>   s   
