
    sh                     z    S SK r S SKJr  S SKJs  Jr  S SKJr  S SKJ	r	J
r
Jr  S/r " S S\R                  5      rg)    N)
LinearReLU)is_parametrized$transfer_parametrizations_and_paramstype_before_parametrizationsLinearc                   v   ^  \ rS rSrSr\R                  r    S S	U 4S jjjrS r	\
S
S j5       rS rSrU =r$ )r      av  
A linear module attached with FakeQuantize modules for weight,
used for quantization aware training.

We adopt the same interface as `torch.nn.Linear`, please see
https://pytorch.org/docs/stable/nn.html#torch.nn.Linear
for documentation.

Similar to `torch.nn.Linear`, with FakeQuantize modules initialized to
default.

Attributes:
    weight: fake quant module for weight
c                    > XVS.n[         TU ]  " XU40 UD6  U(       d   S5       eX@l        UR                  US9U l        g )N)devicedtypez'qconfig must be provided for QAT module)factory_kwargs)super__init__qconfigweightweight_fake_quant)	selfin_featuresout_featuresbiasr   r   r   r   	__class__s	           r/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/torch/ao/nn/qat/modules/linear.pyr   Linear.__init__!   sG     %+;DKNKAAAw!(~!N    c                 v    [         R                  " XR                  U R                  5      U R                  5      $ N)Flinearr   r   r   )r   inputs     r   forwardLinear.forward0   s&    xx55dkkBDIINNr   c                 L   [        U5      U R                  :X  d.   SU R                  -   S-   U R                  R                  -   5       e[        US5      (       d   S5       eUR                  (       d   S5       e[        U5      [
        :X  a  US   nUR                  nU " UR                  UR                  UR                  SLUS9n[        US	5      (       a  [        XS	5        OUR                  Ul        [        US
5      (       a  [        XS
5        U$ UR                  Ul        U$ )zCreate a qat module from a float module or qparams_dict
Args: `mod` a float module, either produced by torch.ao.quantization utilities
or directly from user
z qat.z.from_float only works for r   z,Input float module must have qconfig definedz,Input float module must have a valid qconfigr   N)r   r   r   r   )r   _FLOAT_MODULE__name__hasattrr   r   r   r   r   r   r   r   )clsmoduse_precomputed_fake_quantr   
qat_linears        r   
from_floatLinear.from_float3   s    ,C0C4E4EE 	
ll+, (()	
E sI&&V(VV&{{JJJ{',
:a&C++OO%	

 3))0(K #

J3''0&I  "hhJOr   c                    [         R                  R                  U R                  U R                  U R
                  S L5      n[         R                  R                  U R                  R                  5       5      Ul        U R
                  b<  [         R                  R                  U R
                  R                  5       5      Ul        UR                  U R                  5        U$ r   )torchnnr   r   r   r   	Parameterr   detachtraintraining)r   r   s     r   to_floatLinear.to_floatX   s    d//$1F
 **4;;+=+=+?@99 ((,,TYY-=-=-?@FKT]]#r   )r   r   )TNNN)returnN)F)r$   
__module____qualname____firstlineno____doc__r.   r   r#   r   r    classmethodr*   r3   __static_attributes____classcell__)r   s   @r   r   r      s]     IIM O 
O OO " "H r   )r-   torch.nnr.   torch.nn.functional
functionalr   torch.ao.nn.intrinsicr   torch.nn.utils.parametrizer   r   r   __all__r    r   r   <module>rD      s9        ,  *PRYY Pr   