
    0;ji                         d Z ddlZddlmZmZmZ ddlmZ  G d dej        j                  Z G d dej                  Z	dS )	z*Swish() activation function for Conformer.    N)nnsinpow)	Parameterc                   6    e Zd ZdZdej        dej        fdZdS )SwishzConstruct an Swish object.xreturnc                 0    |t          j        |          z  S )z!Return Swish activation function.)torchsigmoid)selfr	   s     h/root/voice-cloning/.venv/lib/python3.11/site-packages/chatterbox/models/s3gen/transformer/activation.pyforwardzSwish.forward   s    5=####    N)__name__
__module____qualname____doc__r   Tensorr    r   r   r   r      s@        $$$ $%, $ $ $ $ $ $r   r   c                   *     e Zd ZdZd fd	Zd Z xZS )Snakea  
    Implementation of a sine-based periodic activation function
    Shape:
        - Input: (B, C, T)
        - Output: (B, C, T), same shape as the input
    Parameters:
        - alpha - trainable parameter
    References:
        - This activation function is from this paper by Liu Ziyin, Tilman Hartwig, Masahito Ueda:
        https://arxiv.org/abs/2006.08195
    Examples:
        >>> a1 = snake(256)
        >>> x = torch.randn(256)
        >>> x = a1(x)
          ?TFc                 L   t          t          |                                            || _        || _        | j        r*t          t          j        |          |z            | _        n)t          t          j	        |          |z            | _        || j        _
        d| _        dS )a   
        Initialization.
        INPUT:
            - in_features: shape of the input
            - alpha: trainable parameter
            alpha is initialized to 1 by default, higher values = higher-frequency.
            alpha will be trained along with the rest of your model.
        g&.>N)superr   __init__in_featuresalpha_logscaler   r   zerosalphaonesrequires_gradno_div_by_zero)r   r   r!   alpha_trainabler   	__class__s        r   r   zSnake.__init__2   s     	eT##%%%& - 	D"5;{#;#;e#CDDDJJ"5:k#:#:U#BCCDJ#2
 )r   c                     | j                             d                              d          }| j        rt          j        |          }|d|| j        z   z  t          t          ||z            d          z  z   }|S )u   
        Forward pass of the function.
        Applies the function to the input elementwise.
        Snake ∶= x + 1/a * sin^2 (xa)
        r   r      )r!   	unsqueezer   r   expr$   r   r   )r   r	   r!   s      r   r   zSnake.forwardI   sv     
$$Q''11"55 	%Ie$$E 334CE	NNA8N8NNNr   )r   TF)r   r   r   r   r   r   __classcell__)r&   s   @r   r   r   "   sV         * * * * * *.      r   r   )
r   r   r   r   r   torch.nnr   Moduler   r   r   r   r   <module>r/      s   " 1 0                 $ $ $ $ $EHO $ $ $2 2 2 2 2BI 2 2 2 2 2r   