
    sg                         d dl mZ  G d dej                        Z G d dej                        Z G d dej                        Zy)	    )nnc                   *     e Zd ZdZd fd	Zd Z x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
    c                 6    t         |           |r|| _        y y Nsuper__init__qconfigselfr   	__class__s     N/var/www/html/venv/lib/python3.12/site-packages/torch/ao/quantization/stubs.pyr
   zQuantStub.__init__       "DL     c                     |S r    r   xs     r   forwardzQuantStub.forward       r   r   __name__
__module____qualname____doc__r
   r   __classcell__r   s   @r   r   r          #
r   r   c                   *     e Zd ZdZd fd	Zd Z x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
    c                 6    t         |           |r|| _        y y r   r   r   s     r   r
   zDeQuantStub.__init__!   r   r   c                     |S r   r   r   s     r   r   zDeQuantStub.forward&   r   r   r   r   r   s   @r   r!   r!      r   r   r!   c                   \     e Zd ZU dZeed<   eed<   ej                  ed<    fdZ	d Z
 x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                    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__9   s`    &)T27!34	;w#78&)

6??#r   c                 h    | j                  |      }| j                  |      }| j                  |      S r   )r&   r(   r'   )r   Xs     r   r   zQuantWrapper.forwardA   s*    JJqMKKN||Ar   )r   r   r   r   r   __annotations__r!   r   Moduler
   r   r   r   s   @r   r%   r%   *   s*    	 II$r   r%   N)torchr   r1   r   r!   r%   r   r   r   <module>r3      s:    		 $")) $299 r   