




import copy

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


_UpperCAmelCase						:    List[str]      =  logging.get_logger(__name__)

_UpperCAmelCase						:    Optional[int]      =  {
    "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  __lowerCAmelCase							(				lowerCAmelCase):
       _a			       =    '''musicgen_decoder'''
       _a			       =    ['''past_key_values''']






       def __init__( self:       Optional[Any]							,       _lowerCAmelCase:       Union[str, Any]=20_48							,       _lowerCAmelCase:       Optional[int]=20_48							,       _lowerCAmelCase:       int=24							,       _lowerCAmelCase:       int=40_96							,       _lowerCAmelCase:       int=16							,       _lowerCAmelCase:       List[str]=0.0							,       _lowerCAmelCase:       Optional[Any]=True							,       _lowerCAmelCase:       Optional[int]="gelu"							,       _lowerCAmelCase:       List[Any]=10_24							,       _lowerCAmelCase:       Union[str, Any]=0.1							,       _lowerCAmelCase:       Optional[Any]=0.0							,       _lowerCAmelCase:       Optional[int]=0.0							,       _lowerCAmelCase:       Optional[Any]=0.02							,       _lowerCAmelCase:       Optional[int]=False							,       _lowerCAmelCase:       List[str]=4							,       _lowerCAmelCase:       Any=20_48							,       _lowerCAmelCase:       Optional[int]=20_48							,       _lowerCAmelCase:       List[str]=None							,       _lowerCAmelCase:       Optional[int]=False							,       **_lowerCAmelCase:       int							,       ):
         lowercase     :Optional[Any]   						=    vocab_size
         lowercase     :Optional[int]   						=    max_position_embeddings
         lowercase     :List[Any]   						=    hidden_size
         lowercase     :Optional[Any]   						=    ffn_dim
         lowercase     :List[str]   						=    num_hidden_layers
         lowercase     :Tuple   						=    num_attention_heads
         lowercase     :int   						=    dropout
         lowercase     :Dict   						=    attention_dropout
         lowercase     :Any   						=    activation_dropout
         lowercase     :str   						=    activation_function
         lowercase     :Union[str, Any]   						=    initializer_factor
         lowercase     :Tuple   						=    layerdrop
         lowercase     :int   						=    use_cache
         lowercase     :Dict   						=    scale_embedding  # scale factor will be sqrt(d_model) if True
         lowercase     :Optional[Any]   						=    num_codebooks
         super().__init__(
             pad_token_id=_lowerCAmelCase							,       bos_token_id=_lowerCAmelCase							,       eos_token_id=_lowerCAmelCase							,       tie_word_embeddings=_lowerCAmelCase							,       **_lowerCAmelCase							,       )







class  __lowerCAmelCase							(				lowerCAmelCase):
       _a			       =    '''musicgen'''
       _a			       =    True






       def __init__( self:       Dict							,       **_lowerCAmelCase:       int					):
         super().__init__(**_lowerCAmelCase					)
         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"					)

         lowercase     :Optional[Any]   						=    kwargs.pop("text_encoder"					)
         lowercase     :List[Any]   						=    text_encoder_config.pop("model_type"					)

         lowercase     :Tuple   						=    kwargs.pop("audio_encoder"					)
         lowercase     :int   						=    audio_encoder_config.pop("model_type"					)

         lowercase     :Union[str, Any]   						=    kwargs.pop("decoder"					)

         lowercase     :int   						=    AutoConfig.for_model(_lowerCAmelCase							,       **_lowerCAmelCase					)
         lowercase     :Dict   						=    AutoConfig.for_model(_lowerCAmelCase							,       **_lowerCAmelCase					)
         lowercase     :Union[str, Any]   						=    MusicgenDecoderConfig(**_lowerCAmelCase					)
         lowercase     :int   						=    True






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






       def        SCREAMING_SNAKE_CASE     ( self:       str					):
         lowercase     :Optional[Any]   						=    copy.deepcopy(self.__dict__					)
         lowercase     :List[Any]   						=    self.text_encoder.to_dict()
         lowercase     :Tuple   						=    self.audio_encoder.to_dict()
         lowercase     :Optional[Any]   						=    self.decoder.to_dict()
         lowercase     :Any   						=    self.__class__.model_type
         return output









from unittest.mock import patch

import datasets
from datasets import Dataset



def    UpperCAmelCase__	(  ):
  lowercase     :Any   						=    Dataset.from_dict({"col_1": [3, 2, 0, 1]} )

  with patch("tqdm.auto.tqdm" ) as mock_tqdm:
    datasets.disable_progress_bar()
    dset.map(lambda lowerCamelCase : {"col_2": x["col_1"] + 1} )
    mock_tqdm.assert_not_called()

    mock_tqdm.reset_mock()

    datasets.enable_progress_bar()
    dset.map(lambda lowerCamelCase : {"col_2": x["col_1"] + 1} )
    mock_tqdm.assert_called()



