






import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto.configuration_auto import AutoConfig


a      =       logging.get_logger(__name__)

a      =       {
    'facebook/musicgen-small': 'https://huggingface.co/facebook/musicgen-small/resolve/main/config.json',
    # See all Musicgen models at https://huggingface.co/models?filter=musicgen
}
class        __snake_case(					A_      ):
 lowercase :       int		      =		'''musicgen_decoder'''
 lowercase :       Union[str, Any]		      =		['''past_key_values''']



 def __init__(	self   :   str ,		UpperCAmelCase__   :   List[str]=2_048 ,		UpperCAmelCase__   :   Optional[int]=2_048 ,		UpperCAmelCase__   :   List[str]=24 ,		UpperCAmelCase__   :   Dict=4_096 ,		UpperCAmelCase__   :   int=16 ,		UpperCAmelCase__   :   Any=0.0 ,		UpperCAmelCase__   :   List[Any]=True ,		UpperCAmelCase__   :   Optional[Any]="gelu" ,		UpperCAmelCase__   :   Tuple=1_024 ,		UpperCAmelCase__   :   List[Any]=0.1 ,		UpperCAmelCase__   :   Any=0.0 ,		UpperCAmelCase__   :   Dict=0.0 ,		UpperCAmelCase__   :   Optional[Any]=0.02 ,		UpperCAmelCase__   :   int=False ,		UpperCAmelCase__   :   str=4 ,		UpperCAmelCase__   :   Tuple=2_048 ,		UpperCAmelCase__   :   List[str]=2_048 ,		UpperCAmelCase__   :   Union[str, Any]=None ,		UpperCAmelCase__   :   str=False ,		**UpperCAmelCase__   :   Dict ,		):

    """simple docstring"""






    lowercase__						:	List[Any]         = vocab_size
    lowercase__						:	List[Any]         = max_position_embeddings
    lowercase__						:	Optional[Any]         = hidden_size
    lowercase__						:	Dict         = ffn_dim
    lowercase__						:	Union[str, Any]         = num_hidden_layers
    lowercase__						:	str         = num_attention_heads
    lowercase__						:	int         = dropout
    lowercase__						:	Optional[Any]         = attention_dropout
    lowercase__						:	Any         = activation_dropout
    lowercase__						:	int         = activation_function
    lowercase__						:	Tuple         = initializer_factor
    lowercase__						:	Tuple         = layerdrop
    lowercase__						:	Tuple         = use_cache
    lowercase__						:	List[Any]         = scale_embedding  # scale factor will be sqrt(d_model) if True
    lowercase__						:	Any         = num_codebooks
    super().__init__(
        pad_token_id=UpperCAmelCase__ ,		bos_token_id=UpperCAmelCase__ ,		eos_token_id=UpperCAmelCase__ ,		tie_word_embeddings=UpperCAmelCase__ ,		**UpperCAmelCase__ ,		)
class        __snake_case(					A_      ):
 lowercase :       List[Any]		      =		'''musicgen'''
 lowercase :       Any		      =		True



 def __init__(	self   :   Dict ,		**UpperCAmelCase__   :   Tuple	):

    """simple docstring"""






    super().__init__(**UpperCAmelCase__	)
    if "text_encoder" not in kwargs or "audio_encoder" not in kwargs or "decoder" not in kwargs:
       raise ValueError("""Config has to be initialized with text_encoder, audio_encoder and decoder config"""	)

    lowercase__						:	Union[str, Any]         = kwargs.pop("""text_encoder"""	)
    lowercase__						:	List[str]         = text_encoder_config.pop("""model_type"""	)

    lowercase__						:	List[Any]         = kwargs.pop("""audio_encoder"""	)
    lowercase__						:	List[str]         = audio_encoder_config.pop("""model_type"""	)

    lowercase__						:	Union[str, Any]         = kwargs.pop("""decoder"""	)

    lowercase__						:	Dict         = AutoConfig.for_model(UpperCAmelCase__ ,		**UpperCAmelCase__	)
    lowercase__						:	List[Any]         = AutoConfig.for_model(UpperCAmelCase__ ,		**UpperCAmelCase__	)
    lowercase__						:	int         = MusicgenDecoderConfig(**UpperCAmelCase__	)
    lowercase__						:	Optional[int]         = True



 @classmethod
 def 						UpperCAmelCase    (	cls   :   List[Any] ,		UpperCAmelCase__   :   PretrainedConfig ,		UpperCAmelCase__   :   PretrainedConfig ,		UpperCAmelCase__   :   MusicgenDecoderConfig ,		**UpperCAmelCase__   :   List[str] ,		):

    """simple docstring"""






    return cls(
        text_encoder=text_encoder_config.to_dict() ,		audio_encoder=audio_encoder_config.to_dict() ,		decoder=decoder_config.to_dict() ,		**UpperCAmelCase__ ,		)







 def 						UpperCAmelCase    (	self   :   Dict	):

    """simple docstring"""






    lowercase__						:	Optional[Any]         = copy.deepcopy(self.__dict__	)
    lowercase__						:	List[str]         = self.text_encoder.to_dict()
    lowercase__						:	Tuple         = self.audio_encoder.to_dict()
    lowercase__						:	Dict         = self.decoder.to_dict()
    lowercase__						:	Dict         = self.__class__.model_type
    return output










from dataclasses import dataclass
from typing import Callable, Optional

import datasets
@dataclass
class        __snake_case(					datasets.BuilderConfig      ):
 lowercase :       Optional[Callable]		      =		None
 lowercase :       Optional[dict]		      =		None
 lowercase :       Optional[datasets.Features]		      =		None



 def 						UpperCAmelCase    (	self   :   int	):

    """simple docstring"""






    assert self.generator is not None, "generator must be specified"

    if self.gen_kwargs is None:
       lowercase__						:	List[Any]         = {}
class        __snake_case(					datasets.GeneratorBasedBuilder      ):
 lowercase :       Dict		      =		GeneratorConfig



 def 						UpperCAmelCase    (	self   :   Any	):

    """simple docstring"""






    return datasets.DatasetInfo(features=self.config.features	)



 def 						UpperCAmelCase    (	self   :   List[str] ,		UpperCAmelCase__   :   Optional[int]	):

    """simple docstring"""






    return [datasets.SplitGenerator(name=datasets.Split.TRAIN ,		gen_kwargs=self.config.gen_kwargs	)]







 def 						UpperCAmelCase    (	self   :   Dict ,		**UpperCAmelCase__   :   List[str]	):

    """simple docstring"""






    for idx, ex in enumerate(self.config.generator(**UpperCAmelCase__	)	):
       yield idx, ex


