ó
    Eñis.  ã                   ó8  • S SK Jr  S SKr/ SQr " S S\R                  R
                  5      r " S S\R                  R                  5      r " S S	\R                  R                  5      r " S
 S\R                  R                  5      r	 " S S\R                  R                  5      r
 " S S\R                  R                  5      r " S S\R                  R                  R                  R                  5      r " S S\R                  R                  5      rg)é    )ÚwarnN)ÚReLU6Ú	HardswishÚELUÚ	LeakyReLUÚSigmoidÚSoftmaxÚMultiheadAttentionÚPReLUc                   óP   ^ • \ rS rSrSrSU 4S jjrS rS r\SS j5       r	Sr
U =r$ )	r   é   a¢  Applies the element-wise function:

:math:`\text{ReLU6}(x) = \min(\max(x_0, x), q(6))`, where :math:`x_0` is the
zero_point, and :math:`q(6)` is the quantized representation of number 6.

Args:
    inplace: can optionally do the operation in-place. Default: ``False``

Shape:
    - Input: :math:`(N, *)` where `*` means, any number of additional
      dimensions
    - Output: :math:`(N, *)`, same shape as the input

.. image:: ../scripts/activation_images/ReLU6.png

Examples::

    >>> m = nn.quantized.ReLU6()
    >>> input = torch.randn(2)
    >>> # xdoctest: +SKIP
    >>> input = torch.quantize_per_tensor(input, 1.0, 0, dtype=torch.qint32)
    >>> output = m(input)
c                 ó0   >• [         TU ]  U5        Xl        g ©N)ÚsuperÚ__init__Úinplace)Úselfr   Ú	__class__s     €Úe/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torch/ao/nn/quantized/modules/activation.pyr   ÚReLU6.__init__,   s   ø€ Ü‰Ñ˜Ô!Ø�ó    c                 óh   • [         R                  R                  R                  XR                  5      $ r   )ÚtorchÚopsÚ	quantizedÚrelu6r   ©r   Úinputs     r   ÚforwardÚReLU6.forward0   s!   € Ü�y‰y×"Ñ"×(Ñ(¨·±Ó=Ð=r   c                 ó   • g)NÚQuantizedReLU6© ©r   s    r   Ú	_get_nameÚReLU6._get_name3   ó   € Ør   c                 ó,   • [        U R                  5      $ r   )r   r   )ÚmodÚuse_precomputed_fake_quants     r   Ú
from_floatÚReLU6.from_float6   s   € ä�S—[‘[Ó!Ð!r   )r   ©F)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r%   Ústaticmethodr+   Ú__static_attributes__Ú__classcell__©r   s   @r   r   r      s+   ø† ñ÷0ò>ò ð ó"ó ö"r   r   c                   ó`   ^ • \ rS rSrSrS	U 4S jjrS rS r\S
S j5       r	\
S 5       rSrU =r$ )r   é;   z¶This is the quantized version of :class:`~torch.nn.Hardswish`.

Args:
    scale: quantization scale of the output tensor
    zero_point: quantization zero point of the output tensor
c                 óÆ   >• X4S.n[         TU ]  5         U R                  S[        R                  " U40 UD65        U R                  S[        R                  " U40 UD65        g ©N)ÚdeviceÚdtypeÚscaleÚ
zero_point©r   r   Úregister_bufferr   Útensor)r   r=   r>   r;   r<   Úfactory_kwargsr   s         €r   r   ÚHardswish.__init__C   sR   ø€ Ø$*Ñ;ˆÜ‰ÑÔà×Ñ˜W¤e§l¢l°5Ñ&K¸NÑ&KÔLà×Ñ˜\¬5¯<ª<¸
Ñ+UÀnÑ+UÕVr   c                 ó~   • [         R                  R                  R                  XR                  U R
                  5      $ r   )r   r   r   Ú	hardswishr=   r>   r   s     r   r   ÚHardswish.forwardK   s'   € Ü�y‰y×"Ñ"×,Ñ,¨U·J±JÀÇÁÓPÐPr   c                 ó   • g)NÚQuantizedHardswishr#   r$   s    r   r%   ÚHardswish._get_nameN   ó   € Ø#r   c                 óv   • U R                   R                  5       u  p#[        [        U5      [	        U5      5      $ r   )Úactivation_post_processÚcalculate_qparamsr   ÚfloatÚint©r)   r*   r=   r>   s       r   r+   ÚHardswish.from_floatQ   s.   € à×7Ñ7×IÑIÓKÑˆÜœ˜u›¤s¨:£Ó7Ð7r   c                 ó8   • U " [        U5      [        U5      5      $ r   )rN   rO   ©Úclsr)   r=   r>   s       r   Úfrom_referenceÚHardswish.from_referenceV   s   € á”5˜“<¤ Z£Ó1Ð1r   r#   )NNr-   ©r.   r/   r0   r1   r2   r   r   r%   r3   r+   ÚclassmethodrU   r4   r5   r6   s   @r   r   r   ;   sA   ø† ñ÷WòQò$ð ó8ó ð8ð ñ2ó ö2r   r   c                   ó`   ^ • \ rS rSrSrS	U 4S jjrS rS r\S
S j5       r	\
S 5       rSrU =r$ )r   é[   zÑThis is the quantized equivalent of :class:`~torch.nn.ELU`.

Args:
    scale: quantization scale of the output tensor
    zero_point: quantization zero point of the output tensor
    alpha: the alpha constant
c                 ó<   >• [         TU ]  U5        Xl        X l        g r   )r   r   r=   r>   )r   r=   r>   Úalphar   s       €r   r   ÚELU.__init__d   s   ø€ Ü‰Ñ˜ÔØŒ
Ø$�r   c                 ó¼   • [         R                  R                  R                  R                  R                  XR                  U R                  U R                  5      $ r   )	r   ÚaoÚnnr   Ú
functionalÚelur=   r>   r\   r   s     r   r   ÚELU.forwardi   s<   € Ü�x‰x�{‰{×$Ñ$×/Ñ/×3Ñ3Ø—:‘:˜tŸ™°·
±
ó
ð 	
r   c                 ó   • g)NÚQuantizedELUr#   r$   s    r   r%   ÚELU._get_namen   s   € Ør   c                 óŒ   • U R                   R                  5       u  p#[        [        U5      [	        U5      U R
                  5      $ r   )rL   rM   r   rN   rO   r\   rP   s       r   r+   ÚELU.from_floatq   s4   € à×7Ñ7×IÑIÓKÑˆÜ”5˜“<¤ Z£°#·)±)Ó<Ð<r   c                 óN   • U " [        U5      [        U5      UR                  5      $ r   )rN   rO   r\   rS   s       r   rU   ÚELU.from_referencev   s   € á”5˜“<¤ Z£°#·)±)Ó<Ð<r   )r=   r>   )ç      ð?r-   rW   r6   s   @r   r   r   [   s?   ø† ñ÷%ò

ò
ð ó=ó ð=ð ñ=ó ö=r   r   c                   ó€   ^ • \ rS rSrSr    SS\S\S\S\SS4
U 4S	 jjjrS
 r	S r
\SS j5       r\S 5       rSrU =r$ )r   é{   a  This is the quantized equivalent of :class:`~torch.nn.LeakyReLU`.

Args:
    scale: quantization scale of the output tensor
    zero_point: quantization zero point of the output tensor
    negative_slope: Controls the angle of the negative slope. Default: 1e-2
Nr=   r>   Únegative_sloper   Úreturnc                 óÈ   >• XVS.n[         TU ]  X45        U R                  S[        R                  " U40 UD65        U R                  S[        R                  " U40 UD65        g r:   r?   )	r   r=   r>   rn   r   r;   r<   rB   r   s	           €r   r   ÚLeakyReLU.__init__„   sV   ø€ ð %+Ñ;ˆÜ‰Ñ˜Ô1à×Ñ˜W¤e§l¢l°5Ñ&K¸NÑ&KÔLà×Ñ˜\¬5¯<ª<¸
Ñ+UÀnÑ+UÕVr   c                 óª   • [         R                  R                  R                  XR                  U R
                  U R                  U R                  5      $ r   )r   r   r   Ú
leaky_relurn   r   r=   r>   r   s     r   r   ÚLeakyReLU.forward”   s:   € Ü�y‰y×"Ñ"×-Ñ-Ø×&Ñ&¨¯©°d·j±jÀ$Ç/Á/ó
ð 	
r   c                 ó   • g)NÚQuantizedLeakyReLUr#   r$   s    r   r%   ÚLeakyReLU._get_name™   rJ   r   c                 óœ   • UR                   R                  5       u  p4U " [        U5      [        U5      UR                  UR
                  5      $ r   )rL   rM   rN   rO   rn   r   )rT   r)   r*   r=   r>   s        r   r+   ÚLeakyReLU.from_floatœ   s<   € à×7Ñ7×IÑIÓKÑˆÙ”5˜“<¤ Z£°#×2DÑ2DÀcÇkÁkÓRÐRr   c                 ód   • U " [        U5      [        U5      UR                  UR                  5      $ r   )rN   rO   rn   r   rS   s       r   rU   ÚLeakyReLU.from_reference¡   s%   € á”5˜“<¤ Z£°#×2DÑ2DÀcÇkÁkÓRÐRr   r#   )g{®Gáz„?FNNr-   )r.   r/   r0   r1   r2   rN   rO   Úboolr   r   r%   rX   r+   rU   r4   r5   r6   s   @r   r   r   {   s�   ø† ñð !%ØØØñWàðWð ðWð ð	Wð
 ðWð 
÷Wð Wò 
ò
$ð óSó ðSð ñSó öSr   r   c                   óR   ^ • \ rS rSrSrS\S\4U 4S jjrS r\	S	S j5       r
SrU =r$ )
r   é¦   z·This is the quantized equivalent of :class:`~torch.nn.Sigmoid`.

Args:
    scale: quantization scale of the output tensor
    zero_point: quantization zero point of the output tensor
Úoutput_scaleÚoutput_zero_pointc                 ó:   >• [         TU ]  5         Xl        X l        g r   )r   r   r   r€   )r   r   r€   r   s      €r   r   ÚSigmoid.__init__®   s   ø€ Ü‰ÑÔØ(ÔØ!2Õr   c                 ó~   • [         R                  R                  R                  XR                  U R
                  5      $ r   )r   r   r   Úsigmoidr   r€   r   s     r   r   ÚSigmoid.forward³   s0   € Ü�y‰y×"Ñ"×*Ñ*Ø×$Ñ$ d×&<Ñ&<ó
ð 	
r   c                 ór   • UR                   R                  5       u  nnU " [        U5      [        U5      5      $ r   )rL   rM   rN   rO   )rT   r)   r*   r   r€   s        r   r+   ÚSigmoid.from_float¸   s9   € ð
 ×'Ñ'×9Ñ9Ó;ñ	
ØØá”5˜Ó&¬Ð,=Ó(>Ó?Ð?r   )r   r€   r-   )r.   r/   r0   r1   r2   rN   rO   r   r   rX   r+   r4   r5   r6   s   @r   r   r   ¦   s6   ø† ñð3 Uð 3¸s÷ 3ò

ð
 ó@ó ö@r   r   c                   ó`   ^ • \ rS rSrSrS	U 4S jjrS rS r\S
S j5       r	\
S 5       rSrU =r$ )r	   éÁ   a  This is the quantized version of :class:`~torch.nn.Softmax`.

Args:
    dim: A dimension along which Softmax will be computed (so every slice along dim will sum to 1).
    scale: quantization scale of the output tensor
    zero_point: quantization zero point of the output tensor
c                 óF   >• [         TU ]  5         Xl        X l        X0l        g r   )r   r   Údimr=   r>   )r   r‹   r=   r>   r   s       €r   r   ÚSoftmax.__init__Ê   s   ø€ Ü‰ÑÔØŒØŒ
Ø$�r   c                 ó  • U R                   nUc;  Sn[        R                  R                  R	                  SUR                  5       U5      n[        R
                  R                  R                  XU R                  U R                  5      $ )Né   Úsoftmax)
r‹   r   r`   ra   Ú_get_softmax_dimr   r   r�   r=   r>   )r   r   r‹   Ú
stacklevels       r   r   ÚSoftmax.forwardÐ   sg   € Ø�h‰hˆØ‰;ØˆJô —(‘(×%Ñ%×6Ñ6Ø˜5Ÿ9™9›;¨
óˆCô �y‰y×"Ñ"×*Ñ*¨5°t·z±zÀ4Ç?Á?ÓSÐSr   c                 ó   • g)NÚQuantizedSoftmaxr#   r$   s    r   r%   ÚSoftmax._get_nameÛ   s   € Ø!r   c                 óŒ   • U R                   R                  5       u  p#[        U R                  [	        U5      [        U5      5      $ r   )rL   rM   r	   r‹   rN   rO   rP   s       r   r+   ÚSoftmax.from_floatÞ   s4   € à×7Ñ7×IÑIÓKÑˆÜ�s—w‘w¤ e£¬c°*«oÓ>Ð>r   c                 óN   • U " UR                   [        U5      [        U5      5      $ r   )r‹   rN   rO   rS   s       r   rU   ÚSoftmax.from_referenceã   s   € á�3—7‘7œE %›L¬#¨j«/Ó:Ð:r   )r‹   r=   r>   )Nrk   r   r-   rW   r6   s   @r   r	   r	   Á   s@   ø† ñ÷%ò	Tò"ð ó?ó ð?ð ñ;ó ö;r   r	   c                   óŽ   • \ rS rSr\R
                  R                  R                  R                  r	S r
\S 5       r\S 5       rSrg)r
   éè   c                 ó   • g)NÚQuantizedMultiheadAttentionr#   r$   s    r   r%   ÚMultiheadAttention._get_nameì   s   € Ø,r   c                 ó   • [        S5      e)NzpIt looks like you are trying to convert a non-observed MHA module. Please, see the examples on quantizable MHAs.)ÚNotImplementedError)rT   Úothers     r   r+   ÚMultiheadAttention.from_floatï   s   € ô "ð0ó
ð 	
r   c                 ó8  • [         R                  R                  R                  US SSS S9nXl        UR
                  be  UR                  R                  S5      n[         R                  " USS9u  pE[         R                  " X4U[         R                  5      n[        USU5        UR                  be  UR                  R                  S5      n[         R                  " WSS9u  pE[         R                  " XdU[         R                  5      n[        USU5        U?U?U$ )NFT)Úmappingr   Úremove_qconfigÚconvert_custom_config_dictÚbias_k)Úreduce_rangeÚbias_v)r   r_   ÚquantizationÚconvertr   r§   Ú_parametersÚpopÚ_choose_qparams_per_tensorÚquantize_per_tensorÚquint8Úsetattrr©   Úin_proj_weightÚin_proj_bias)rT   r¡   Ú	convertedr§   ÚscÚzpr©   s          r   Úfrom_observedÚ MultiheadAttention.from_observedù   s  € ä—H‘H×)Ñ)×1Ñ1ØØØØØ'+ð 2ð 
ˆ	ð "Ôð ×ÑÑ'Ø×*Ñ*×.Ñ.¨xÓ8ˆFÜ×5Ò5°fÈ5ÑQ‰FˆBÜ×.Ò.¨v¸2¼u¿|¹|ÓLˆFÜ�I˜x¨Ô0à×ÑÑ'Ø×*Ñ*×.Ñ.¨xÓ8ˆFÜ×5Ò5ØØ"ñ‰FˆBô ×.Ò.¨v¸2¼u¿|¹|ÓLˆFÜ�I˜x¨Ô0àÐ$ØÐ"àÐr   r#   N)r.   r/   r0   r1   r   r_   r`   Úquantizabler
   Ú_FLOAT_MODULEr%   rX   r+   r·   r4   r#   r   r   r
   r
   è   sH   † à—H‘H—K‘K×+Ñ+×>Ñ>€Mò-ð ñ
ó ð
ð ñ ó ó r   r
   c            	       óÐ   ^ • \ rS rSrSr SS\S\S\SS4U 4S jjjrS	\R                  SS4S
 jr
S\R                  S\R                  4S jrS r\SS j5       r\S 5       rSrU =r$ )r   i  a  This is the quantized equivalent of :class:`~torch.nn.PReLU`.

Args:
    scale: quantization scale of the output tensor
    zero_point: quantization zero point of the output tensor
    num_parameters: number of parameters: 1, or the number of channels at input. Default: 1
r   r€   Únum_parametersro   Nc                 óø   >• [         TU ]  5         X0l        Xl        X l        [
        R                  " U[
        R                  S9n[
        R                  " USS[
        R                  S9nU R                  U5        g )N)r<   rk   r   )r=   r>   r<   )r   r   r¼   r=   r>   r   ÚrandnrN   r¯   r°   Ú
set_weight)r   r   r€   r¼   ÚwÚqwr   s         €r   r   ÚPReLU.__init__&  sZ   ø€ ô 	‰ÑÔØ,ÔØ!Œ
Ø+ŒÜ�KŠK˜¬e¯k©kÑ:ˆÜ×&Ò& q°ÀÌÏÉÑVˆØ�‰˜Õr   rÀ   c                 ó   • Xl         g r   )Úweight)r   rÀ   s     r   r¿   ÚPReLU.set_weight1  s   € Ø�r   r   c                 ó”   • [         R                  R                  R                  XR                  U R
                  U R                  5      $ r   )r   r   r   ÚprelurÄ   r=   r>   r   s     r   r   ÚPReLU.forward4  s2   € Ü�y‰y×"Ñ"×(Ñ(Ø—;‘; §
¡
¨D¯O©Oó
ð 	
r   c                 ó   • g)NÚQuantizedPReLUr#   r$   s    r   r%   ÚPReLU._get_name9  r'   r   c                 ó$  • UR                   R                  5       u  p4U " [        U5      [        U5      UR                  5      nUR
                  R                  5       nUR                  R                  5       nU" U5        UR                  [        R                  :w  a  [        SUR                   3SS9  UR                  5       u  p‰[        R                  " U[        U5      [        U	5      [        R                  5      n
UR                  U
5        U$ ©Nz9PReLU's weight observer should have dtype quint8 but got é   )r‘   )rL   rM   rN   rO   r¼   rÄ   Úqconfigr<   r   r°   r   r¯   r¿   )rT   r)   r*   r=   r>   ÚqpreluÚfloat_wtÚobserverÚwt_scaleÚwt_zpÚqweights              r   r+   ÚPReLU.from_float<  s×   € à×7Ñ7×IÑIÓKÑˆÙ”U˜5“\¤3 z£?°C×4FÑ4FÓGˆØ—:‘:×#Ñ#Ó%ˆØ—;‘;×%Ñ%Ó'ˆÙ�ÔØ�>‰>œUŸ\™\Ó)ÜØKÈHÏNÉNÐK[Ð\Øòð #×4Ñ4Ó6‰ˆÜ×+Ò+Ø”e˜H“o¤s¨5£z´5·<±<ó
ˆð 	×Ñ˜'Ô"Øˆr   c                 óì  • U " [        U5      [        U5      UR                  5      nUR                  R                  5       nUR                  R                  5       nU" U5        UR
                  [        R                  :w  a  [        SUR
                   3SS9  UR                  5       u  px[        R                  " U[        U5      [        U5      [        R                  5      n	UR                  U	5        U$ rÍ   )rN   rO   r¼   rÄ   rÏ   r<   r   r°   r   rM   r¯   r¿   )
rT   r)   r=   r>   rÐ   rÑ   rÒ   rÓ   rÔ   rÕ   s
             r   rU   ÚPReLU.from_referenceO  sÀ   € á”U˜5“\¤3 z£?°C×4FÑ4FÓGˆØ—:‘:×#Ñ#Ó%ˆØ—;‘;×%Ñ%Ó'ˆÙ�ÔØ�>‰>œUŸ\™\Ó)ÜØKÈHÏNÉNÐK[Ð\Øòð #×4Ñ4Ó6‰ˆÜ×+Ò+Ø”e˜H“o¤s¨5£z´5·<±<ó
ˆð 	×Ñ˜'Ô"Øˆr   )r¼   r=   rÄ   r>   )é   r-   )r.   r/   r0   r1   r2   rN   rO   r   r   ÚTensorr¿   r   r%   rX   r+   rU   r4   r5   r6   s   @r   r   r     s˜   ø† ñð RSñ	Ø!ð	Ø69ð	ØKNð	à	÷	ð 	ð˜EŸL™Lð ¨Tô ð
˜UŸ\™\ð 
¨e¯l©lô 
ò
 ð óó ðð$ ñó ör   r   )Úwarningsr   r   Ú__all__r`   ÚReLUr   r   r   r   r   r	   r_   r¹   r
   ÚModuler   r#   r   r   Ú<module>rß      sÒ   ðå ã ò	€ô%"ˆE�H‰H�M‰Mô %"ôP2�—‘×"Ñ"ô 2ô@=ˆ%�(‰(�,‰,ô =ô@(S�—‘×"Ñ"ô (SôV@ˆe�h‰h×Ñô @ô6$;ˆe�h‰h×Ñô $;ôN2˜Ÿ™Ÿ™×0Ñ0×CÑCô 2ôjBˆE�H‰H�O‰Oõ Br   