U
    Kºc`  ã                   @   s~   d dl mZ d dlm  mZ d dlmZ ddlmZ d dl	m
Z
mZmZ ddgZG dd„ dejeƒZG d	d„ dejeƒZdS )
é    N)ÚTensoré   )ÚReferenceQuantizedModule)ÚOptionalÚDictÚAnyÚ	EmbeddingÚEmbeddingBagc                       sv   e Zd ZdZdeeee ee eeeee ee	e
ef  ddœ
‡ fdd„Zdd	„ Zeed
œdd„Zedd„ ƒZ‡  ZS )r   aR   A reference quantized Embedding module that fits into the
    FX Graph Mode Quantization workflow, activation will be floating point Tensor,
    we will store floating point weight as well in the module, but in forward we'll
    quantize and dequantize the weight before running the floating point functional
    embedding operator.
    Nç       @F)
Únum_embeddingsÚembedding_dimÚpadding_idxÚmax_normÚ	norm_typeÚscale_grad_by_freqÚsparseÚ_weightÚweight_qparamsÚreturnc                    s.   t ƒ  |||||||||	|
¡
 |  ||	¡ d S ©N©ÚsuperÚ__init__Z_init_weight_qparams)Úselfr   r   r   r   r   r   r   r   ÚdeviceÚdtyper   ©Ú	__class__© úR/tmp/pip-unpacked-wheel-gikjz4vx/torch/ao/nn/quantized/reference/modules/sparse.pyr      s         ÿzEmbedding.__init__c                 C   s   dS ©NzQuantizedEmbedding(Reference)r   ©r   r   r   r   Ú	_get_name   s    zEmbedding._get_name)Úinputr   c              	   C   s(   |   ¡ }t ||| j| j| j| j| j¡S r   )Ú
get_weightÚFZ	embeddingr   r   r   r   r   )r   r#   Úweight_quant_dequantr   r   r   Úforward   s         þzEmbedding.forwardc                 C   s4   | |j |j|j|j|j|j|j|j|jj|jj	|ƒS r   )
r   r   r   r   r   r   r   Úweightr   r   ©ÚclsÚmodr   r   r   r   Ú
from_float"   s    õzEmbedding.from_float)	NNr
   FFNNNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úintr   ÚfloatÚboolr   r   Ústrr   r   r"   r'   Úclassmethodr,   Ú__classcell__r   r   r   r   r   	   s.                ü    ü	c                       sˆ   e Zd ZdZdeeee eeeeee	 eee ee
eef  ddœ‡ fdd„Zd	d
„ Zde	ee	 ee	 e	dœdd„Zedd„ ƒZ‡  ZS )r	   aU   A reference quantized EmbeddingBag module that fits into the
    FX Graph Mode Quantization workflow, activation will be floating point Tensor,
    we will store floating point weight as well in the module, but in forward we'll
    quantize and dequantize the weight before running the floating point functional
    embedding operator.
    Nr
   FÚmean)r   r   r   r   r   Úmoder   r   Úinclude_last_offsetr   r   r   c                    s2   t ƒ  |||||||||	|
||¡ |  ||¡ d S r   r   )r   r   r   r   r   r   r8   r   r   r9   r   r   r   r   r   r   r   r   8   s          þzEmbeddingBag.__init__c                 C   s   dS r    r   r!   r   r   r   r"   C   s    zEmbeddingBag._get_name)r#   ÚoffsetsÚper_sample_weightsr   c                 C   s4   |   ¡ }t |||| j| j| j| j| j|| j| j	¡S r   )
r$   r%   Zembedding_bagr   r   r   r8   r   r9   r   )r   r#   r:   r;   r&   r   r   r   r'   F   s    
    üzEmbeddingBag.forwardc                 C   s<   | |j |j|j|j|j|j|j|j|j|j	|jj
|jj|ƒS r   )r   r   r   r   r   r8   r   r(   r9   r   r   r   r)   r   r   r   r,   N   s    ózEmbeddingBag.from_float)Nr
   Fr7   FNFNNNN)NN)r-   r.   r/   r0   r1   r   r2   r3   r4   r   r   r   r   r"   r'   r5   r,   r6   r   r   r   r   r	   1   s8                    û      û)Ztorch.nnÚnnZtorch.nn.functionalZ
functionalr%   Ztorchr   Úutilsr   Útypingr   r   r   Ú__all__r   r	   r   r   r   r   Ú<module>   s   (