

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


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


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

lowerCAmelCase       :				int         =					'\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 	_A						(					__magic_name__):
  SCREAMING_SNAKE_CASE      : Dict    =					'''bark_module'''
  SCREAMING_SNAKE_CASE      : str    =					['''past_key_values''']

  SCREAMING_SNAKE_CASE      : str    =					{
      '''num_attention_heads''': '''num_heads''',
      '''num_hidden_layers''': '''num_layers''',
      '''vocab_size''': '''input_vocab_size''',
      '''window_size''': '''block_size''',
  }

  def __init__(			self	,   _SCREAMING_SNAKE_CASE=1024	,   _SCREAMING_SNAKE_CASE=1_0048	,   _SCREAMING_SNAKE_CASE=1_0048	,   _SCREAMING_SNAKE_CASE=12	,   _SCREAMING_SNAKE_CASE=12	,   _SCREAMING_SNAKE_CASE=768	,   _SCREAMING_SNAKE_CASE=0.0	,   _SCREAMING_SNAKE_CASE=True	,   _SCREAMING_SNAKE_CASE=0.02	,   _SCREAMING_SNAKE_CASE=True	,   **_SCREAMING_SNAKE_CASE	,   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					int          =       block_size
        SCREAMING_SNAKE_CASE_			:					List[str]          =       input_vocab_size
        SCREAMING_SNAKE_CASE_			:					str          =       output_vocab_size
        SCREAMING_SNAKE_CASE_			:					Union[str, Any]          =       num_layers
        SCREAMING_SNAKE_CASE_			:					List[Any]          =       num_heads
        SCREAMING_SNAKE_CASE_			:					List[Any]          =       hidden_size
        SCREAMING_SNAKE_CASE_			:					Any          =       dropout
        SCREAMING_SNAKE_CASE_			:					Dict          =       bias
        SCREAMING_SNAKE_CASE_			:					Union[str, Any]          =       use_cache
        SCREAMING_SNAKE_CASE_			:					int          =       initializer_range

        super().__init__(**_SCREAMING_SNAKE_CASE   )



  @classmethod
  def 	UpperCAmelCase      (			cls	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE = None	,   _SCREAMING_SNAKE_CASE = False	,   _SCREAMING_SNAKE_CASE = False	,   _SCREAMING_SNAKE_CASE = None	,   _SCREAMING_SNAKE_CASE = "main"	,   **_SCREAMING_SNAKE_CASE	,   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					Tuple          =       cache_dir
        SCREAMING_SNAKE_CASE_			:					str          =       force_download
        SCREAMING_SNAKE_CASE_			:					Tuple          =       local_files_only
        SCREAMING_SNAKE_CASE_			:					List[Any]          =       revision

        cls._set_token_in_kwargs(_SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE   )

        SCREAMING_SNAKE_CASE_    ,  SCREAMING_SNAKE_CASE_			:					Any          =       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":
              SCREAMING_SNAKE_CASE_			:					str          =       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 	_A						(					__magic_name__):
  SCREAMING_SNAKE_CASE      : 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 	_A						(					__magic_name__):
  SCREAMING_SNAKE_CASE      : 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 	_A						(					__magic_name__):
  SCREAMING_SNAKE_CASE      : List[Any]    =					'''fine_acoustics'''

  def __init__(			self	,   _SCREAMING_SNAKE_CASE=True	,   _SCREAMING_SNAKE_CASE=8	,   _SCREAMING_SNAKE_CASE=1	,   **_SCREAMING_SNAKE_CASE   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					Union[str, Any]          =       n_codes_total
        SCREAMING_SNAKE_CASE_			:					Optional[int]          =       n_codes_given

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

class 	_A						(					__magic_name__):
  SCREAMING_SNAKE_CASE      : Any    =					'''bark'''
  SCREAMING_SNAKE_CASE      : Dict    =					True

  def __init__(			self	,   _SCREAMING_SNAKE_CASE = None	,   _SCREAMING_SNAKE_CASE = None	,   _SCREAMING_SNAKE_CASE = None	,   _SCREAMING_SNAKE_CASE = None	,   _SCREAMING_SNAKE_CASE=0.02	,   **_SCREAMING_SNAKE_CASE	,   ):





        """simple docstring"""







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

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

        if fine_acoustics_config is None:
              SCREAMING_SNAKE_CASE_			:					List[Any]          =       {}
              logger.info('fine_acoustics_config is None. initializing the fine model with default values.'   )

        if codec_config is None:
              SCREAMING_SNAKE_CASE_			:					Optional[Any]          =       {}
              logger.info('codec_config is None. initializing the codec model with default values.'   )

        SCREAMING_SNAKE_CASE_			:					Optional[int]          =       BarkSemanticConfig(**_SCREAMING_SNAKE_CASE   )
        SCREAMING_SNAKE_CASE_			:					Dict          =       BarkCoarseConfig(**_SCREAMING_SNAKE_CASE   )
        SCREAMING_SNAKE_CASE_			:					Tuple          =       BarkFineConfig(**_SCREAMING_SNAKE_CASE   )
        SCREAMING_SNAKE_CASE_			:					List[str]          =       AutoConfig.for_model(**_SCREAMING_SNAKE_CASE   )

        SCREAMING_SNAKE_CASE_			:					Tuple          =       initializer_range

        super().__init__(**_SCREAMING_SNAKE_CASE   )

  @classmethod
  def 	UpperCAmelCase      (			cls	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   **_SCREAMING_SNAKE_CASE	,   ):





        """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 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					str          =       copy.deepcopy(self.__dict__   )

        SCREAMING_SNAKE_CASE_			:					List[str]          =       self.semantic_config.to_dict()
        SCREAMING_SNAKE_CASE_			:					Union[str, Any]          =       self.coarse_acoustics_config.to_dict()
        SCREAMING_SNAKE_CASE_			:					List[str]          =       self.fine_acoustics_config.to_dict()
        SCREAMING_SNAKE_CASE_			:					List[str]          =       self.codec_config.to_dict()

        SCREAMING_SNAKE_CASE_			:					Optional[int]          =       self.__class__.model_type
        return output









import unittest

from transformers import ErnieMConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

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


if is_torch_available():
    import torch

    from transformers import (
        ErnieMForInformationExtraction,
        ErnieMForMultipleChoice,
        ErnieMForQuestionAnswering,
        ErnieMForSequenceClassification,
        ErnieMForTokenClassification,
        ErnieMModel,
    )
    from transformers.models.ernie_m.modeling_ernie_m import ERNIE_M_PRETRAINED_MODEL_ARCHIVE_LIST
class 	_A						:

  def __init__(			self	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE=13	,   _SCREAMING_SNAKE_CASE=7	,   _SCREAMING_SNAKE_CASE=True	,   _SCREAMING_SNAKE_CASE=True	,   _SCREAMING_SNAKE_CASE=True	,   _SCREAMING_SNAKE_CASE=99	,   _SCREAMING_SNAKE_CASE=32	,   _SCREAMING_SNAKE_CASE=5	,   _SCREAMING_SNAKE_CASE=4	,   _SCREAMING_SNAKE_CASE=37	,   _SCREAMING_SNAKE_CASE="gelu"	,   _SCREAMING_SNAKE_CASE=0.1	,   _SCREAMING_SNAKE_CASE=0.1	,   _SCREAMING_SNAKE_CASE=512	,   _SCREAMING_SNAKE_CASE=16	,   _SCREAMING_SNAKE_CASE=2	,   _SCREAMING_SNAKE_CASE=0.02	,   _SCREAMING_SNAKE_CASE=3	,   _SCREAMING_SNAKE_CASE=4	,   _SCREAMING_SNAKE_CASE=None	,   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					Tuple          =       parent
        SCREAMING_SNAKE_CASE_			:					Tuple          =       batch_size
        SCREAMING_SNAKE_CASE_			:					Dict          =       seq_length
        SCREAMING_SNAKE_CASE_			:					Optional[int]          =       is_training
        SCREAMING_SNAKE_CASE_			:					str          =       use_input_mask
        SCREAMING_SNAKE_CASE_			:					str          =       use_labels
        SCREAMING_SNAKE_CASE_			:					int          =       vocab_size
        SCREAMING_SNAKE_CASE_			:					Any          =       hidden_size
        SCREAMING_SNAKE_CASE_			:					int          =       num_hidden_layers
        SCREAMING_SNAKE_CASE_			:					Optional[Any]          =       num_attention_heads
        SCREAMING_SNAKE_CASE_			:					List[Any]          =       intermediate_size
        SCREAMING_SNAKE_CASE_			:					Dict          =       hidden_act
        SCREAMING_SNAKE_CASE_			:					Tuple          =       hidden_dropout_prob
        SCREAMING_SNAKE_CASE_			:					Optional[int]          =       attention_probs_dropout_prob
        SCREAMING_SNAKE_CASE_			:					Union[str, Any]          =       max_position_embeddings
        SCREAMING_SNAKE_CASE_			:					Optional[Any]          =       type_vocab_size
        SCREAMING_SNAKE_CASE_			:					str          =       type_sequence_label_size
        SCREAMING_SNAKE_CASE_			:					Dict          =       initializer_range
        SCREAMING_SNAKE_CASE_			:					Optional[Any]          =       num_labels
        SCREAMING_SNAKE_CASE_			:					Optional[int]          =       num_choices
        SCREAMING_SNAKE_CASE_			:					Union[str, Any]          =       scope

  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					List[Any]          =       ids_tensor([self.batch_size, self.seq_length]	,   self.vocab_size   )

        SCREAMING_SNAKE_CASE_			:					Optional[Any]          =       None
        if self.use_input_mask:
              SCREAMING_SNAKE_CASE_			:					Tuple          =       random_attention_mask([self.batch_size, self.seq_length]   )

        SCREAMING_SNAKE_CASE_			:					int          =       None
        SCREAMING_SNAKE_CASE_			:					int          =       None
        SCREAMING_SNAKE_CASE_			:					Optional[Any]          =       None
        if self.use_labels:
              SCREAMING_SNAKE_CASE_			:					List[str]          =       ids_tensor([self.batch_size]	,   self.type_sequence_label_size   )
              SCREAMING_SNAKE_CASE_			:					str          =       ids_tensor([self.batch_size, self.seq_length]	,   self.num_labels   )
              SCREAMING_SNAKE_CASE_			:					List[str]          =       ids_tensor([self.batch_size]	,   self.num_choices   )

        SCREAMING_SNAKE_CASE_			:					int          =       self.get_config()

        return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels

  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					int          =       ids_tensor([self.batch_size, self.seq_length]	,   self.vocab_size   )

        SCREAMING_SNAKE_CASE_			:					int          =       None
        if self.use_input_mask:
              SCREAMING_SNAKE_CASE_			:					str          =       random_attention_mask([self.batch_size, self.seq_length]   )
        SCREAMING_SNAKE_CASE_			:					Optional[int]          =       self.get_config()

        return config, input_ids, input_mask

  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        return ErnieMConfig(
            vocab_size=self.vocab_size	,   hidden_size=self.hidden_size	,   num_hidden_layers=self.num_hidden_layers	,   num_attention_heads=self.num_attention_heads	,   intermediate_size=self.intermediate_size	,   hidden_act=self.hidden_act	,   hidden_dropout_prob=self.hidden_dropout_prob	,   attention_probs_dropout_prob=self.attention_probs_dropout_prob	,   max_position_embeddings=self.max_position_embeddings	,   type_vocab_size=self.type_vocab_size	,   initializer_range=self.initializer_range	,   )

  def 	UpperCAmelCase      (			self	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					Optional[Any]          =       ErnieMModel(config=_SCREAMING_SNAKE_CASE   )
        model.to(_SCREAMING_SNAKE_CASE   )
        model.eval()
        SCREAMING_SNAKE_CASE_			:					Tuple          =       model(_SCREAMING_SNAKE_CASE	,   return_dict=_SCREAMING_SNAKE_CASE   )
        self.parent.assertEqual(result.last_hidden_state.shape	,   (self.batch_size, self.seq_length, self.hidden_size)   )

  def 	UpperCAmelCase      (			self	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					Union[str, Any]          =       ErnieMForQuestionAnswering(config=_SCREAMING_SNAKE_CASE   )
        model.to(_SCREAMING_SNAKE_CASE   )
        model.eval()
        SCREAMING_SNAKE_CASE_			:					Dict          =       model(
            _SCREAMING_SNAKE_CASE	,   attention_mask=_SCREAMING_SNAKE_CASE	,   start_positions=_SCREAMING_SNAKE_CASE	,   end_positions=_SCREAMING_SNAKE_CASE	,   )
        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 	UpperCAmelCase      (			self	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					List[Any]          =       ErnieMForInformationExtraction(config=_SCREAMING_SNAKE_CASE   )
        model.to(_SCREAMING_SNAKE_CASE   )
        model.eval()
        SCREAMING_SNAKE_CASE_			:					List[str]          =       torch.ones_like(_SCREAMING_SNAKE_CASE	,   dtype=torch.floataa   )
        SCREAMING_SNAKE_CASE_			:					Optional[int]          =       model(
            _SCREAMING_SNAKE_CASE	,   attention_mask=_SCREAMING_SNAKE_CASE	,   start_positions=_SCREAMING_SNAKE_CASE	,   end_positions=_SCREAMING_SNAKE_CASE	,   )
        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 	UpperCAmelCase      (			self	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					str          =       self.num_labels
        SCREAMING_SNAKE_CASE_			:					Tuple          =       ErnieMForSequenceClassification(_SCREAMING_SNAKE_CASE   )
        model.to(_SCREAMING_SNAKE_CASE   )
        model.eval()
        SCREAMING_SNAKE_CASE_			:					List[Any]          =       model(_SCREAMING_SNAKE_CASE	,   attention_mask=_SCREAMING_SNAKE_CASE	,   labels=_SCREAMING_SNAKE_CASE   )
        self.parent.assertEqual(result.logits.shape	,   (self.batch_size, self.num_labels)   )

  def 	UpperCAmelCase      (			self	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					Union[str, Any]          =       self.num_labels
        SCREAMING_SNAKE_CASE_			:					List[Any]          =       ErnieMForTokenClassification(config=_SCREAMING_SNAKE_CASE   )
        model.to(_SCREAMING_SNAKE_CASE   )
        model.eval()
        input_ids.to(_SCREAMING_SNAKE_CASE   )
        input_mask.to(_SCREAMING_SNAKE_CASE   )
        token_labels.to(_SCREAMING_SNAKE_CASE   )

        SCREAMING_SNAKE_CASE_			:					Optional[Any]          =       model(_SCREAMING_SNAKE_CASE	,   attention_mask=_SCREAMING_SNAKE_CASE	,   labels=_SCREAMING_SNAKE_CASE   )

        self.parent.assertEqual(result.logits.shape	,   (self.batch_size, self.seq_length, self.num_labels)   )

  def 	UpperCAmelCase      (			self	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					str          =       self.num_choices
        SCREAMING_SNAKE_CASE_			:					List[str]          =       ErnieMForMultipleChoice(config=_SCREAMING_SNAKE_CASE   )
        model.to(_SCREAMING_SNAKE_CASE   )
        model.eval()
        SCREAMING_SNAKE_CASE_			:					List[Any]          =       input_ids.unsqueeze(1   ).expand(-1	,   self.num_choices	,   -1   ).contiguous()
        SCREAMING_SNAKE_CASE_			:					Optional[Any]          =       input_mask.unsqueeze(1   ).expand(-1	,   self.num_choices	,   -1   ).contiguous()
        SCREAMING_SNAKE_CASE_			:					List[str]          =       model(
            _SCREAMING_SNAKE_CASE	,   attention_mask=_SCREAMING_SNAKE_CASE	,   labels=_SCREAMING_SNAKE_CASE	,   )
        self.parent.assertEqual(result.logits.shape	,   (self.batch_size, self.num_choices)   )



  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					Any          =       self.prepare_config_and_inputs()
        (
            (
            SCREAMING_SNAKE_CASE_
        )    ,  (
            SCREAMING_SNAKE_CASE_
        )    ,  (
            SCREAMING_SNAKE_CASE_
        )    ,  (
            SCREAMING_SNAKE_CASE_
        )    ,  (
            SCREAMING_SNAKE_CASE_
        )    ,  (
            SCREAMING_SNAKE_CASE_
        )    ,  
        )			:					str          =       config_and_inputs
        SCREAMING_SNAKE_CASE_			:					Optional[int]          =       {'input_ids': input_ids, 'attention_mask': input_mask}
        return config, inputs_dict

@require_torch
class 	_A						(					__magic_name__				,       __magic_name__				,       unittest.TestCase):
  SCREAMING_SNAKE_CASE      : str    =					(
      (
          ErnieMModel,
          ErnieMForMultipleChoice,
          ErnieMForQuestionAnswering,
          ErnieMForSequenceClassification,
          ErnieMForTokenClassification,
      )
      if is_torch_available()
      else ()
  )
  SCREAMING_SNAKE_CASE      : Optional[int]    =					()
  SCREAMING_SNAKE_CASE      : Union[str, Any]    =					(
      {
          '''feature-extraction''': ErnieMModel,
          '''question-answering''': ErnieMForQuestionAnswering,
          '''text-classification''': ErnieMForSequenceClassification,
          '''token-classification''': ErnieMForTokenClassification,
          '''zero-shot''': ErnieMForSequenceClassification,
      }
      if is_torch_available()
      else {}
  )
  SCREAMING_SNAKE_CASE      : Union[str, Any]    =					False

  def 	UpperCAmelCase      (			self	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE	,   _SCREAMING_SNAKE_CASE   ):





        """simple docstring"""







        if pipeline_test_casse_name == "QAPipelineTests":
              return True

        return False

  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					Optional[int]          =       ErnieMModelTester(self   )
        SCREAMING_SNAKE_CASE_			:					Dict          =       ConfigTester(self	,   config_class=_SCREAMING_SNAKE_CASE	,   hidden_size=37   )

  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        self.config_tester.run_common_tests()

  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					Optional[Any]          =       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE   )

  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					Dict          =       self.model_tester.prepare_config_and_inputs()
        for type in ["absolute", "relative_key", "relative_key_query"]:
              SCREAMING_SNAKE_CASE_			:					Optional[int]          =       type
              self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE   )

  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					List[Any]          =       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_multiple_choice(*_SCREAMING_SNAKE_CASE   )

  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					int          =       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_question_answering(*_SCREAMING_SNAKE_CASE   )

  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					Union[str, Any]          =       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_sequence_classification(*_SCREAMING_SNAKE_CASE   )

  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					Tuple          =       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_information_extraction(*_SCREAMING_SNAKE_CASE   )

  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					int          =       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_token_classification(*_SCREAMING_SNAKE_CASE   )



  @slow
  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        for model_name in ERNIE_M_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              SCREAMING_SNAKE_CASE_			:					int          =       ErnieMModel.from_pretrained(_SCREAMING_SNAKE_CASE   )
              self.assertIsNotNone(_SCREAMING_SNAKE_CASE   )

@require_torch
class 	_A						(					unittest.TestCase):

  @slow
  def 	UpperCAmelCase      (			self   ):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_			:					Tuple          =       ErnieMModel.from_pretrained('susnato/ernie-m-base_pytorch'   )
        model.eval()
        SCREAMING_SNAKE_CASE_			:					List[str]          =       torch.tensor([[0, 1, 2, 3, 4, 5]]   )
        SCREAMING_SNAKE_CASE_			:					Tuple          =       model(_SCREAMING_SNAKE_CASE   )[0]

        # TODO Replace vocab size
        SCREAMING_SNAKE_CASE_			:					List[Any]          =       768

        SCREAMING_SNAKE_CASE_			:					Optional[int]          =       torch.Size((1, 6, hidden_size)   )
        self.assertEqual(output.shape	,   _SCREAMING_SNAKE_CASE   )

        SCREAMING_SNAKE_CASE_			:					Optional[Any]          =       torch.tensor(
            [[[-0.0012, 0.1245, -0.0214], [-0.0742, 0.0244, -0.0771], [-0.0333, 0.1164, -0.1554]]]   )

        self.assertTrue(torch.allclose(output[:, :3, :3]	,   _SCREAMING_SNAKE_CASE	,   atol=1e-3   )   )






