U
    yh                     @   sF   d dl mZ G dd dejZG dd dejZG dd dejZdS )	    )nnc                       s*   e Zd ZdZd fdd	Zdd Z  ZS )	QuantStuba  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
    Nc                    s   t    |r|| _d S Nsuper__init__qconfigselfr   	__class__ M/var/www/html/venv/lib/python3.8/site-packages/torch/ao/quantization/stubs.pyr      s    
zQuantStub.__init__c                 C   s   |S r   r   r
   xr   r   r   forward   s    zQuantStub.forward)N__name__
__module____qualname____doc__r   r   __classcell__r   r   r   r   r      s   r   c                       s*   e Zd ZdZd fdd	Zdd Z  ZS )DeQuantStuba  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
    Nc                    s   t    |r|| _d S r   r   r	   r   r   r   r      s    
zDeQuantStub.__init__c                 C   s   |S r   r   r   r   r   r   r   #   s    zDeQuantStub.forward)Nr   r   r   r   r   r      s   r   c                       sD   e Zd ZU dZeed< eed< ejed<  fddZ	dd Z
  ZS )	QuantWrappera  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   getattrZ
add_moduler   r   trainZtraining)r
   r   r   r   r   r   r   6   s    
zQuantWrapper.__init__c                 C   s   |  |}| |}| |S r   )r   r   r   )r
   Xr   r   r   r   >   s    

zQuantWrapper.forward)r   r   r   r   r   __annotations__r   r   Moduler   r   r   r   r   r   r   r   '   s   


r   N)Ztorchr   r!   r   r   r   r   r   r   r   <module>   s   