o
    i                     @   sn   d dl mZ d dlZd dlmZ d dlmZ g dZG dd dejZG dd	 d	ejZ	G d
d dejZ
dS )    )AnyN)nn)QConfig)	QuantStubDeQuantStubQuantWrapperc                       B   e Zd ZdZd
dedB f fddZdejdejfdd	Z  Z	S )r   a  Quantize stub module, before calibration, this is same as an observer,
    it will be swapped as `nnq.Quantize` in `convert`.

    Args:
        qconfig: quantization configuration for the tensor,
            if qconfig is not provided, we will get qconfig from parent modules
    Nqconfigc                       t    |r|| _d S d S Nsuper__init__r	   selfr	   	__class__ ]/sda-disk/www/egybert/egybert_env/lib/python3.10/site-packages/torch/ao/quantization/stubs.pyr         

zQuantStub.__init__xreturnc                 C      |S r   r   r   r   r   r   r   forward      zQuantStub.forwardr   )
__name__
__module____qualname____doc__r   r   torchTensorr   __classcell__r   r   r   r   r          r   c                       r   )r   a  Dequantize stub module, before calibration, this is same as identity,
    this will be swapped as `nnq.DeQuantize` in `convert`.

    Args:
        qconfig: quantization configuration for the tensor,
            if qconfig is not provided, we will get qconfig from parent modules
    Nr	   c                    r
   r   r   r   r   r   r   r   &   r   zDeQuantStub.__init__r   r   c                 C   r   r   r   r   r   r   r   r   +   r   zDeQuantStub.forwardr   )
r   r   r   r   r   r   r    r!   r   r"   r   r   r   r   r      r#   r   c                       sZ   e Zd ZU dZeed< eed< ejed< dejf fddZ	de
jde
jfd	d
Z  ZS )r   a  A wrapper class that wraps the input module, adds QuantStub and
    DeQuantStub and surround the call to module with call to quant and dequant
    modules.

    This is used by the `quantization` utility functions to add the quant and
    dequant modules, before `convert` function `QuantStub` will just be observer,
    it observes the input tensor, after `convert`, `QuantStub`
    will be swapped to `nnq.Quantize` which does actual quantization. Similarly
    for `DeQuantStub`.
    quantdequantmodulec                    sR   t    t|dd }| dt| | dt| | d| | |j d S )Nr	   r$   r%   r&   )r   r   getattr
add_moduler   r   traintraining)r   r&   r	   r   r   r   r   ?   s   
zQuantWrapper.__init__Xr   c                 C   s   |  |}| |}| |S r   )r$   r&   r%   )r   r+   r   r   r   r   G   s   


zQuantWrapper.forward)r   r   r   r   r   __annotations__r   r   Moduler   r    r!   r   r"   r   r   r   r   r   /   s   
 
r   )typingr   r    r   torch.ao.quantizationr   __all__r-   r   r   r   r   r   r   r   <module>   s    