

from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCAmelCase       :				Dict         =					logging.get_logger(__name__)

lowerCAmelCase       :				int         =					{
    'MCG-NJU/videomae-base': 'https://huggingface.co/MCG-NJU/videomae-base/resolve/main/config.json',
}
class 	_A						(					__magic_name__):
		SCREAMING_SNAKE_CASE      : Optional[int]    =					'''videomae'''

		def __init__(			self	,   _SCREAMING_SNAKE_CASE=224	,   _SCREAMING_SNAKE_CASE=16	,   _SCREAMING_SNAKE_CASE=3	,   _SCREAMING_SNAKE_CASE=16	,   _SCREAMING_SNAKE_CASE=2	,   _SCREAMING_SNAKE_CASE=768	,   _SCREAMING_SNAKE_CASE=12	,   _SCREAMING_SNAKE_CASE=12	,   _SCREAMING_SNAKE_CASE=3072	,   _SCREAMING_SNAKE_CASE="gelu"	,   _SCREAMING_SNAKE_CASE=0.0	,   _SCREAMING_SNAKE_CASE=0.0	,   _SCREAMING_SNAKE_CASE=0.02	,   _SCREAMING_SNAKE_CASE=1e-12	,   _SCREAMING_SNAKE_CASE=True	,   _SCREAMING_SNAKE_CASE=True	,   _SCREAMING_SNAKE_CASE=6	,   _SCREAMING_SNAKE_CASE=384	,   _SCREAMING_SNAKE_CASE=4	,   _SCREAMING_SNAKE_CASE=1536	,   _SCREAMING_SNAKE_CASE=True	,   **_SCREAMING_SNAKE_CASE	,   ):





								"""simple docstring"""







								super().__init__(**_SCREAMING_SNAKE_CASE   )

								SCREAMING_SNAKE_CASE_			:					Dict          =       image_size
								SCREAMING_SNAKE_CASE_			:					Any          =       patch_size
								SCREAMING_SNAKE_CASE_			:					Optional[int]          =       num_channels
								SCREAMING_SNAKE_CASE_			:					Dict          =       num_frames
								SCREAMING_SNAKE_CASE_			:					Tuple          =       tubelet_size

								SCREAMING_SNAKE_CASE_			:					str          =       hidden_size
								SCREAMING_SNAKE_CASE_			:					Dict          =       num_hidden_layers
								SCREAMING_SNAKE_CASE_			:					int          =       num_attention_heads
								SCREAMING_SNAKE_CASE_			:					Optional[int]          =       intermediate_size
								SCREAMING_SNAKE_CASE_			:					Union[str, Any]          =       hidden_act
								SCREAMING_SNAKE_CASE_			:					Any          =       hidden_dropout_prob
								SCREAMING_SNAKE_CASE_			:					Union[str, Any]          =       attention_probs_dropout_prob
								SCREAMING_SNAKE_CASE_			:					Any          =       initializer_range
								SCREAMING_SNAKE_CASE_			:					Union[str, Any]          =       layer_norm_eps
								SCREAMING_SNAKE_CASE_			:					str          =       qkv_bias
								SCREAMING_SNAKE_CASE_			:					Dict          =       use_mean_pooling

								SCREAMING_SNAKE_CASE_			:					Union[str, Any]          =       decoder_num_attention_heads
								SCREAMING_SNAKE_CASE_			:					Any          =       decoder_hidden_size
								SCREAMING_SNAKE_CASE_			:					Dict          =       decoder_num_hidden_layers
								SCREAMING_SNAKE_CASE_			:					List[str]          =       decoder_intermediate_size
								SCREAMING_SNAKE_CASE_			:					str          =       norm_pix_loss









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






