U
    ,-eZ                     @   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   zBase 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   j/var/www/html/Darija-Ai-Train/env/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   zQuantization 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 rt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   zHow 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    	
*


