
    g/!                     z    d Z ddlZddlmZ ddlZddlmZ ddlm	Z	  e	j
        e          Z G d de          ZdS )	zEnCodec model configuration    N)Optional   )PretrainedConfig)loggingc                        e Zd ZdZdZg dddddddd	dg d
dddddddddddddf fd	Zedee         fd            Z	edee         fd            Z
edefd            Zedefd            Z xZS )EncodecConfiga  
    This is the configuration class to store the configuration of an [`EncodecModel`]. It is used to instantiate a
    Encodec model according to the specified arguments, defining the model architecture. Instantiating a configuration
    with the defaults will yield a similar configuration to that of the
    [facebook/encodec_24khz](https://huggingface.co/facebook/encodec_24khz) architecture.

    Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
    documentation from [`PretrainedConfig`] for more information.

    Args:
        target_bandwidths (`List[float]`, *optional*, defaults to `[1.5, 3.0, 6.0, 12.0, 24.0]`):
            The range of diffent bandwiths the model can encode audio with.
        sampling_rate (`int`, *optional*, defaults to 24000):
            The sampling rate at which the audio waveform should be digitalized expressed in hertz (Hz).
        audio_channels (`int`, *optional*, defaults to 1):
            Number of channels in the audio data. Either 1 for mono or 2 for stereo.
        normalize (`bool`, *optional*, defaults to `False`):
            Whether the audio shall be normalized when passed.
        chunk_length_s (`float`, *optional*):
            If defined the audio is pre-processed into chunks of lengths `chunk_length_s` and then encoded.
        overlap (`float`, *optional*):
            Defines the overlap between each chunk. It is used to compute the `chunk_stride` using the following
            formulae : `int((1.0 - self.overlap) * self.chunk_length)`.
        hidden_size (`int`, *optional*, defaults to 128):
            Intermediate representation dimension.
        num_filters (`int`, *optional*, defaults to 32):
            Number of convolution kernels of first `EncodecConv1d` down sampling layer.
        num_residual_layers (`int`,  *optional*, defaults to 1):
            Number of residual layers.
        upsampling_ratios (`Sequence[int]` , *optional*, defaults to `[8, 5, 4, 2]`):
            Kernel size and stride ratios. The encoder uses downsampling ratios instead of upsampling ratios, hence it
            will use the ratios in the reverse order to the ones specified here that must match the decoder order.
        norm_type (`str`, *optional*, defaults to `"weight_norm"`):
            Normalization method. Should be in `["weight_norm", "time_group_norm"]`
        kernel_size (`int`, *optional*, defaults to 7):
            Kernel size for the initial convolution.
        last_kernel_size (`int`, *optional*, defaults to 7):
            Kernel size for the last convolution layer.
        residual_kernel_size (`int`, *optional*, defaults to 3):
            Kernel size for the residual layers.
        dilation_growth_rate (`int`, *optional*, defaults to 2):
            How much to increase the dilation with each layer.
        use_causal_conv (`bool`, *optional*, defaults to `True`):
            Whether to use fully causal convolution.
        pad_mode (`str`, *optional*, defaults to `"reflect"`):
            Padding mode for the convolutions.
        compress (`int`, *optional*, defaults to 2):
            Reduced dimensionality in residual branches (from Demucs v3).
        num_lstm_layers (`int`, *optional*, defaults to 2):
            Number of LSTM layers at the end of the encoder.
        trim_right_ratio (`float`, *optional*, defaults to 1.0):
            Ratio for trimming at the right of the transposed convolution under the `use_causal_conv = True` setup. If
            equal to 1.0, it means that all the trimming is done at the right.
        codebook_size (`int`, *optional*, defaults to 1024):
            Number of discret codes that make up VQVAE.
        codebook_dim (`int`, *optional*):
            Dimension of the codebook vectors. If not defined, uses `hidden_size`.
        use_conv_shortcut (`bool`, *optional*, defaults to `True`):
            Whether to use a convolutional layer as the 'skip' connection in the `EncodecResnetBlock` block. If False,
            an identity function will be used, giving a generic residual connection.

    Example:

    ```python
    >>> from transformers import EncodecModel, EncodecConfig

    >>> # Initializing a "facebook/encodec_24khz" style configuration
    >>> configuration = EncodecConfig()

    >>> # Initializing a model (with random weights) from the "facebook/encodec_24khz" style configuration
    >>> model = EncodecModel(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```encodec)g      ?g      @g      @g      (@g      8@i]     FN       )            weight_norm   r   r   Treflect      ?i   c                    || _         || _        || _        || _        || _        || _        || _        || _        |	| _        |
| _	        || _
        || _        || _        || _        || _        || _        || _        || _        || _        || _        || _        ||n|| _        || _        | j
        dvrt/          d| j
                    t1                      j        di | d S )N)r   time_group_normzIself.norm_type must be one of `"weight_norm"`, `"time_group_norm"`), got  )target_bandwidthssampling_rateaudio_channels	normalizechunk_length_soverlaphidden_sizenum_filtersnum_residual_layersupsampling_ratios	norm_typekernel_sizelast_kernel_sizeresidual_kernel_sizedilation_growth_rateuse_causal_convpad_modecompressnum_lstm_layerstrim_right_ratiocodebook_sizecodebook_dimuse_conv_shortcut
ValueErrorsuper__init__)selfr   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   kwargs	__class__s                            m/var/www/html/ai-engine/env/lib/python3.11/site-packages/transformers/models/encodec/configuration_encodec.pyr1   zEncodecConfig.__init__l   s   6 "3*,",&&#6 !2"& 0$8!$8!.  . 0*,8,DLL+!2>!CCCl\`\jll   	""6"""""    returnc                 L    | j         d S t          | j         | j        z            S N)r   intr   r2   s    r5   chunk_lengthzEncodecConfig.chunk_length   s)    &4t*T-??@@@r6   c                 |    | j         | j        d S t          dt          d| j        z
  | j        z                      S )Nr
   r   )r   r   maxr:   r<   r;   s    r5   chunk_stridezEncodecConfig.chunk_stride   s>    &$,*>4q#sT\1T5FFGGHHHr6   c                 l    t          j        | j                  }t          j        | j        |z            S r9   )npprodr!   mathceilr   )r2   
hop_lengths     r5   
frame_ratezEncodecConfig.frame_rate   s,    WT344
y+j8999r6   c                 R    t          d| j        d         z  | j        dz  z            S )Ni  
   )r:   r   rF   r;   s    r5   num_quantizerszEncodecConfig.num_quantizers   s)    4$04429MNOOOr6   )__name__
__module____qualname____doc__
model_typer1   propertyr   r:   r<   r?   rF   rJ   __classcell__)r4   s   @r5   r   r      sZ       J JX J 655&,,18# 8# 8# 8# 8# 8#v Ahsm A A A XA Ihsm I I I XI :C : : : X: P P P P XP P P P Pr6   r   )rN   rC   typingr   numpyrA   configuration_utilsr   utilsr   
get_loggerrK   loggerr   r   r6   r5   <module>rX      s    " !            3 3 3 3 3 3       
	H	%	%`P `P `P `P `P$ `P `P `P `P `Pr6   