o
    hZ                     @   sr  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 g d	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   _/var/www/html/ai/venv/lib/python3.10/site-packages/torch/ao/quantization/quantizer/quantizer.pyr   !   s    r   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.
    dtypeobserver_or_fake_quant_ctrN	quant_min	quant_maxqschemech_axisF
is_dynamicc                 C   s   | j tvrtd| j  d| jd ur+| jd ur+| j| jkr+td| j d| j d| jd ur>| jtvr>td| j d| jd urL| jdk rNtdd S 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   
 
r   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    scale
zero_pointNr"   r#   r$   )r   r   r   r.   r    r/   floatr0   r"   r	   r#   r$   r   r   r   r   r   T   s   
 
r   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
    edge_or_nodeN)r   r   r   r   r   r/   r   r   r   r   r   h   s   
 r   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 Tensorsderived_fromderive_qparams_fnr    Nr"   r#   r$   r%   )r   r   r   r   r   r   r/   r   r   r
   r   r.   r    r"   r	   r0   r#   r$   r%   r   r   r   r   r   q   s   
 
r   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   dictr9   r   r   r   r/   r:   r	   r;   r1   r   r   r   r   r   ~   s
   
 r   c                   @   sD   e Zd ZedejjdejjfddZedejjddfddZdS )r   modelreturnc                 C      d S Nr   r,   r=   r   r   r   annotate      zQuantizer.annotateNc                 C   r?   r@   r   rA   r   r   r   validate   rC   zQuantizer.validate)	r   r   r   r   r.   fxGraphModulerB   rD   r   r   r   r   r      s
    r   )+abcr   r   dataclassesr   r   typingr   r   r   r	   r
   r   r.   r   torch.ao.quantizationr   torch.ao.quantization.qconfigr   torch.fxr   __all__uint8int8int32float16float32r(   per_tensor_affineper_tensor_symmetricper_channel_affineper_channel_symmetric per_channel_affine_float_qparamsr+   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s>     	

*	

