code: 
  
  
  
  
  
  
  import inspect
  import unittest
  
  from transformers import ResNetConfig
  from transformers.testing_utils import require_torch, require_vision, slow, torch_device
  from transformers.utils import cached_property, is_torch_available, is_vision_available
  
  from ...test_backbone_common import BackboneTesterMixin
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
  from ...test_pipeline_mixin import PipelineTesterMixin
  
  
  if is_torch_available():
     import torch
     from torch import nn
  
     from transformers import ResNetBackbone, ResNetForImageClassification, ResNetModel
     from transformers.models.resnet.modeling_resnet import RESNET_PRETRAINED_MODEL_ARCHIVE_LIST
  
  
  if is_vision_available():
     from PIL import Image
  
     from transformers import AutoImageProcessor
  
  
  
  class 							_A :
      """simple docstring"""
  
      def __init__(							self			:    Optional[Any]   ,    __SCREAMING_SNAKE_CASE			:    List[str]   ,    __SCREAMING_SNAKE_CASE			:    Tuple=3   ,    __SCREAMING_SNAKE_CASE			:    Union[str, Any]=32   ,    __SCREAMING_SNAKE_CASE			:    str=3   ,    __SCREAMING_SNAKE_CASE			:    List[str]=10   ,    __SCREAMING_SNAKE_CASE			:    Union[str, Any]=[10, 20, 30, 40]   ,    __SCREAMING_SNAKE_CASE			:    Any=[1, 1, 2, 1]   ,    __SCREAMING_SNAKE_CASE			:    List[str]=True   ,    __SCREAMING_SNAKE_CASE			:    Any=True   ,    __SCREAMING_SNAKE_CASE			:    Optional[Any]="relu"   ,    __SCREAMING_SNAKE_CASE			:    Dict=3   ,    __SCREAMING_SNAKE_CASE			:    Optional[Any]=None   ,    __SCREAMING_SNAKE_CASE			:    Tuple=["stage2", "stage3", "stage4"]   ,    __SCREAMING_SNAKE_CASE			:    Tuple=[2, 3, 4]   ,    )			->       Union[str, Any]:
             __UpperCAmelCase    							=parent
             __UpperCAmelCase    							=batch_size
             __UpperCAmelCase    							=image_size
             __UpperCAmelCase    							=num_channels
             __UpperCAmelCase    							=embeddings_size
             __UpperCAmelCase    							=hidden_sizes
             __UpperCAmelCase    							=depths
             __UpperCAmelCase    							=is_training
             __UpperCAmelCase    							=use_labels
             __UpperCAmelCase    							=hidden_act
             __UpperCAmelCase    							=num_labels
             __UpperCAmelCase    							=scope
             __UpperCAmelCase    							=len(__SCREAMING_SNAKE_CASE			)
             __UpperCAmelCase    							=out_features
             __UpperCAmelCase    							=out_indices
  
  
  
      def _a       (							self			:    int			)			->       List[str]:
             __UpperCAmelCase    							=floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]			)
  
             __UpperCAmelCase    							=None
             if self.use_labels:
                    __UpperCAmelCase    							=ids_tensor([self.batch_size]   ,    self.num_labels			)
  
             __UpperCAmelCase    							=self.get_config()
  
             return config, pixel_values, labels
  
  
  
      def _a       (							self			:    int			)			->       List[str]:
             return ResNetConfig(
                 num_channels=self.num_channels   ,    embeddings_size=self.embeddings_size   ,    hidden_sizes=self.hidden_sizes   ,    depths=self.depths   ,    hidden_act=self.hidden_act   ,    num_labels=self.num_labels   ,    out_features=self.out_features   ,    out_indices=self.out_indices   ,    )
  
  
  
      def _a       (							self			:    Optional[int]   ,    __SCREAMING_SNAKE_CASE			:    int   ,    __SCREAMING_SNAKE_CASE			:    List[str]   ,    __SCREAMING_SNAKE_CASE			:    Optional[Any]			)			->       str:
             __UpperCAmelCase    							=ResNetModel(config=__SCREAMING_SNAKE_CASE			)
             model.to(__SCREAMING_SNAKE_CASE			)
             model.eval()
             __UpperCAmelCase    							=model(__SCREAMING_SNAKE_CASE			)
             # expected last hidden states: B, C, H // 32, W // 32
             self.parent.assertEqual(
                 result.last_hidden_state.shape   ,    (self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32)   ,    )
  
  
  
      def _a       (							self			:    Tuple   ,    __SCREAMING_SNAKE_CASE			:    Union[str, Any]   ,    __SCREAMING_SNAKE_CASE			:    Tuple   ,    __SCREAMING_SNAKE_CASE			:    Any			)			->       Dict:
             __UpperCAmelCase    							=self.num_labels
             __UpperCAmelCase    							=ResNetForImageClassification(__SCREAMING_SNAKE_CASE			)
             model.to(__SCREAMING_SNAKE_CASE			)
             model.eval()
             __UpperCAmelCase    							=model(__SCREAMING_SNAKE_CASE   ,    labels=__SCREAMING_SNAKE_CASE			)
             self.parent.assertEqual(result.logits.shape   ,    (self.batch_size, self.num_labels)			)
  
  
  
      def _a       (							self			:    Dict   ,    __SCREAMING_SNAKE_CASE			:    Any   ,    __SCREAMING_SNAKE_CASE			:    List[Any]   ,    __SCREAMING_SNAKE_CASE			:    Optional[int]			)			->       int:
             __UpperCAmelCase    							=ResNetBackbone(config=__SCREAMING_SNAKE_CASE			)
             model.to(__SCREAMING_SNAKE_CASE			)
             model.eval()
             __UpperCAmelCase    							=model(__SCREAMING_SNAKE_CASE			)
  
             # verify feature maps
             self.parent.assertEqual(len(result.feature_maps			)   ,    len(config.out_features			)			)
             self.parent.assertListEqual(list(result.feature_maps[0].shape			)   ,    [self.batch_size, self.hidden_sizes[1], 4, 4]			)
  
             # verify channels
             self.parent.assertEqual(len(model.channels			)   ,    len(config.out_features			)			)
             self.parent.assertListEqual(model.channels   ,    config.hidden_sizes[1:]			)
  
             # verify backbone works with out_features=None
             __UpperCAmelCase    							=None
             __UpperCAmelCase    							=ResNetBackbone(config=__SCREAMING_SNAKE_CASE			)
             model.to(__SCREAMING_SNAKE_CASE			)
             model.eval()
             __UpperCAmelCase    							=model(__SCREAMING_SNAKE_CASE			)
  
             # verify feature maps
             self.parent.assertEqual(len(result.feature_maps			)   ,    1			)
             self.parent.assertListEqual(list(result.feature_maps[0].shape			)   ,    [self.batch_size, self.hidden_sizes[-1], 1, 1]			)
  
             # verify channels
             self.parent.assertEqual(len(model.channels			)   ,    1			)
             self.parent.assertListEqual(model.channels   ,    [config.hidden_sizes[-1]]			)
  
  
  
      def _a       (							self			:    Tuple			)			->       List[str]:
             __UpperCAmelCase    							=self.prepare_config_and_inputs()
             __UpperCAmelCase							,   __UpperCAmelCase							,   __UpperCAmelCase    							=config_and_inputs
             __UpperCAmelCase    							={"""pixel_values""": pixel_values}
             return config, inputs_dict
  
  
  
  
  @require_torch
  class 							_A (    UpperCamelCase				,				UpperCamelCase				,				unittest.TestCase							):
      """simple docstring"""
  
      lowerCamelCase  :       int   =   (
          (
              ResNetModel,
              ResNetForImageClassification,
              ResNetBackbone,
          )
          if is_torch_available()
          else ()
      )
      lowerCamelCase  :       int   =   (
          {'feature-extraction': ResNetModel, 'image-classification': ResNetForImageClassification}
          if is_torch_available()
          else {}
      )
  
      lowerCamelCase  :       Union[str, Any]   =   True
      lowerCamelCase  :       Any   =   False
      lowerCamelCase  :       List[str]   =   False
      lowerCamelCase  :       Any   =   False
      lowerCamelCase  :       List[Any]   =   False
  
  
  
      def _a       (							self			:    Union[str, Any]			)			->       Dict:
             __UpperCAmelCase    							=ResNetModelTester(self			)
             __UpperCAmelCase    							=ConfigTester(self   ,    config_class=__SCREAMING_SNAKE_CASE   ,    has_text_modality=__SCREAMING_SNAKE_CASE			)
  
  
  
      def _a       (							self			:    Optional[int]			)			->       Dict:
             self.create_and_test_config_common_properties()
             self.config_tester.create_and_test_config_to_json_string()
             self.config_tester.create_and_test_config_to_json_file()
             self.config_tester.create_and_test_config_from_and_save_pretrained()
             self.config_tester.create_and_test_config_with_num_labels()
             self.config_tester.check_config_can_be_init_without_params()
             self.config_tester.check_config_arguments_init()
  
  
  
      def _a       (							self			:    Tuple			)			->       Optional[Any]:
             return
  
  
  
      @unittest.skip(reason="""ResNet does not use inputs_embeds"""			)
      def _a       (							self			:    str			)			->       Optional[Any]:
             pass
  
  
  
      @unittest.skip(reason="""ResNet does not support input and output embeddings"""			)
      def _a       (							self			:    Any			)			->       Optional[int]:
             pass
  
  
  
      def _a       (							self			:    Any			)			->       Any:
             __UpperCAmelCase							,   __UpperCAmelCase    							=self.model_tester.prepare_config_and_inputs_for_common()
  
             for model_class in self.all_model_classes:
                    __UpperCAmelCase    							=model_class(__SCREAMING_SNAKE_CASE			)
                    __UpperCAmelCase    							=inspect.signature(model.forward			)
                    # signature.parameters is an OrderedDict => so arg_names order is deterministic
                    __UpperCAmelCase    							=[*signature.parameters.keys()]
  
                    __UpperCAmelCase    							=["""pixel_values"""]
                    self.assertListEqual(arg_names[:1]   ,    __SCREAMING_SNAKE_CASE			)
  
  
  
      def _a       (							self			:    Tuple			)			->       Any:
             __UpperCAmelCase    							=self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*__SCREAMING_SNAKE_CASE			)
  
  
  
      def _a       (							self			:    str			)			->       str:
             __UpperCAmelCase    							=self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_backbone(*__SCREAMING_SNAKE_CASE			)
  
  
  
      def _a       (							self			:    Dict			)			->       Tuple:
             __UpperCAmelCase							,   __UpperCAmelCase    							=self.model_tester.prepare_config_and_inputs_for_common()
  
             for model_class in self.all_model_classes:
                    __UpperCAmelCase    							=model_class(config=__SCREAMING_SNAKE_CASE			)
                    for name, module in model.named_modules():
                           if isinstance(__SCREAMING_SNAKE_CASE   ,    (nn.BatchNormad, nn.GroupNorm)			):
                                  self.assertTrue(
                                      torch.all(module.weight == 1			)   ,    msg=f'''Parameter {name} of model {model_class} seems not properly initialized'''   ,    )
                                  self.assertTrue(
                                      torch.all(module.bias == 0			)   ,    msg=f'''Parameter {name} of model {model_class} seems not properly initialized'''   ,    )
  
  
  
      def _a       (							self			:    Dict			)			->       Optional[Any]:
             def check_hidden_states_output(__SCREAMING_SNAKE_CASE			:    List[Any]   ,    __SCREAMING_SNAKE_CASE			:    Any   ,    __SCREAMING_SNAKE_CASE			:    List[Any]			):
                    __UpperCAmelCase    							=model_class(__SCREAMING_SNAKE_CASE			)
                    model.to(__SCREAMING_SNAKE_CASE			)
                    model.eval()
  
                    with torch.no_grad():
                           __UpperCAmelCase    							=model(**self._prepare_for_class(__SCREAMING_SNAKE_CASE   ,    __SCREAMING_SNAKE_CASE			)			)
  
                    __UpperCAmelCase    							=outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states
  
                    __UpperCAmelCase    							=self.model_tester.num_stages
                    self.assertEqual(len(__SCREAMING_SNAKE_CASE			)   ,    expected_num_stages + 1			)
  
                    # ResNet's feature maps are of shape (batch_size, num_channels, height, width)
                    self.assertListEqual(
                        list(hidden_states[0].shape[-2:]			)   ,    [self.model_tester.image_size // 4, self.model_tester.image_size // 4]   ,    )
  
             __UpperCAmelCase							,   __UpperCAmelCase    							=self.model_tester.prepare_config_and_inputs_for_common()
             __UpperCAmelCase    							=["""basic""", """bottleneck"""]
             for model_class in self.all_model_classes:
                    for layer_type in layers_type:
                           __UpperCAmelCase    							=layer_type
                           __UpperCAmelCase    							=True
                           check_hidden_states_output(__SCREAMING_SNAKE_CASE   ,    __SCREAMING_SNAKE_CASE   ,    __SCREAMING_SNAKE_CASE			)
  
                           # check that output_hidden_states also work using config
                           del inputs_dict["output_hidden_states"]
                           __UpperCAmelCase    							=True
  
                           check_hidden_states_output(__SCREAMING_SNAKE_CASE   ,    __SCREAMING_SNAKE_CASE   ,    __SCREAMING_SNAKE_CASE			)
  
  
  
      @unittest.skip(reason="""ResNet does not use feedforward chunking"""			)
      def _a       (							self			:    Optional[int]			)			->       int:
             pass
  
  
  
      def _a       (							self			:    Tuple			)			->       List[str]:
             __UpperCAmelCase    							=self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_image_classification(*__SCREAMING_SNAKE_CASE			)
  
  
  
      @slow
      def _a       (							self			:    Dict			)			->       Union[str, Any]:
             for model_name in RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                    __UpperCAmelCase    							=ResNetModel.from_pretrained(__SCREAMING_SNAKE_CASE			)
                    self.assertIsNotNone(__SCREAMING_SNAKE_CASE			)
  
  
  
  
  
  
  
  def 			lowercase__  (				)  ->							Union[str, Any]:
  
  
  
  
  
  
  
         """simple docstring"""
  
  
  
  
  
  
         __UpperCAmelCase    							=Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""		)
         return image
  
  
  
  @require_torch
  @require_vision
  class 							_A (    unittest.TestCase							):
      """simple docstring"""
  
      @cached_property
      def _a       (							self			:    Optional[int]			)			->       List[str]:
             return (
                 AutoImageProcessor.from_pretrained(RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]			)
                 if is_vision_available()
                 else None
             )
  
  
  
      @slow
      def _a       (							self			:    List[Any]			)			->       Dict:
             __UpperCAmelCase    							=ResNetForImageClassification.from_pretrained(RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]			).to(__SCREAMING_SNAKE_CASE			)
  
             __UpperCAmelCase    							=self.default_image_processor
             __UpperCAmelCase    							=prepare_img()
             __UpperCAmelCase    							=image_processor(images=__SCREAMING_SNAKE_CASE   ,    return_tensors="""pt"""			).to(__SCREAMING_SNAKE_CASE			)
  
             # forward pass
             with torch.no_grad():
                    __UpperCAmelCase    							=model(**__SCREAMING_SNAKE_CASE			)
  
             # verify the logits
             __UpperCAmelCase    							=torch.Size((1, 1000)			)
             self.assertEqual(outputs.logits.shape   ,    __SCREAMING_SNAKE_CASE			)
  
             __UpperCAmelCase    							=torch.tensor([-11.1_069, -9.7_877, -8.3_777]			).to(__SCREAMING_SNAKE_CASE			)
  
             self.assertTrue(torch.allclose(outputs.logits[0, :3]   ,    __SCREAMING_SNAKE_CASE   ,    atol=1e-4			)			)
  
  
  
  
  @require_torch
  class 							_A (    UpperCamelCase				,				unittest.TestCase							):
      """simple docstring"""
  
      lowerCamelCase  :       Tuple   =   (ResNetBackbone,) if is_torch_available() else ()
      lowerCamelCase  :       int   =   False
      lowerCamelCase  :       Optional[int]   =   ResNetConfig
  
  
  
      def _a       (							self			:    List[Any]			)			->       str:
             __UpperCAmelCase    							=ResNetModelTester(self			)
  
  
  
  
  
style_context: 
  
  
  
  
  
  
  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 :
      """simple docstring"""
  
      def __init__(							self			:    Any   ,    __SCREAMING_SNAKE_CASE			:    str   ,    __SCREAMING_SNAKE_CASE			:    List[str]=13   ,    __SCREAMING_SNAKE_CASE			:    Union[str, Any]=7   ,    __SCREAMING_SNAKE_CASE			:    List[Any]=True   ,    __SCREAMING_SNAKE_CASE			:    Optional[int]=True   ,    __SCREAMING_SNAKE_CASE			:    Optional[int]=True   ,    __SCREAMING_SNAKE_CASE			:    str=99   ,    __SCREAMING_SNAKE_CASE			:    int=32   ,    __SCREAMING_SNAKE_CASE			:    str=5   ,    __SCREAMING_SNAKE_CASE			:    int=4   ,    __SCREAMING_SNAKE_CASE			:    List[str]=37   ,    __SCREAMING_SNAKE_CASE			:    int="gelu"   ,    __SCREAMING_SNAKE_CASE			:    Tuple=0.1   ,    __SCREAMING_SNAKE_CASE			:    List[str]=0.1   ,    __SCREAMING_SNAKE_CASE			:    Optional[int]=512   ,    __SCREAMING_SNAKE_CASE			:    int=16   ,    __SCREAMING_SNAKE_CASE			:    int=2   ,    __SCREAMING_SNAKE_CASE			:    Any=0.02   ,    __SCREAMING_SNAKE_CASE			:    Dict=3   ,    __SCREAMING_SNAKE_CASE			:    Dict=4   ,    __SCREAMING_SNAKE_CASE			:    str=None   ,    )			->       Optional[Any]:
             __UpperCAmelCase    							=parent
             __UpperCAmelCase    							=batch_size
             __UpperCAmelCase    							=seq_length
             __UpperCAmelCase    							=is_training
             __UpperCAmelCase    							=use_input_mask
             __UpperCAmelCase    							=use_labels
             __UpperCAmelCase    							=vocab_size
             __UpperCAmelCase    							=hidden_size
             __UpperCAmelCase    							=num_hidden_layers
             __UpperCAmelCase    							=num_attention_heads
             __UpperCAmelCase    							=intermediate_size
             __UpperCAmelCase    							=hidden_act
             __UpperCAmelCase    							=hidden_dropout_prob
             __UpperCAmelCase    							=attention_probs_dropout_prob
             __UpperCAmelCase    							=max_position_embeddings
             __UpperCAmelCase    							=type_vocab_size
             __UpperCAmelCase    							=type_sequence_label_size
             __UpperCAmelCase    							=initializer_range
             __UpperCAmelCase    							=num_labels
             __UpperCAmelCase    							=num_choices
             __UpperCAmelCase    							=scope
  
  
  
      def _a       (							self			:    str			)			->       Optional[Any]:
             __UpperCAmelCase    							=ids_tensor([self.batch_size, self.seq_length]   ,    self.vocab_size			)
  
             __UpperCAmelCase    							=None
             if self.use_input_mask:
                    __UpperCAmelCase    							=random_attention_mask([self.batch_size, self.seq_length]			)
  
             __UpperCAmelCase    							=None
             __UpperCAmelCase    							=None
             __UpperCAmelCase    							=None
             if self.use_labels:
                    __UpperCAmelCase    							=ids_tensor([self.batch_size]   ,    self.type_sequence_label_size			)
                    __UpperCAmelCase    							=ids_tensor([self.batch_size, self.seq_length]   ,    self.num_labels			)
                    __UpperCAmelCase    							=ids_tensor([self.batch_size]   ,    self.num_choices			)
  
             __UpperCAmelCase    							=self.get_config()
  
             return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels
  
  
  
      def _a       (							self			:    Optional[Any]			)			->       Any:
             __UpperCAmelCase    							=ids_tensor([self.batch_size, self.seq_length]   ,    self.vocab_size			)
  
             __UpperCAmelCase    							=None
             if self.use_input_mask:
                    __UpperCAmelCase    							=random_attention_mask([self.batch_size, self.seq_length]			)
             __UpperCAmelCase    							=self.get_config()
  
             return config, input_ids, input_mask
  
  
  
      def _a       (							self			:    List[str]			)			->       List[str]:
             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			:    str   ,    __SCREAMING_SNAKE_CASE			:    Optional[int]   ,    __SCREAMING_SNAKE_CASE			:    List[str]   ,    __SCREAMING_SNAKE_CASE			:    Optional[int]   ,    __SCREAMING_SNAKE_CASE			:    Union[str, Any]   ,    __SCREAMING_SNAKE_CASE			:    str   ,    __SCREAMING_SNAKE_CASE			:    Dict			)			->       Optional[int]:
             __UpperCAmelCase    							=ErnieMModel(config=__SCREAMING_SNAKE_CASE			)
             model.to(__SCREAMING_SNAKE_CASE			)
             model.eval()
             __UpperCAmelCase    							=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 _a       (							self			:    Tuple   ,    __SCREAMING_SNAKE_CASE			:    List[str]   ,    __SCREAMING_SNAKE_CASE			:    Optional[Any]   ,    __SCREAMING_SNAKE_CASE			:    List[Any]   ,    __SCREAMING_SNAKE_CASE			:    Tuple   ,    __SCREAMING_SNAKE_CASE			:    Any   ,    __SCREAMING_SNAKE_CASE			:    Dict			)			->       int:
             __UpperCAmelCase    							=ErnieMForQuestionAnswering(config=__SCREAMING_SNAKE_CASE			)
             model.to(__SCREAMING_SNAKE_CASE			)
             model.eval()
             __UpperCAmelCase    							=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 _a       (							self			:    Optional[Any]   ,    __SCREAMING_SNAKE_CASE			:    List[str]   ,    __SCREAMING_SNAKE_CASE			:    List[Any]   ,    __SCREAMING_SNAKE_CASE			:    List[str]   ,    __SCREAMING_SNAKE_CASE			:    Tuple   ,    __SCREAMING_SNAKE_CASE			:    Dict   ,    __SCREAMING_SNAKE_CASE			:    Optional[Any]			)			->       Any:
             __UpperCAmelCase    							=ErnieMForInformationExtraction(config=__SCREAMING_SNAKE_CASE			)
             model.to(__SCREAMING_SNAKE_CASE			)
             model.eval()
             __UpperCAmelCase    							=torch.ones_like(__SCREAMING_SNAKE_CASE   ,    dtype=torch.floataa			)
             __UpperCAmelCase    							=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 _a       (							self			:    Union[str, Any]   ,    __SCREAMING_SNAKE_CASE			:    Optional[int]   ,    __SCREAMING_SNAKE_CASE			:    Optional[int]   ,    __SCREAMING_SNAKE_CASE			:    Any   ,    __SCREAMING_SNAKE_CASE			:    Optional[int]   ,    __SCREAMING_SNAKE_CASE			:    List[Any]   ,    __SCREAMING_SNAKE_CASE			:    Optional[Any]			)			->       str:
             __UpperCAmelCase    							=self.num_labels
             __UpperCAmelCase    							=ErnieMForSequenceClassification(__SCREAMING_SNAKE_CASE			)
             model.to(__SCREAMING_SNAKE_CASE			)
             model.eval()
             __UpperCAmelCase    							=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 _a       (							self			:    Dict   ,    __SCREAMING_SNAKE_CASE			:    Optional[Any]   ,    __SCREAMING_SNAKE_CASE			:    List[Any]   ,    __SCREAMING_SNAKE_CASE			:    Union[str, Any]   ,    __SCREAMING_SNAKE_CASE			:    Dict   ,    __SCREAMING_SNAKE_CASE			:    Optional[int]   ,    __SCREAMING_SNAKE_CASE			:    Dict			)			->       Dict:
             __UpperCAmelCase    							=self.num_labels
             __UpperCAmelCase    							=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			)
  
             __UpperCAmelCase    							=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 _a       (							self			:    Optional[Any]   ,    __SCREAMING_SNAKE_CASE			:    Union[str, Any]   ,    __SCREAMING_SNAKE_CASE			:    Optional[int]   ,    __SCREAMING_SNAKE_CASE			:    Tuple   ,    __SCREAMING_SNAKE_CASE			:    int   ,    __SCREAMING_SNAKE_CASE			:    Tuple   ,    __SCREAMING_SNAKE_CASE			:    Optional[Any]			)			->       List[Any]:
             __UpperCAmelCase    							=self.num_choices
             __UpperCAmelCase    							=ErnieMForMultipleChoice(config=__SCREAMING_SNAKE_CASE			)
             model.to(__SCREAMING_SNAKE_CASE			)
             model.eval()
             __UpperCAmelCase    							=input_ids.unsqueeze(1			).expand(-1   ,    self.num_choices   ,    -1			).contiguous()
             __UpperCAmelCase    							=input_mask.unsqueeze(1			).expand(-1   ,    self.num_choices   ,    -1			).contiguous()
             __UpperCAmelCase    							=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 _a       (							self			:    Any			)			->       List[str]:
             __UpperCAmelCase    							=self.prepare_config_and_inputs()
             (
                 (
                 __UpperCAmelCase
             )							,   (
                 __UpperCAmelCase
             )							,   (
                 __UpperCAmelCase
             )							,   (
                 __UpperCAmelCase
             )							,   (
                 __UpperCAmelCase
             )							,   (
                 __UpperCAmelCase
             )							,   
             )    							=config_and_inputs
             __UpperCAmelCase    							={"""input_ids""": input_ids, """attention_mask""": input_mask}
             return config, inputs_dict
  
  
  
  
  @require_torch
  class 							_A (    UpperCamelCase				,				UpperCamelCase				,				unittest.TestCase							):
      """simple docstring"""
  
      lowerCamelCase  :       Union[str, Any]   =   (
          (
              ErnieMModel,
              ErnieMForMultipleChoice,
              ErnieMForQuestionAnswering,
              ErnieMForSequenceClassification,
              ErnieMForTokenClassification,
          )
          if is_torch_available()
          else ()
      )
      lowerCamelCase  :       Optional[Any]   =   ()
      lowerCamelCase  :       str   =   (
          {
              'feature-extraction': ErnieMModel,
              'question-answering': ErnieMForQuestionAnswering,
              'text-classification': ErnieMForSequenceClassification,
              'token-classification': ErnieMForTokenClassification,
              'zero-shot': ErnieMForSequenceClassification,
          }
          if is_torch_available()
          else {}
      )
      lowerCamelCase  :       Optional[int]   =   False
  
  
  
      def _a       (							self			:    Dict   ,    __SCREAMING_SNAKE_CASE			:    Dict   ,    __SCREAMING_SNAKE_CASE			:    Union[str, Any]   ,    __SCREAMING_SNAKE_CASE			:    List[Any]   ,    __SCREAMING_SNAKE_CASE			:    int   ,    __SCREAMING_SNAKE_CASE			:    int			)			->       Optional[int]:
             if pipeline_test_casse_name == "QAPipelineTests":
                    return True
  
             return False
  
  
  
      def _a       (							self			:    Optional[int]			)			->       List[Any]:
             __UpperCAmelCase    							=ErnieMModelTester(self			)
             __UpperCAmelCase    							=ConfigTester(self   ,    config_class=__SCREAMING_SNAKE_CASE   ,    hidden_size=37			)
  
  
  
      def _a       (							self			:    int			)			->       List[str]:
             self.config_tester.run_common_tests()
  
  
  
      def _a       (							self			:    str			)			->       str:
             __UpperCAmelCase    							=self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*__SCREAMING_SNAKE_CASE			)
  
  
  
      def _a       (							self			:    Optional[int]			)			->       List[str]:
             __UpperCAmelCase    							=self.model_tester.prepare_config_and_inputs()
             for type in ["absolute", "relative_key", "relative_key_query"]:
                    __UpperCAmelCase    							=type
                    self.model_tester.create_and_check_model(*__SCREAMING_SNAKE_CASE			)
  
  
  
      def _a       (							self			:    Optional[int]			)			->       str:
             __UpperCAmelCase    							=self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_multiple_choice(*__SCREAMING_SNAKE_CASE			)
  
  
  
      def _a       (							self			:    List[str]			)			->       Union[str, Any]:
             __UpperCAmelCase    							=self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_question_answering(*__SCREAMING_SNAKE_CASE			)
  
  
  
      def _a       (							self			:    Any			)			->       str:
             __UpperCAmelCase    							=self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_sequence_classification(*__SCREAMING_SNAKE_CASE			)
  
  
  
      def _a       (							self			:    str			)			->       List[Any]:
             __UpperCAmelCase    							=self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_information_extraction(*__SCREAMING_SNAKE_CASE			)
  
  
  
      def _a       (							self			:    List[Any]			)			->       List[str]:
             __UpperCAmelCase    							=self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_token_classification(*__SCREAMING_SNAKE_CASE			)
  
  
  
      @slow
      def _a       (							self			:    List[str]			)			->       Optional[Any]:
             for model_name in ERNIE_M_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                    __UpperCAmelCase    							=ErnieMModel.from_pretrained(__SCREAMING_SNAKE_CASE			)
                    self.assertIsNotNone(__SCREAMING_SNAKE_CASE			)
  
  
  
  
  @require_torch
  class 							_A (    unittest.TestCase							):
      """simple docstring"""
  
      @slow
      def _a       (							self			:    Tuple			)			->       Optional[Any]:
             __UpperCAmelCase    							=ErnieMModel.from_pretrained("""susnato/ernie-m-base_pytorch"""			)
             model.eval()
             __UpperCAmelCase    							=torch.tensor([[0, 1, 2, 3, 4, 5]]			)
             __UpperCAmelCase    							=model(__SCREAMING_SNAKE_CASE			)[0]
  
             # TODO Replace vocab size
             __UpperCAmelCase    							=768
  
             __UpperCAmelCase    							=torch.Size((1, 6, hidden_size)			)
             self.assertEqual(output.shape   ,    __SCREAMING_SNAKE_CASE			)
  
             __UpperCAmelCase    							=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]   ,    __SCREAMING_SNAKE_CASE   ,    atol=1e-3			)			)
  
  
  
  
  