Ë
    ÄÓ^j�  ã                   óz   — d dl Z d dlmZ d dlmc mZ d dlmZ d dlm	Z	m
Z
mZ dgZ G d„ dej                  «      Zy)é    N)Ú
LinearReLU)Úis_parametrizedÚ$transfer_parametrizations_and_paramsÚtype_before_parametrizationsÚLinearc                   óf   ‡ — e Zd ZdZej
                  Z	 	 	 	 d	 dˆ fd„Zd„ Ze	dd„«       Z
d„ Zˆ xZS )	r   až  
    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                 óŠ   •— ||dœ}t        ‰| �  |||fi |¤Ž |st        d«      ‚|| _        |j	                  |¬«      | _        y )N)ÚdeviceÚdtypez'qconfig must be provided for QAT module)Úfactory_kwargs)ÚsuperÚ__init__ÚAssertionErrorÚqconfigÚweightÚweight_fake_quant)	ÚselfÚin_featuresÚout_featuresÚbiasr   r
   r   r   Ú	__class__s	           €úi/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/torch/ao/nn/qat/modules/linear.pyr   zLinear.__init__"   sN   ø€ ð %+°UÑ;ˆÜ‰Ñ˜ l°DÑK¸NÒKÙÜ Ð!JÓKÐKØˆŒØ!(§¡¸~ Ó!NˆÕó    c                 óv   — t        j                  || j                  | j                  «      | j                  «      S ©N)ÚFÚlinearr   r   r   )r   Úinputs     r   ÚforwardzLinear.forward2   s(   € Ü�x‰x˜˜t×5Ñ5°d·k±kÓBÀDÇIÁIÓNÐNr   c           
      óh  — t        |«      | j                  k7  rEt        d| j                  › d| j                  j                  › dt        |«      j                  › �«      ‚t	        |d«      st        d«      ‚|j
                  st        d«      ‚t        |«      t        k(  r|d   }|j
                  } | |j                  |j                  |j                  du|¬	«      }t        |d
«      rt        ||d
«       n|j                  |_        t        |d«      rt        ||d«       |S |j                  |_	        |S )zµCreate 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 z, got r   z,Input float module must have qconfig definedz,Input float module must have a valid qconfigr   N)r   r   r   r   )r   Ú_FLOAT_MODULEr   Ú__name__Úhasattrr   r   r   r   r   r   r   r   )ÚclsÚmodÚuse_precomputed_fake_quantr   Ú
qat_linears        r   Ú
from_floatzLinear.from_float5   s&  € ô (¨Ó,°×0AÑ0AÒAÜ Ø�s—|‘|�nÐ$?Ø×$Ñ$×-Ñ-Ð.¨fÔ5QÐRUÓ5V×5_Ñ5_Ð4`ðbóð ô �s˜IÔ&Ü Ð!OÓPÐPØ�{Š{Ü Ð!OÓPÐPÜ'¨Ó,´
Ò:Ø�a‘&ˆCà—+‘+ˆÙØ�O‰OØ×ÑØ—‘ Ð%Øô	
ˆ
ô ˜3 Ô)Ü0°°jÀ(ÕKà #§
¡
ˆJÔä˜3 Ô'Ü0°°jÀ&ÔIð Ðð "Ÿh™hˆJŒOàÐr   c                 óÆ  — t         j                  j                  | j                  | j                  | j
                  d u«      }t         j                  j                  | j                  j                  «       «      |_        | j
                  �<t         j                  j                  | j
                  j                  «       «      |_        |j                  | j                  «       |S r   )ÚtorchÚnnr   r   r   r   Ú	Parameterr   ÚdetachÚtrainÚtraining)r   r   s     r   Úto_floatzLinear.to_float[   s—   € Ü—‘—‘Ø×Ñ˜d×/Ñ/°·±À$Ð1Fó
ˆô Ÿ™×*Ñ*¨4¯;©;×+=Ñ+=Ó+?Ó@ˆŒØ�9‰9Ð ÜŸ(™(×,Ñ,¨T¯Y©Y×-=Ñ-=Ó-?Ó@ˆFŒKØ�‰�T—]‘]Ô#Øˆr   )TNNN)ÚreturnN)F)r"   Ú
__module__Ú__qualname__Ú__doc__r+   r   r!   r   r   Úclassmethodr(   r0   Ú__classcell__)r   s   @r   r   r      sR   ø„ ñð —I‘I€Mð ØØØðOð 
õOò Oð ò#ó ð#öJr   )r*   Útorch.nnr+   Útorch.nn.functionalÚ
functionalr   Útorch.ao.nn.intrinsicr   Útorch.nn.utils.parametrizer   r   r   Ú__all__r   © r   r   ú<module>r>      s9   ðã Ý ß Ð Ý ,÷ñ ð ˆ*€ôSˆR�Y‰Yõ Sr   