
    i                         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ej                        Z G d d	ej                        Z	 G d
 dej                        Z
y)    )AnyN)nn)QConfig)	QuantStubDeQuantStubQuantWrapperc                   h     e Zd ZdZddedz  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                 6    t         |           |r|| _        y y Nsuper__init__r
   selfr
   	__class__s     U/var/www/html/engine/venv/lib/python3.12/site-packages/torch/ao/quantization/stubs.pyr   zQuantStub.__init__       "DL     xreturnc                     |S r    r   r   s     r   forwardzQuantStub.forward       r   r   )
__name__
__module____qualname____doc__r   r   torchTensorr   __classcell__r   s   @r   r   r      s3    #$ #
 %,, r   r   c                   h     e Zd ZdZddedz  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                 6    t         |           |r|| _        y y 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$   s   @r   r   r      s3    #d
 #
 %,, 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                    t         |           t        |dd       }| j                  dt	        |             | j                  dt        |             | j                  d|       | j                  |j                         y )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7!34	;w#78&)

6??#r   Xr   c                 h    | j                  |      }| j                  |      }| j                  |      S r   )r)   r+   r*   )r   r1   s     r   r   zQuantWrapper.forwardG   s*    JJqMKKN||Ar   )r   r   r   r    r   __annotations__r   r   Moduler   r!   r"   r   r#   r$   s   @r   r   r   /   sK    	 II$ryy $ %,, r   r   )typingr   r!   r   torch.ao.quantizationr   __all__r4   r   r   r   r   r   r   <module>r8      sH       ) 7		 $")) $299 r   