



"""simple docstring"""
import csv
import dataclasses
import json
from dataclasses import dataclass
from typing import List, Optional, Union

from ...utils import is_tf_available, is_torch_available, logging


__SCREAMING_SNAKE_CASE     :  Tuple										=					logging.get_logger(__name__)


@dataclass
class 							lowerCamelCase_:





					'''simple docstring'''



					lowercase__      :				str
					lowercase__      :				str
					lowercase__      :				Optional[str]        =       None
					lowercase__      :				Optional[str]        =       None

					def 	snake_case__					(			self      ):
									return json.dumps(dataclasses.asdict(self      ) ,				indent=2      ) + "\n"


@dataclass(frozen=A__			)
class 							lowerCamelCase_:





					'''simple docstring'''



					lowercase__      :				List[int]
					lowercase__      :				Optional[List[int]]        =       None
					lowercase__      :				Optional[List[int]]        =       None
					lowercase__      :				Optional[Union[int, float]]        =       None

					def 	snake_case__					(			self      ):
									return json.dumps(dataclasses.asdict(self      )      ) + "\n"


class 							lowerCamelCase_:





					'''simple docstring'''



					def 	snake_case__					(			self ,				lowerCamelCase__      ):
									raise NotImplementedError()

					def 	snake_case__					(			self ,				lowerCamelCase__      ):
									raise NotImplementedError()

					def 	snake_case__					(			self ,				lowerCamelCase__      ):
									raise NotImplementedError()

					def 	snake_case__					(			self ,				lowerCamelCase__      ):
									raise NotImplementedError()

					def 	snake_case__					(			self      ):
									raise NotImplementedError()

					def 	snake_case__					(			self ,				lowerCamelCase__      ):
									if len(self.get_labels()      ) > 1:
													_lowerCamelCase					     = self.get_labels()[int(example.label      )]
									return example





					@classmethod
					def 	snake_case__					(			cls ,				lowerCamelCase__ ,				lowerCamelCase__=None      ):
									with open(lowerCamelCase__ ,				'''r''' ,				encoding='''utf-8-sig'''      ) as f:
													return list(csv.reader(lowerCamelCase__ ,				delimiter='''\t''' ,				quotechar=lowerCamelCase__      )      )


class 							lowerCamelCase_(      A__			):





					'''simple docstring'''



					def __init__(			self ,				lowerCamelCase__=None ,				lowerCamelCase__=None ,				lowerCamelCase__="classification" ,				lowerCamelCase__=False      ):
									_lowerCamelCase					     = [] if labels is None else labels
									_lowerCamelCase					     = [] if examples is None else examples
									_lowerCamelCase					     = mode
									_lowerCamelCase					     = verbose

					def __len__(			self      ):
									return len(self.examples      )

					def __getitem__(			self ,				lowerCamelCase__      ):
									if isinstance(lowerCamelCase__ ,				lowerCamelCase__      ):
													return SingleSentenceClassificationProcessor(labels=self.labels ,				examples=self.examples[idx]      )
									return self.examples[idx]

					@classmethod
					def 	snake_case__					(			cls ,				lowerCamelCase__ ,				lowerCamelCase__="" ,				lowerCamelCase__=0 ,				lowerCamelCase__=1 ,				lowerCamelCase__=None ,				lowerCamelCase__=False ,				**lowerCamelCase__      ):
									_lowerCamelCase					     = cls(**lowerCamelCase__      )
									processor.add_examples_from_csv(
									    lowerCamelCase__ ,				split_name=lowerCamelCase__ ,				column_label=lowerCamelCase__ ,				column_text=lowerCamelCase__ ,				column_id=lowerCamelCase__ ,				skip_first_row=lowerCamelCase__ ,				overwrite_labels=lowerCamelCase__ ,				overwrite_examples=lowerCamelCase__ ,				)
									return processor

					@classmethod
					def 	snake_case__					(			cls ,				lowerCamelCase__ ,				lowerCamelCase__=None ,				**lowerCamelCase__      ):
									_lowerCamelCase					     = cls(**lowerCamelCase__      )
									processor.add_examples(lowerCamelCase__ ,				labels=lowerCamelCase__      )
									return processor

					def 	snake_case__					(			self ,				lowerCamelCase__ ,				lowerCamelCase__="" ,				lowerCamelCase__=0 ,				lowerCamelCase__=1 ,				lowerCamelCase__=None ,				lowerCamelCase__=False ,				lowerCamelCase__=False ,				lowerCamelCase__=False ,				):
									_lowerCamelCase					     = self._read_tsv(lowerCamelCase__      )
									if skip_first_row:
													_lowerCamelCase					     = lines[1:]
									_lowerCamelCase					     = []
									_lowerCamelCase					     = []
									_lowerCamelCase					     = []
									for i, line in enumerate(lowerCamelCase__      ):
													texts.append(line[column_text]      )
													labels.append(line[column_label]      )
													if column_id is not None:
																	ids.append(line[column_id]      )
													else:
																	_lowerCamelCase					     = F"""{split_name}-{i}""" if split_name else str(lowerCamelCase__      )
																	ids.append(lowerCamelCase__      )

									return self.add_examples(
									    lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__ ,				overwrite_labels=lowerCamelCase__ ,				overwrite_examples=lowerCamelCase__      )

					def 	snake_case__					(			self ,				lowerCamelCase__ ,				lowerCamelCase__=None ,				lowerCamelCase__=None ,				lowerCamelCase__=False ,				lowerCamelCase__=False      ):
									if labels is not None and len(lowerCamelCase__      ) != len(lowerCamelCase__      ):
													raise ValueError(
													    F"""Text and labels have mismatched lengths {len(lowerCamelCase__      )} and {len(lowerCamelCase__      )}"""      )
									if ids is not None and len(lowerCamelCase__      ) != len(lowerCamelCase__      ):
													raise ValueError(F"""Text and ids have mismatched lengths {len(lowerCamelCase__      )} and {len(lowerCamelCase__      )}"""      )
									if ids is None:
													_lowerCamelCase					     = [None] * len(lowerCamelCase__      )
									if labels is None:
													_lowerCamelCase					     = [None] * len(lowerCamelCase__      )
									_lowerCamelCase					     = []
									_lowerCamelCase					     = set()
									for text_or_text_and_label, label, guid in zip(lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__      ):
													if isinstance(lowerCamelCase__ ,				(tuple, list)      ) and label is None:
																	_lowerCamelCase     ,   _lowerCamelCase					     = text_or_text_and_label
													else:
																	_lowerCamelCase					     = text_or_text_and_label
													added_labels.add(lowerCamelCase__      )
													examples.append(InputExample(guid=lowerCamelCase__ ,				text_a=lowerCamelCase__ ,				text_b=lowerCamelCase__ ,				label=lowerCamelCase__      )      )

									# Update examples
									if overwrite_examples:
													_lowerCamelCase					     = examples
									else:
													self.examples.extend(lowerCamelCase__      )

									# Update labels
									if overwrite_labels:
													_lowerCamelCase					     = list(lowerCamelCase__      )
									else:
													_lowerCamelCase					     = list(set(self.labels      ).union(lowerCamelCase__      )      )

									return self.examples





					def 	snake_case__					(			self ,				lowerCamelCase__ ,				lowerCamelCase__=None ,				lowerCamelCase__=False ,				lowerCamelCase__=0 ,				lowerCamelCase__=True ,				lowerCamelCase__=None ,				):
									if max_length is None:
													_lowerCamelCase					     = tokenizer.max_len

									_lowerCamelCase					     = {label: i for i, label in enumerate(self.labels      )}

									_lowerCamelCase					     = []
									for ex_index, example in enumerate(self.examples      ):
													if ex_index % 1_0_0_0_0 == 0:
																	logger.info(F"""Tokenizing example {ex_index}"""      )

													_lowerCamelCase					     = tokenizer.encode(
													    example.text_a ,				add_special_tokens=lowerCamelCase__ ,				max_length=min(lowerCamelCase__ ,				tokenizer.max_len      ) ,				)
													all_input_ids.append(lowerCamelCase__      )

									_lowerCamelCase					     = max(len(lowerCamelCase__      ) for input_ids in all_input_ids      )

									_lowerCamelCase					     = []
									for ex_index, (input_ids, example) in enumerate(zip(lowerCamelCase__ ,				self.examples      )      ):
													if ex_index % 1_0_0_0_0 == 0:
																	logger.info(F"""Writing example {ex_index}/{len(self.examples      )}"""      )
													# The mask has 1 for real tokens and 0 for padding tokens. Only real
													# tokens are attended to.
													_lowerCamelCase					     = [1 if mask_padding_with_zero else 0] * len(lowerCamelCase__      )

													# Zero-pad up to the sequence length.
													_lowerCamelCase					     = batch_length - len(lowerCamelCase__      )
													if pad_on_left:
																	_lowerCamelCase					     = ([pad_token] * padding_length) + input_ids
																	_lowerCamelCase					     = ([0 if mask_padding_with_zero else 1] * padding_length) + attention_mask
													else:
																	_lowerCamelCase					     = input_ids + ([pad_token] * padding_length)
																	_lowerCamelCase					     = attention_mask + ([0 if mask_padding_with_zero else 1] * padding_length)

													if len(lowerCamelCase__      ) != batch_length:
																	raise ValueError(F"""Error with input length {len(lowerCamelCase__      )} vs {batch_length}"""      )
													if len(lowerCamelCase__      ) != batch_length:
																	raise ValueError(F"""Error with input length {len(lowerCamelCase__      )} vs {batch_length}"""      )

													if self.mode == "classification":
																	_lowerCamelCase					     = label_map[example.label]
													elif self.mode == "regression":
																	_lowerCamelCase					     = float(example.label      )
													else:
																	raise ValueError(self.mode      )

													if ex_index < 5 and self.verbose:
																	logger.info('''*** Example ***'''      )
																	logger.info(F"""guid: {example.guid}"""      )
																	logger.info(F"""input_ids: {" ".join([str(lowerCamelCase__      ) for x in input_ids]      )}"""      )
																	logger.info(F"""attention_mask: {" ".join([str(lowerCamelCase__      ) for x in attention_mask]      )}"""      )
																	logger.info(F"""label: {example.label} (id = {label})"""      )

													features.append(InputFeatures(input_ids=lowerCamelCase__ ,				attention_mask=lowerCamelCase__ ,				label=lowerCamelCase__      )      )

									if return_tensors is None:
													return features
									elif return_tensors == "tf":
													if not is_tf_available():
																	raise RuntimeError('''return_tensors set to \'tf\' but TensorFlow 2.0 can\'t be imported'''      )
													import tensorflow as tf

													def gen():
																	for ex in features:
																					yield ({"input_ids": ex.input_ids, "attention_mask": ex.attention_mask}, ex.label)

													_lowerCamelCase					     = tf.data.Dataset.from_generator(
													    lowerCamelCase__ ,				({'''input_ids''': tf.intaa, '''attention_mask''': tf.intaa}, tf.intaa) ,				({'''input_ids''': tf.TensorShape([None]      ), '''attention_mask''': tf.TensorShape([None]      )}, tf.TensorShape([]      )) ,				)
													return dataset
									elif return_tensors == "pt":
													if not is_torch_available():
																	raise RuntimeError('''return_tensors set to \'pt\' but PyTorch can\'t be imported'''      )
													import torch
													from torch.utils.data import TensorDataset

													_lowerCamelCase					     = torch.tensor([f.input_ids for f in features] ,				dtype=torch.long      )
													_lowerCamelCase					     = torch.tensor([f.attention_mask for f in features] ,				dtype=torch.long      )
													if self.mode == "classification":
																	_lowerCamelCase					     = torch.tensor([f.label for f in features] ,				dtype=torch.long      )
													elif self.mode == "regression":
																	_lowerCamelCase					     = torch.tensor([f.label for f in features] ,				dtype=torch.float      )

													_lowerCamelCase					     = TensorDataset(lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__      )
													return dataset
									else:
													raise ValueError('''return_tensors should be one of \'tf\' or \'pt\''''      )





"""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 							lowerCamelCase_:





					'''simple docstring'''



					def __init__(			self ,				lowerCamelCase__ ,				lowerCamelCase__=1_3 ,				lowerCamelCase__=7 ,				lowerCamelCase__=True ,				lowerCamelCase__=True ,				lowerCamelCase__=True ,				lowerCamelCase__=9_9 ,				lowerCamelCase__=3_2 ,				lowerCamelCase__=5 ,				lowerCamelCase__=4 ,				lowerCamelCase__=3_7 ,				lowerCamelCase__="gelu" ,				lowerCamelCase__=0.1 ,				lowerCamelCase__=0.1 ,				lowerCamelCase__=5_1_2 ,				lowerCamelCase__=1_6 ,				lowerCamelCase__=2 ,				lowerCamelCase__=0.0_2 ,				lowerCamelCase__=3 ,				lowerCamelCase__=4 ,				lowerCamelCase__=None ,				):
									_lowerCamelCase					     = parent
									_lowerCamelCase					     = batch_size
									_lowerCamelCase					     = seq_length
									_lowerCamelCase					     = is_training
									_lowerCamelCase					     = use_input_mask
									_lowerCamelCase					     = use_labels
									_lowerCamelCase					     = vocab_size
									_lowerCamelCase					     = hidden_size
									_lowerCamelCase					     = num_hidden_layers
									_lowerCamelCase					     = num_attention_heads
									_lowerCamelCase					     = intermediate_size
									_lowerCamelCase					     = hidden_act
									_lowerCamelCase					     = hidden_dropout_prob
									_lowerCamelCase					     = attention_probs_dropout_prob
									_lowerCamelCase					     = max_position_embeddings
									_lowerCamelCase					     = type_vocab_size
									_lowerCamelCase					     = type_sequence_label_size
									_lowerCamelCase					     = initializer_range
									_lowerCamelCase					     = num_labels
									_lowerCamelCase					     = num_choices
									_lowerCamelCase					     = scope

					def 	snake_case__					(			self      ):
									_lowerCamelCase					     = ids_tensor([self.batch_size, self.seq_length] ,				self.vocab_size      )

									_lowerCamelCase					     = None
									if self.use_input_mask:
													_lowerCamelCase					     = random_attention_mask([self.batch_size, self.seq_length]      )

									_lowerCamelCase					     = None
									_lowerCamelCase					     = None
									_lowerCamelCase					     = None
									if self.use_labels:
													_lowerCamelCase					     = ids_tensor([self.batch_size] ,				self.type_sequence_label_size      )
													_lowerCamelCase					     = ids_tensor([self.batch_size, self.seq_length] ,				self.num_labels      )
													_lowerCamelCase					     = ids_tensor([self.batch_size] ,				self.num_choices      )

									_lowerCamelCase					     = self.get_config()

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

					def 	snake_case__					(			self      ):
									_lowerCamelCase					     = ids_tensor([self.batch_size, self.seq_length] ,				self.vocab_size      )

									_lowerCamelCase					     = None
									if self.use_input_mask:
													_lowerCamelCase					     = random_attention_mask([self.batch_size, self.seq_length]      )
									_lowerCamelCase					     = self.get_config()

									return config, input_ids, input_mask

					def 	snake_case__					(			self      ):
									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 	snake_case__					(			self ,				lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__      ):
									_lowerCamelCase					     = ErnieMModel(config=lowerCamelCase__      )
									model.to(lowerCamelCase__      )
									model.eval()
									_lowerCamelCase					     = model(lowerCamelCase__ ,				return_dict=lowerCamelCase__      )
									self.parent.assertEqual(result.last_hidden_state.shape ,				(self.batch_size, self.seq_length, self.hidden_size)      )

					def 	snake_case__					(			self ,				lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__      ):
									_lowerCamelCase					     = ErnieMForQuestionAnswering(config=lowerCamelCase__      )
									model.to(lowerCamelCase__      )
									model.eval()
									_lowerCamelCase					     = model(
									    lowerCamelCase__ ,				attention_mask=lowerCamelCase__ ,				start_positions=lowerCamelCase__ ,				end_positions=lowerCamelCase__ ,				)
									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 	snake_case__					(			self ,				lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__      ):
									_lowerCamelCase					     = ErnieMForInformationExtraction(config=lowerCamelCase__      )
									model.to(lowerCamelCase__      )
									model.eval()
									_lowerCamelCase					     = torch.ones_like(lowerCamelCase__ ,				dtype=torch.floataa      )
									_lowerCamelCase					     = model(
									    lowerCamelCase__ ,				attention_mask=lowerCamelCase__ ,				start_positions=lowerCamelCase__ ,				end_positions=lowerCamelCase__ ,				)
									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 	snake_case__					(			self ,				lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__      ):
									_lowerCamelCase					     = self.num_labels
									_lowerCamelCase					     = ErnieMForSequenceClassification(lowerCamelCase__      )
									model.to(lowerCamelCase__      )
									model.eval()
									_lowerCamelCase					     = model(lowerCamelCase__ ,				attention_mask=lowerCamelCase__ ,				labels=lowerCamelCase__      )
									self.parent.assertEqual(result.logits.shape ,				(self.batch_size, self.num_labels)      )

					def 	snake_case__					(			self ,				lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__      ):
									_lowerCamelCase					     = self.num_labels
									_lowerCamelCase					     = ErnieMForTokenClassification(config=lowerCamelCase__      )
									model.to(lowerCamelCase__      )
									model.eval()
									input_ids.to(lowerCamelCase__      )
									input_mask.to(lowerCamelCase__      )
									token_labels.to(lowerCamelCase__      )

									_lowerCamelCase					     = model(lowerCamelCase__ ,				attention_mask=lowerCamelCase__ ,				labels=lowerCamelCase__      )

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

					def 	snake_case__					(			self ,				lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__      ):
									_lowerCamelCase					     = self.num_choices
									_lowerCamelCase					     = ErnieMForMultipleChoice(config=lowerCamelCase__      )
									model.to(lowerCamelCase__      )
									model.eval()
									_lowerCamelCase					     = input_ids.unsqueeze(1      ).expand(-1 ,				self.num_choices ,				-1      ).contiguous()
									_lowerCamelCase					     = input_mask.unsqueeze(1      ).expand(-1 ,				self.num_choices ,				-1      ).contiguous()
									_lowerCamelCase					     = model(
									    lowerCamelCase__ ,				attention_mask=lowerCamelCase__ ,				labels=lowerCamelCase__ ,				)
									self.parent.assertEqual(result.logits.shape ,				(self.batch_size, self.num_choices)      )





					def 	snake_case__					(			self      ):
									_lowerCamelCase					     = self.prepare_config_and_inputs()
									(
									    (
									    _lowerCamelCase
									)     ,   (
									    _lowerCamelCase
									)     ,   (
									    _lowerCamelCase
									)     ,   (
									    _lowerCamelCase
									)     ,   (
									    _lowerCamelCase
									)     ,   (
									    _lowerCamelCase
									)     ,   
									)					     = config_and_inputs
									_lowerCamelCase					     = {'''input_ids''': input_ids, '''attention_mask''': input_mask}
									return config, inputs_dict


@require_torch
class 							lowerCamelCase_(      A__, A__, unittest.TestCase			):





					'''simple docstring'''



					lowercase__      :				Optional[Any]        =       (
					    (
					        ErnieMModel,
					        ErnieMForMultipleChoice,
					        ErnieMForQuestionAnswering,
					        ErnieMForSequenceClassification,
					        ErnieMForTokenClassification,
					    )
					    if is_torch_available()
					    else ()
					)
					lowercase__      :				List[Any]        =       ()
					lowercase__      :				Union[str, Any]        =       (
					    {
					        'feature-extraction': ErnieMModel,
					        'question-answering': ErnieMForQuestionAnswering,
					        'text-classification': ErnieMForSequenceClassification,
					        'token-classification': ErnieMForTokenClassification,
					        'zero-shot': ErnieMForSequenceClassification,
					    }
					    if is_torch_available()
					    else {}
					)
					lowercase__      :				Optional[int]        =       False

					def 	snake_case__					(			self ,				lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__ ,				lowerCamelCase__      ):
									if pipeline_test_casse_name == "QAPipelineTests":
													return True

									return False

					def 	snake_case__					(			self      ):
									_lowerCamelCase					     = ErnieMModelTester(self      )
									_lowerCamelCase					     = ConfigTester(self ,				config_class=lowerCamelCase__ ,				hidden_size=3_7      )

					def 	snake_case__					(			self      ):
									self.config_tester.run_common_tests()

					def 	snake_case__					(			self      ):
									_lowerCamelCase					     = self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*lowerCamelCase__      )

					def 	snake_case__					(			self      ):
									_lowerCamelCase					     = self.model_tester.prepare_config_and_inputs()
									for type in ["absolute", "relative_key", "relative_key_query"]:
													_lowerCamelCase					     = type
													self.model_tester.create_and_check_model(*lowerCamelCase__      )

					def 	snake_case__					(			self      ):
									_lowerCamelCase					     = self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_multiple_choice(*lowerCamelCase__      )

					def 	snake_case__					(			self      ):
									_lowerCamelCase					     = self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_question_answering(*lowerCamelCase__      )

					def 	snake_case__					(			self      ):
									_lowerCamelCase					     = self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_sequence_classification(*lowerCamelCase__      )

					def 	snake_case__					(			self      ):
									_lowerCamelCase					     = self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_information_extraction(*lowerCamelCase__      )

					def 	snake_case__					(			self      ):
									_lowerCamelCase					     = self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_token_classification(*lowerCamelCase__      )





					@slow
					def 	snake_case__					(			self      ):
									for model_name in ERNIE_M_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													_lowerCamelCase					     = ErnieMModel.from_pretrained(lowerCamelCase__      )
													self.assertIsNotNone(lowerCamelCase__      )


@require_torch
class 							lowerCamelCase_(      unittest.TestCase			):





					'''simple docstring'''



					@slow
					def 	snake_case__					(			self      ):
									_lowerCamelCase					     = ErnieMModel.from_pretrained('''susnato/ernie-m-base_pytorch'''      )
									model.eval()
									_lowerCamelCase					     = torch.tensor([[0, 1, 2, 3, 4, 5]]      )
									_lowerCamelCase					     = model(lowerCamelCase__      )[0]

									# TODO Replace vocab size
									_lowerCamelCase					     = 7_6_8

									_lowerCamelCase					     = torch.Size((1, 6, hidden_size)      )
									self.assertEqual(output.shape ,				lowerCamelCase__      )

									_lowerCamelCase					     = torch.tensor(
									    [[[-0.0_0_1_2, 0.1_2_4_5, -0.0_2_1_4], [-0.0_7_4_2, 0.0_2_4_4, -0.0_7_7_1], [-0.0_3_3_3, 0.1_1_6_4, -0.1_5_5_4]]]      )

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