
    qin(                         d Z ddlmZ ddlmZ ddlmZ  ej                  e      Z	 G d de      Z
 G d d	e      Zd	dgZy
)zMusicGen model configuration   )PreTrainedConfig)logging   )
AutoConfigc                   `     e Zd ZdZdZdZdgZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fd	Z xZS )MusicgenDecoderConfiga  
    This is the configuration class to store the configuration of an [`MusicgenDecoder`]. It is used to instantiate a
    MusicGen decoder according to the specified arguments, defining the model architecture. Instantiating a
    configuration with the defaults will yield a similar configuration to that of the MusicGen
    [facebook/musicgen-small](https://huggingface.co/facebook/musicgen-small) architecture.

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


    Args:
        vocab_size (`int`, *optional*, defaults to 2048):
            Vocabulary size of the MusicgenDecoder model. Defines the number of different tokens that can be
            represented by the `inputs_ids` passed when calling [`MusicgenDecoder`].
        hidden_size (`int`, *optional*, defaults to 1024):
            Dimensionality of the layers and the pooler layer.
        num_hidden_layers (`int`, *optional*, defaults to 24):
            Number of decoder layers.
        num_attention_heads (`int`, *optional*, defaults to 16):
            Number of attention heads for each attention layer in the Transformer block.
        ffn_dim (`int`, *optional*, defaults to 4096):
            Dimensionality of the "intermediate" (often named feed-forward) layer in the Transformer block.
        activation_function (`str` or `function`, *optional*, defaults to `"gelu"`):
            The non-linear activation function (function or string) in the decoder and pooler. If string, `"gelu"`,
            `"relu"`, `"silu"` and `"gelu_new"` are supported.
        dropout (`float`, *optional*, defaults to 0.1):
            The dropout probability for all fully connected layers in the embeddings, text_encoder, and pooler.
        attention_dropout (`float`, *optional*, defaults to 0.0):
            The dropout ratio for the attention probabilities.
        activation_dropout (`float`, *optional*, defaults to 0.0):
            The dropout ratio for activations inside the fully connected layer.
        max_position_embeddings (`int`, *optional*, defaults to 2048):
            The maximum sequence length that this model might ever be used with. Typically, set this to something large
            just in case (e.g., 512 or 1024 or 2048).
        initializer_factor (`float`, *optional*, defaults to 0.02):
            The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
        layerdrop (`float`, *optional*, defaults to 0.0):
            The LayerDrop probability for the decoder. See the [LayerDrop paper](see https://huggingface.co/papers/1909.11556)
            for more details.
        scale_embedding (`bool`, *optional*, defaults to `False`):
            Scale embeddings by diving by sqrt(hidden_size).
        use_cache (`bool`, *optional*, defaults to `True`):
            Whether the model should return the last key/values attentions (not used by all models)
        num_codebooks (`int`, *optional*, defaults to 4):
            The number of parallel codebooks forwarded to the model.
        tie_word_embeddings(`bool`, *optional*, defaults to `False`):
            Whether input and output word embeddings should be tied.
        audio_channels (`int`, *optional*, defaults to 1
            Number of channels in the audio data. Either 1 for mono or 2 for stereo. Stereo models generate a separate
            audio stream for the left/right output channels. Mono models generate a single audio stream output.
    musicgen_decoderdecoder_configpast_key_valuesc                    || _         || _        || _        || _        || _        |	| _        || _        || _        || _        |
| _	        || _
        || _        || _        || _        || _        || _        || _        || _        |dvrt%        d| d      || _        || _        || _        || _        || _        t1        | d  di | y )N)   r   z4Expected 1 (mono) or 2 (stereo) audio channels, got z
 channels. )
is_decoderadd_cross_attentioncross_attention_hidden_size
vocab_sizemax_position_embeddingshidden_sizeffn_dimnum_hidden_layersnum_attention_headsdropoutattention_dropoutactivation_dropoutactivation_functioninitializer_factor	layerdrop	use_cachescale_embeddingnum_codebooks
ValueErroraudio_channelstie_word_embeddingspad_token_idbos_token_ideos_token_id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                            e/opt/pipecat/venv/lib/python3.12/site-packages/transformers/models/musicgen/configuration_musicgen.pyr(   zMusicgenDecoderConfig.__init__Q   s    6 %#6 +F($'>$&!2#6 !2"4#6 "4"".*'STbSccmnoo,#6 ((("6"    )   r.      i              Tgelui   g?r1   r1   g{Gz?F   r   r.   r.   NFFFN)	__name__
__module____qualname____doc__
model_typebase_config_keykeys_to_ignore_at_inferencer(   __classcell__r+   s   @r,   r   r      so    2h $J&O#4"5  $"!!$(16# 6#r-   r   c                   F     e Zd ZdZdZeeedZdZ fdZ	e
d        Z xZS )MusicgenConfiga  
    This is the configuration class to store the configuration of a [`MusicgenModel`]. It is used to instantiate a
    MusicGen model according to the specified arguments, defining the text encoder, audio encoder and MusicGen decoder
    configs.

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

    Args:
        text_encoder (`Union[dict, `PretrainedConfig`]`):
            An instance of a configuration object that defines the text encoder config.
        audio_encoder (`Union[dict, `PretrainedConfig`]`):
            An instance of a configuration object that defines the audio encoder config.
        decoder (`Union[dict, `PretrainedConfig`]`):
            An instance of a configuration object that defines the decoder config.

    Example:

    ```python
    >>> from transformers import (
    ...     MusicgenConfig,
    ...     MusicgenDecoderConfig,
    ...     T5Config,
    ...     EncodecConfig,
    ...     MusicgenForConditionalGeneration,
    ... )

    >>> # Initializing text encoder, audio encoder, and decoder model configurations
    >>> text_encoder_config = T5Config()
    >>> audio_encoder_config = EncodecConfig()
    >>> decoder_config = MusicgenDecoderConfig()

    >>> configuration = MusicgenConfig(
    ...     text_encoder=text_encoder_config,
    ...     audio_encoder=audio_encoder_config,
    ...     decoder=decoder_config,
    ... )

    >>> # Initializing a MusicgenForConditionalGeneration (with random weights) from the facebook/musicgen-small style configuration
    >>> model = MusicgenForConditionalGeneration(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    >>> config_text_encoder = model.config.text_encoder
    >>> config_audio_encoder = model.config.audio_encoder
    >>> config_decoder = model.config.decoder

    >>> # Saving the model, including its configuration
    >>> model.save_pretrained("musicgen-model")

    >>> # loading model and config from pretrained folder
    >>> musicgen_config = MusicgenConfig.from_pretrained("musicgen-model")
    >>> model = MusicgenForConditionalGeneration.from_pretrained("musicgen-model", config=musicgen_config)
    ```musicgen)text_encoderaudio_encoderdecoderTc                    t        |t              r'|j                  d      }t        j                  |fi |}t        |t              r'|j                  d      }t        j                  |fi |}t        |t              rt        di |}|| _        || _        || _        | j                  j                  | _	        |j                  dd      | _        d|d<   t        | 4  di | y )Nr8   tie_encoder_decoderFTis_encoder_decoderr   )
isinstancedictpopr   	for_modelr   r@   rA   rB   r   getrD   r'   r(   )r)   r@   rA   rB   r*   text_encoder_model_typeaudio_encoder_model_typer+   s          r,   r(   zMusicgenConfig.__init__   s    lD)&2&6&6|&D#%//0GX<XLmT*'4'8'8'F$&001I[][Mgt$+6g6G(*"&,,"A"A#)::.CU#K '+#$"6"r-   c                 .    | j                   j                  S )N)rA   sampling_rate)r)   s    r,   rN   zMusicgenConfig.sampling_rate   s     !!///r-   )r4   r5   r6   r7   r8   r   r   sub_configshas_no_defaults_at_initr(   propertyrN   r;   r<   s   @r,   r>   r>      sA    5n J"#(K
 ##* 0 0r-   r>   N)r7   configuration_utilsr   utilsr   auto.configuration_autor   
get_loggerr4   loggerr   r>   __all__r   r-   r,   <module>rX      sT    # 3  0 
		H	%o#, o#dX0% X0v 4
5r-   