'''simple docstring'''




import unittest

from transformers import FunnelConfig, FunnelTokenizer, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
  import torch

  from transformers import (
      MODEL_FOR_PRETRAINING_MAPPING,
      FunnelBaseModel,
      FunnelForMaskedLM,
      FunnelForMultipleChoice,
      FunnelForPreTraining,
      FunnelForQuestionAnswering,
      FunnelForSequenceClassification,
      FunnelForTokenClassification,
      FunnelModel,
  )




class 					a__   :






     def __init__(				self	:	Optional[Any]						,       a	:	int						,       a	:	List[Any]=13						,       a	:	Any=7						,       a	:	Any=True						,       a	:	List[Any]=True						,       a	:	Tuple=True						,       a	:	str=True						,       a	:	Union[str, Any]=99						,       a	:	Tuple=[1, 1, 2]						,       a	:	List[str]=1						,       a	:	Any=32						,       a	:	List[Any]=4						,       a	:	Tuple=8						,       a	:	List[str]=37						,       a	:	Optional[Any]="gelu_new"						,       a	:	int=0.1						,       a	:	int=0.1						,       a	:	Tuple=0.0						,       a	:	Any=5_12						,       a	:	List[str]=3						,       a	:	Union[str, Any]=0.02						,       a	:	Tuple=3						,       a	:	List[Any]=4						,       a	:	Any=None						,       a	:	str=False						,       ):





         """simple docstring"""



         __lowerCamelCase						=						parent
         __lowerCamelCase						=						batch_size
         __lowerCamelCase						=						seq_length
         __lowerCamelCase						=						is_training
         __lowerCamelCase						=						use_input_mask
         __lowerCamelCase						=						use_token_type_ids
         __lowerCamelCase						=						use_labels
         __lowerCamelCase						=						vocab_size
         __lowerCamelCase						=						block_sizes
         __lowerCamelCase						=						num_decoder_layers
         __lowerCamelCase						=						d_model
         __lowerCamelCase						=						n_head
         __lowerCamelCase						=						d_head
         __lowerCamelCase						=						d_inner
         __lowerCamelCase						=						hidden_act
         __lowerCamelCase						=						hidden_dropout
         __lowerCamelCase						=						attention_dropout
         __lowerCamelCase						=						activation_dropout
         __lowerCamelCase						=						max_position_embeddings
         __lowerCamelCase						=						type_vocab_size
         __lowerCamelCase						=						2
         __lowerCamelCase						=						num_labels
         __lowerCamelCase						=						num_choices
         __lowerCamelCase						=						scope
         __lowerCamelCase						=						initializer_std

         # Used in the tests to check the size of the first attention layer
         __lowerCamelCase						=						n_head
         # Used in the tests to check the size of the first hidden state
         __lowerCamelCase						=						self.d_model
         # Used in the tests to check the number of output hidden states/attentions
         __lowerCamelCase						=						sum(self.block_sizes					) + (0 if base else self.num_decoder_layers)
         # FunnelModel adds two hidden layers: input embeddings and the sum of the upsampled encoder hidden state with
         # the last hidden state of the first block (which is the first hidden state of the decoder).
         if not base:
             __lowerCamelCase						=						self.num_hidden_layers + 2






     def      SCREAMING_SNAKE_CASE__     (				self	:	str					):





         """simple docstring"""



         __lowerCamelCase						=						ids_tensor([self.batch_size, self.seq_length]						,       self.vocab_size					)

         __lowerCamelCase						=						None
         if self.use_input_mask:
             __lowerCamelCase						=						ids_tensor([self.batch_size, self.seq_length]						,       vocab_size=2					)

         __lowerCamelCase						=						None
         if self.use_token_type_ids:
             __lowerCamelCase						=						ids_tensor([self.batch_size, self.seq_length]						,       self.type_vocab_size					)

         __lowerCamelCase						=						None
         __lowerCamelCase						=						None
         __lowerCamelCase						=						None
         if self.use_labels:
             __lowerCamelCase						=						ids_tensor([self.batch_size]						,       self.type_sequence_label_size					)
             __lowerCamelCase						=						ids_tensor([self.batch_size, self.seq_length]						,       self.num_labels					)
             __lowerCamelCase						=						ids_tensor([self.batch_size]						,       self.num_choices					)
             __lowerCamelCase						=						ids_tensor([self.batch_size, self.seq_length]						,       1					)

         __lowerCamelCase						=						self.get_config()

         return (
             config,
             input_ids,
             token_type_ids,
             input_mask,
             sequence_labels,
             token_labels,
             choice_labels,
             fake_token_labels,
         )






     def      SCREAMING_SNAKE_CASE__     (				self	:	Union[str, Any]					):





         """simple docstring"""



         return FunnelConfig(
             vocab_size=self.vocab_size						,       block_sizes=self.block_sizes						,       num_decoder_layers=self.num_decoder_layers						,       d_model=self.d_model						,       n_head=self.n_head						,       d_head=self.d_head						,       d_inner=self.d_inner						,       hidden_act=self.hidden_act						,       hidden_dropout=self.hidden_dropout						,       attention_dropout=self.attention_dropout						,       activation_dropout=self.activation_dropout						,       max_position_embeddings=self.max_position_embeddings						,       type_vocab_size=self.type_vocab_size						,       initializer_std=self.initializer_std						,       )






     def      SCREAMING_SNAKE_CASE__     (				self	:	Any						,       a	:	Tuple						,       a	:	Tuple						,       a	:	int						,       a	:	Any						,       a	:	List[Any]						,       a	:	List[str]						,       a	:	Any						,       a	:	Tuple						,       ):





         """simple docstring"""



         __lowerCamelCase						=						FunnelModel(config=a					)
         model.to(a					)
         model.eval()
         __lowerCamelCase						=						model(a						,       attention_mask=a						,       token_type_ids=a					)
         __lowerCamelCase						=						model(a						,       token_type_ids=a					)
         __lowerCamelCase						=						model(a					)
         self.parent.assertEqual(result.last_hidden_state.shape						,       (self.batch_size, self.seq_length, self.d_model)					)

         __lowerCamelCase						=						False
         __lowerCamelCase						=						model(a					)
         self.parent.assertEqual(result.last_hidden_state.shape						,       (self.batch_size, self.seq_length, self.d_model)					)

         __lowerCamelCase						=						False
         __lowerCamelCase						=						model(a					)
         self.parent.assertEqual(result.last_hidden_state.shape						,       (self.batch_size, self.seq_length, self.d_model)					)






     def      SCREAMING_SNAKE_CASE__     (				self	:	int						,       a	:	Dict						,       a	:	Union[str, Any]						,       a	:	str						,       a	:	Union[str, Any]						,       a	:	List[Any]						,       a	:	Optional[int]						,       a	:	Union[str, Any]						,       a	:	Dict						,       ):





         """simple docstring"""



         __lowerCamelCase						=						FunnelBaseModel(config=a					)
         model.to(a					)
         model.eval()
         __lowerCamelCase						=						model(a						,       attention_mask=a						,       token_type_ids=a					)
         __lowerCamelCase						=						model(a						,       token_type_ids=a					)
         __lowerCamelCase						=						model(a					)
         self.parent.assertEqual(result.last_hidden_state.shape						,       (self.batch_size, 2, self.d_model)					)

         __lowerCamelCase						=						False
         __lowerCamelCase						=						model(a					)
         self.parent.assertEqual(result.last_hidden_state.shape						,       (self.batch_size, 3, self.d_model)					)

         __lowerCamelCase						=						False
         __lowerCamelCase						=						model(a					)
         self.parent.assertEqual(result.last_hidden_state.shape						,       (self.batch_size, 2, self.d_model)					)






     def      SCREAMING_SNAKE_CASE__     (				self	:	List[Any]						,       a	:	Dict						,       a	:	List[Any]						,       a	:	Dict						,       a	:	List[Any]						,       a	:	Optional[int]						,       a	:	Optional[int]						,       a	:	int						,       a	:	List[Any]						,       ):





         """simple docstring"""



         __lowerCamelCase						=						self.num_labels
         __lowerCamelCase						=						FunnelForPreTraining(config=a					)
         model.to(a					)
         model.eval()
         __lowerCamelCase						=						model(a						,       attention_mask=a						,       token_type_ids=a						,       labels=a					)
         self.parent.assertEqual(result.logits.shape						,       (self.batch_size, self.seq_length)					)






     def      SCREAMING_SNAKE_CASE__     (				self	:	Any						,       a	:	Optional[Any]						,       a	:	int						,       a	:	Union[str, Any]						,       a	:	Union[str, Any]						,       a	:	Optional[Any]						,       a	:	Tuple						,       a	:	int						,       a	:	Dict						,       ):





         """simple docstring"""



         __lowerCamelCase						=						FunnelForMaskedLM(config=a					)
         model.to(a					)
         model.eval()
         __lowerCamelCase						=						model(a						,       attention_mask=a						,       token_type_ids=a						,       labels=a					)
         self.parent.assertEqual(result.logits.shape						,       (self.batch_size, self.seq_length, self.vocab_size)					)






     def      SCREAMING_SNAKE_CASE__     (				self	:	int						,       a	:	Tuple						,       a	:	Dict						,       a	:	Union[str, Any]						,       a	:	Any						,       a	:	Union[str, Any]						,       a	:	Optional[int]						,       a	:	Any						,       a	:	str						,       ):





         """simple docstring"""



         __lowerCamelCase						=						self.num_labels
         __lowerCamelCase						=						FunnelForSequenceClassification(a					)
         model.to(a					)
         model.eval()
         __lowerCamelCase						=						model(a						,       attention_mask=a						,       token_type_ids=a						,       labels=a					)
         self.parent.assertEqual(result.logits.shape						,       (self.batch_size, self.num_labels)					)






     def      SCREAMING_SNAKE_CASE__     (				self	:	Dict						,       a	:	Tuple						,       a	:	List[str]						,       a	:	Union[str, Any]						,       a	:	str						,       a	:	Tuple						,       a	:	List[str]						,       a	:	Union[str, Any]						,       a	:	Tuple						,       ):





         """simple docstring"""



         __lowerCamelCase						=						self.num_choices
         __lowerCamelCase						=						FunnelForMultipleChoice(config=a					)
         model.to(a					)
         model.eval()
         __lowerCamelCase						=						input_ids.unsqueeze(1					).expand(-1						,       self.num_choices						,       -1					).contiguous()
         __lowerCamelCase						=						token_type_ids.unsqueeze(1					).expand(-1						,       self.num_choices						,       -1					).contiguous()
         __lowerCamelCase						=						input_mask.unsqueeze(1					).expand(-1						,       self.num_choices						,       -1					).contiguous()
         __lowerCamelCase						=						model(
             a						,       attention_mask=a						,       token_type_ids=a						,       labels=a						,       )
         self.parent.assertEqual(result.logits.shape						,       (self.batch_size, self.num_choices)					)






     def      SCREAMING_SNAKE_CASE__     (				self	:	Optional[Any]						,       a	:	List[str]						,       a	:	Union[str, Any]						,       a	:	Optional[Any]						,       a	:	Optional[Any]						,       a	:	Any						,       a	:	Union[str, Any]						,       a	:	Any						,       a	:	Union[str, Any]						,       ):





         """simple docstring"""



         __lowerCamelCase						=						self.num_labels
         __lowerCamelCase						=						FunnelForTokenClassification(config=a					)
         model.to(a					)
         model.eval()
         __lowerCamelCase						=						model(a						,       attention_mask=a						,       token_type_ids=a						,       labels=a					)
         self.parent.assertEqual(result.logits.shape						,       (self.batch_size, self.seq_length, self.num_labels)					)






     def      SCREAMING_SNAKE_CASE__     (				self	:	Tuple						,       a	:	Union[str, Any]						,       a	:	List[str]						,       a	:	Optional[Any]						,       a	:	List[Any]						,       a	:	List[str]						,       a	:	List[Any]						,       a	:	str						,       a	:	str						,       ):





         """simple docstring"""



         __lowerCamelCase						=						FunnelForQuestionAnswering(config=a					)
         model.to(a					)
         model.eval()
         __lowerCamelCase						=						model(
             a						,       attention_mask=a						,       token_type_ids=a						,       start_positions=a						,       end_positions=a						,       )
         self.parent.assertEqual(result.start_logits.shape						,       (self.batch_size, self.seq_length)					)
         self.parent.assertEqual(result.end_logits.shape						,       (self.batch_size, self.seq_length)					)






     def      SCREAMING_SNAKE_CASE__     (				self	:	Any					):





         """simple docstring"""



         __lowerCamelCase						=						self.prepare_config_and_inputs()
         (
             (
             __lowerCamelCase
         )			,						(
             __lowerCamelCase
         )			,						(
             __lowerCamelCase
         )			,						(
             __lowerCamelCase
         )			,						(
             __lowerCamelCase
         )			,						(
             __lowerCamelCase
         )			,						(
             __lowerCamelCase
         )			,						(
             __lowerCamelCase
         )			,						
         )						=						config_and_inputs
         __lowerCamelCase						=						{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
         return config, inputs_dict




@require_torch
class 					a__   (     UpperCAmelCase__							,     UpperCAmelCase__							,     unittest.TestCase				):
     lowerCamelCase						:  Dict							=False
     lowerCamelCase						:  Any							=False
     lowerCamelCase						:  Optional[int]							=(
         (
             FunnelModel,
             FunnelForMaskedLM,
             FunnelForPreTraining,
             FunnelForQuestionAnswering,
             FunnelForTokenClassification,
         )
         if is_torch_available()
         else ()
     )
     lowerCamelCase						:  int							=(
         {
             "feature-extraction": (FunnelBaseModel, FunnelModel),
             "fill-mask": FunnelForMaskedLM,
             "question-answering": FunnelForQuestionAnswering,
             "text-classification": FunnelForSequenceClassification,
             "token-classification": FunnelForTokenClassification,
             "zero-shot": FunnelForSequenceClassification,
         }
         if is_torch_available()
         else {}
     )






     def      SCREAMING_SNAKE_CASE__     (				self	:	List[str]						,       a	:	Any						,       a	:	Union[str, Any]						,       a	:	int=False					):





         """simple docstring"""



         __lowerCamelCase						=						super()._prepare_for_class(a						,       a						,       return_labels=a					)

         if return_labels:
             if model_class in get_values(a					):
                 __lowerCamelCase						=						torch.zeros(
                     (self.model_tester.batch_size, self.model_tester.seq_length)						,       dtype=torch.long						,       device=a					)
         return inputs_dict






     def      SCREAMING_SNAKE_CASE__     (				self	:	Dict					):





         """simple docstring"""



         __lowerCamelCase						=						FunnelModelTester(self					)
         __lowerCamelCase						=						ConfigTester(self						,       config_class=a					)






     def      SCREAMING_SNAKE_CASE__     (				self	:	Any					):





         """simple docstring"""



         self.config_tester.run_common_tests()






     def      SCREAMING_SNAKE_CASE__     (				self	:	str					):





         """simple docstring"""



         __lowerCamelCase						=						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*a					)






     def      SCREAMING_SNAKE_CASE__     (				self	:	Optional[int]					):





         """simple docstring"""



         __lowerCamelCase						=						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_pretraining(*a					)






     def      SCREAMING_SNAKE_CASE__     (				self	:	Dict					):





         """simple docstring"""



         __lowerCamelCase						=						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_masked_lm(*a					)






     def      SCREAMING_SNAKE_CASE__     (				self	:	List[str]					):





         """simple docstring"""



         __lowerCamelCase						=						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_token_classification(*a					)






     def      SCREAMING_SNAKE_CASE__     (				self	:	List[str]					):





         """simple docstring"""



         __lowerCamelCase						=						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_question_answering(*a					)






     def      SCREAMING_SNAKE_CASE__     (				self	:	Optional[Any]						,       a	:	int					):





         """simple docstring"""



         if hasattr(a						,       '''weight'''					) and module.weight is not None:
             module.weight.data.fill_(3					)
         if hasattr(a						,       '''bias'''					) and module.bias is not None:
             module.bias.data.fill_(3					)

         for param in ["r_w_bias", "r_r_bias", "r_kernel", "r_s_bias", "seg_embed"]:
             if hasattr(a						,       a					) and getattr(a						,       a					) is not None:
                 __lowerCamelCase						=						getattr(a						,       a					)
                 weight.data.fill_(3					)




@require_torch
class 					a__   (     UpperCAmelCase__							,     unittest.TestCase				):
     lowerCamelCase						:  Optional[Any]							=False
     lowerCamelCase						:  Any							=False
     lowerCamelCase						:  Union[str, Any]							=(
         (FunnelBaseModel, FunnelForMultipleChoice, FunnelForSequenceClassification) if is_torch_available() else ()
     )






     def      SCREAMING_SNAKE_CASE__     (				self	:	int					):





         """simple docstring"""



         __lowerCamelCase						=						FunnelModelTester(self						,       base=a					)
         __lowerCamelCase						=						ConfigTester(self						,       config_class=a					)






     def      SCREAMING_SNAKE_CASE__     (				self	:	Dict					):





         """simple docstring"""



         self.config_tester.run_common_tests()






     def      SCREAMING_SNAKE_CASE__     (				self	:	Optional[int]					):





         """simple docstring"""



         __lowerCamelCase						=						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_base_model(*a					)






     def      SCREAMING_SNAKE_CASE__     (				self	:	Dict					):





         """simple docstring"""



         __lowerCamelCase						=						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_sequence_classification(*a					)






     def      SCREAMING_SNAKE_CASE__     (				self	:	Union[str, Any]					):





         """simple docstring"""



         __lowerCamelCase						=						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_multiple_choice(*a					)






     def      SCREAMING_SNAKE_CASE__     (				self	:	int					):





         """simple docstring"""



         __lowerCamelCase			,						__lowerCamelCase						=						self.model_tester.prepare_config_and_inputs_for_common()
         __lowerCamelCase						=						True

         for model_class in self.all_model_classes:
             if model_class.__name__ == "FunnelBaseModel":
                 continue
             __lowerCamelCase						=						model_class(a					)
             model.to(a					)
             model.train()
             __lowerCamelCase						=						self._prepare_for_class(a						,       a						,       return_labels=a					)
             __lowerCamelCase						=						model(**a					).loss
             loss.backward()






     def      SCREAMING_SNAKE_CASE__     (				self	:	List[Any]						,       a	:	Optional[int]					):





         """simple docstring"""



         if hasattr(a						,       '''weight'''					) and module.weight is not None:
             module.weight.data.fill_(3					)
         if hasattr(a						,       '''bias'''					) and module.bias is not None:
             module.bias.data.fill_(3					)

         for param in ["r_w_bias", "r_r_bias", "r_kernel", "r_s_bias", "seg_embed"]:
             if hasattr(a						,       a					) and getattr(a						,       a					) is not None:
                 __lowerCamelCase						=						getattr(a						,       a					)
                 weight.data.fill_(3					)




@require_torch
@require_sentencepiece
@require_tokenizers
class 					a__   (     unittest.TestCase				):






     def      SCREAMING_SNAKE_CASE__     (				self	:	Tuple					):





         """simple docstring"""



         __lowerCamelCase						=						13
         __lowerCamelCase						=						7
         __lowerCamelCase						=						torch.arange(0						,       batch_size * sequence_length					).long().reshape(a						,       a					)
         __lowerCamelCase						=						[0, 1, 2, 3, 4, 5, 6, 4, 1, 3, 5, 0, 1]
         __lowerCamelCase						=						torch.tensor([[2] + [0] * a + [1] * (sequence_length - a - 1) for a in lengths]					)

         __lowerCamelCase						=						FunnelModel.from_pretrained('''sgugger/funnel-random-tiny'''					)
         __lowerCamelCase						=						model(a						,       token_type_ids=a					)[0].abs()

         __lowerCamelCase						=						torch.tensor(23_44.83_52					)
         __lowerCamelCase						=						torch.tensor(0.80_52					)
         self.assertTrue(torch.allclose(output.sum()						,       a						,       atol=1e-4					)					)
         self.assertTrue(torch.allclose(output.mean()						,       a						,       atol=1e-4					)					)

         __lowerCamelCase						=						torch.tensor([[1] * 7, [1] * 4 + [0] * 3] * 6 + [[0, 1, 1, 0, 0, 1, 1]]					)
         __lowerCamelCase						=						model(a						,       attention_mask=a						,       token_type_ids=a					)[0].abs()

         __lowerCamelCase						=						torch.tensor(23_43.84_25					)
         __lowerCamelCase						=						torch.tensor(0.80_49					)
         self.assertTrue(torch.allclose(output.sum()						,       a						,       atol=1e-4					)					)
         self.assertTrue(torch.allclose(output.mean()						,       a						,       atol=1e-4					)					)






     @slow
     def      SCREAMING_SNAKE_CASE__     (				self	:	Dict					):





         """simple docstring"""



         __lowerCamelCase						=						FunnelTokenizer.from_pretrained('''huggingface/funnel-small'''					)
         __lowerCamelCase						=						FunnelModel.from_pretrained('''huggingface/funnel-small'''					)
         __lowerCamelCase						=						tokenizer('''Hello! I am the Funnel Transformer model.'''						,       return_tensors='''pt'''					)
         __lowerCamelCase						=						model(**a					)[0]

         __lowerCamelCase						=						torch.tensor(2_35.72_46					)
         __lowerCamelCase						=						torch.tensor(0.02_56					)
         self.assertTrue(torch.allclose(output.sum()						,       a						,       atol=1e-4					)					)
         self.assertTrue(torch.allclose(output.mean()						,       a						,       atol=1e-4					)					)

'''simple docstring'''




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 					a__   (     UpperCAmelCase__				):
     lowerCamelCase						:  Union[str, Any]							="musicgen_decoder"
     lowerCamelCase						:  List[Any]							=["past_key_values"]






     def __init__(				self	:	List[str]						,       a	:	Dict=20_48						,       a	:	Any=20_48						,       a	:	int=24						,       a	:	Optional[Any]=40_96						,       a	:	Tuple=16						,       a	:	Optional[int]=0.0						,       a	:	Tuple=True						,       a	:	Dict="gelu"						,       a	:	Optional[Any]=10_24						,       a	:	Optional[Any]=0.1						,       a	:	Tuple=0.0						,       a	:	Optional[int]=0.0						,       a	:	Any=0.02						,       a	:	str=False						,       a	:	List[Any]=4						,       a	:	List[str]=20_48						,       a	:	Any=20_48						,       a	:	Dict=None						,       a	:	str=False						,       **a	:	Tuple						,       ):





         """simple docstring"""



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




class 					a__   (     UpperCAmelCase__				):
     lowerCamelCase						:  Any							="musicgen"
     lowerCamelCase						:  str							=True






     def __init__(				self	:	str						,       **a	:	int					):





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

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

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

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

         __lowerCamelCase						=						AutoConfig.for_model(a						,       **a					)
         __lowerCamelCase						=						AutoConfig.for_model(a						,       **a					)
         __lowerCamelCase						=						MusicgenDecoderConfig(**a					)
         __lowerCamelCase						=						True






     @classmethod
     def      SCREAMING_SNAKE_CASE__     (				cls	:	Dict						,       a	:	PretrainedConfig						,       a	:	PretrainedConfig						,       a	:	MusicgenDecoderConfig						,       **a	:	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      SCREAMING_SNAKE_CASE__     (				self	:	List[Any]					):





         """simple docstring"""



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