
import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_base import BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import PaddingStrategy, logging
from .tokenization_realm import RealmTokenizer


lowerCamelCase__	=							logging.get_logger(__name__)

lowerCamelCase__	=							{"vocab_file": "vocab.txt", "tokenizer_file": "tokenizer.json"}

lowerCamelCase__	=							{
    "vocab_file": {
        "google/realm-cc-news-pretrained-embedder": (
            "https://huggingface.co/google/realm-cc-news-pretrained-embedder/resolve/main/vocab.txt"
        ),
        "google/realm-cc-news-pretrained-encoder": (
            "https://huggingface.co/google/realm-cc-news-pretrained-encoder/resolve/main/vocab.txt"
        ),
        "google/realm-cc-news-pretrained-scorer": (
            "https://huggingface.co/google/realm-cc-news-pretrained-scorer/resolve/main/vocab.txt"
        ),
        "google/realm-cc-news-pretrained-openqa": (
            "https://huggingface.co/google/realm-cc-news-pretrained-openqa/aresolve/main/vocab.txt"
        ),
        "google/realm-orqa-nq-openqa": "https://huggingface.co/google/realm-orqa-nq-openqa/resolve/main/vocab.txt",
        "google/realm-orqa-nq-reader": "https://huggingface.co/google/realm-orqa-nq-reader/resolve/main/vocab.txt",
        "google/realm-orqa-wq-openqa": "https://huggingface.co/google/realm-orqa-wq-openqa/resolve/main/vocab.txt",
        "google/realm-orqa-wq-reader": "https://huggingface.co/google/realm-orqa-wq-reader/resolve/main/vocab.txt",
    },
    "tokenizer_file": {
        "google/realm-cc-news-pretrained-embedder": (
            "https://huggingface.co/google/realm-cc-news-pretrained-embedder/resolve/main/tokenizer.jsont"
        ),
        "google/realm-cc-news-pretrained-encoder": (
            "https://huggingface.co/google/realm-cc-news-pretrained-encoder/resolve/main/tokenizer.json"
        ),
        "google/realm-cc-news-pretrained-scorer": (
            "https://huggingface.co/google/realm-cc-news-pretrained-scorer/resolve/main/tokenizer.json"
        ),
        "google/realm-cc-news-pretrained-openqa": (
            "https://huggingface.co/google/realm-cc-news-pretrained-openqa/aresolve/main/tokenizer.json"
        ),
        "google/realm-orqa-nq-openqa": (
            "https://huggingface.co/google/realm-orqa-nq-openqa/resolve/main/tokenizer.json"
        ),
        "google/realm-orqa-nq-reader": (
            "https://huggingface.co/google/realm-orqa-nq-reader/resolve/main/tokenizer.json"
        ),
        "google/realm-orqa-wq-openqa": (
            "https://huggingface.co/google/realm-orqa-wq-openqa/resolve/main/tokenizer.json"
        ),
        "google/realm-orqa-wq-reader": (
            "https://huggingface.co/google/realm-orqa-wq-reader/resolve/main/tokenizer.json"
        ),
    },
}

lowerCamelCase__	=							{
    "google/realm-cc-news-pretrained-embedder": 512,
    "google/realm-cc-news-pretrained-encoder": 512,
    "google/realm-cc-news-pretrained-scorer": 512,
    "google/realm-cc-news-pretrained-openqa": 512,
    "google/realm-orqa-nq-openqa": 512,
    "google/realm-orqa-nq-reader": 512,
    "google/realm-orqa-wq-openqa": 512,
    "google/realm-orqa-wq-reader": 512,
}

lowerCamelCase__	=							{
    "google/realm-cc-news-pretrained-embedder": {"do_lower_case": True},
    "google/realm-cc-news-pretrained-encoder": {"do_lower_case": True},
    "google/realm-cc-news-pretrained-scorer": {"do_lower_case": True},
    "google/realm-cc-news-pretrained-openqa": {"do_lower_case": True},
    "google/realm-orqa-nq-openqa": {"do_lower_case": True},
    "google/realm-orqa-nq-reader": {"do_lower_case": True},
    "google/realm-orqa-wq-openqa": {"do_lower_case": True},
    "google/realm-orqa-wq-reader": {"do_lower_case": True},
}







class        lowerCAmelCase__      (   __lowercase	):
						UpperCamelCase_							: int	=		VOCAB_FILES_NAMES
						UpperCamelCase_							: int	=		PRETRAINED_VOCAB_FILES_MAP
						UpperCamelCase_							: str	=		PRETRAINED_INIT_CONFIGURATION
						UpperCamelCase_							: Dict	=		PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
						UpperCamelCase_							: str	=		RealmTokenizer

						def __init__(			self       ,							a=None       ,							a=None       ,							a=True       ,							a="[UNK]"       ,							a="[SEP]"       ,							a="[PAD]"       ,							a="[CLS]"       ,							a="[MASK]"       ,							a=True       ,							a=None       ,							**a       ,							)					->      Union[str, Any]:


								'''simple docstring'''

								super().__init__(
								    a       ,							tokenizer_file=a       ,							do_lower_case=a       ,							unk_token=a       ,							sep_token=a       ,							pad_token=a       ,							cls_token=a       ,							mask_token=a       ,							tokenize_chinese_chars=a       ,							strip_accents=a       ,							**a       ,							)

								_UpperCamelCase						    =	json.loads(self.backend_tokenizer.normalizer.__getstate__()				)
								if (
								    normalizer_state.get("""lowercase"""       ,							a				) != do_lower_case
								    or normalizer_state.get("""strip_accents"""       ,							a				) != strip_accents
								    or normalizer_state.get("""handle_chinese_chars"""       ,							a				) != tokenize_chinese_chars
								):
										_UpperCamelCase						    =	getattr(a       ,							normalizer_state.pop("""type"""				)				)
										_UpperCamelCase						    =	do_lower_case
										_UpperCamelCase						    =	strip_accents
										_UpperCamelCase						    =	tokenize_chinese_chars
										_UpperCamelCase						    =	normalizer_class(**a				)

								_UpperCamelCase						    =	do_lower_case

						def  A_				(			self       ,							a       ,							**a				)					->      Dict:


								'''simple docstring'''

								_UpperCamelCase						    =	PaddingStrategy.MAX_LENGTH

								_UpperCamelCase						    =	text
								_UpperCamelCase						    =	kwargs.pop("""text_pair"""       ,							a				)
								_UpperCamelCase						    =	kwargs.pop("""return_tensors"""       ,							a				)

								_UpperCamelCase						    =	{
								    """input_ids""": [],
								    """attention_mask""": [],
								    """token_type_ids""": [],
								}

								for idx, candidate_text in enumerate(a				):
										if batch_text_pair is not None:
												_UpperCamelCase						    =	batch_text_pair[idx]
										else:
												_UpperCamelCase						    =	None

										_UpperCamelCase						    =	super().__call__(a       ,							a       ,							return_tensors=a       ,							**a				)

										_UpperCamelCase						    =	encoded_candidates.get("""input_ids"""				)
										_UpperCamelCase						    =	encoded_candidates.get("""attention_mask"""				)
										_UpperCamelCase						    =	encoded_candidates.get("""token_type_ids"""				)

										if encoded_input_ids is not None:
												output_data["input_ids"].append(a				)
										if encoded_attention_mask is not None:
												output_data["attention_mask"].append(a				)
										if encoded_token_type_ids is not None:
												output_data["token_type_ids"].append(a				)

								_UpperCamelCase						    =	{key: item for key, item in output_data.items() if len(a				) != 0}

								return BatchEncoding(a       ,							tensor_type=a				)

						def  A_				(			self       ,							a       ,							a=None				)					->      int:


								'''simple docstring'''

								_UpperCamelCase						    =	[self.cls_token_id] + token_ids_a + [self.sep_token_id]

								if token_ids_a:
										output += token_ids_a + [self.sep_token_id]

								return output

						def  A_				(			self       ,							a       ,							a = None				)					->      List[int]:


								'''simple docstring'''

								_UpperCamelCase						    =	[self.sep_token_id]
								_UpperCamelCase						    =	[self.cls_token_id]
								if token_ids_a is None:
										return len(cls + token_ids_a + sep				) * [0]
								return len(cls + token_ids_a + sep				) * [0] + len(token_ids_a + sep				) * [1]







						def  A_				(			self       ,							a       ,							a = None				)					->      Tuple[str]:


								'''simple docstring'''

								_UpperCamelCase						    =	self._tokenizer.model.save(a       ,							name=a				)
								return tuple(a				)





import os
import tempfile
import unittest

from transformers import NezhaConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_torch_gpu, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
		import torch

		from transformers import (
		    MODEL_FOR_PRETRAINING_MAPPING,
		    NezhaForMaskedLM,
		    NezhaForMultipleChoice,
		    NezhaForNextSentencePrediction,
		    NezhaForPreTraining,
		    NezhaForQuestionAnswering,
		    NezhaForSequenceClassification,
		    NezhaForTokenClassification,
		    NezhaModel,
		)
		from transformers.models.nezha.modeling_nezha import NEZHA_PRETRAINED_MODEL_ARCHIVE_LIST







class        lowerCAmelCase__      :

						def __init__(			self       ,							a       ,							a=13       ,							a=7       ,							a=True       ,							a=True       ,							a=True       ,							a=True       ,							a=99       ,							a=32       ,							a=5       ,							a=4       ,							a=37       ,							a="gelu"       ,							a=0.1       ,							a=0.1       ,							a=1_28       ,							a=32       ,							a=16       ,							a=2       ,							a=0.02       ,							a=3       ,							a=4       ,							a=None       ,							)					->      Optional[int]:


								'''simple docstring'''

								_UpperCamelCase						    =	parent
								_UpperCamelCase						    =	batch_size
								_UpperCamelCase						    =	seq_length
								_UpperCamelCase						    =	is_training
								_UpperCamelCase						    =	use_input_mask
								_UpperCamelCase						    =	use_token_type_ids
								_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				)					->      List[Any]:


								'''simple docstring'''

								_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
								if self.use_token_type_ids:
										_UpperCamelCase						    =	ids_tensor([self.batch_size, self.seq_length]       ,							self.type_vocab_size				)

								_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, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels

						def  A_				(			self				)					->      Optional[Any]:


								'''simple docstring'''

								return NezhaConfig(
								    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       ,							is_decoder=a       ,							initializer_range=self.initializer_range       ,							)

						def  A_				(			self				)					->      int:


								'''simple docstring'''

								(
								    (
								    _UpperCamelCase
								)    ,	(
								    _UpperCamelCase
								)    ,	(
								    _UpperCamelCase
								)    ,	(
								    _UpperCamelCase
								)    ,	(
								    _UpperCamelCase
								)    ,	(
								    _UpperCamelCase
								)    ,	(
								    _UpperCamelCase
								)    ,	
								)						    =	self.prepare_config_and_inputs()

								_UpperCamelCase						    =	True
								_UpperCamelCase						    =	floats_tensor([self.batch_size, self.seq_length, self.hidden_size]				)
								_UpperCamelCase						    =	ids_tensor([self.batch_size, self.seq_length]       ,							vocab_size=2				)

								return (
								    config,
								    input_ids,
								    token_type_ids,
								    input_mask,
								    sequence_labels,
								    token_labels,
								    choice_labels,
								    encoder_hidden_states,
								    encoder_attention_mask,
								)

						def  A_				(			self       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a				)					->      Union[str, Any]:


								'''simple docstring'''

								_UpperCamelCase						    =	NezhaModel(config=a				)
								model.to(a				)
								model.eval()
								_UpperCamelCase						    =	model(a       ,							attention_mask=a       ,							token_type_ids=a				)
								_UpperCamelCase						    =	model(a       ,							token_type_ids=a				)
								_UpperCamelCase						    =	model(a				)
								self.parent.assertEqual(result.last_hidden_state.shape       ,							(self.batch_size, self.seq_length, self.hidden_size)				)
								self.parent.assertEqual(result.pooler_output.shape       ,							(self.batch_size, self.hidden_size)				)

						def  A_				(			self       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a       ,							)					->      List[Any]:


								'''simple docstring'''

								_UpperCamelCase						    =	True
								_UpperCamelCase						    =	NezhaModel(a				)
								model.to(a				)
								model.eval()
								_UpperCamelCase						    =	model(
								    a       ,							attention_mask=a       ,							token_type_ids=a       ,							encoder_hidden_states=a       ,							encoder_attention_mask=a       ,							)
								_UpperCamelCase						    =	model(
								    a       ,							attention_mask=a       ,							token_type_ids=a       ,							encoder_hidden_states=a       ,							)
								_UpperCamelCase						    =	model(a       ,							attention_mask=a       ,							token_type_ids=a				)
								self.parent.assertEqual(result.last_hidden_state.shape       ,							(self.batch_size, self.seq_length, self.hidden_size)				)
								self.parent.assertEqual(result.pooler_output.shape       ,							(self.batch_size, self.hidden_size)				)

						def  A_				(			self       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a				)					->      Dict:


								'''simple docstring'''

								_UpperCamelCase						    =	NezhaForMaskedLM(config=a				)
								model.to(a				)
								model.eval()
								_UpperCamelCase						    =	model(a       ,							attention_mask=a       ,							token_type_ids=a       ,							labels=a				)
								self.parent.assertEqual(result.logits.shape       ,							(self.batch_size, self.seq_length, self.vocab_size)				)

						def  A_				(			self       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a				)					->      Optional[int]:


								'''simple docstring'''

								_UpperCamelCase						    =	NezhaForNextSentencePrediction(config=a				)
								model.to(a				)
								model.eval()
								_UpperCamelCase						    =	model(
								    a       ,							attention_mask=a       ,							token_type_ids=a       ,							labels=a       ,							)
								self.parent.assertEqual(result.logits.shape       ,							(self.batch_size, 2)				)

						def  A_				(			self       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a				)					->      Dict:


								'''simple docstring'''

								_UpperCamelCase						    =	NezhaForPreTraining(config=a				)
								model.to(a				)
								model.eval()
								_UpperCamelCase						    =	model(
								    a       ,							attention_mask=a       ,							token_type_ids=a       ,							labels=a       ,							next_sentence_label=a       ,							)
								self.parent.assertEqual(result.prediction_logits.shape       ,							(self.batch_size, self.seq_length, self.vocab_size)				)
								self.parent.assertEqual(result.seq_relationship_logits.shape       ,							(self.batch_size, 2)				)

						def  A_				(			self       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a				)					->      List[str]:


								'''simple docstring'''

								_UpperCamelCase						    =	NezhaForQuestionAnswering(config=a				)
								model.to(a				)
								model.eval()
								_UpperCamelCase						    =	model(
								    a       ,							attention_mask=a       ,							token_type_ids=a       ,							start_positions=a       ,							end_positions=a       ,							)
								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       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a				)					->      Optional[int]:


								'''simple docstring'''

								_UpperCamelCase						    =	self.num_labels
								_UpperCamelCase						    =	NezhaForSequenceClassification(a				)
								model.to(a				)
								model.eval()
								_UpperCamelCase						    =	model(a       ,							attention_mask=a       ,							token_type_ids=a       ,							labels=a				)
								self.parent.assertEqual(result.logits.shape       ,							(self.batch_size, self.num_labels)				)

						def  A_				(			self       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a				)					->      Dict:


								'''simple docstring'''

								_UpperCamelCase						    =	self.num_labels
								_UpperCamelCase						    =	NezhaForTokenClassification(config=a				)
								model.to(a				)
								model.eval()
								_UpperCamelCase						    =	model(a       ,							attention_mask=a       ,							token_type_ids=a       ,							labels=a				)
								self.parent.assertEqual(result.logits.shape       ,							(self.batch_size, self.seq_length, self.num_labels)				)

						def  A_				(			self       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a				)					->      Any:


								'''simple docstring'''

								_UpperCamelCase						    =	self.num_choices
								_UpperCamelCase						    =	NezhaForMultipleChoice(config=a				)
								model.to(a				)
								model.eval()
								_UpperCamelCase						    =	input_ids.unsqueeze(1				).expand(-1       ,							self.num_choices       ,							-1				).contiguous()
								_UpperCamelCase						    =	token_type_ids.unsqueeze(1				).expand(-1       ,							self.num_choices       ,							-1				).contiguous()
								_UpperCamelCase						    =	input_mask.unsqueeze(1				).expand(-1       ,							self.num_choices       ,							-1				).contiguous()
								_UpperCamelCase						    =	model(
								    a       ,							attention_mask=a       ,							token_type_ids=a       ,							labels=a       ,							)
								self.parent.assertEqual(result.logits.shape       ,							(self.batch_size, self.num_choices)				)







						def  A_				(			self				)					->      Tuple:


								'''simple docstring'''

								_UpperCamelCase						    =	self.prepare_config_and_inputs()
								(
								    (
								    _UpperCamelCase
								)    ,	(
								    _UpperCamelCase
								)    ,	(
								    _UpperCamelCase
								)    ,	(
								    _UpperCamelCase
								)    ,	(
								    _UpperCamelCase
								)    ,	(
								    _UpperCamelCase
								)    ,	(
								    _UpperCamelCase
								)    ,	
								)						    =	config_and_inputs
								_UpperCamelCase						    =	{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
								return config, inputs_dict







@require_torch
class        lowerCAmelCase__      (   __lowercase		,	__lowercase		,	__lowercase		,	unittest.TestCase	):
						UpperCamelCase_							: int	=		(
						    (
						        NezhaModel,
						        NezhaForMaskedLM,
						        NezhaForMultipleChoice,
						        NezhaForNextSentencePrediction,
						        NezhaForPreTraining,
						        NezhaForQuestionAnswering,
						        NezhaForSequenceClassification,
						        NezhaForTokenClassification,
						    )
						    if is_torch_available()
						    else ()
						)
						UpperCamelCase_							: Dict	=		(
						    {
						        "feature-extraction": NezhaModel,
						        "fill-mask": NezhaForMaskedLM,
						        "question-answering": NezhaForQuestionAnswering,
						        "text-classification": NezhaForSequenceClassification,
						        "token-classification": NezhaForTokenClassification,
						        "zero-shot": NezhaForSequenceClassification,
						    }
						    if is_torch_available()
						    else {}
						)
						UpperCamelCase_							: Dict	=		True

						def  A_				(			self       ,							a       ,							a       ,							a=False				)					->      List[Any]:


								'''simple docstring'''

								_UpperCamelCase						    =	super()._prepare_for_class(a       ,							a       ,							return_labels=a				)

								if return_labels:
										if model_class in get_values(a				):
												_UpperCamelCase						    =	torch.zeros(
												    (self.model_tester.batch_size, self.model_tester.seq_length)       ,							dtype=torch.long       ,							device=a				)
												_UpperCamelCase						    =	torch.zeros(
												    self.model_tester.batch_size       ,							dtype=torch.long       ,							device=a				)
								return inputs_dict

						def  A_				(			self				)					->      Optional[int]:


								'''simple docstring'''

								_UpperCamelCase						    =	NezhaModelTester(self				)
								_UpperCamelCase						    =	ConfigTester(self       ,							config_class=a       ,							hidden_size=37				)

						def  A_				(			self				)					->      List[str]:


								'''simple docstring'''

								self.config_tester.run_common_tests()

						def  A_				(			self				)					->      Any:


								'''simple docstring'''

								_UpperCamelCase						    =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*a				)

						def  A_				(			self				)					->      List[Any]:


								'''simple docstring'''

								_UpperCamelCase						    =	self.model_tester.prepare_config_and_inputs_for_decoder()
								self.model_tester.create_and_check_model_as_decoder(*a				)

						def  A_				(			self				)					->      Dict:


								'''simple docstring'''

								(
								    (
								    _UpperCamelCase
								)    ,	(
								    _UpperCamelCase
								)    ,	(
								    _UpperCamelCase
								)    ,	(
								    _UpperCamelCase
								)    ,	(
								    _UpperCamelCase
								)    ,	(
								    _UpperCamelCase
								)    ,	(
								    _UpperCamelCase
								)    ,	(
								    _UpperCamelCase
								)    ,	(
								    _UpperCamelCase
								)    ,	
								)						    =	self.model_tester.prepare_config_and_inputs_for_decoder()

								_UpperCamelCase						    =	None

								self.model_tester.create_and_check_model_as_decoder(
								    a       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a       ,							a       ,							)

						def  A_				(			self				)					->      str:


								'''simple docstring'''

								_UpperCamelCase						    =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_masked_lm(*a				)

						def  A_				(			self				)					->      Union[str, Any]:


								'''simple docstring'''

								_UpperCamelCase						    =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_multiple_choice(*a				)

						def  A_				(			self				)					->      str:


								'''simple docstring'''

								_UpperCamelCase						    =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_next_sequence_prediction(*a				)

						def  A_				(			self				)					->      int:


								'''simple docstring'''

								_UpperCamelCase						    =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_pretraining(*a				)

						def  A_				(			self				)					->      List[str]:


								'''simple docstring'''

								_UpperCamelCase						    =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_question_answering(*a				)

						def  A_				(			self				)					->      Any:


								'''simple docstring'''

								_UpperCamelCase						    =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_sequence_classification(*a				)

						def  A_				(			self				)					->      List[str]:


								'''simple docstring'''

								_UpperCamelCase						    =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_token_classification(*a				)

						@slow
						def  A_				(			self				)					->      List[Any]:


								'''simple docstring'''

								for model_name in NEZHA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										_UpperCamelCase						    =	NezhaModel.from_pretrained(a				)
										self.assertIsNotNone(a				)







						@slow
						@require_torch_gpu
						def  A_				(			self				)					->      Optional[Any]:


								'''simple docstring'''

								_UpperCamelCase    ,	_UpperCamelCase						    =	self.model_tester.prepare_config_and_inputs_for_common()
								for model_class in self.all_model_classes:
										# NezhaForMultipleChoice behaves incorrectly in JIT environments.
										if model_class == NezhaForMultipleChoice:
												return

										_UpperCamelCase						    =	True
										_UpperCamelCase						    =	model_class(config=a				)

										_UpperCamelCase						    =	self._prepare_for_class(a       ,							a				)
										_UpperCamelCase						    =	torch.jit.trace(
										    a       ,							(inputs_dict["""input_ids"""].to("""cpu"""				), inputs_dict["""attention_mask"""].to("""cpu"""				))				)

										with tempfile.TemporaryDirectory() as tmp:
												torch.jit.save(a       ,							os.path.join(a       ,							"""bert.pt"""				)				)
												_UpperCamelCase						    =	torch.jit.load(os.path.join(a       ,							"""bert.pt"""				)       ,							map_location=a				)
												loaded(inputs_dict["""input_ids"""].to(a				)       ,							inputs_dict["""attention_mask"""].to(a				)				)







@require_torch
class        lowerCAmelCase__      (   unittest.TestCase	):

						@slow
						def  A_				(			self				)					->      List[str]:


								'''simple docstring'''

								_UpperCamelCase						    =	NezhaModel.from_pretrained("""sijunhe/nezha-cn-base"""				)
								_UpperCamelCase						    =	torch.tensor([[0, 1, 2, 3, 4, 5]]				)
								_UpperCamelCase						    =	torch.tensor([[0, 1, 1, 1, 1, 1]]				)
								with torch.no_grad():
										_UpperCamelCase						    =	model(a       ,							attention_mask=a				)[0]
								_UpperCamelCase						    =	torch.Size((1, 6, 7_68)				)
								self.assertEqual(output.shape       ,							a				)
								_UpperCamelCase						    =	torch.tensor([[[0.0685, 0.2441, 0.1102], [0.0600, 0.1906, 0.1349], [0.0221, 0.0819, 0.0586]]]				)

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







						@slow
						def  A_				(			self				)					->      List[str]:


								'''simple docstring'''

								_UpperCamelCase						    =	NezhaForMaskedLM.from_pretrained("""sijunhe/nezha-cn-base"""				)
								_UpperCamelCase						    =	torch.tensor([[0, 1, 2, 3, 4, 5]]				)
								_UpperCamelCase						    =	torch.tensor([[1, 1, 1, 1, 1, 1]]				)
								with torch.no_grad():
										_UpperCamelCase						    =	model(a       ,							attention_mask=a				)[0]
								_UpperCamelCase						    =	torch.Size((1, 6, 2_11_28)				)
								self.assertEqual(output.shape       ,							a				)
								_UpperCamelCase						    =	torch.tensor(
								    [[-2.7939, -1.7902, -2.2189], [-2.8585, -1.8908, -2.3723], [-2.6499, -1.7750, -2.2558]]				)

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



