o
    …wÖi1  ã                
   @   sn   d dl Z d dlmZ ddgZe jjdde jde jdede jfd	d
„ƒZG dd„ dej	ƒZ
G dd„ dejƒZdS )é    NÚSwishÚSnakeç•Ö&è.>ÚxÚalphaÚepsÚreturnc                 C   sN   | j }|  |d |d d¡} | ||  ¡ t ||  ¡ d¡  } |  |¡} | S )zY
    equation for snake activation function: x + (alpha + eps)^-1 * sin(alpha * x)^2
    r   é   éÿÿÿÿé   )ÚshapeÚreshapeÚ
reciprocalÚtorchÚsinÚpow)r   r   r   r   © r   úi/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/nemo/collections/asr/parts/utils/activations.pyÚsnake   s
   $
r   c                       s<   e Zd ZdZdef‡ fdd„Zdejdejfdd„Z‡  Z	S )	r   zT
    Snake activation function introduced in 'https://arxiv.org/abs/2006.08195'
    Úchannelsc                    s$   t ƒ  ¡  t t d|d¡¡| _d S )Nr	   )ÚsuperÚ__init__ÚnnÚ	Parameterr   Úonesr   )Úselfr   ©Ú	__class__r   r   r   &   s   
zSnake.__init__r   r   c                 C   s   t || jƒS )N)r   r   )r   r   r   r   r   Úforward*   s   zSnake.forward)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úintr   r   ÚTensorr   Ú__classcell__r   r   r   r   r   !   s    c                   @   s   e Zd ZdZdS )r   zž
    Swish activation function introduced in 'https://arxiv.org/abs/1710.05941'
    Mathematically identical to SiLU. See note in nn.SiLU for references.
    N)r   r    r!   r"   r   r   r   r   r   .   s    )r   )r   Útorch.nnr   Ú__all__ÚjitÚscriptr$   Úfloatr   ÚModuler   ÚSiLUr   r   r   r   r   Ú<module>   s   $