a
    ‘º”hú  ã                   @   sr   d dl mZ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 )é    )ÚAnyÚOptionalN)Únn)ÚQConfig)Ú	QuantStubÚDeQuantStubÚQuantWrapperc                       s@   e Zd ZdZd	ee dœ‡ fdd„Zejejdœ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                    s   t ƒ  ¡  |r|| _d S ©N©ÚsuperÚ__init__r
   ©Úselfr
   ©Ú	__class__© úI/var/www/auris/lib/python3.9/site-packages/torch/ao/quantization/stubs.pyr      s    
zQuantStub.__init__©ÚxÚreturnc                 C   s   |S r   r   ©r   r   r   r   r   Úforward   s    zQuantStub.forward)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   ÚtorchÚTensorr   Ú__classcell__r   r   r   r   r      s   r   c                       s@   e Zd ZdZd	ee dœ‡ fdd„Zejejdœdd„Z	‡  Z
S )
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                    s   t ƒ  ¡  |r|| _d S r   r   r   r   r   r   r   &   s    
zDeQuantStub.__init__r   c                 C   s   |S r   r   r   r   r   r   r   +   s    zDeQuantStub.forward)N)r   r   r   r   r   r   r   r   r   r   r    r   r   r   r   r      s   r   c                       sX   e Zd ZU dZeed< eed< ejed< ejdœ‡ fdd„Z	e
je
jdœ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Úmodule)r#   c                    sR   t ƒ  ¡  t|dd ƒ}|  dt|ƒ¡ |  dt|ƒ¡ |  d|¡ |  |j¡ d S )Nr
   r!   r"   r#   )r   r   ÚgetattrZ
add_moduler   r   ZtrainZ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   r   Ztorch.ao.quantizationr   Ú__all__r'   r   r   r   r   r   r   r   Ú<module>   s   