U
    ©Ê¹jZ  ã                   @   s|  d dl mZmZ d dlmZmZ d dlmZmZm	Z	m
Z
mZmZ d dlZd dlmZ d dlmZ d dlmZ d dlmZ d	d
ddddddgZejejejejejgZejejejejej gZ!G dd
„ d
eƒZ"eddd�G dd„ de"ƒƒZ#eddd�G dd„ de"ƒƒZ$eeeef ef Z%de%_&eddd�G dd„ de"ƒƒZ'eddd�G dd„ de"ƒƒZ(eG dd„ dƒƒZ)G dd	„ d	eƒZ*dS )é    )ÚABCÚabstractmethod)Ú	dataclassÚfield)ÚCallableÚDictÚListÚOptionalÚTupleÚUnionN)ÚTensor)ÚObserverOrFakeQuantize)Ú"_ObserverOrFakeQuantizeConstructor)ÚNodeÚ	QuantizerÚQuantizationSpecBaseÚQuantizationSpecÚFixedQParamsQuantizationSpecÚ
EdgeOrNodeÚSharedQuantizationSpecÚDerivedQuantizationSpecÚQuantizationAnnotationc                   @   s   e Zd ZdZdS )r   z™Base class for different types of quantization specs that allows users to
    specify how to quantize a Tensor (input/output of a Node) in the model
    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   úh/var/www/html/bwave/python/venv/lib/python3.8/site-packages/torch/ao/quantization/quantizer/quantizer.pyr   !   s   T)ÚeqÚfrozenc                   @   sz   e Zd ZU dZejed< eed< dZe	e
 ed< dZe	e
 ed< dZe	ej ed< dZe	e
 ed< d	Zeed
< dd„ ZdS )r   z”Quantization spec for common operators that allows user to specify how to
    quantize a Tensor, this includes dtype, quant_min, quant_max etc.
    ÚdtypeZobserver_or_fake_quant_ctrNÚ	quant_minÚ	quant_maxÚqschemeÚch_axisFÚ
is_dynamicc                 C   sœ   | j tkrtd| j › d�ƒ‚| jd k	rV| jd k	rV| j| jkrVtd| j› d| j› d�ƒ‚| jd k	r|| jtkr|td| j› d�ƒ‚| jd k	r˜| jdk r˜tdƒ‚d S )NzUnsupported dtype Ú.z
quant_min z must be <= quant_max zUnsupported qscheme r   zCh_axis is < 0.)	r    ÚSUPPORTED_DTYPESÚ	TypeErrorr!   r"   Ú
ValueErrorr#   ÚSUPPORTED_QSCHEMESr$   )Úselfr   r   r   Ú__post_init__;   s    
ÿþ
ýÿzQuantizationSpec.__post_init__)r   r   r   r   Útorchr    Ú__annotations__r   r!   r	   Úintr"   r#   r$   r%   Úboolr,   r   r   r   r   r   )   s   

c                   @   sZ   e Zd ZU ejed< eed< eed< dZe	e ed< dZ
e	e ed< dZe	ej ed< dS )r   r    ÚscaleZ
zero_pointNr!   r"   r#   )r   r   r   r-   r    r.   Úfloatr/   r!   r	   r"   r#   r   r   r   r   r   T   s   

z)torch.ao.quantization.quantizer.quantizerc                   @   s   e Zd ZU dZeed< dS )r   zg
    Quantization spec for the Tensors whose quantization parameters are shared with other Tensors
    Zedge_or_nodeN)r   r   r   r   r   r.   r   r   r   r   r   h   s   
c                   @   sˆ   e Zd ZU dZee ed< eee ge	e
e
f f ed< ejed< dZee ed< dZee ed< dZeej ed< dZee ed	< dS )
r   z^Quantization spec for the Tensors whose quantization parameters are derived from other TensorsZderived_fromZderive_qparams_fnr    Nr!   r"   r#   r$   )r   r   r   r   r   r   r.   r   r   r
   r   r-   r    r!   r	   r/   r"   r#   r$   r   r   r   r   r   q   s   

c                   @   sH   e Zd ZU dZeed�Zeee	f e
d< dZee	 e
d< dZee
d< dS )r   zÂHow are input arguemnt or output should be quantized,
    expressed as QuantizationSpec, this corresponds to how a Tensor in the
    operator Graph is observed (PTQ) or fake quantized (QAT)
    )Údefault_factoryÚinput_qspec_mapNÚoutput_qspecFÚ
_annotated)r   r   r   r   r   Údictr4   r   r   r   r.   r5   r	   r6   r0   r   r   r   r   r   ~   s   
c                   @   s@   e Zd Zeejjejjdœdd„ƒZeejjddœdd„ƒZdS )r   )ÚmodelÚreturnc                 C   s   d S ©Nr   ©r+   r8   r   r   r   Úannotate“   s    zQuantizer.annotateNc                 C   s   d S r:   r   r;   r   r   r   Úvalidate˜   s    zQuantizer.validate)	r   r   r   r   r-   ZfxZGraphModuler<   r=   r   r   r   r   r   �   s   )+Úabcr   r   Údataclassesr   r   Útypingr   r   r   r	   r
   r   r-   r   Ztorch.ao.quantizationr   Ztorch.ao.quantization.qconfigr   Ztorch.fxr   Ú__all__Zuint8Zint8Zint32Zfloat16Zfloat32r'   Zper_tensor_affineZper_tensor_symmetricZper_channel_affineZper_channel_symmetricZ per_channel_affine_float_qparamsr*   r   r   r   r   r   r   r   r   r   r   r   r   r   Ú<module>   sJ    øû	
*


