





import copy

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


__A    :   Optional[Any]          =       logging.get_logger(__name__)

__A    :   Union[str, Any]          =       {
    """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      A_	(a_      ):
	UpperCAmelCase__ =      '''musicgen_decoder'''
	UpperCAmelCase__ =      ['''past_key_values''']
	def __init__(   self							, _A=2_0_4_8							, _A=2_0_4_8							, _A=2_4							, _A=4_0_9_6							, _A=1_6							, _A=0.0							, _A=True							, _A="gelu"							, _A=1_0_2_4							, _A=0.1							, _A=0.0							, _A=0.0							, _A=0.02							, _A=False							, _A=4							, _A=2_0_4_8							, _A=2_0_4_8							, _A=None							, _A=False							, **_A							, ):






						'''simple docstring'''







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

class      A_	(a_      ):
	UpperCAmelCase__ =      '''musicgen'''
	UpperCAmelCase__ =      True
	def __init__(   self							, **_A		):






						'''simple docstring'''







						super().__init__(**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'''		)

						UpperCAmelCase       		=    kwargs.pop('''text_encoder'''		)
						UpperCAmelCase       		=    text_encoder_config.pop('''model_type'''		)

						UpperCAmelCase       		=    kwargs.pop('''audio_encoder'''		)
						UpperCAmelCase       		=    audio_encoder_config.pop('''model_type'''		)

						UpperCAmelCase       		=    kwargs.pop('''decoder'''		)

						UpperCAmelCase       		=    AutoConfig.for_model(snake_case__							, **snake_case__		)
						UpperCAmelCase       		=    AutoConfig.for_model(snake_case__							, **snake_case__		)
						UpperCAmelCase       		=    MusicgenDecoderConfig(**snake_case__		)
						UpperCAmelCase       		=    True
	@classmethod
	def 					_lowercase    (   cls							, _A							, _A							, _A							, **_A							, ):






						'''simple docstring'''







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







	def 					_lowercase    (   self		):






						'''simple docstring'''







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










import json
import os
import tempfile
import unittest

from transformers.modelcard import ModelCard

class      A_	(unittest.TestCase      ):
	def 					_lowercase    (   self		):






				'''simple docstring'''







				UpperCAmelCase       		=    {
				    '''model_details''': {
				        '''Organization''': '''testing''',
				        '''Model date''': '''today''',
				        '''Model version''': '''v2.1, Developed by Test Corp in 2019.''',
				        '''Architecture''': '''Convolutional Neural Network.''',
				    },
				    '''metrics''': '''BLEU and ROUGE-1''',
				    '''evaluation_data''': {
				        '''Datasets''': {'''BLEU''': '''My-great-dataset-v1''', '''ROUGE-1''': '''My-short-dataset-v2.1'''},
				        '''Preprocessing''': '''See details on https://arxiv.org/pdf/1810.03993.pdf''',
				    },
				    '''training_data''': {
				        '''Dataset''': '''English Wikipedia dump dated 2018-12-01''',
				        '''Preprocessing''': (
				            '''Using SentencePiece vocabulary of size 52k tokens. See details on'''
				            ''' https://arxiv.org/pdf/1810.03993.pdf'''
				        ),
				    },
				    '''quantitative_analyses''': {'''BLEU''': 55.1, '''ROUGE-1''': 7_6},
				}
	def 					_lowercase    (   self		):






				'''simple docstring'''







				UpperCAmelCase       		=    ModelCard.from_dict(self.inputs_dict		)
				self.assertTrue(hasattr(_A							, '''model_details'''		)		)
				self.assertTrue(hasattr(_A							, '''intended_use'''		)		)
				self.assertTrue(hasattr(_A							, '''factors'''		)		)
				self.assertTrue(hasattr(_A							, '''metrics'''		)		)
				self.assertTrue(hasattr(_A							, '''evaluation_data'''		)		)
				self.assertTrue(hasattr(_A							, '''training_data'''		)		)
				self.assertTrue(hasattr(_A							, '''quantitative_analyses'''		)		)
				self.assertTrue(hasattr(_A							, '''ethical_considerations'''		)		)
				self.assertTrue(hasattr(_A							, '''caveats_and_recommendations'''		)		)
	def 					_lowercase    (   self		):






				'''simple docstring'''







				UpperCAmelCase       		=    ModelCard.from_dict(self.inputs_dict		)
				UpperCAmelCase       		=    json.loads(modelcard.to_json_string()		)
				for key, value in self.inputs_dict.items():
							self.assertEqual(obj[key]							, _A		)
	def 					_lowercase    (   self		):






				'''simple docstring'''







				UpperCAmelCase       		=    ModelCard.from_dict(self.inputs_dict		)

				with tempfile.TemporaryDirectory() as tmpdirname:
							UpperCAmelCase       		=    os.path.join(_A							, '''modelcard.json'''		)
							model_card_first.to_json_file(_A		)
							UpperCAmelCase       		=    ModelCard.from_json_file(_A		)

				self.assertEqual(model_card_second.to_dict()							, model_card_first.to_dict()		)







	def 					_lowercase    (   self		):






				'''simple docstring'''







				UpperCAmelCase       		=    ModelCard.from_dict(self.inputs_dict		)

				with tempfile.TemporaryDirectory() as tmpdirname:
							model_card_first.save_pretrained(_A		)
							UpperCAmelCase       		=    ModelCard.from_pretrained(_A		)

				self.assertEqual(model_card_second.to_dict()							, model_card_first.to_dict()		)



