





import copy
import os
from typing import Dict, Optional, Union

from ...configuration_utils import PretrainedConfig
from ...utils import add_start_docstrings, logging
from ..auto import AutoConfig


_UpperCAmelCase										=					logging.get_logger(__name__)


_UpperCAmelCase										=					{
    'suno/bark-small': 'https://huggingface.co/suno/bark-small/resolve/main/config.json',
    'suno/bark': 'https://huggingface.co/suno/bark/resolve/main/config.json',
}

_UpperCAmelCase										=					'\n    This is the configuration class to store the configuration of a [`{model}`]. It is used to instantiate the model\n    according to the specified arguments, defining the model architecture. Instantiating a configuration with the\n    defaults will yield a similar configuration to that of the Bark [suno/bark](https://huggingface.co/suno/bark)\n    architecture.\n\n    Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the\n    documentation from [`PretrainedConfig`] for more information.\n\n    Args:\n        block_size (`int`, *optional*, defaults to 1024):\n            The maximum sequence length that this model might ever be used with. Typically set this to something large\n            just in case (e.g., 512 or 1024 or 2048).\n        input_vocab_size (`int`, *optional*, defaults to 10_048):\n            Vocabulary size of a Bark sub-model. Defines the number of different tokens that can be represented by the\n            `inputs_ids` passed when calling [`{model}`]. Defaults to 10_048 but should be carefully thought with\n            regards to the chosen sub-model.\n        output_vocab_size (`int`, *optional*, defaults to 10_048):\n            Output vocabulary size of a Bark sub-model. Defines the number of different tokens that can be represented\n            by the: `output_ids` when passing forward a [`{model}`]. Defaults to 10_048 but should be carefully thought\n            with regards to the chosen sub-model.\n        num_layers (`int`, *optional*, defaults to 12):\n            Number of hidden layers in the given sub-model.\n        num_heads (`int`, *optional*, defaults to 12):\n            Number of attention heads for each attention layer in the Transformer architecture.\n        hidden_size (`int`, *optional*, defaults to 768):\n            Dimensionality of the "intermediate" (often named feed-forward) layer in the architecture.\n        dropout (`float`, *optional*, defaults to 0.0):\n            The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.\n        bias (`bool`, *optional*, defaults to `True`):\n            Whether or not to use bias in the linear layers and layer norm layers.\n        initializer_range (`float`, *optional*, defaults to 0.02):\n            The standard deviation of the truncated_normal_initializer for initializing all weight matrices.\n        use_cache (`bool`, *optional*, defaults to `True`):\n            Whether or not the model should return the last key/values attentions (not used by all models).\n'



class 				_UpperCamelCase       (						lowerCAmelCase_  ):
       _UpperCamelCase					:       Optional[Any]       = '''bark_module'''
       _UpperCamelCase					:       Optional[int]       = ['''past_key_values''']

       _UpperCamelCase					:       Tuple       = {
           '''num_attention_heads''': '''num_heads''',
           '''num_hidden_layers''': '''num_layers''',
           '''vocab_size''': '''input_vocab_size''',
           '''window_size''': '''block_size''',
       }

       def __init__(		self:			List[str]       , _SCREAMING_SNAKE_CASE:			List[str]=1024       , _SCREAMING_SNAKE_CASE:			int=10048       , _SCREAMING_SNAKE_CASE:			Union[str, Any]=10048       , _SCREAMING_SNAKE_CASE:			Tuple=12       , _SCREAMING_SNAKE_CASE:			Any=12       , _SCREAMING_SNAKE_CASE:			str=768       , _SCREAMING_SNAKE_CASE:			int=0.0       , _SCREAMING_SNAKE_CASE:			List[str]=True       , _SCREAMING_SNAKE_CASE:			List[str]=0.02       , _SCREAMING_SNAKE_CASE:			Any=True       , **_SCREAMING_SNAKE_CASE:			Union[str, Any]       , )							->			Dict:




              """simple docstring"""


              UpperCamelCase_ 							=	block_size
              UpperCamelCase_ 							=	input_vocab_size
              UpperCamelCase_ 							=	output_vocab_size
              UpperCamelCase_ 							=	num_layers
              UpperCamelCase_ 							=	num_heads
              UpperCamelCase_ 							=	hidden_size
              UpperCamelCase_ 							=	dropout
              UpperCamelCase_ 							=	bias
              UpperCamelCase_ 							=	use_cache
              UpperCamelCase_ 							=	initializer_range

              super().__init__(**_SCREAMING_SNAKE_CASE		)



       @classmethod
       def lowercase			(		cls:			Union[str, Any]       , _SCREAMING_SNAKE_CASE:			Union[str, os.PathLike]       , _SCREAMING_SNAKE_CASE:			Optional[Union[str, os.PathLike]] = None       , _SCREAMING_SNAKE_CASE:			bool = False       , _SCREAMING_SNAKE_CASE:			bool = False       , _SCREAMING_SNAKE_CASE:			Optional[Union[str, bool]] = None       , _SCREAMING_SNAKE_CASE:			str = "main"       , **_SCREAMING_SNAKE_CASE:			str       , )							->			"PretrainedConfig":




              """simple docstring"""


              UpperCamelCase_ 							=	cache_dir
              UpperCamelCase_ 							=	force_download
              UpperCamelCase_ 							=	local_files_only
              UpperCamelCase_ 							=	revision

              cls._set_token_in_kwargs(_SCREAMING_SNAKE_CASE       , _SCREAMING_SNAKE_CASE		)

              UpperCamelCase_							,			UpperCamelCase_ 							=	cls.get_config_dict(_SCREAMING_SNAKE_CASE       , **_SCREAMING_SNAKE_CASE		)

              # get the config dict if we are loading from Bark
              if config_dict.get("model_type"		) == "bark":
                     UpperCamelCase_ 							=	config_dict[f'''{cls.model_type}_config''']

              if "model_type" in config_dict and hasattr(cls       , "model_type"		) and config_dict["model_type"] != cls.model_type:
                     logger.warning(
                         f'''You are using a model of type {config_dict["model_type"]} to instantiate a model of type '''
                         f'''{cls.model_type}. This is not supported for all configurations of models and can yield errors.'''		)

              return cls.from_dict(_SCREAMING_SNAKE_CASE       , **_SCREAMING_SNAKE_CASE		)



@add_start_docstrings(
    BARK_SUBMODELCONFIG_START_DOCSTRING.format(config='''BarkSemanticConfig'''	,    model='''BarkSemanticModel'''  )	,    '''
    Example:

    ```python
    >>> from transformers import BarkSemanticConfig, BarkSemanticModel

    >>> # Initializing a Bark sub-module style configuration
    >>> configuration = BarkSemanticConfig()

    >>> # Initializing a model (with random weights) from the suno/bark style configuration
    >>> model = BarkSemanticModel(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```'''	,    )
class 				_UpperCamelCase       (						lowerCAmelCase_  ):
       _UpperCamelCase					:       Union[str, Any]       = '''semantic'''



@add_start_docstrings(
    BARK_SUBMODELCONFIG_START_DOCSTRING.format(config='''BarkCoarseConfig'''	,    model='''BarkCoarseModel'''  )	,    '''
    Example:

    ```python
    >>> from transformers import BarkCoarseConfig, BarkCoarseModel

    >>> # Initializing a Bark sub-module style configuration
    >>> configuration = BarkCoarseConfig()

    >>> # Initializing a model (with random weights) from the suno/bark style configuration
    >>> model = BarkCoarseModel(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```'''	,    )
class 				_UpperCamelCase       (						lowerCAmelCase_  ):
       _UpperCamelCase					:       Optional[Any]       = '''coarse_acoustics'''



@add_start_docstrings(
    BARK_SUBMODELCONFIG_START_DOCSTRING.format(config='''BarkFineConfig'''	,    model='''BarkFineModel'''  )	,    '''
        n_codes_total (`int`, *optional*, defaults to 8):
            The total number of audio codebooks predicted. Used in the fine acoustics sub-model.
        n_codes_given (`int`, *optional*, defaults to 1):
            The number of audio codebooks predicted in the coarse acoustics sub-model. Used in the acoustics
            sub-models.
    Example:

    ```python
    >>> from transformers import BarkFineConfig, BarkFineModel

    >>> # Initializing a Bark sub-module style configuration
    >>> configuration = BarkFineConfig()

    >>> # Initializing a model (with random weights) from the suno/bark style configuration
    >>> model = BarkFineModel(configuration)

    >>> # Accessing the model configuration
    >>> configuration = model.config
    ```'''	,    )
class 				_UpperCamelCase       (						lowerCAmelCase_  ):
       _UpperCamelCase					:       Tuple       = '''fine_acoustics'''

       def __init__(		self:			List[str]       , _SCREAMING_SNAKE_CASE:			List[str]=True       , _SCREAMING_SNAKE_CASE:			Optional[Any]=8       , _SCREAMING_SNAKE_CASE:			Dict=1       , **_SCREAMING_SNAKE_CASE:			List[Any]		)							->			List[str]:




              """simple docstring"""


              UpperCamelCase_ 							=	n_codes_total
              UpperCamelCase_ 							=	n_codes_given

              super().__init__(tie_word_embeddings=_SCREAMING_SNAKE_CASE       , **_SCREAMING_SNAKE_CASE		)



class 				_UpperCamelCase       (						lowerCAmelCase_  ):
       _UpperCamelCase					:       List[Any]       = '''bark'''
       _UpperCamelCase					:       List[Any]       = True

       def __init__(		self:			Tuple       , _SCREAMING_SNAKE_CASE:			Dict = None       , _SCREAMING_SNAKE_CASE:			Dict = None       , _SCREAMING_SNAKE_CASE:			Dict = None       , _SCREAMING_SNAKE_CASE:			Dict = None       , _SCREAMING_SNAKE_CASE:			Tuple=0.02       , **_SCREAMING_SNAKE_CASE:			Optional[int]       , )							->			Any:




              """simple docstring"""


              if semantic_config is None:
                     UpperCamelCase_ 							=	{}
                     logger.info("semantic_config is None. initializing the semantic model with default values."		)

              if coarse_acoustics_config is None:
                     UpperCamelCase_ 							=	{}
                     logger.info("coarse_acoustics_config is None. initializing the coarse model with default values."		)

              if fine_acoustics_config is None:
                     UpperCamelCase_ 							=	{}
                     logger.info("fine_acoustics_config is None. initializing the fine model with default values."		)

              if codec_config is None:
                     UpperCamelCase_ 							=	{}
                     logger.info("codec_config is None. initializing the codec model with default values."		)

              UpperCamelCase_ 							=	BarkSemanticConfig(**_SCREAMING_SNAKE_CASE		)
              UpperCamelCase_ 							=	BarkCoarseConfig(**_SCREAMING_SNAKE_CASE		)
              UpperCamelCase_ 							=	BarkFineConfig(**_SCREAMING_SNAKE_CASE		)
              UpperCamelCase_ 							=	AutoConfig.for_model(**_SCREAMING_SNAKE_CASE		)

              UpperCamelCase_ 							=	initializer_range

              super().__init__(**_SCREAMING_SNAKE_CASE		)

       @classmethod
       def lowercase			(		cls:			Any       , _SCREAMING_SNAKE_CASE:			BarkSemanticConfig       , _SCREAMING_SNAKE_CASE:			BarkCoarseConfig       , _SCREAMING_SNAKE_CASE:			BarkFineConfig       , _SCREAMING_SNAKE_CASE:			AutoConfig       , **_SCREAMING_SNAKE_CASE:			List[Any]       , )							->			Dict:




              """simple docstring"""


              return cls(
                  semantic_config=semantic_config.to_dict()       , coarse_acoustics_config=coarse_acoustics_config.to_dict()       , fine_acoustics_config=fine_acoustics_config.to_dict()       , codec_config=codec_config.to_dict()       , **_SCREAMING_SNAKE_CASE       , )



       def lowercase			(		self:			str		)							->			Optional[int]:




              """simple docstring"""


              UpperCamelCase_ 							=	copy.deepcopy(self.__dict__		)

              UpperCamelCase_ 							=	self.semantic_config.to_dict()
              UpperCamelCase_ 							=	self.coarse_acoustics_config.to_dict()
              UpperCamelCase_ 							=	self.fine_acoustics_config.to_dict()
              UpperCamelCase_ 							=	self.codec_config.to_dict()

              UpperCamelCase_ 							=	self.__class__.model_type
              return output








from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


_UpperCAmelCase										=					logging.get_logger(__name__)

_UpperCAmelCase										=					{
    'mnaylor/mega-base-wikitext': 'https://huggingface.co/mnaylor/mega-base-wikitext/resolve/main/config.json',
}



class 				_UpperCamelCase       (						lowerCAmelCase_  ):
       _UpperCamelCase					:       Union[str, Any]       = '''mega'''

       def __init__(		self:			Optional[int]       , _SCREAMING_SNAKE_CASE:			Union[str, Any]=30522       , _SCREAMING_SNAKE_CASE:			Optional[Any]=128       , _SCREAMING_SNAKE_CASE:			Any=4       , _SCREAMING_SNAKE_CASE:			Tuple=256       , _SCREAMING_SNAKE_CASE:			List[str]=16       , _SCREAMING_SNAKE_CASE:			Dict=True       , _SCREAMING_SNAKE_CASE:			Optional[int]=64       , _SCREAMING_SNAKE_CASE:			Union[str, Any]=False       , _SCREAMING_SNAKE_CASE:			List[Any]=-1       , _SCREAMING_SNAKE_CASE:			Tuple=None       , _SCREAMING_SNAKE_CASE:			Optional[Any]=True       , _SCREAMING_SNAKE_CASE:			Optional[int]="scalenorm"       , _SCREAMING_SNAKE_CASE:			int=True       , _SCREAMING_SNAKE_CASE:			List[str]="silu"       , _SCREAMING_SNAKE_CASE:			int="softmax"       , _SCREAMING_SNAKE_CASE:			List[Any]=0.1       , _SCREAMING_SNAKE_CASE:			Optional[int]=0.1       , _SCREAMING_SNAKE_CASE:			Optional[Any]=0.1       , _SCREAMING_SNAKE_CASE:			Tuple=False       , _SCREAMING_SNAKE_CASE:			List[Any]=True       , _SCREAMING_SNAKE_CASE:			Tuple=256       , _SCREAMING_SNAKE_CASE:			Any=True       , _SCREAMING_SNAKE_CASE:			List[Any]=0.1       , _SCREAMING_SNAKE_CASE:			Optional[Any]=2048       , _SCREAMING_SNAKE_CASE:			Any=False       , _SCREAMING_SNAKE_CASE:			Optional[Any]=2       , _SCREAMING_SNAKE_CASE:			List[str]=0.02       , _SCREAMING_SNAKE_CASE:			Tuple=0.2       , _SCREAMING_SNAKE_CASE:			Optional[int]=0.02       , _SCREAMING_SNAKE_CASE:			Tuple=1.0       , _SCREAMING_SNAKE_CASE:			List[str]=1       , _SCREAMING_SNAKE_CASE:			List[Any]=0       , _SCREAMING_SNAKE_CASE:			Optional[Any]=2       , _SCREAMING_SNAKE_CASE:			Optional[int]="rotary"       , _SCREAMING_SNAKE_CASE:			Optional[Any]=None       , _SCREAMING_SNAKE_CASE:			Any=True       , _SCREAMING_SNAKE_CASE:			Optional[Any]=True       , **_SCREAMING_SNAKE_CASE:			Union[str, Any]       , )							->			Optional[Any]:




              """simple docstring"""


              super().__init__(pad_token_id=_SCREAMING_SNAKE_CASE       , bos_token_id=_SCREAMING_SNAKE_CASE       , eos_token_id=_SCREAMING_SNAKE_CASE       , **_SCREAMING_SNAKE_CASE		)

              UpperCamelCase_ 							=	vocab_size
              UpperCamelCase_ 							=	hidden_size
              UpperCamelCase_ 							=	num_hidden_layers
              UpperCamelCase_ 							=	activation
              UpperCamelCase_ 							=	attention_activation
              UpperCamelCase_ 							=	intermediate_size
              UpperCamelCase_ 							=	ema_projection_size
              UpperCamelCase_ 							=	bidirectional
              UpperCamelCase_ 							=	shared_representation_size
              UpperCamelCase_ 							=	use_chunking
              UpperCamelCase_ 							=	chunk_size
              UpperCamelCase_ 							=	truncation
              UpperCamelCase_ 							=	normalize_before_mega
              UpperCamelCase_ 							=	normalization_type
              UpperCamelCase_ 							=	norm_affine
              UpperCamelCase_ 							=	dropout_prob
              UpperCamelCase_ 							=	hidden_dropout_prob
              UpperCamelCase_ 							=	attention_probs_dropout_prob
              UpperCamelCase_ 							=	use_feature_dropout
              UpperCamelCase_ 							=	use_normalized_ffn
              UpperCamelCase_ 							=	nffn_hidden_size
              UpperCamelCase_ 							=	normalize_before_ffn
              UpperCamelCase_ 							=	nffn_activation_dropout_prob
              UpperCamelCase_ 							=	max_positions
              UpperCamelCase_ 							=	add_token_type_embeddings
              UpperCamelCase_ 							=	type_vocab_size
              UpperCamelCase_ 							=	initializer_range
              UpperCamelCase_ 							=	ema_delta_alpha_range
              UpperCamelCase_ 							=	ema_beta_range
              UpperCamelCase_ 							=	ema_gamma_omega_range
              UpperCamelCase_ 							=	relative_positional_bias
              UpperCamelCase_ 							=	use_cache
              UpperCamelCase_ 							=	classifier_dropout
              UpperCamelCase_ 							=	add_lm_hidden_dense_layer
              UpperCamelCase_ 							=	1  # not used but required by Hugging Face



class 				_UpperCamelCase       (						lowerCAmelCase_  ):

       @property
       def lowercase			(		self:			Optional[int]		)							->			Mapping[str, Mapping[int, str]]:




              """simple docstring"""


              if self.task == "multiple-choice":
                     UpperCamelCase_ 							=	{0: "batch", 1: "choice", 2: "sequence"}
              else:
                     UpperCamelCase_ 							=	{0: "batch", 1: "sequence"}
              return OrderedDict(
                  [
                      ("input_ids", dynamic_axis),
                      ("attention_mask", dynamic_axis),
                  ]		)

