code: 
  
  
  
  
  
  
  """simple docstring"""
  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 					UpperCamelCase__   :
  
  
  
  
  
  
  
      """simple docstring"""
  
  
  
  
  
  
  
      def __init__(		self   :  Any							,						UpperCamelCase_   :  List[Any]							,						UpperCamelCase_   :  Any=1_3							,						UpperCamelCase_   :  List[str]=7							,						UpperCamelCase_   :  Any=True							,						UpperCamelCase_   :  int=True							,						UpperCamelCase_   :  Tuple=True							,						UpperCamelCase_   :  Dict=9_9							,						UpperCamelCase_   :  str=3_2							,						UpperCamelCase_   :  List[str]=5							,						UpperCamelCase_   :  Any=4							,						UpperCamelCase_   :  Union[str, Any]=3_7							,						UpperCamelCase_   :  Optional[Any]="gelu"							,						UpperCamelCase_   :  List[Any]=0.1							,						UpperCamelCase_   :  Union[str, Any]=0.1							,						UpperCamelCase_   :  str=5_1_2							,						UpperCamelCase_   :  str=1_6							,						UpperCamelCase_   :  int=2							,						UpperCamelCase_   :  Union[str, Any]=0.02							,						UpperCamelCase_   :  Any=3							,						UpperCamelCase_   :  int=4							,						UpperCamelCase_   :  Union[str, Any]=None							,						):
  
  
  
  
  
             '''simple docstring'''
  
             __magic_name__										=						parent
             __magic_name__										=						batch_size
             __magic_name__										=						seq_length
             __magic_name__										=						is_training
             __magic_name__										=						use_input_mask
             __magic_name__										=						use_labels
             __magic_name__										=						vocab_size
             __magic_name__										=						hidden_size
             __magic_name__										=						num_hidden_layers
             __magic_name__										=						num_attention_heads
             __magic_name__										=						intermediate_size
             __magic_name__										=						hidden_act
             __magic_name__										=						hidden_dropout_prob
             __magic_name__										=						attention_probs_dropout_prob
             __magic_name__										=						max_position_embeddings
             __magic_name__										=						type_vocab_size
             __magic_name__										=						type_sequence_label_size
             __magic_name__										=						initializer_range
             __magic_name__										=						num_labels
             __magic_name__										=						num_choices
             __magic_name__										=						scope
  
  
  
  
  
  
  
      def 							a__ (		self   :  str   ):
  
  
  
  
  
             '''simple docstring'''
  
             __magic_name__										=						ids_tensor([self.batch_size, self.seq_length]							,						self.vocab_size   )
  
             __magic_name__										=						None
             if self.use_input_mask:
                    __magic_name__										=						random_attention_mask([self.batch_size, self.seq_length]   )
  
             __magic_name__										=						None
             __magic_name__										=						None
             __magic_name__										=						None
             if self.use_labels:
                    __magic_name__										=						ids_tensor([self.batch_size]							,						self.type_sequence_label_size   )
                    __magic_name__										=						ids_tensor([self.batch_size, self.seq_length]							,						self.num_labels   )
                    __magic_name__										=						ids_tensor([self.batch_size]							,						self.num_choices   )
  
             __magic_name__										=						self.get_config()
  
             return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels
  
  
  
  
  
  
  
      def 							a__ (		self   :  Any   ):
  
  
  
  
  
             '''simple docstring'''
  
             __magic_name__										=						ids_tensor([self.batch_size, self.seq_length]							,						self.vocab_size   )
  
             __magic_name__										=						None
             if self.use_input_mask:
                    __magic_name__										=						random_attention_mask([self.batch_size, self.seq_length]   )
             __magic_name__										=						self.get_config()
  
             return config, input_ids, input_mask
  
  
  
  
  
  
  
      def 							a__ (		self   :  List[str]   ):
  
  
  
  
  
             '''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 							a__ (		self   :  List[str]							,						UpperCamelCase_   :  List[Any]							,						UpperCamelCase_   :  Optional[int]							,						UpperCamelCase_   :  Optional[int]							,						UpperCamelCase_   :  Union[str, Any]							,						UpperCamelCase_   :  List[Any]							,						UpperCamelCase_   :  List[Any]   ):
  
  
  
  
  
             '''simple docstring'''
  
             __magic_name__										=						ErnieMModel(config=lowercase_   )
             model.to(lowercase_   )
             model.eval()
             __magic_name__										=						model(lowercase_							,						return_dict=lowercase_   )
             self.parent.assertEqual(result.last_hidden_state.shape							,						(self.batch_size, self.seq_length, self.hidden_size)   )
  
  
  
  
  
  
  
      def 							a__ (		self   :  Tuple							,						UpperCamelCase_   :  Any							,						UpperCamelCase_   :  Optional[int]							,						UpperCamelCase_   :  List[Any]							,						UpperCamelCase_   :  List[str]							,						UpperCamelCase_   :  Any							,						UpperCamelCase_   :  List[str]   ):
  
  
  
  
  
             '''simple docstring'''
  
             __magic_name__										=						ErnieMForQuestionAnswering(config=lowercase_   )
             model.to(lowercase_   )
             model.eval()
             __magic_name__										=						model(
                 lowercase_							,						attention_mask=lowercase_							,						start_positions=lowercase_							,						end_positions=lowercase_							,						)
             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 							a__ (		self   :  List[str]							,						UpperCamelCase_   :  Any							,						UpperCamelCase_   :  List[str]							,						UpperCamelCase_   :  Any							,						UpperCamelCase_   :  int							,						UpperCamelCase_   :  Dict							,						UpperCamelCase_   :  Dict   ):
  
  
  
  
  
             '''simple docstring'''
  
             __magic_name__										=						ErnieMForInformationExtraction(config=lowercase_   )
             model.to(lowercase_   )
             model.eval()
             __magic_name__										=						torch.ones_like(lowercase_							,						dtype=torch.floataa   )
             __magic_name__										=						model(
                 lowercase_							,						attention_mask=lowercase_							,						start_positions=lowercase_							,						end_positions=lowercase_							,						)
             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 							a__ (		self   :  List[Any]							,						UpperCamelCase_   :  int							,						UpperCamelCase_   :  int							,						UpperCamelCase_   :  str							,						UpperCamelCase_   :  List[str]							,						UpperCamelCase_   :  Dict							,						UpperCamelCase_   :  Optional[Any]   ):
  
  
  
  
  
             '''simple docstring'''
  
             __magic_name__										=						self.num_labels
             __magic_name__										=						ErnieMForSequenceClassification(lowercase_   )
             model.to(lowercase_   )
             model.eval()
             __magic_name__										=						model(lowercase_							,						attention_mask=lowercase_							,						labels=lowercase_   )
             self.parent.assertEqual(result.logits.shape							,						(self.batch_size, self.num_labels)   )
  
  
  
  
  
  
  
      def 							a__ (		self   :  List[Any]							,						UpperCamelCase_   :  Union[str, Any]							,						UpperCamelCase_   :  Optional[Any]							,						UpperCamelCase_   :  Any							,						UpperCamelCase_   :  List[Any]							,						UpperCamelCase_   :  Union[str, Any]							,						UpperCamelCase_   :  str   ):
  
  
  
  
  
             '''simple docstring'''
  
             __magic_name__										=						self.num_labels
             __magic_name__										=						ErnieMForTokenClassification(config=lowercase_   )
             model.to(lowercase_   )
             model.eval()
             input_ids.to(lowercase_   )
             input_mask.to(lowercase_   )
             token_labels.to(lowercase_   )
  
             __magic_name__										=						model(lowercase_							,						attention_mask=lowercase_							,						labels=lowercase_   )
  
             self.parent.assertEqual(result.logits.shape							,						(self.batch_size, self.seq_length, self.num_labels)   )
  
  
  
  
  
  
  
      def 							a__ (		self   :  Optional[Any]							,						UpperCamelCase_   :  Dict							,						UpperCamelCase_   :  int							,						UpperCamelCase_   :  Tuple							,						UpperCamelCase_   :  Optional[Any]							,						UpperCamelCase_   :  str							,						UpperCamelCase_   :  int   ):
  
  
  
  
  
             '''simple docstring'''
  
             __magic_name__										=						self.num_choices
             __magic_name__										=						ErnieMForMultipleChoice(config=lowercase_   )
             model.to(lowercase_   )
             model.eval()
             __magic_name__										=						input_ids.unsqueeze(1   ).expand(-1							,						self.num_choices							,						-1   ).contiguous()
             __magic_name__										=						input_mask.unsqueeze(1   ).expand(-1							,						self.num_choices							,						-1   ).contiguous()
             __magic_name__										=						model(
                 lowercase_							,						attention_mask=lowercase_							,						labels=lowercase_							,						)
             self.parent.assertEqual(result.logits.shape							,						(self.batch_size, self.num_choices)   )
  
  
  
  
  
  
  
      def 							a__ (		self   :  List[Any]   ):
  
  
  
  
  
             '''simple docstring'''
  
             __magic_name__										=						self.prepare_config_and_inputs()
             (
                 (
                 __magic_name__   
             )							,     (
                 __magic_name__   
             )							,     (
                 __magic_name__   
             )							,     (
                 __magic_name__   
             )							,     (
                 __magic_name__   
             )							,     (
                 __magic_name__   
             )							,        
             )										=						config_and_inputs
             __magic_name__										=						{'input_ids': input_ids, 'attention_mask': input_mask}
             return config, inputs_dict
  
  
  
  @require_torch
  class 					UpperCamelCase__   (							lowerCamelCase__       ,  lowerCamelCase__       ,  unittest.TestCase):
  
  
  
  
  
  
  
      """simple docstring"""
      __UpperCAmelCase											=   (
          (
              ErnieMModel,
              ErnieMForMultipleChoice,
              ErnieMForQuestionAnswering,
              ErnieMForSequenceClassification,
              ErnieMForTokenClassification,
          )
          if is_torch_available()
          else ()
      )
      __UpperCAmelCase											=   ()
      __UpperCAmelCase											=   (
          {
              'feature-extraction': ErnieMModel,
              'question-answering': ErnieMForQuestionAnswering,
              'text-classification': ErnieMForSequenceClassification,
              'token-classification': ErnieMForTokenClassification,
              'zero-shot': ErnieMForSequenceClassification,
          }
          if is_torch_available()
          else {}
      )
      __UpperCAmelCase											=   False
  
  
  
  
  
  
  
      def 							a__ (		self   :  Optional[int]							,						UpperCamelCase_   :  Any							,						UpperCamelCase_   :  Any							,						UpperCamelCase_   :  List[str]							,						UpperCamelCase_   :  Dict							,						UpperCamelCase_   :  Union[str, Any]   ):
  
  
  
  
  
             '''simple docstring'''
  
             if pipeline_test_casse_name == "QAPipelineTests":
                    return True
  
             return False
  
  
  
  
  
  
  
      def 							a__ (		self   :  List[str]   ):
  
  
  
  
  
             '''simple docstring'''
  
             __magic_name__										=						ErnieMModelTester(self   )
             __magic_name__										=						ConfigTester(self							,						config_class=lowercase_							,						hidden_size=3_7   )
  
  
  
  
  
  
  
      def 							a__ (		self   :  Any   ):
  
  
  
  
  
             '''simple docstring'''
  
             self.config_tester.run_common_tests()
  
  
  
  
  
  
  
      def 							a__ (		self   :  Tuple   ):
  
  
  
  
  
             '''simple docstring'''
  
             __magic_name__										=						self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*lowercase_   )
  
  
  
  
  
  
  
      def 							a__ (		self   :  Tuple   ):
  
  
  
  
  
             '''simple docstring'''
  
             __magic_name__										=						self.model_tester.prepare_config_and_inputs()
             for type in ["absolute", "relative_key", "relative_key_query"]:
                    __magic_name__										=						type
                    self.model_tester.create_and_check_model(*lowercase_   )
  
  
  
  
  
  
  
      def 							a__ (		self   :  Optional[Any]   ):
  
  
  
  
  
             '''simple docstring'''
  
             __magic_name__										=						self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_multiple_choice(*lowercase_   )
  
  
  
  
  
  
  
      def 							a__ (		self   :  List[str]   ):
  
  
  
  
  
             '''simple docstring'''
  
             __magic_name__										=						self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_question_answering(*lowercase_   )
  
  
  
  
  
  
  
      def 							a__ (		self   :  Union[str, Any]   ):
  
  
  
  
  
             '''simple docstring'''
  
             __magic_name__										=						self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_sequence_classification(*lowercase_   )
  
  
  
  
  
  
  
      def 							a__ (		self   :  Optional[int]   ):
  
  
  
  
  
             '''simple docstring'''
  
             __magic_name__										=						self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_information_extraction(*lowercase_   )
  
  
  
  
  
  
  
      def 							a__ (		self   :  Any   ):
  
  
  
  
  
             '''simple docstring'''
  
             __magic_name__										=						self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_token_classification(*lowercase_   )
  
  
  
  
  
  
  
      @slow
      def 							a__ (		self   :  List[Any]   ):
  
  
  
  
  
             '''simple docstring'''
  
             for model_name in ERNIE_M_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                    __magic_name__										=						ErnieMModel.from_pretrained(lowercase_   )
                    self.assertIsNotNone(lowercase_   )
  
  
  
  @require_torch
  class 					UpperCamelCase__   (							unittest.TestCase):
  
  
  
  
  
  
  
      """simple docstring"""
  
  
  
  
  
  
  
      @slow
      def 							a__ (		self   :  Dict   ):
  
  
  
  
  
             '''simple docstring'''
  
             __magic_name__										=						ErnieMModel.from_pretrained('susnato/ernie-m-base_pytorch'   )
             model.eval()
             __magic_name__										=						torch.tensor([[0, 1, 2, 3, 4, 5]]   )
             __magic_name__										=						model(lowercase_   )[0]
  
             # TODO Replace vocab size
             __magic_name__										=						7_6_8
  
             __magic_name__										=						torch.Size((1, 6, hidden_size)   )
             self.assertEqual(output.shape							,						lowercase_   )
  
             __magic_name__										=						torch.tensor(
                 [[[-0.0_012, 0.1_245, -0.0_214], [-0.0_742, 0.0_244, -0.0_771], [-0.0_333, 0.1_164, -0.1_554]]]   )
  
             self.assertTrue(torch.allclose(output[:, :3, :3]							,						lowercase_							,						atol=1e-3   )   )
style_context: 
  
  
  
  
  
  
  """simple docstring"""
  from typing import TYPE_CHECKING
  
  from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available
  
  
  snake_case   :   str    		=		{"""configuration_sew_d""": ["""SEW_D_PRETRAINED_CONFIG_ARCHIVE_MAP""", """SEWDConfig"""]}
  
  try:
   if not is_torch_available():
    raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
   pass
  else:
   snake_case   :   Union[str, Any]    		=		[
       """SEW_D_PRETRAINED_MODEL_ARCHIVE_LIST""",
       """SEWDForCTC""",
       """SEWDForSequenceClassification""",
       """SEWDModel""",
       """SEWDPreTrainedModel""",
   ]
  
  if TYPE_CHECKING:
   from .configuration_sew_d import SEW_D_PRETRAINED_CONFIG_ARCHIVE_MAP, SEWDConfig
  
   try:
    if not is_torch_available():
     raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
    pass
   else:
    from .modeling_sew_d import (
        SEW_D_PRETRAINED_MODEL_ARCHIVE_LIST,
        SEWDForCTC,
        SEWDForSequenceClassification,
        SEWDModel,
        SEWDPreTrainedModel,
    )
  
  
  else:
   import sys
  
   snake_case   :   Union[str, Any]    		=		_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)