
    |Yh                         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ej                  Z	 G d d	ej                  Z
 G d
 dej                  ZdS )    )AnyOptionalN)nn)QConfig)	QuantStubDeQuantStubQuantWrapperc                   Z     e Zd ZdZddee         f fdZdej        dej        fdZ	 x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__s     m/var/www/tools.fuzzalab.pt/emblema-extractor/venv/lib/python3.11/site-packages/torch/ao/quantization/stubs.pyr   zQuantStub.__init__   6     	#"DLLL	# 	#    xreturnc                     |S r    r   r   s     r   forwardzQuantStub.forward       r   r   )__name__
__module____qualname____doc__r   r   r   torchTensorr   __classcell__r   s   @r   r   r      s~         # # 1 # # # # # #
 %,        r   r   c                   Z     e Zd ZdZddee         f fdZdej        dej        fdZ	 x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                 ^    t                                                       |r	|| _        d S d S r   r   r   s     r   r   zDeQuantStub.__init__&   r   r   r   r   c                     |S r   r   r   s     r   r   zDeQuantStub.forward+   r   r   r   )r   r   r    r!   r   r   r   r"   r#   r   r$   r%   s   @r   r   r      s}         # # # # # # # #
 %,        r   r   c                        e Zd ZU dZeed<   eed<   ej        ed<   dej        f fdZ	de
j        de
j        fdZ x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                 V   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   s      r   r   zQuantWrapper.__init__?   s    &)T227!3!3444	;w#7#7888&)))

6?#####r   Xr   c                     |                      |          }|                     |          }|                     |          S r   )r*   r,   r+   )r   r2   s     r   r   zQuantWrapper.forwardG   s0    JJqMMKKNN||Ar   )r   r   r    r!   r   __annotations__r   r   Moduler   r"   r#   r   r$   r%   s   @r   r	   r	   /   s         	 	 I$ry $ $ $ $ $ $ %,        r   r	   )typingr   r   r"   r   torch.ao.quantizationr   __all__r5   r   r   r	   r   r   r   <module>r9      s                           ) ) ) ) ) ) 7
6
6    	   $    ")   $    29     r   