




"""simple docstring"""





import copy

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


_lowercase		 =      logging.get_logger(__name__)

_lowercase		 =      {
    """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  __lowercase    (     snake_case_		):


				'''simple docstring'''


				_lowerCAmelCase		     ="musicgen_decoder"
				_lowerCAmelCase		     =["past_key_values"]

				def __init__(				self				:       Tuple ,SCREAMING_SNAKE_CASE_				:       Optional[int]=2_0_4_8 ,SCREAMING_SNAKE_CASE_				:       Union[str, Any]=2_0_4_8 ,SCREAMING_SNAKE_CASE_				:       Union[str, Any]=2_4 ,SCREAMING_SNAKE_CASE_				:       List[Any]=4_0_9_6 ,SCREAMING_SNAKE_CASE_				:       Union[str, Any]=1_6 ,SCREAMING_SNAKE_CASE_				:       Optional[int]=0.0 ,SCREAMING_SNAKE_CASE_				:       str=True ,SCREAMING_SNAKE_CASE_				:       Any="gelu" ,SCREAMING_SNAKE_CASE_				:       List[str]=1_0_2_4 ,SCREAMING_SNAKE_CASE_				:       int=0.1 ,SCREAMING_SNAKE_CASE_				:       Dict=0.0 ,SCREAMING_SNAKE_CASE_				:       int=0.0 ,SCREAMING_SNAKE_CASE_				:       int=0.02 ,SCREAMING_SNAKE_CASE_				:       str=False ,SCREAMING_SNAKE_CASE_				:       str=4 ,SCREAMING_SNAKE_CASE_				:       Dict=2_0_4_8 ,SCREAMING_SNAKE_CASE_				:       Tuple=2_0_4_8 ,SCREAMING_SNAKE_CASE_				:       Tuple=None ,SCREAMING_SNAKE_CASE_				:       List[str]=False ,**SCREAMING_SNAKE_CASE_				:       Dict ,):
										snake_case__    :   int							     =   vocab_size
										snake_case__    :   Dict							     =   max_position_embeddings
										snake_case__    :   Optional[int]							     =   hidden_size
										snake_case__    :   List[Any]							     =   ffn_dim
										snake_case__    :   List[Any]							     =   num_hidden_layers
										snake_case__    :   Union[str, Any]							     =   num_attention_heads
										snake_case__    :   Optional[Any]							     =   dropout
										snake_case__    :   Any							     =   attention_dropout
										snake_case__    :   Union[str, Any]							     =   activation_dropout
										snake_case__    :   Tuple							     =   activation_function
										snake_case__    :   List[str]							     =   initializer_factor
										snake_case__    :   List[str]							     =   layerdrop
										snake_case__    :   List[str]							     =   use_cache
										snake_case__    :   Any							     =   scale_embedding  # scale factor will be sqrt(d_model) if True
										snake_case__    :   Union[str, Any]							     =   num_codebooks
										super().__init__(
										    pad_token_id=SCREAMING_SNAKE_CASE_ ,bos_token_id=SCREAMING_SNAKE_CASE_ ,eos_token_id=SCREAMING_SNAKE_CASE_ ,tie_word_embeddings=SCREAMING_SNAKE_CASE_ ,**SCREAMING_SNAKE_CASE_ ,)







class  __lowercase    (     snake_case_		):


				'''simple docstring'''


				_lowerCAmelCase		     ="musicgen"
				_lowerCAmelCase		     =True

				def __init__(				self				:       List[Any] ,**SCREAMING_SNAKE_CASE_				:       Dict ):
										super().__init__(**SCREAMING_SNAKE_CASE_ )
										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''' )

										snake_case__    :   Optional[int]							     =   kwargs.pop('''text_encoder''' )
										snake_case__    :   Dict							     =   text_encoder_config.pop('''model_type''' )

										snake_case__    :   Union[str, Any]							     =   kwargs.pop('''audio_encoder''' )
										snake_case__    :   Tuple							     =   audio_encoder_config.pop('''model_type''' )

										snake_case__    :   Optional[int]							     =   kwargs.pop('''decoder''' )

										snake_case__    :   str							     =   AutoConfig.for_model(SCREAMING_SNAKE_CASE_ ,**SCREAMING_SNAKE_CASE_ )
										snake_case__    :   int							     =   AutoConfig.for_model(SCREAMING_SNAKE_CASE_ ,**SCREAMING_SNAKE_CASE_ )
										snake_case__    :   Optional[Any]							     =   MusicgenDecoderConfig(**SCREAMING_SNAKE_CASE_ )
										snake_case__    :   Optional[int]							     =   True

				@classmethod
				def  _lowerCamelCase   (				cls				:       Union[str, Any] ,SCREAMING_SNAKE_CASE_				:       PretrainedConfig ,SCREAMING_SNAKE_CASE_				:       PretrainedConfig ,SCREAMING_SNAKE_CASE_				:       MusicgenDecoderConfig ,**SCREAMING_SNAKE_CASE_				:       str ,):
										return cls(
										    text_encoder=text_encoder_config.to_dict() ,audio_encoder=audio_encoder_config.to_dict() ,decoder=decoder_config.to_dict() ,**SCREAMING_SNAKE_CASE_ ,)





				def  _lowerCamelCase   (				self				:       Dict ):
										snake_case__    :   str							     =   copy.deepcopy(self.__dict__ )
										snake_case__    :   Dict							     =   self.text_encoder.to_dict()
										snake_case__    :   List[str]							     =   self.audio_encoder.to_dict()
										snake_case__    :   Union[str, Any]							     =   self.decoder.to_dict()
										snake_case__    :   Union[str, Any]							     =   self.__class__.model_type
										return output








"""simple docstring"""





class  __lowercase    :


				'''simple docstring'''


				class  __lowercase    :


								'''simple docstring'''


								_lowerCAmelCase		     ="_prev", "_data", "_next"

								def __init__(				self				:       List[Any] ,SCREAMING_SNAKE_CASE_				:       int ,SCREAMING_SNAKE_CASE_				:       Union[str, Any] ,SCREAMING_SNAKE_CASE_				:       Any ):
														snake_case__    :   Any							     =   link_p
														snake_case__    :   List[str]							     =   element
														snake_case__    :   str							     =   link_n





								def  _lowerCamelCase   (				self				:       Optional[Any] ):
														return (
														    F''' Prev -> {self._prev is not None}, Next -> {self._next is not None}'''
														)







				def __init__(				self				:       Any ):
										snake_case__    :   int							     =   self._Node(SCREAMING_SNAKE_CASE_ ,SCREAMING_SNAKE_CASE_ ,SCREAMING_SNAKE_CASE_ )
										snake_case__    :   Optional[int]							     =   self._Node(SCREAMING_SNAKE_CASE_ ,SCREAMING_SNAKE_CASE_ ,SCREAMING_SNAKE_CASE_ )
										snake_case__    :   Union[str, Any]							     =   self._trailer
										snake_case__    :   Union[str, Any]							     =   self._header
										snake_case__    :   Any							     =   0

				def __len__(				self				:       str ):
										return self._size

				def  _lowerCamelCase   (				self				:       Union[str, Any] ):
										return self.__len__() == 0

				def  _lowerCamelCase   (				self				:       Any ,SCREAMING_SNAKE_CASE_				:       List[Any] ,SCREAMING_SNAKE_CASE_				:       List[str] ,SCREAMING_SNAKE_CASE_				:       Dict ):
										# Create new_node by setting it's prev.link -> header
										# setting it's next.link -> trailer
										snake_case__    :   Dict							     =   self._Node(SCREAMING_SNAKE_CASE_ ,SCREAMING_SNAKE_CASE_ ,SCREAMING_SNAKE_CASE_ )
										snake_case__    :   Any							     =   new_node
										snake_case__    :   str							     =   new_node
										self._size += 1
										return self





				def  _lowerCamelCase   (				self				:       Union[str, Any] ,SCREAMING_SNAKE_CASE_				:       Dict ):
										snake_case__    :   Union[str, Any]							     =   node._prev
										snake_case__    :   Union[str, Any]							     =   node._next

										snake_case__    :   List[Any]							     =   successor
										snake_case__    :   Dict							     =   predecessor
										self._size -= 1
										snake_case__    :   Dict							     =   node._data
										snake_case__    :   List[str]							     =   None
										del node
										return temp







class  __lowercase    (     _DoublyLinkedBase		):


				'''simple docstring'''


				def  _lowerCamelCase   (				self				:       Optional[int] ):
										if self.is_empty():
																raise Exception('''List is empty''' )
										return self._header._next._data

				def  _lowerCamelCase   (				self				:       Union[str, Any] ):
										if self.is_empty():
																raise Exception('''List is empty''' )
										return self._trailer._prev._data

				def  _lowerCamelCase   (				self				:       Any ,SCREAMING_SNAKE_CASE_				:       Dict ):
										return self._insert(self._header ,SCREAMING_SNAKE_CASE_ ,self._header._next )

				def  _lowerCamelCase   (				self				:       Dict ,SCREAMING_SNAKE_CASE_				:       Union[str, Any] ):
										return self._insert(self._trailer._prev ,SCREAMING_SNAKE_CASE_ ,self._trailer )

				def  _lowerCamelCase   (				self				:       Optional[int] ):
										if self.is_empty():
																raise IndexError('''remove_first from empty list''' )
										return self._delete(self._header._next )





				def  _lowerCamelCase   (				self				:       Optional[Any] ):
										if self.is_empty():
																raise IndexError('''remove_first from empty list''' )
										return self._delete(self._trailer._prev )


