




import argparse
import json

import gdown
import numpy as np
import torch
from huggingface_hub import hf_hub_download

from transformers import TimesformerConfig, TimesformerForVideoClassification, VideoMAEImageProcessor
def 					snake_case_     (		SCREAMING_SNAKE_CASE_				)			-> int:
							lowercase__  :       Optional[Any]   					=							TimesformerConfig()

							if "large" in model_name:
														lowercase__  :       Optional[int]   					=							96

							if "hr" in model_name:
														lowercase__  :       str   					=							16
														lowercase__  :       str   					=							4_48

							lowercase__  :       Optional[int]   					=							"huggingface/label-files"
							if "k400" in model_name:
														lowercase__  :       Optional[int]   					=							4_00
														lowercase__  :       Dict   					=							"kinetics400-id2label.json"
							elif "k600" in model_name:
														lowercase__  :       Dict   					=							6_00
														lowercase__  :       Any   					=							"kinetics600-id2label.json"
							elif "ssv2" in model_name:
														lowercase__  :       Optional[int]   					=							1_74
														lowercase__  :       str   					=							"something-something-v2-id2label.json"
							else:
														raise ValueError("Model name should either contain \'k400\', \'k600\' or \'ssv2\'."				)
							lowercase__  :       int   					=							json.load(open(hf_hub_download(lowercase_				,lowercase_				,repo_type="dataset"				)				,"r"				)				)
							lowercase__  :       str   					=							{int(lowercase_				): v for k, v in idalabel.items()}
							lowercase__  :       Tuple   					=							idalabel
							lowercase__  :       Any   					=							{v: k for k, v in idalabel.items()}

							return config
def 					snake_case_     (		SCREAMING_SNAKE_CASE_				)			-> str:
							if "encoder." in name:
														lowercase__  :       Optional[Any]   					=							name.replace("encoder."				,""				)
							if "cls_token" in name:
														lowercase__  :       Union[str, Any]   					=							name.replace("cls_token"				,"timesformer.embeddings.cls_token"				)
							if "pos_embed" in name:
														lowercase__  :       Union[str, Any]   					=							name.replace("pos_embed"				,"timesformer.embeddings.position_embeddings"				)
							if "time_embed" in name:
														lowercase__  :       Union[str, Any]   					=							name.replace("time_embed"				,"timesformer.embeddings.time_embeddings"				)
							if "patch_embed.proj" in name:
														lowercase__  :       int   					=							name.replace("patch_embed.proj"				,"timesformer.embeddings.patch_embeddings.projection"				)
							if "patch_embed.norm" in name:
														lowercase__  :       List[str]   					=							name.replace("patch_embed.norm"				,"timesformer.embeddings.norm"				)
							if "blocks" in name:
														lowercase__  :       Dict   					=							name.replace("blocks"				,"timesformer.encoder.layer"				)
							if "attn.proj" in name:
														lowercase__  :       List[str]   					=							name.replace("attn.proj"				,"attention.output.dense"				)
							if "attn" in name and "bias" not in name and "temporal" not in name:
														lowercase__  :       Dict   					=							name.replace("attn"				,"attention.self"				)
							if "attn" in name and "temporal" not in name:
														lowercase__  :       Tuple   					=							name.replace("attn"				,"attention.attention"				)
							if "temporal_norm1" in name:
														lowercase__  :       Optional[Any]   					=							name.replace("temporal_norm1"				,"temporal_layernorm"				)
							if "temporal_attn.proj" in name:
														lowercase__  :       List[str]   					=							name.replace("temporal_attn"				,"temporal_attention.output.dense"				)
							if "temporal_fc" in name:
														lowercase__  :       Tuple   					=							name.replace("temporal_fc"				,"temporal_dense"				)
							if "norm1" in name and "temporal" not in name:
														lowercase__  :       Optional[int]   					=							name.replace("norm1"				,"layernorm_before"				)
							if "norm2" in name:
														lowercase__  :       str   					=							name.replace("norm2"				,"layernorm_after"				)
							if "mlp.fc1" in name:
														lowercase__  :       Optional[Any]   					=							name.replace("mlp.fc1"				,"intermediate.dense"				)
							if "mlp.fc2" in name:
														lowercase__  :       Dict   					=							name.replace("mlp.fc2"				,"output.dense"				)
							if "norm.weight" in name and "fc" not in name and "temporal" not in name:
														lowercase__  :       Tuple   					=							name.replace("norm.weight"				,"timesformer.layernorm.weight"				)
							if "norm.bias" in name and "fc" not in name and "temporal" not in name:
														lowercase__  :       Dict   					=							name.replace("norm.bias"				,"timesformer.layernorm.bias"				)
							if "head" in name:
														lowercase__  :       List[str]   					=							name.replace("head"				,"classifier"				)

							return name
def 					snake_case_     (		SCREAMING_SNAKE_CASE_				,SCREAMING_SNAKE_CASE_				)			-> Optional[Any]:
							for key in orig_state_dict.copy().keys():
														lowercase__  :       Any   					=							orig_state_dict.pop(lowercase_				)

														if key.startswith("model."				):
																					lowercase__  :       List[Any]   					=							key.replace("model."				,""				)

														if "qkv" in key:
																					lowercase__  :       str   					=							key.split("."				)
																					lowercase__  :       List[Any]   					=							int(key_split[1]				)
																					lowercase__  :       Tuple   					=							"timesformer.encoder.layer."
																					if "temporal" in key:
																												lowercase__  :       int   					=							".temporal_attention.attention.qkv."
																					else:
																												lowercase__  :       Optional[int]   					=							".attention.attention.qkv."
																					if "weight" in key:
																												lowercase__  :       str   					=							val
																					else:
																												lowercase__  :       List[str]   					=							val
														else:
																					lowercase__  :       Optional[int]   					=							val

							return orig_state_dict
def 					snake_case_     (		)			-> str:
							lowercase__  :       Dict   					=							hf_hub_download(
							    repo_id="hf-internal-testing/spaghetti-video"				,filename="eating_spaghetti.npy"				,repo_type="dataset"				)
							lowercase__  :       Any   					=							np.load(lowercase_				)
							return list(lowercase_				)
def 					snake_case_     (		SCREAMING_SNAKE_CASE_				,SCREAMING_SNAKE_CASE_				,SCREAMING_SNAKE_CASE_				,SCREAMING_SNAKE_CASE_				)			-> int:
							lowercase__  :       Optional[Any]   					=							get_timesformer_config(lowercase_				)

							lowercase__  :       List[Any]   					=							TimesformerForVideoClassification(lowercase_				)

							# download original checkpoint, hosted on Google Drive
							lowercase__  :       Union[str, Any]   					=							"pytorch_model.bin"
							gdown.cached_download(lowercase_				,lowercase_				,quiet=lowercase_				)
							lowercase__  :       int   					=							torch.load(lowercase_				,map_location="cpu"				)
							if "model" in files:
														lowercase__  :       Union[str, Any]   					=							files["model"]
							elif "module" in files:
														lowercase__  :       Optional[int]   					=							files["module"]
							else:
														lowercase__  :       List[Any]   					=							files["model_state"]
							lowercase__  :       int   					=							convert_state_dict(lowercase_				,lowercase_				)

							model.load_state_dict(lowercase_				)
							model.eval()

							# verify model on basic input
							lowercase__  :       Optional[int]   					=							VideoMAEImageProcessor(image_mean=[0.5, 0.5, 0.5]				,image_std=[0.5, 0.5, 0.5]				)
							lowercase__  :       Optional[Any]   					=							prepare_video()
							lowercase__  :       Any   					=							image_processor(video[:8]				,return_tensors="pt"				)

							lowercase__  :       Tuple   					=							model(**lowercase_				)
							lowercase__  :       Optional[Any]   					=							outputs.logits

							lowercase__  :       List[str]   					=							[
							    # Kinetics-400 checkpoints (hr = high resolution input of 448px instead of 224px)
							    "timesformer-base-finetuned-k400",
							    "timesformer-large-finetuned-k400",
							    "timesformer-hr-finetuned-k400",
							    # Kinetics-600 checkpoints (hr = high resolution input of 448px instead of 224px)
							    "timesformer-base-finetuned-k600",
							    "timesformer-large-finetuned-k600",
							    "timesformer-hr-finetuned-k600",
							    # Something-Something-v2 checkpoints (hr = high resolution input of 448px instead of 224px)
							    "timesformer-base-finetuned-ssv2",
							    "timesformer-large-finetuned-ssv2",
							    "timesformer-hr-finetuned-ssv2",
							]

							# NOTE: logits were tested with image_mean and image_std equal to [0.5, 0.5, 0.5] and [0.5, 0.5, 0.5]
							if model_name == "timesformer-base-finetuned-k400":
														lowercase__  :       Union[str, Any]   					=							torch.Size([1, 4_00]				)
														lowercase__  :       List[str]   					=							torch.tensor([-0.3016, -0.7713, -0.4205]				)
							elif model_name == "timesformer-base-finetuned-k600":
														lowercase__  :       List[Any]   					=							torch.Size([1, 6_00]				)
														lowercase__  :       List[Any]   					=							torch.tensor([-0.7267, -0.7466, 3.2404]				)
							elif model_name == "timesformer-base-finetuned-ssv2":
														lowercase__  :       List[str]   					=							torch.Size([1, 1_74]				)
														lowercase__  :       int   					=							torch.tensor([-0.9059, 0.6433, -3.1457]				)
							elif model_name == "timesformer-large-finetuned-k400":
														lowercase__  :       Optional[Any]   					=							torch.Size([1, 4_00]				)
														lowercase__  :       Dict   					=							torch.tensor([0, 0, 0]				)
							elif model_name == "timesformer-large-finetuned-k600":
														lowercase__  :       Tuple   					=							torch.Size([1, 6_00]				)
														lowercase__  :       Tuple   					=							torch.tensor([0, 0, 0]				)
							elif model_name == "timesformer-large-finetuned-ssv2":
														lowercase__  :       List[Any]   					=							torch.Size([1, 1_74]				)
														lowercase__  :       Optional[int]   					=							torch.tensor([0, 0, 0]				)
							elif model_name == "timesformer-hr-finetuned-k400":
														lowercase__  :       int   					=							torch.Size([1, 4_00]				)
														lowercase__  :       str   					=							torch.tensor([-0.9617, -3.7311, -3.7708]				)
							elif model_name == "timesformer-hr-finetuned-k600":
														lowercase__  :       List[str]   					=							torch.Size([1, 6_00]				)
														lowercase__  :       List[Any]   					=							torch.tensor([2.5273, 0.7127, 1.8848]				)
							elif model_name == "timesformer-hr-finetuned-ssv2":
														lowercase__  :       str   					=							torch.Size([1, 1_74]				)
														lowercase__  :       str   					=							torch.tensor([-3.6756, -0.7513, 0.7180]				)
							else:
														raise ValueError(F"""Model name not supported. Should be one of {model_names}"""				)

							# verify logits
							assert logits.shape == expected_shape
							assert torch.allclose(logits[0, :3]				,lowercase_				,atol=1E-4				)
							print("Logits ok!"				)

							if pytorch_dump_folder_path is not None:
														print(F"""Saving model and image processor to {pytorch_dump_folder_path}"""				)
														image_processor.save_pretrained(lowercase_				)
														model.save_pretrained(lowercase_				)

							if push_to_hub:
														print("Pushing to the hub..."				)
														model.push_to_hub(F"""fcakyon/{model_name}"""				)


if __name__ == "__main__":
						__a  :		Any			=    argparse.ArgumentParser()
						# Required parameters
						parser.add_argument(
						    '''--checkpoint_url''',
						    default='''https://drive.google.com/u/1/uc?id=17yvuYp9L4mn-HpIcK5Zo6K3UoOy1kA5l&export=download''',
						    type=str,
						    help=(
						        '''URL of the original PyTorch checkpoint (on Google Drive) you\'d like to convert. Should be a direct'''
						        ''' download link.'''
						    ),
						)
						parser.add_argument(
						    '''--pytorch_dump_folder_path''',
						    default='''''',
						    type=str,
						    help='''Path to the output PyTorch model directory.''',
						)
						parser.add_argument('''--model_name''', default='''timesformer-base-finetuned-k400''', type=str, help='''Name of the model.''')
						parser.add_argument(
						    '''--push_to_hub''', action='''store_true''', help='''Whether or not to push the converted model to the 🤗 hub.'''
						)

						__a  :		Dict			=    parser.parse_args()
						convert_timesformer_checkpoint(
						    args.checkpoint_url, args.pytorch_dump_folder_path, args.model_name, args.push_to_hub
						)




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