





import copy

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


_lowerCamelCase       =	logging.get_logger(__name__)

_lowerCamelCase       =	{
    '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__			):
							lowerCamelCase_							=    "musicgen_decoder"
							lowerCamelCase_							=    ["past_key_values"]


							def __init__(							self			:Tuple							, __A			:int=2048							, __A			:Union[str, Any]=2048							, __A			:Optional[Any]=24							, __A			:Any=4096							, __A			:Tuple=16							, __A			:int=0.0							, __A			:Tuple=True							, __A			:int="gelu"							, __A			:Any=1024							, __A			:Tuple=0.1							, __A			:List[str]=0.0							, __A			:Optional[Any]=0.0							, __A			:Dict=0.0_2							, __A			:Any=False							, __A			:str=4							, __A			:List[Any]=2048							, __A			:List[Any]=2048							, __A			:Any=None							, __A			:str=False							, **__A			:Optional[int]							, )      ->      Any:



									"""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=__A							, bos_token_id=__A							, eos_token_id=__A							, tie_word_embeddings=__A							, **__A							, )




class      UpperCamelCase_				(   UpperCamelCase__			):
							lowerCamelCase_							=    "musicgen"
							lowerCamelCase_							=    True


							def __init__(							self			:Tuple							, **__A			:int						)      ->      Tuple:



									"""simple docstring"""



									super().__init__(**__A						)
									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(__A							, **__A						)
									SCREAMING_SNAKE_CASE__								=					AutoConfig.for_model(__A							, **__A						)
									SCREAMING_SNAKE_CASE__								=					MusicgenDecoderConfig(**__A						)
									SCREAMING_SNAKE_CASE__								=					True


							@classmethod
							def    _snake_case     (							cls			:Tuple							, __A			:PretrainedConfig							, __A			:PretrainedConfig							, __A			:MusicgenDecoderConfig							, **__A			:Dict							, )      ->      str:



									"""simple docstring"""



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


							def    _snake_case     (							self			:Union[str, Any]						)      ->      List[Any]:



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






import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin




class      UpperCamelCase_				(   UpperCamelCase__			):
							lowerCamelCase_							=    ["image_processor", "tokenizer"]
							lowerCamelCase_							=    "AutoImageProcessor"
							lowerCamelCase_							=    "AutoTokenizer"


							def __init__(							self			:Any							, __A			:List[str]=None							, __A			:Dict=None							, **__A			:List[str]						)      ->      List[Any]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=					None
									if "feature_extractor" in kwargs:
											warnings.warn(
											    """The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"""
											    """ instead."""							, __A							, )
											SCREAMING_SNAKE_CASE__								=					kwargs.pop("""feature_extractor"""						)

									SCREAMING_SNAKE_CASE__								=					image_processor if image_processor is not None else feature_extractor
									if image_processor is None:
											raise ValueError("""You need to specify an `image_processor`."""						)
									if tokenizer is None:
											raise ValueError("""You need to specify a `tokenizer`."""						)

									super().__init__(__A							, __A						)
									SCREAMING_SNAKE_CASE__								=					self.image_processor
									SCREAMING_SNAKE_CASE__								=					False


							def __call__(							self			:List[str]							, *__A			:int							, **__A			:Optional[int]						)      ->      Optional[Any]:



									"""simple docstring"""



									if self._in_target_context_manager:
											return self.current_processor(*__A							, **__A						)

									SCREAMING_SNAKE_CASE__								=					kwargs.pop("""images"""							, __A						)
									SCREAMING_SNAKE_CASE__								=					kwargs.pop("""text"""							, __A						)
									if len(__A						) > 0:
											SCREAMING_SNAKE_CASE__								=					args[0]
											SCREAMING_SNAKE_CASE__								=					args[1:]

									if images is None and text is None:
											raise ValueError("""You need to specify either an `images` or `text` input to process."""						)

									if images is not None:
											SCREAMING_SNAKE_CASE__								=					self.image_processor(__A							, *__A							, **__A						)
									if text is not None:
											SCREAMING_SNAKE_CASE__								=					self.tokenizer(__A							, **__A						)

									if text is None:
											return inputs
									elif images is None:
											return encodings
									else:
											SCREAMING_SNAKE_CASE__								=					encodings["""input_ids"""]
											return inputs


							def    _snake_case     (							self			:Any							, *__A			:Optional[Any]							, **__A			:int						)      ->      List[Any]:



									"""simple docstring"""



									return self.tokenizer.batch_decode(*__A							, **__A						)


							def    _snake_case     (							self			:str							, *__A			:Optional[int]							, **__A			:List[Any]						)      ->      List[str]:



									"""simple docstring"""



									return self.tokenizer.decode(*__A							, **__A						)


							@contextmanager
							def    _snake_case     (							self			:Dict						)      ->      List[str]:



									"""simple docstring"""



									warnings.warn(
									    """`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your """
									    """labels by using the argument `text` of the regular `__call__` method (either in the same call as """
									    """your images inputs, or in a separate call."""						)
									SCREAMING_SNAKE_CASE__								=					True
									SCREAMING_SNAKE_CASE__								=					self.tokenizer
									yield
									SCREAMING_SNAKE_CASE__								=					self.image_processor
									SCREAMING_SNAKE_CASE__								=					False


							@property
							def    _snake_case     (							self			:List[str]						)      ->      int:



									"""simple docstring"""



									warnings.warn(
									    """`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."""							, __A							, )
									return self.image_processor_class


							@property
							def    _snake_case     (							self			:str						)      ->      List[Any]:



									"""simple docstring"""



									warnings.warn(
									    """`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."""							, __A							, )
									return self.image_processor