a
    ÞñhŠ  ã                D   @   sÊ  d dl Z d dl mZ d dlm  mZ d dlm  mZ d dlm  m  m	Z
 d dlm  m  mZ d dlm  m	Z d dlm  m	  mZ d dlm  mZ ddlmZmZ ejejejejejejejejejejejejejejejejej ej ej!ej!ej"ej"ej#ej#ej$ej$ej%ej%ej&ej&ej'ej'ej(ej(ej)ej)ej*ej*eej+eej,ej-ej.ej/e
j/ej0e
j0ej1e
j1ej2e
j2ej3e
j3ej4e
j4ej0e
j0ej2e
j2ej5ejej6e
j0ejejejeji"Z7ejejejejej5ej5ej6ej6ej0ej0ej2ej2iZ8ejejej9ej9ej:ej:ej;ej;ej<ej<iZ=ehZ>ej?hZ@ejAe jBjCj	jAejDe jBjCj	jDejEe jBjCj	jEejFe jBjCj	jFiZGdd„ ZHdd„ ZId	d
„ ZJdd„ ZKdd„ ZLdd„ ZMdd„ ZNdd„ ZOdd„ ZPdd„ ZQdd„ ZRdS )é    N)Únné   )Ú	QuantStubÚDeQuantStubc                 C   s   t |dƒsJ dƒ‚|t| < dS )aG   Register a mapping from `float_source__module_class` to `static_quant_target_module_class`
    `static_quant_target_module_class` must have from_float defined as a class method
    The mapping is used in the convert step of post training static quantization to
    convert a float module to a statically quantized module.
    Ú
from_floatz4from_float must be defined in quantized module classN)ÚhasattrÚSTATIC_QUANT_MODULE_MAPPINGS)Úfloat_source_module_classZ static_quant_target_module_class© r
   úh/home/yuhw/wc/uboone-dl-vtx/venv/lib/python3.9/site-packages/torch/quantization/quantization_mappings.pyÚ$register_static_quant_module_mapping[   s    r   c                   C   s   t S )z> Get module mapping for post training static quantization
    )r   r
   r
   r
   r   Ú get_static_quant_module_mappingsf   s    r   c                 C   s*   t  | d¡}|dus&J d | ¡d ƒ‚|S )zd Get the statically quantized module class corresponding to
    the floating point module class
    NzFloating point module class {}z5 does not have a corresponding quantized module class)r   ÚgetÚformat)Zfloat_module_classZstatic_quant_module_classr
   r
   r   Úget_static_quant_module_classk   s    
ÿÿr   c                 C   s   t |dƒsJ dƒ‚|t| < dS )a  Register a mapping from `float_source_module_class` to `qat_target_module_class`,
    `qat_target_module_class` must have from_float defined as a class method
    This mapping is used in prepare step of quantization aware training to swap
    a float module to a qat module.
    r   z.from_float must be defined in qat module classN)r   ÚQAT_MODULE_MAPPINGS)r	   Zqat_target_module_classr
   r
   r   Úregister_qat_module_mappingu   s    r   c                   C   s   t S )z8 Get module mapping for quantization aware training
    )r   r
   r
   r
   r   Úget_qat_module_mappings   s    r   c                 C   s   t |dƒsJ dƒ‚|t| < dS )aI   Register a mapping from `float_source_module_class` to `dynamic_quant_target_module_class`,
    `dynamic_quant_target_module_class` must have from_float defined as a class method
    This mapping is used in convert step of post training dynamic
    quantization to swap a float module to a dynamically quantized
    module.
    r   z?from_float must be defined in dynamically quantized module typeN)r   ÚDYNAMIC_QUANT_MODULE_MAPPINGS)r	   Z!dynamic_quant_target_module_classr
   r
   r   Ú#register_dynamic_quant_module_class„   s    r   c                   C   s   t S )z? Get module mapping for post training dynamic quantization
    )r   r
   r
   r
   r   Ú!get_dynamic_quant_module_mappings�   s    r   c                  C   s0   t t ¡ ƒt t ¡ ƒB t t ¡ ƒB tB t } | S )zX Get the list of module types that we'll attach qconfig
    attribute to in prepare
    )Úsetr   Úkeysr   r   Ú_INCLUDE_QCONFIG_PROPAGATE_LISTÚ_EXCLUDE_QCONFIG_PROPAGATE_LIST)Z#QCONFIG_PROPAGATE_MODULE_CLASS_LISTr
   r
   r   Úget_qconfig_propagation_list”   s    

ÿ
þýüÿr   c                  C   sT   t t ¡ ƒt t ¡ ƒB t t ¡ ƒB t t ¡ ƒB t t ¡ ƒB t t ¡ ƒB tB t } | S )zT Get list of module class types that we will record output
    in numeric suite
    )r   r   Úvaluesr   r   r   r   r   )Z.NUMERIC_SUITE_COMPARE_MODEL_OUTPUT_MODULE_LISTr
   r
   r   Úget_compare_output_module_list¡   s     

ÿ
þ
ý
ü
ûúø	r   c                 C   s   |t | < dS )zÉ Register a mapping from `floating_point_op` (torch or functional) to `quantized_op`
    This is used in convert step of fx based graph mode quantization
    to convert a float op to quantized op.
    N)Ú$FLOAT_TO_QUANTIZED_OPERATOR_MAPPINGS©Zfloat_opZquantized_opr
   r
   r   Ú#register_quantized_operator_mapping°   s    r    c                 C   s&   t  | d¡}|dus"J d | ¡ƒ‚|S )zD Get the quantized operator corresponding to the float operator
    Nz4Operator {} does not have corresponding quantized op)r   r   r   r   r
   r
   r   Úget_quantized_operator·   s
    
ÿr!   )SZtorchr   Ztorch.nn.functionalZ
functionalÚFZtorch.nn.intrinsicZ	intrinsicZnniZtorch.nn.intrinsic.quantizedZ	quantizedZnniqZtorch.nn.intrinsic.qatZqatZnniqatZtorch.nn.quantizedZnnqZtorch.nn.quantized.dynamicZdynamicZnnqdZtorch.nn.qatZnnqatZstubsr   r   ZLinearZReLUZReLU6Z	HardswishZELUZConv1dZConv2dZConv3dZConvTranspose1dZConvTranspose2dZBatchNorm2dZBatchNorm3dZ	LayerNormZ	GroupNormZInstanceNorm1dZInstanceNorm2dZInstanceNorm3dZ	EmbeddingZEmbeddingBagZQuantizeZ
DeQuantizeZFloatFunctionalZQFunctionalZ
ConvReLU1dZ
ConvReLU2dZ
ConvReLU3dZ
LinearReLUZBNReLU2dZBNReLU3dZConvBn2dZConvBnReLU2dr   r   ZLSTMZLSTMCellZRNNCellZGRUCellr   r   Z
Sequentialr   ZeluZ_opsÚopsZ	hardswishZinstance_normZ
layer_normr   r   r   r   r   r   r   r   r   r   r    r!   r
   r
   r
   r   Ú<module>   sš   Û*ùû
ÿÿü

