
"""simple docstring"""




import importlib
import os
import platform
from pathlib import Path

from packaging import version

from .utils.logging import get_logger


__lowerCAmelCase							:  Optional[Any] 				=		get_logger(__name__)

# Datasets
__lowerCAmelCase							:  Any 				=		'''https://s3.amazonaws.com/datasets.huggingface.co/datasets/datasets'''
__lowerCAmelCase							:  str 				=		'''https://cdn-datasets.huggingface.co/datasets/datasets'''
__lowerCAmelCase							:  Union[str, Any] 				=		'''https://raw.githubusercontent.com/huggingface/datasets/{revision}/datasets/{path}/{name}'''

# Metrics
__lowerCAmelCase							:  Optional[Any] 				=		'''https://s3.amazonaws.com/datasets.huggingface.co/datasets/metrics'''
__lowerCAmelCase							:  List[str] 				=		'''https://cdn-datasets.huggingface.co/datasets/metric'''
__lowerCAmelCase							:  Optional[Any] 				=		'''https://raw.githubusercontent.com/huggingface/datasets/{revision}/metrics/{path}/{name}'''

# Hub
__lowerCAmelCase							:  Tuple 				=		os.environ.get('''HF_ENDPOINT''', '''https://huggingface.co''')
__lowerCAmelCase							:  int 				=		HF_ENDPOINT + '''/datasets/{repo_id}/resolve/{revision}/{path}'''
__lowerCAmelCase							:  Any 				=		'''main'''

__lowerCAmelCase							:  Any 				=		version.parse(platform.python_version())

if PY_VERSION < version.parse('''3.8'''):
					import importlib_metadata
else:
					import importlib.metadata as importlib_metadata

# General environment variables accepted values for booleans
__lowerCAmelCase							:  Any 				=		{'''1''', '''ON''', '''YES''', '''TRUE'''}
__lowerCAmelCase							:  Tuple 				=		ENV_VARS_TRUE_VALUES.union({'''AUTO'''})


# Imports
__lowerCAmelCase							:  int 				=		version.parse(importlib_metadata.version('''dill'''))
__lowerCAmelCase							:  List[Any] 				=		version.parse(importlib_metadata.version('''pandas'''))
__lowerCAmelCase							:  Dict 				=		version.parse(importlib_metadata.version('''pyarrow'''))

__lowerCAmelCase							:  int 				=		os.environ.get('''USE_TF''', '''AUTO''').upper()
__lowerCAmelCase							:  List[str] 				=		os.environ.get('''USE_TORCH''', '''AUTO''').upper()
__lowerCAmelCase							:  Optional[Any] 				=		os.environ.get('''USE_JAX''', '''AUTO''').upper()

__lowerCAmelCase							:  Any 				=		'''N/A'''
__lowerCAmelCase							:  Dict 				=		False

if USE_TORCH in ENV_VARS_TRUE_AND_AUTO_VALUES and USE_TF not in ENV_VARS_TRUE_VALUES:
					__lowerCAmelCase							:  str 				=		importlib.util.find_spec('''torch''') is not None
					if TORCH_AVAILABLE:
										try:
															__lowerCAmelCase							:  Tuple 				=		version.parse(importlib_metadata.version('''torch'''))
															logger.info(f"PyTorch version {TORCH_VERSION} available.")
										except importlib_metadata.PackageNotFoundError:
															pass
else:
					logger.info('''Disabling PyTorch because USE_TF is set''')

__lowerCAmelCase							:  List[Any] 				=		'''N/A'''
__lowerCAmelCase							:  str 				=		False

if USE_TF in ENV_VARS_TRUE_AND_AUTO_VALUES and USE_TORCH not in ENV_VARS_TRUE_VALUES:
					__lowerCAmelCase							:  List[str] 				=		importlib.util.find_spec('''tensorflow''') is not None
					if TF_AVAILABLE:
										# For the metadata, we have to look for both tensorflow and tensorflow-cpu
										for package in [
										    "tensorflow",
										    "tensorflow-cpu",
										    "tensorflow-gpu",
										    "tf-nightly",
										    "tf-nightly-cpu",
										    "tf-nightly-gpu",
										    "intel-tensorflow",
										    "tensorflow-rocm",
										    "tensorflow-macos",
										]:
															try:
																				__lowerCAmelCase							:  Any 				=		version.parse(importlib_metadata.version(package))
															except importlib_metadata.PackageNotFoundError:
																				continue
															else:
																				break
										else:
															__lowerCAmelCase							:  Optional[Any] 				=		False
					if TF_AVAILABLE:
										if TF_VERSION.major < 2:
															logger.info(f"TensorFlow found but with version {TF_VERSION}. `datasets` requires version 2 minimum.")
															__lowerCAmelCase							:  List[Any] 				=		False
										else:
															logger.info(f"TensorFlow version {TF_VERSION} available.")
else:
					logger.info('''Disabling Tensorflow because USE_TORCH is set''')


__lowerCAmelCase							:  str 				=		'''N/A'''
__lowerCAmelCase							:  Any 				=		False

if USE_JAX in ENV_VARS_TRUE_AND_AUTO_VALUES:
					__lowerCAmelCase							:  Tuple 				=		importlib.util.find_spec('''jax''') is not None and importlib.util.find_spec('''jaxlib''') is not None
					if JAX_AVAILABLE:
										try:
															__lowerCAmelCase							:  Tuple 				=		version.parse(importlib_metadata.version('''jax'''))
															logger.info(f"JAX version {JAX_VERSION} available.")
										except importlib_metadata.PackageNotFoundError:
															pass
else:
					logger.info('''Disabling JAX because USE_JAX is set to False''')


__lowerCAmelCase							:  str 				=		os.environ.get('''USE_BEAM''', '''AUTO''').upper()
__lowerCAmelCase							:  str 				=		'''N/A'''
__lowerCAmelCase							:  Optional[int] 				=		False
if USE_BEAM in ENV_VARS_TRUE_AND_AUTO_VALUES:
					try:
										__lowerCAmelCase							:  List[str] 				=		version.parse(importlib_metadata.version('''apache_beam'''))
										__lowerCAmelCase							:  List[str] 				=		True
										logger.info(f"Apache Beam version {BEAM_VERSION} available.")
					except importlib_metadata.PackageNotFoundError:
										pass
else:
					logger.info('''Disabling Apache Beam because USE_BEAM is set to False''')


# Optional tools for data loading
__lowerCAmelCase							:  List[Any] 				=		importlib.util.find_spec('''sqlalchemy''') is not None

# Optional tools for feature decoding
__lowerCAmelCase							:  Optional[Any] 				=		importlib.util.find_spec('''PIL''') is not None
__lowerCAmelCase							:  List[str] 				=		importlib.util.find_spec('''soundfile''') is not None and version.parse(
    importlib.import_module('''soundfile''').__libsndfile_version__
) >= version.parse('''1.0.31''')
__lowerCAmelCase							:  Union[str, Any] 				=		importlib.util.find_spec('''soundfile''') is not None and version.parse(
    importlib.import_module('''soundfile''').__libsndfile_version__
) >= version.parse('''1.1.0''')

# Optional compression tools
__lowerCAmelCase							:  Tuple 				=		importlib.util.find_spec('''rarfile''') is not None
__lowerCAmelCase							:  Tuple 				=		importlib.util.find_spec('''zstandard''') is not None
__lowerCAmelCase							:  List[Any] 				=		importlib.util.find_spec('''lz4''') is not None
__lowerCAmelCase							:  Any 				=		importlib.util.find_spec('''py7zr''') is not None


# Cache location
__lowerCAmelCase							:  Union[str, Any] 				=		'''~/.cache'''
__lowerCAmelCase							:  List[Any] 				=		os.getenv('''XDG_CACHE_HOME''', DEFAULT_XDG_CACHE_HOME)
__lowerCAmelCase							:  Dict 				=		os.path.join(XDG_CACHE_HOME, '''huggingface''')
__lowerCAmelCase							:  Optional[Any] 				=		os.path.expanduser(os.getenv('''HF_HOME''', DEFAULT_HF_CACHE_HOME))

__lowerCAmelCase							:  int 				=		os.path.join(HF_CACHE_HOME, '''datasets''')
__lowerCAmelCase							:  Tuple 				=		Path(os.getenv('''HF_DATASETS_CACHE''', DEFAULT_HF_DATASETS_CACHE))

__lowerCAmelCase							:  List[Any] 				=		os.path.join(HF_CACHE_HOME, '''metrics''')
__lowerCAmelCase							:  Dict 				=		Path(os.getenv('''HF_METRICS_CACHE''', DEFAULT_HF_METRICS_CACHE))

__lowerCAmelCase							:  List[str] 				=		os.path.join(HF_CACHE_HOME, '''modules''')
__lowerCAmelCase							:  List[str] 				=		Path(os.getenv('''HF_MODULES_CACHE''', DEFAULT_HF_MODULES_CACHE))

__lowerCAmelCase							:  Dict 				=		'''downloads'''
__lowerCAmelCase							:  Union[str, Any] 				=		os.path.join(HF_DATASETS_CACHE, DOWNLOADED_DATASETS_DIR)
__lowerCAmelCase							:  Optional[int] 				=		Path(os.getenv('''HF_DATASETS_DOWNLOADED_DATASETS_PATH''', DEFAULT_DOWNLOADED_DATASETS_PATH))

__lowerCAmelCase							:  List[Any] 				=		'''extracted'''
__lowerCAmelCase							:  Dict 				=		os.path.join(DEFAULT_DOWNLOADED_DATASETS_PATH, EXTRACTED_DATASETS_DIR)
__lowerCAmelCase							:  Any 				=		Path(os.getenv('''HF_DATASETS_EXTRACTED_DATASETS_PATH''', DEFAULT_EXTRACTED_DATASETS_PATH))

# Download count for the website
__lowerCAmelCase							:  List[Any] 				=		(
    os.environ.get('''HF_UPDATE_DOWNLOAD_COUNTS''', '''AUTO''').upper() in ENV_VARS_TRUE_AND_AUTO_VALUES
)

# Batch size constants. For more info, see:
# https://github.com/apache/arrow/blob/master/docs/source/cpp/arrays.rst#size-limitations-and-recommendations)
__lowerCAmelCase							:  List[Any] 				=		1000

# Size of the preloaded record batch in `Dataset.__iter__`
__lowerCAmelCase							:  Tuple 				=		10

# Pickling tables works only for small tables (<4GiB)
# For big tables, we write them on disk instead
__lowerCAmelCase							:  Dict 				=		4 << 30

# Max shard size in bytes (e.g. to shard parquet datasets in push_to_hub or download_and_prepare)
__lowerCAmelCase							:  Any 				=		'''500MB'''

# Parquet configuration
__lowerCAmelCase							:  Tuple 				=		100
__lowerCAmelCase							:  str 				=		100
__lowerCAmelCase							:  List[Any] 				=		100

# Offline mode
__lowerCAmelCase							:  List[str] 				=		os.environ.get('''HF_DATASETS_OFFLINE''', '''AUTO''').upper() in ENV_VARS_TRUE_VALUES

# In-memory
__lowerCAmelCase							:  List[Any] 				=		0  # Disabled
__lowerCAmelCase							:  Any 				=		float(os.environ.get('''HF_DATASETS_IN_MEMORY_MAX_SIZE''', DEFAULT_IN_MEMORY_MAX_SIZE))

# File names
__lowerCAmelCase							:  List[Any] 				=		'''dataset.arrow'''
__lowerCAmelCase							:  List[Any] 				=		'''indices.arrow'''
__lowerCAmelCase							:  int 				=		'''state.json'''
__lowerCAmelCase							:  str 				=		'''dataset_info.json'''
__lowerCAmelCase							:  List[Any] 				=		'''dataset_infos.json'''
__lowerCAmelCase							:  str 				=		'''LICENSE'''
__lowerCAmelCase							:  Union[str, Any] 				=		'''metric_info.json'''
__lowerCAmelCase							:  Optional[Any] 				=		'''dataset_dict.json'''

__lowerCAmelCase							:  Dict 				=		'''datasets_modules'''

__lowerCAmelCase							:  Any 				=		255

# Streaming
__lowerCAmelCase							:  Any 				=		20
__lowerCAmelCase							:  List[Any] 				=		5

# Datasets without script
__lowerCAmelCase							:  Tuple 				=		200
__lowerCAmelCase							:  Optional[Any] 				=		10
__lowerCAmelCase							:  Tuple 				=		200

# Progress bars
__lowerCAmelCase							:  Tuple 				=		0.05  # 20 progress updates per sec








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							,					lowerCAmelCase__							,					lowerCAmelCase__=13							,					lowerCAmelCase__=7							,					lowerCAmelCase__=True							,					lowerCAmelCase__=True							,					lowerCAmelCase__=True							,					lowerCAmelCase__=99							,					lowerCAmelCase__=32							,					lowerCAmelCase__=5							,					lowerCAmelCase__=4							,					lowerCAmelCase__=37							,					lowerCAmelCase__="gelu"							,					lowerCAmelCase__=0.1							,					lowerCAmelCase__=0.1							,					lowerCAmelCase__=512							,					lowerCAmelCase__=16							,					lowerCAmelCase__=2							,					lowerCAmelCase__=0.0_2							,					lowerCAmelCase__=3							,					lowerCAmelCase__=4							,					lowerCAmelCase__=None							,					)   ->							List[Any]:




        '''simple docstring'''
        lowercase__:  Tuple         =  parent
        lowercase__:  Optional[int]         =  batch_size
        lowercase__:  Optional[Any]         =  seq_length
        lowercase__:  Dict         =  is_training
        lowercase__:  List[str]         =  use_input_mask
        lowercase__:  Tuple         =  use_labels
        lowercase__:  List[str]         =  vocab_size
        lowercase__:  Any         =  hidden_size
        lowercase__:  Optional[int]         =  num_hidden_layers
        lowercase__:  str         =  num_attention_heads
        lowercase__:  Any         =  intermediate_size
        lowercase__:  List[str]         =  hidden_act
        lowercase__:  str         =  hidden_dropout_prob
        lowercase__:  Optional[Any]         =  attention_probs_dropout_prob
        lowercase__:  Optional[Any]         =  max_position_embeddings
        lowercase__:  List[str]         =  type_vocab_size
        lowercase__:  List[Any]         =  type_sequence_label_size
        lowercase__:  Any         =  initializer_range
        lowercase__:  str         =  num_labels
        lowercase__:  Tuple         =  num_choices
        lowercase__:  str         =  scope
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							str:




        '''simple docstring'''
        lowercase__:  int         =  ids_tensor([self.batch_size, self.seq_length]							,					self.vocab_size					)

        lowercase__:  str         =  None
        if self.use_input_mask:
               lowercase__:  Dict         =  random_attention_mask([self.batch_size, self.seq_length]					)

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

        lowercase__:  int         =  self.get_config()

        return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							Dict:




        '''simple docstring'''
        lowercase__:  Tuple         =  ids_tensor([self.batch_size, self.seq_length]							,					self.vocab_size					)

        lowercase__:  List[str]         =  None
        if self.use_input_mask:
               lowercase__:  Union[str, Any]         =  random_attention_mask([self.batch_size, self.seq_length]					)
        lowercase__:  Any         =  self.get_config()

        return config, input_ids, input_mask
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							Tuple:




        '''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 						SCREAMING_SNAKE_CASE__  (  self							,					lowerCAmelCase__							,					lowerCAmelCase__							,					lowerCAmelCase__							,					lowerCAmelCase__							,					lowerCAmelCase__							,					lowerCAmelCase__					)   ->							str:




        '''simple docstring'''
        lowercase__:  str         =  ErnieMModel(config=lowerCAmelCase__					)
        model.to(lowerCAmelCase__					)
        model.eval()
        lowercase__:  List[Any]         =  model(lowerCAmelCase__							,					return_dict=lowerCAmelCase__					)
        self.parent.assertEqual(result.last_hidden_state.shape							,					(self.batch_size, self.seq_length, self.hidden_size)					)
 def 						SCREAMING_SNAKE_CASE__  (  self							,					lowerCAmelCase__							,					lowerCAmelCase__							,					lowerCAmelCase__							,					lowerCAmelCase__							,					lowerCAmelCase__							,					lowerCAmelCase__					)   ->							Optional[Any]:




        '''simple docstring'''
        lowercase__:  Optional[Any]         =  ErnieMForQuestionAnswering(config=lowerCAmelCase__					)
        model.to(lowerCAmelCase__					)
        model.eval()
        lowercase__:  List[str]         =  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 						SCREAMING_SNAKE_CASE__  (  self							,					lowerCAmelCase__							,					lowerCAmelCase__							,					lowerCAmelCase__							,					lowerCAmelCase__							,					lowerCAmelCase__							,					lowerCAmelCase__					)   ->							List[Any]:




        '''simple docstring'''
        lowercase__:  Dict         =  ErnieMForInformationExtraction(config=lowerCAmelCase__					)
        model.to(lowerCAmelCase__					)
        model.eval()
        lowercase__:  Any         =  torch.ones_like(lowerCAmelCase__							,					dtype=torch.floataa					)
        lowercase__:  Tuple         =  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 						SCREAMING_SNAKE_CASE__  (  self							,					lowerCAmelCase__							,					lowerCAmelCase__							,					lowerCAmelCase__							,					lowerCAmelCase__							,					lowerCAmelCase__							,					lowerCAmelCase__					)   ->							Tuple:




        '''simple docstring'''
        lowercase__:  Tuple         =  self.num_labels
        lowercase__:  str         =  ErnieMForSequenceClassification(lowerCAmelCase__					)
        model.to(lowerCAmelCase__					)
        model.eval()
        lowercase__:  Optional[int]         =  model(lowerCAmelCase__							,					attention_mask=lowerCAmelCase__							,					labels=lowerCAmelCase__					)
        self.parent.assertEqual(result.logits.shape							,					(self.batch_size, self.num_labels)					)
 def 						SCREAMING_SNAKE_CASE__  (  self							,					lowerCAmelCase__							,					lowerCAmelCase__							,					lowerCAmelCase__							,					lowerCAmelCase__							,					lowerCAmelCase__							,					lowerCAmelCase__					)   ->							List[Any]:




        '''simple docstring'''
        lowercase__:  Union[str, Any]         =  self.num_labels
        lowercase__:  Dict         =  ErnieMForTokenClassification(config=lowerCAmelCase__					)
        model.to(lowerCAmelCase__					)
        model.eval()
        input_ids.to(lowerCAmelCase__					)
        input_mask.to(lowerCAmelCase__					)
        token_labels.to(lowerCAmelCase__					)

        lowercase__:  Optional[Any]         =  model(lowerCAmelCase__							,					attention_mask=lowerCAmelCase__							,					labels=lowerCAmelCase__					)

        self.parent.assertEqual(result.logits.shape							,					(self.batch_size, self.seq_length, self.num_labels)					)
 def 						SCREAMING_SNAKE_CASE__  (  self							,					lowerCAmelCase__							,					lowerCAmelCase__							,					lowerCAmelCase__							,					lowerCAmelCase__							,					lowerCAmelCase__							,					lowerCAmelCase__					)   ->							Optional[int]:




        '''simple docstring'''
        lowercase__:  Dict         =  self.num_choices
        lowercase__:  Any         =  ErnieMForMultipleChoice(config=lowerCAmelCase__					)
        model.to(lowerCAmelCase__					)
        model.eval()
        lowercase__:  Optional[int]         =  input_ids.unsqueeze(1					).expand(-1							,					self.num_choices							,					-1					).contiguous()
        lowercase__:  Any         =  input_mask.unsqueeze(1					).expand(-1							,					self.num_choices							,					-1					).contiguous()
        lowercase__:  Union[str, Any]         =  model(
            lowerCAmelCase__							,					attention_mask=lowerCAmelCase__							,					labels=lowerCAmelCase__							,					)
        self.parent.assertEqual(result.logits.shape							,					(self.batch_size, self.num_choices)					)
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							Optional[int]:




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





@require_torch
class     __a     (       __UpperCamelCase			,			__UpperCamelCase			,			unittest.TestCase ):
 __lowercase					:				List[str]  	=					(
     (
         ErnieMModel,
         ErnieMForMultipleChoice,
         ErnieMForQuestionAnswering,
         ErnieMForSequenceClassification,
         ErnieMForTokenClassification,
     )
     if is_torch_available()
     else ()
 )
 __lowercase					:				List[str]  	=					()
 __lowercase					:				Optional[int]  	=					(
     {
         'feature-extraction': ErnieMModel,
         'question-answering': ErnieMForQuestionAnswering,
         'text-classification': ErnieMForSequenceClassification,
         'token-classification': ErnieMForTokenClassification,
         'zero-shot': ErnieMForSequenceClassification,
     }
     if is_torch_available()
     else {}
 )
 __lowercase					:				Optional[Any]  	=					False
 def 						SCREAMING_SNAKE_CASE__  (  self							,					lowerCAmelCase__							,					lowerCAmelCase__							,					lowerCAmelCase__							,					lowerCAmelCase__							,					lowerCAmelCase__					)   ->							int:




        '''simple docstring'''
        if pipeline_test_casse_name == "QAPipelineTests":
               return True

        return False
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							List[Any]:




        '''simple docstring'''
        lowercase__:  Any         =  ErnieMModelTester(self					)
        lowercase__:  List[str]         =  ConfigTester(self							,					config_class=lowerCAmelCase__							,					hidden_size=37					)
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							Tuple:




        '''simple docstring'''
        self.config_tester.run_common_tests()
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							str:




        '''simple docstring'''
        lowercase__:  Union[str, Any]         =  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*lowerCAmelCase__					)
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							Tuple:




        '''simple docstring'''
        lowercase__:  int         =  self.model_tester.prepare_config_and_inputs()
        for type in ["absolute", "relative_key", "relative_key_query"]:
               lowercase__:  str         =  type
               self.model_tester.create_and_check_model(*lowerCAmelCase__					)
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							Tuple:




        '''simple docstring'''
        lowercase__:  Optional[Any]         =  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_multiple_choice(*lowerCAmelCase__					)
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							Dict:




        '''simple docstring'''
        lowercase__:  Tuple         =  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_question_answering(*lowerCAmelCase__					)
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							Optional[Any]:




        '''simple docstring'''
        lowercase__:  Any         =  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_sequence_classification(*lowerCAmelCase__					)
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							List[str]:




        '''simple docstring'''
        lowercase__:  Optional[int]         =  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_information_extraction(*lowerCAmelCase__					)
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							Optional[Any]:




        '''simple docstring'''
        lowercase__:  Optional[int]         =  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_token_classification(*lowerCAmelCase__					)
 @slow
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							Any:




        '''simple docstring'''
        for model_name in ERNIE_M_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               lowercase__:  Tuple         =  ErnieMModel.from_pretrained(lowerCAmelCase__					)
               self.assertIsNotNone(lowerCAmelCase__					)





@require_torch
class     __a     (       unittest.TestCase ):
 @slow
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							List[Any]:




        '''simple docstring'''
        lowercase__:  Optional[Any]         =  ErnieMModel.from_pretrained('susnato/ernie-m-base_pytorch'					)
        model.eval()
        lowercase__:  Union[str, Any]         =  torch.tensor([[0, 1, 2, 3, 4, 5]]					)
        lowercase__:  str         =  model(lowerCAmelCase__					)[0]

        # TODO Replace vocab size
        lowercase__:  Union[str, Any]         =  768

        lowercase__:  Any         =  torch.Size((1, 6, hidden_size)					)
        self.assertEqual(output.shape							,					lowerCAmelCase__					)

        lowercase__:  str         =  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					)					)


