Ë
    g^(hG-  ã                   ó8  — d dl mZ d dlZg d¢Z G d„ dej                  j
                  «      Z G d„ dej                  j                  «      Z G d„ d	ej                  j                  «      Z G d
„ dej                  j                  «      Z	 G d„ dej                  j                  «      Z
 G d„ dej                  j                  «      Z G d„ dej                  j                  j                  j                  «      Z G d„ dej                  j                  «      Zy)é    )ÚwarnN)ÚReLU6Ú	HardswishÚELUÚ	LeakyReLUÚSigmoidÚSoftmaxÚMultiheadAttentionÚPReLUc                   óB   ‡ — e Zd ZdZdˆ fd„	Zd„ Zd„ Zedd„«       Zˆ xZ	S )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                 ó2   •— t         ‰| �  |«       || _        y ©N)ÚsuperÚ__init__Úinplace)Úselfr   Ú	__class__s     €úf/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/torch/ao/nn/quantized/modules/activation.pyr   zReLU6.__init__,   s   ø€ Ü‰Ñ˜Ô!Øˆ�ó    c                 ój   — t         j                  j                  j                  || j                  «      S r   )ÚtorchÚopsÚ	quantizedÚrelu6r   ©r   Úinputs     r   ÚforwardzReLU6.forward0   s#   € Ü�y‰y×"Ñ"×(Ñ(¨°·±Ó=Ð=r   c                  ó   — y)NÚQuantizedReLU6© ©r   s    r   Ú	_get_namezReLU6._get_name3   ó   € Ør   c                 ó,   — t        | j                  «      S r   )r   r   )ÚmodÚuse_precomputed_fake_quants     r   Ú
from_floatzReLU6.from_float6   s   € ä�S—[‘[Ó!Ð!r   ©F)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r"   Ústaticmethodr'   Ú__classcell__©r   s   @r   r   r      s+   ø„ ñõ0ò>ò ð ò"ó ô"r   r   c                   óR   ‡ — e Zd ZdZdˆ fd„	Zd„ Zd„ Zedd„«       Ze	d„ «       Z
ˆ xZS )	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                 óÄ   •— ||dœ}t         ‰| �  «        | j                  dt        j                  |fi |¤Ž«       | j                  dt        j                  |fi |¤Ž«       y ©N)ÚdeviceÚdtypeÚscaleÚ
zero_point©r   r   Úregister_bufferr   Útensor)r   r5   r6   r3   r4   Úfactory_kwargsr   s         €r   r   zHardswish.__init__C   sT   ø€ Ø$*°UÑ;ˆÜ‰ÑÔØ×Ñ˜W¤e§l¡l°5Ñ&K¸NÑ&KÔLØ×Ñ˜\¬5¯<©<¸
Ñ+UÀnÑ+UÕVr   c                 ó€   — t         j                  j                  j                  || j                  | j
                  «      S r   )r   r   r   Ú	hardswishr5   r6   r   s     r   r   zHardswish.forwardI   s)   € Ü�y‰y×"Ñ"×,Ñ,¨U°D·J±JÀÇÁÓPÐPr   c                  ó   — y)NÚQuantizedHardswishr    r!   s    r   r"   zHardswish._get_nameL   ó   € Ø#r   c                 óx   — | j                   j                  «       \  }}t        t        |«      t	        |«      «      S r   )Úactivation_post_processÚcalculate_qparamsr   ÚfloatÚint©r%   r&   r5   r6   s       r   r'   zHardswish.from_floatO   s0   € à×7Ñ7×IÑIÓKÑˆˆzÜœ˜u›¤s¨:£Ó7Ð7r   c                 ó8   —  | t        |«      t        |«      «      S r   )rC   rD   ©Úclsr%   r5   r6   s       r   Úfrom_referencezHardswish.from_referenceT   s   € á”5˜“<¤ Z£Ó1Ð1r   )NNr(   ©r)   r*   r+   r,   r   r   r"   r-   r'   ÚclassmethodrI   r.   r/   s   @r   r   r   ;   sA   ø„ ñõWòQò$ð ò8ó ð8ð ñ2ó ô2r   r   c                   óR   ‡ — e Zd ZdZdˆ fd„	Zd„ Zd„ Zedd„«       Ze	d„ «       Z
ˆ xZS )	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         ‰| �  |«       || _        || _        y r   )r   r   r5   r6   )r   r5   r6   Úalphar   s       €r   r   zELU.__init__b   s   ø€ Ü‰Ñ˜ÔØˆŒ
Ø$ˆ�r   c                 ó¾   — t         j                  j                  j                  j                  j                  || j                  | j                  | j                  «      S r   )	r   ÚaoÚnnr   Ú
functionalÚelur5   r6   rN   r   s     r   r   zELU.forwardg   s>   € Ü�x‰x�{‰{×$Ñ$×/Ñ/×3Ñ3Ø�4—:‘:˜tŸ™°·
±
ó
ð 	
r   c                  ó   — y)NÚQuantizedELUr    r!   s    r   r"   zELU._get_namel   s   € Ør   c                 óŽ   — | j                   j                  «       \  }}t        t        |«      t	        |«      | j
                  «      S r   )rA   rB   r   rC   rD   rN   rE   s       r   r'   zELU.from_floato   s6   € à×7Ñ7×IÑIÓKÑˆˆzÜ”5˜“<¤ Z£°#·)±)Ó<Ð<r   c                 óN   —  | t        |«      t        |«      |j                  «      S r   )rC   rD   rN   rG   s       r   rI   zELU.from_referencet   s   € á”5˜“<¤ Z£°#·)±)Ó<Ð<r   )ç      ð?r(   rJ   r/   s   @r   r   r   Y   s?   ø„ ñõ%ò

ò
ð ò=ó ð=ð ñ=ó ô=r   r   c                   óp   ‡ — e Zd ZdZ	 	 	 	 ddededededdf
ˆ fd„Zd	„ Zd
„ Z	e
dd„«       Ze
d„ «       Zˆ xZS )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
    Nr5   r6   Únegative_sloper   Úreturnc                 óÈ   •— ||dœ}t         ‰| �  ||«       | j                  dt        j                  |fi |¤Ž«       | j                  dt        j                  |fi |¤Ž«       y r2   r7   )	r   r5   r6   rZ   r   r3   r4   r:   r   s	           €r   r   zLeakyReLU.__init__‚   sZ   ø€ ð %+°UÑ;ˆÜ‰Ñ˜¨Ô1Ø×Ñ˜W¤e§l¡l°5Ñ&K¸NÑ&KÔLØ×Ñ˜\¬5¯<©<¸
Ñ+UÀnÑ+UÕVr   c                 ó¬   — t         j                  j                  j                  || j                  | j
                  | j                  | j                  «      S r   )r   r   r   Ú
leaky_relurZ   r   r5   r6   r   s     r   r   zLeakyReLU.forward�   s<   € Ü�y‰y×"Ñ"×-Ñ-Ø�4×&Ñ&¨¯©°d·j±jÀ$Ç/Á/ó
ð 	
r   c                  ó   — y)NÚQuantizedLeakyReLUr    r!   s    r   r"   zLeakyReLU._get_name•   r?   r   c                 óž   — |j                   j                  «       \  }} | t        |«      t        |«      |j                  |j
                  «      S r   )rA   rB   rC   rD   rZ   r   )rH   r%   r&   r5   r6   s        r   r'   zLeakyReLU.from_float˜   s>   € à×7Ñ7×IÑIÓKÑˆˆzÙ”5˜“<¤ Z£°#×2DÑ2DÀcÇkÁkÓRÐRr   c                 ód   —  | t        |«      t        |«      |j                  |j                  «      S r   )rC   rD   rZ   r   rG   s       r   rI   zLeakyReLU.from_reference�   s%   € á”5˜“<¤ Z£°#×2DÑ2DÀcÇkÁkÓRÐRr   )g{®Gáz„?FNNr(   )r)   r*   r+   r,   rC   rD   Úboolr   r   r"   rK   r'   rI   r.   r/   s   @r   r   r   y   s‡   ø„ ñð !%ØØØñWàðWð ðWð ð	Wð
 ðWð 
õWò
ò
$ð òSó ðSð ñSó ôSr   r   c                   óD   ‡ — e Zd ZdZdedefˆ fd„Zd„ Zedd„«       Z	ˆ xZ
S )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         ‰| �  «        || _        || _        y r   )r   r   re   rf   )r   re   rf   r   s      €r   r   zSigmoid.__init__ª   s   ø€ Ü‰ÑÔØ(ˆÔØ!2ˆÕr   c                 ó€   — t         j                  j                  j                  || j                  | j
                  «      S r   )r   r   r   Úsigmoidre   rf   r   s     r   r   zSigmoid.forward¯   s2   € Ü�y‰y×"Ñ"×*Ñ*Ø�4×$Ñ$ d×&<Ñ&<ó
ð 	
r   c                 ór   — |j                   j                  «       \  }} | t        |«      t        |«      «      S r   )rA   rB   rC   rD   )rH   r%   r&   re   rf   s        r   r'   zSigmoid.from_float´   s9   € ð
 ×'Ñ'×9Ñ9Ó;ñ	
ØØá”5˜Ó&¬Ð,=Ó(>Ó?Ð?r   r(   )r)   r*   r+   r,   rC   rD   r   r   rK   r'   r.   r/   s   @r   r   r   ¢   s6   ø„ ñð3 Uð 3¸sõ 3ò

ð
 ò@ó ô@r   r   c                   óR   ‡ — e Zd ZdZdˆ fd„	Zd„ Zd„ Zedd„«       Ze	d„ «       Z
ˆ xZS )	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                 óL   •— t         ‰| �  «        || _        || _        || _        y r   )r   r   Údimr5   r6   )r   rm   r5   r6   r   s       €r   r   zSoftmax.__init__Æ   s#   ø€ Ü‰ÑÔØˆŒØˆŒ
Ø$ˆ�r   c                 ó  — | j                   }|€;d}t        j                  j                  j	                  d|j                  «       |«      }t        j
                  j                  j                  ||| j                  | j                  «      S )Né   Úsoftmax)
rm   r   rQ   rR   Ú_get_softmax_dimr   r   rp   r5   r6   )r   r   rm   Ú
stacklevels       r   r   zSoftmax.forwardÌ   si   € Ø�h‰hˆØˆ;ØˆJô —(‘(×%Ñ%×6Ñ6Ø˜5Ÿ9™9›;¨
óˆCô �y‰y×"Ñ"×*Ñ*¨5°#°t·z±zÀ4Ç?Á?ÓSÐSr   c                  ó   — y)NÚQuantizedSoftmaxr    r!   s    r   r"   zSoftmax._get_name×   s   € Ø!r   c                 óŽ   — | j                   j                  «       \  }}t        | j                  t	        |«      t        |«      «      S r   )rA   rB   r	   rm   rC   rD   rE   s       r   r'   zSoftmax.from_floatÚ   s6   € à×7Ñ7×IÑIÓKÑˆˆzÜ�s—w‘w¤ e£¬c°*«oÓ>Ð>r   c                 óN   —  | |j                   t        |«      t        |«      «      S r   )rm   rC   rD   rG   s       r   rI   zSoftmax.from_referenceß   s   € á�3—7‘7œE %›L¬#¨j«/Ó:Ð:r   )NrX   r   r(   rJ   r/   s   @r   r	   r	   ½   s@   ø„ ñõ%ò	Tò"ð ò?ó ð?ð ñ;ó ô;r   r	   c                   ó†   — e Zd Zej                  j
                  j                  j                  Zd„ Z	e
d„ «       Ze
d„ «       Zy)r
   c                  ó   — y)NÚQuantizedMultiheadAttentionr    r!   s    r   r"   zMultiheadAttention._get_nameç   s   € Ø,r   c                 ó   — t        d«      ‚)NzpIt looks like you are trying to convert a non-observed MHA module. Please, see the examples on quantizable MHAs.)ÚNotImplementedError)rH   Úothers     r   r'   zMultiheadAttention.from_floatê   s   € ô "ð0ó
ð 	
r   c                 óH  — t         j                  j                  j                  |d ddd ¬«      }| |_        |j
                  �h|j                  j                  d«      }t        j                  |d¬«      \  }}t        j                  |||t         j                  «      }t        |d|«       |j                  �h|j                  j                  d«      }t        j                  d¬«      \  }}t        j                  |||t         j                  «      }t        |d|«       |`|`|S )NFT)Úmappingr   Úremove_qconfigÚconvert_custom_config_dictÚbias_k)Úreduce_rangeÚbias_v)r   rP   ÚquantizationÚconvertr   r�   Ú_parametersÚpopÚ_choose_qparams_per_tensorÚquantize_per_tensorÚquint8Úsetattrrƒ   Úin_proj_weightÚin_proj_bias)rH   r|   Ú	convertedr�   ÚscÚzprƒ   s          r   Úfrom_observedz MultiheadAttention.from_observedô   s  € ä—H‘H×)Ñ)×1Ñ1ØØØØØ'+ð 2ó 
ˆ	ð "ˆ	Ôð ×ÑÐ'Ø×*Ñ*×.Ñ.¨xÓ8ˆFÜ×5Ñ5°fÈ5ÔQ‰FˆB�Ü×.Ñ.¨v°r¸2¼u¿|¹|ÓLˆFÜ�I˜x¨Ô0à×ÑÐ'Ø×*Ñ*×.Ñ.¨xÓ8ˆFÜ×5Ñ5Ø Uô‰FˆB�ô ×.Ñ.¨v°r¸2¼u¿|¹|ÓLˆFÜ�I˜x¨Ô0àÐ$ØÐ"àÐr   N)r)   r*   r+   r   rP   rQ   Úquantizabler
   Ú_FLOAT_MODULEr"   rK   r'   r‘   r    r   r   r
   r
   ä   sH   „ Ø—H‘H—K‘K×+Ñ+×>Ñ>€Mò-ð ñ
ó ð
ð ñó ñr   r
   c            	       ó¼   ‡ — e Zd ZdZ	 ddedededdfˆ fd„Zdej                  ddfd	„Z	d
ej                  dej                  fd„Z
d„ Zedd„«       Zed„ «       Zˆ xZS )r   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
    re   rf   Únum_parametersr[   Nc                 ó  •— t         ‰| �  «        || _        || _        || _        t        j                  |t
        j                  ¬«      }t        j                  |ddt
        j                  ¬«      }| j                  |«       y )N)r4   rX   r   )r5   r6   r4   )r   r   r•   r5   r6   r   ÚrandnrC   r‰   rŠ   Ú
set_weight)r   re   rf   r•   ÚwÚqwr   s         €r   r   zPReLU.__init__   s`   ø€ ô 	‰ÑÔØ,ˆÔØ!ˆŒ
Ø+ˆŒÜ�K‰K˜¬e¯k©kÔ:ˆÜ×&Ñ& q°ÀÌÏÉÔVˆØ�‰˜Õr   r™   c                 ó   — || _         y r   )Úweight)r   r™   s     r   r˜   zPReLU.set_weight+  s	   € Øˆ�r   r   c                 ó–   — t         j                  j                  j                  || j                  | j
                  | j                  «      S r   )r   r   r   Úprelurœ   r5   r6   r   s     r   r   zPReLU.forward.  s4   € Ü�y‰y×"Ñ"×(Ñ(Ø�4—;‘; §
¡
¨D¯O©Oó
ð 	
r   c                  ó   — y)NÚQuantizedPReLUr    r!   s    r   r"   zPReLU._get_name3  r#   r   c                 ó&  — |j                   j                  «       \  }} | t        |«      t        |«      |j                  «      }|j
                  j                  «       }|j                  j                  «       } ||«       |j                  t        j                  k7  rt        d|j                  › �«       |j                  «       \  }}	t        j                  |t        |«      t        |	«      t        j                  «      }
|j                  |
«       |S ©Nz9PReLU's weight observer should have dtype quint8 but got )rA   rB   rC   rD   r•   rœ   Úqconfigr4   r   rŠ   r   r‰   r˜   )rH   r%   r&   r5   r6   ÚqpreluÚfloat_wtÚobserverÚwt_scaleÚwt_zpÚqweights              r   r'   zPReLU.from_float6  sØ   € à×7Ñ7×IÑIÓKÑˆˆzÙ”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                 óì  —  | t        |«      t        |«      |j                  «      }|j                  j                  «       }|j                  j                  «       } ||«       |j
                  t        j                  k7  rt        d|j
                  › �«       |j                  «       \  }}t        j                  |t        |«      t        |«      t        j                  «      }	|j                  |	«       |S r¢   )rC   rD   r•   rœ   r£   r4   r   rŠ   r   rB   r‰   r˜   )
rH   r%   r5   r6   r¤   r¥   r¦   r§   r¨   r©   s
             r   rI   zPReLU.from_referenceH  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,   rC   rD   r   r   ÚTensorr˜   r   r"   rK   r'   rI   r.   r/   s   @r   r   r     s“   ø„ ñð RSñ	Ø!ð	Ø69ð	ØKNð	à	õ	ð˜EŸL™Lð ¨Tó ð
˜UŸ\™\ð 
¨e¯l©ló 
ò
 ð òó ðð" ñó ôr   r   )Úwarningsr   r   Ú__all__rQ   ÚReLUr   r   r   r   r   r	   rP   r’   r
   ÚModuler   r    r   r   ú<module>r±      sÑ   ðå ã ò	€ô%"ˆE�H‰H�M‰Mô %"ôP2�—‘×"Ñ"ô 2ô<=ˆ%�(‰(�,‰,ô =ô@&S�—‘×"Ñ"ô &SôR@ˆe�h‰h×Ñô @ô6$;ˆe�h‰h×Ñô $;ôN0˜Ÿ™Ÿ™×0Ñ0×CÑCô 0ôf@ˆE�H‰H�O‰Oõ @r   