






import copy

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


UpperCamelCase												=      logging.get_logger(__name__)

UpperCamelCase												=      {
    '''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  __UpperCAmelCase						(_UpperCAmelCase       ):
			__snake_case							: Union[str, Any]							=				"musicgen_decoder"
			__snake_case							: Optional[Any]							=				["past_key_values"]







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







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE       =    vocab_size
									_SCREAMING_SNAKE_CASE       =    max_position_embeddings
									_SCREAMING_SNAKE_CASE       =    hidden_size
									_SCREAMING_SNAKE_CASE       =    ffn_dim
									_SCREAMING_SNAKE_CASE       =    num_hidden_layers
									_SCREAMING_SNAKE_CASE       =    num_attention_heads
									_SCREAMING_SNAKE_CASE       =    dropout
									_SCREAMING_SNAKE_CASE       =    attention_dropout
									_SCREAMING_SNAKE_CASE       =    activation_dropout
									_SCREAMING_SNAKE_CASE       =    activation_function
									_SCREAMING_SNAKE_CASE       =    initializer_factor
									_SCREAMING_SNAKE_CASE       =    layerdrop
									_SCREAMING_SNAKE_CASE       =    use_cache
									_SCREAMING_SNAKE_CASE       =    scale_embedding  # scale factor will be sqrt(d_model) if True
									_SCREAMING_SNAKE_CASE       =    num_codebooks
									super().__init__(
									    pad_token_id=UpperCAmelCase_ ,      bos_token_id=UpperCAmelCase_ ,      eos_token_id=UpperCAmelCase_ ,      tie_word_embeddings=UpperCAmelCase_ ,      **UpperCAmelCase_ ,      )



class  __UpperCAmelCase						(_UpperCAmelCase       ):
			__snake_case							: Optional[Any]							=				"musicgen"
			__snake_case							: Optional[Any]							=				True







			def __init__(      self:    int ,      **UpperCAmelCase_:    List[Any]	):







									'''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"""	)

									_SCREAMING_SNAKE_CASE       =    kwargs.pop("""text_encoder"""	)
									_SCREAMING_SNAKE_CASE       =    text_encoder_config.pop("""model_type"""	)

									_SCREAMING_SNAKE_CASE       =    kwargs.pop("""audio_encoder"""	)
									_SCREAMING_SNAKE_CASE       =    audio_encoder_config.pop("""model_type"""	)

									_SCREAMING_SNAKE_CASE       =    kwargs.pop("""decoder"""	)

									_SCREAMING_SNAKE_CASE       =    AutoConfig.for_model(UpperCAmelCase_ ,      **UpperCAmelCase_	)
									_SCREAMING_SNAKE_CASE       =    AutoConfig.for_model(UpperCAmelCase_ ,      **UpperCAmelCase_	)
									_SCREAMING_SNAKE_CASE       =    MusicgenDecoderConfig(**UpperCAmelCase_	)
									_SCREAMING_SNAKE_CASE       =    True







			@classmethod
			def 				UpperCamelCase (      cls:    Tuple ,      UpperCAmelCase_:    PretrainedConfig ,      UpperCAmelCase_:    PretrainedConfig ,      UpperCAmelCase_:    MusicgenDecoderConfig ,      **UpperCAmelCase_:    Tuple ,      ):







									'''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:    str	):







									'''simple docstring'''




									_SCREAMING_SNAKE_CASE       =    copy.deepcopy(self.__dict__	)
									_SCREAMING_SNAKE_CASE       =    self.text_encoder.to_dict()
									_SCREAMING_SNAKE_CASE       =    self.audio_encoder.to_dict()
									_SCREAMING_SNAKE_CASE       =    self.decoder.to_dict()
									_SCREAMING_SNAKE_CASE       =    self.__class__.model_type
									return output









from ...utils import (
    OptionalDependencyNotAvailable,
    is_torch_available,
    is_transformers_available,
    is_transformers_version,
)


try:
		if not (is_transformers_available() and is_torch_available() and is_transformers_version('''>=''', '''4.27.0''')):
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		from ...utils.dummy_torch_and_transformers_objects import (
		    AudioLDMPipeline,
		)
else:
		from .pipeline_audioldm import AudioLDMPipeline

