Ë
    g^(hê  ã                   ó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J d«       ‚|| _        |j                  |¬«      | _        y )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	           €ú\/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/torch/ao/nn/qat/modules/linear.pyr   zLinear.__init__!   sM   ø€ ð %+°UÑ;ˆÜ‰Ñ˜ l°DÑK¸NÒKÙÐAÐAÓAˆwØˆŒØ!(§¡¸~ Ó!NˆÕó    c                 óv   — t        j                  || j                  | j                  «      | j                  «      S ©N)ÚFÚlinearr   r   r   )r   Úinputs     r   ÚforwardzLinear.forward0   s(   € Ü�x‰x˜˜t×5Ñ5°d·k±kÓBÀDÇIÁIÓNÐNr   c                 ó*  — t        |«      | j                  k(  s.J d| j                  z   dz   | j                  j                  z   «       ‚t        |d«      sJ d«       ‚|j                  sJ 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 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_floatzLinear.from_float3   s  € ô ,¨CÓ0°C×4EÑ4EÒEð 	
ØØ�l‰lñà+ñ,ð ×Ñ×(Ñ(ñ)ó	
ÐEô �s˜IÔ&ÐVÐ(VÓVÐ&Ø�{Š{ÐJÐJÓJˆ{Ü'¨Ó,´
Ò:Ø�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_floatX   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'   r/   Ú__classcell__)r   s   @r   r   r      sR   ø„ ñð —I‘I€Mð ØØØð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>r=      s9   ðã Ý ß Ð Ý ,÷ñ ð ˆ*€ôPˆR�Y‰Yõ Pr   