






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 			_UpperCamelCase:

		def __init__(					self		:    int    ,       SCREAMING_SNAKE_CASE__		:    int    ,       SCREAMING_SNAKE_CASE__		:    Optional[Any]=1_3    ,       SCREAMING_SNAKE_CASE__		:    Optional[int]=7    ,       SCREAMING_SNAKE_CASE__		:    List[Any]=True    ,       SCREAMING_SNAKE_CASE__		:    List[Any]=True    ,       SCREAMING_SNAKE_CASE__		:    int=True    ,       SCREAMING_SNAKE_CASE__		:    List[Any]=True    ,       SCREAMING_SNAKE_CASE__		:    Any=9_9    ,       SCREAMING_SNAKE_CASE__		:    Optional[Any]=3_2    ,       SCREAMING_SNAKE_CASE__		:    Optional[Any]=5    ,       SCREAMING_SNAKE_CASE__		:    int=4    ,       SCREAMING_SNAKE_CASE__		:    Dict=3_7    ,       SCREAMING_SNAKE_CASE__		:    Union[str, Any]="gelu"    ,       SCREAMING_SNAKE_CASE__		:    Optional[int]=0.1    ,       SCREAMING_SNAKE_CASE__		:    Optional[int]=0.1    ,       SCREAMING_SNAKE_CASE__		:    int=1_2_8    ,       SCREAMING_SNAKE_CASE__		:    Optional[Any]=3_2    ,       SCREAMING_SNAKE_CASE__		:    Union[str, Any]=1_6    ,       SCREAMING_SNAKE_CASE__		:    str=2    ,       SCREAMING_SNAKE_CASE__		:    Any=0.02    ,       SCREAMING_SNAKE_CASE__		:    Optional[int]=3    ,       SCREAMING_SNAKE_CASE__		:    Union[str, Any]=4    ,       SCREAMING_SNAKE_CASE__		:    Optional[int]=None    ,       ):



					'''simple docstring'''



					__a						:  Union[str, Any]									=     parent
					__a						:  str									=     batch_size
					__a						:  List[Any]									=     seq_length
					__a						:  List[Any]									=     is_training
					__a						:  str									=     use_input_mask
					__a						:  Union[str, Any]									=     use_token_type_ids
					__a						:  Union[str, Any]									=     use_labels
					__a						:  Dict									=     vocab_size
					__a						:  Tuple									=     hidden_size
					__a						:  List[str]									=     num_hidden_layers
					__a						:  List[Any]									=     num_attention_heads
					__a						:  Union[str, Any]									=     intermediate_size
					__a						:  Tuple									=     hidden_act
					__a						:  int									=     hidden_dropout_prob
					__a						:  Dict									=     attention_probs_dropout_prob
					__a						:  Any									=     max_position_embeddings
					__a						:  Any									=     type_vocab_size
					__a						:  Dict									=     type_sequence_label_size
					__a						:  Optional[int]									=     initializer_range
					__a						:  Tuple									=     num_labels
					__a						:  Any									=     num_choices
					__a						:  Any									=     scope

		def    __lowerCAmelCase  (					self		:    int    ):



					'''simple docstring'''



					__a						:  Optional[int]									=     ids_tensor([self.batch_size, self.seq_length]    ,       self.vocab_size    )

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

					__a						:  str									=     None
					if self.use_token_type_ids:
								__a						:  List[str]									=     ids_tensor([self.batch_size, self.seq_length]    ,       self.type_vocab_size    )

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

					__a						:  Optional[Any]									=     self.get_config()

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

		def    __lowerCAmelCase  (					self		:    Union[str, 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=SCREAMING_SNAKE_CASE__    ,       initializer_range=self.initializer_range    ,       )

		def    __lowerCAmelCase  (					self		:    Optional[Any]    ):



					'''simple docstring'''



					(
					    (
					    __a
					)						,					(
					    __a
					)						,					(
					    __a
					)						,					(
					    __a
					)						,					(
					    __a
					)						,					(
					    __a
					)						,					(
					    __a
					)						,					
					)						:  Tuple									=     self.prepare_config_and_inputs()

					__a						:  str									=     True
					__a						:  Any									=     floats_tensor([self.batch_size, self.seq_length, self.hidden_size]    )
					__a						:  int									=     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    __lowerCAmelCase  (					self		:    str    ,       SCREAMING_SNAKE_CASE__		:    List[str]    ,       SCREAMING_SNAKE_CASE__		:    str    ,       SCREAMING_SNAKE_CASE__		:    Any    ,       SCREAMING_SNAKE_CASE__		:    Dict    ,       SCREAMING_SNAKE_CASE__		:    List[str]    ,       SCREAMING_SNAKE_CASE__		:    Optional[int]    ,       SCREAMING_SNAKE_CASE__		:    Optional[Any]    ):



					'''simple docstring'''



					__a						:  Optional[Any]									=     NezhaModel(config=SCREAMING_SNAKE_CASE__    )
					model.to(SCREAMING_SNAKE_CASE__    )
					model.eval()
					__a						:  Optional[Any]									=     model(SCREAMING_SNAKE_CASE__    ,       attention_mask=SCREAMING_SNAKE_CASE__    ,       token_type_ids=SCREAMING_SNAKE_CASE__    )
					__a						:  str									=     model(SCREAMING_SNAKE_CASE__    ,       token_type_ids=SCREAMING_SNAKE_CASE__    )
					__a						:  Any									=     model(SCREAMING_SNAKE_CASE__    )
					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    __lowerCAmelCase  (					self		:    str    ,       SCREAMING_SNAKE_CASE__		:    Optional[int]    ,       SCREAMING_SNAKE_CASE__		:    Optional[Any]    ,       SCREAMING_SNAKE_CASE__		:    str    ,       SCREAMING_SNAKE_CASE__		:    Optional[Any]    ,       SCREAMING_SNAKE_CASE__		:    str    ,       SCREAMING_SNAKE_CASE__		:    Union[str, Any]    ,       SCREAMING_SNAKE_CASE__		:    Optional[Any]    ,       SCREAMING_SNAKE_CASE__		:    List[str]    ,       SCREAMING_SNAKE_CASE__		:    int    ,       ):



					'''simple docstring'''



					__a						:  Optional[Any]									=     True
					__a						:  List[Any]									=     NezhaModel(SCREAMING_SNAKE_CASE__    )
					model.to(SCREAMING_SNAKE_CASE__    )
					model.eval()
					__a						:  Optional[Any]									=     model(
					    SCREAMING_SNAKE_CASE__    ,       attention_mask=SCREAMING_SNAKE_CASE__    ,       token_type_ids=SCREAMING_SNAKE_CASE__    ,       encoder_hidden_states=SCREAMING_SNAKE_CASE__    ,       encoder_attention_mask=SCREAMING_SNAKE_CASE__    ,       )
					__a						:  Any									=     model(
					    SCREAMING_SNAKE_CASE__    ,       attention_mask=SCREAMING_SNAKE_CASE__    ,       token_type_ids=SCREAMING_SNAKE_CASE__    ,       encoder_hidden_states=SCREAMING_SNAKE_CASE__    ,       )
					__a						:  str									=     model(SCREAMING_SNAKE_CASE__    ,       attention_mask=SCREAMING_SNAKE_CASE__    ,       token_type_ids=SCREAMING_SNAKE_CASE__    )
					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    __lowerCAmelCase  (					self		:    List[Any]    ,       SCREAMING_SNAKE_CASE__		:    List[str]    ,       SCREAMING_SNAKE_CASE__		:    Union[str, Any]    ,       SCREAMING_SNAKE_CASE__		:    str    ,       SCREAMING_SNAKE_CASE__		:    List[str]    ,       SCREAMING_SNAKE_CASE__		:    Tuple    ,       SCREAMING_SNAKE_CASE__		:    Dict    ,       SCREAMING_SNAKE_CASE__		:    Union[str, Any]    ):



					'''simple docstring'''



					__a						:  Dict									=     NezhaForMaskedLM(config=SCREAMING_SNAKE_CASE__    )
					model.to(SCREAMING_SNAKE_CASE__    )
					model.eval()
					__a						:  str									=     model(SCREAMING_SNAKE_CASE__    ,       attention_mask=SCREAMING_SNAKE_CASE__    ,       token_type_ids=SCREAMING_SNAKE_CASE__    ,       labels=SCREAMING_SNAKE_CASE__    )
					self.parent.assertEqual(result.logits.shape    ,       (self.batch_size, self.seq_length, self.vocab_size)    )

		def    __lowerCAmelCase  (					self		:    List[Any]    ,       SCREAMING_SNAKE_CASE__		:    Any    ,       SCREAMING_SNAKE_CASE__		:    Optional[int]    ,       SCREAMING_SNAKE_CASE__		:    str    ,       SCREAMING_SNAKE_CASE__		:    Optional[Any]    ,       SCREAMING_SNAKE_CASE__		:    Tuple    ,       SCREAMING_SNAKE_CASE__		:    Any    ,       SCREAMING_SNAKE_CASE__		:    str    ):



					'''simple docstring'''



					__a						:  Tuple									=     NezhaForNextSentencePrediction(config=SCREAMING_SNAKE_CASE__    )
					model.to(SCREAMING_SNAKE_CASE__    )
					model.eval()
					__a						:  Dict									=     model(
					    SCREAMING_SNAKE_CASE__    ,       attention_mask=SCREAMING_SNAKE_CASE__    ,       token_type_ids=SCREAMING_SNAKE_CASE__    ,       labels=SCREAMING_SNAKE_CASE__    ,       )
					self.parent.assertEqual(result.logits.shape    ,       (self.batch_size, 2)    )

		def    __lowerCAmelCase  (					self		:    int    ,       SCREAMING_SNAKE_CASE__		:    Dict    ,       SCREAMING_SNAKE_CASE__		:    List[str]    ,       SCREAMING_SNAKE_CASE__		:    Union[str, Any]    ,       SCREAMING_SNAKE_CASE__		:    Tuple    ,       SCREAMING_SNAKE_CASE__		:    Dict    ,       SCREAMING_SNAKE_CASE__		:    Tuple    ,       SCREAMING_SNAKE_CASE__		:    Optional[Any]    ):



					'''simple docstring'''



					__a						:  Union[str, Any]									=     NezhaForPreTraining(config=SCREAMING_SNAKE_CASE__    )
					model.to(SCREAMING_SNAKE_CASE__    )
					model.eval()
					__a						:  List[str]									=     model(
					    SCREAMING_SNAKE_CASE__    ,       attention_mask=SCREAMING_SNAKE_CASE__    ,       token_type_ids=SCREAMING_SNAKE_CASE__    ,       labels=SCREAMING_SNAKE_CASE__    ,       next_sentence_label=SCREAMING_SNAKE_CASE__    ,       )
					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    __lowerCAmelCase  (					self		:    int    ,       SCREAMING_SNAKE_CASE__		:    Tuple    ,       SCREAMING_SNAKE_CASE__		:    Optional[Any]    ,       SCREAMING_SNAKE_CASE__		:    int    ,       SCREAMING_SNAKE_CASE__		:    Tuple    ,       SCREAMING_SNAKE_CASE__		:    List[Any]    ,       SCREAMING_SNAKE_CASE__		:    int    ,       SCREAMING_SNAKE_CASE__		:    List[str]    ):



					'''simple docstring'''



					__a						:  Any									=     NezhaForQuestionAnswering(config=SCREAMING_SNAKE_CASE__    )
					model.to(SCREAMING_SNAKE_CASE__    )
					model.eval()
					__a						:  int									=     model(
					    SCREAMING_SNAKE_CASE__    ,       attention_mask=SCREAMING_SNAKE_CASE__    ,       token_type_ids=SCREAMING_SNAKE_CASE__    ,       start_positions=SCREAMING_SNAKE_CASE__    ,       end_positions=SCREAMING_SNAKE_CASE__    ,       )
					self.parent.assertEqual(result.start_logits.shape    ,       (self.batch_size, self.seq_length)    )
					self.parent.assertEqual(result.end_logits.shape    ,       (self.batch_size, self.seq_length)    )

		def    __lowerCAmelCase  (					self		:    Dict    ,       SCREAMING_SNAKE_CASE__		:    Dict    ,       SCREAMING_SNAKE_CASE__		:    Dict    ,       SCREAMING_SNAKE_CASE__		:    str    ,       SCREAMING_SNAKE_CASE__		:    Any    ,       SCREAMING_SNAKE_CASE__		:    Tuple    ,       SCREAMING_SNAKE_CASE__		:    Any    ,       SCREAMING_SNAKE_CASE__		:    List[Any]    ):



					'''simple docstring'''



					__a						:  int									=     self.num_labels
					__a						:  Any									=     NezhaForSequenceClassification(SCREAMING_SNAKE_CASE__    )
					model.to(SCREAMING_SNAKE_CASE__    )
					model.eval()
					__a						:  Any									=     model(SCREAMING_SNAKE_CASE__    ,       attention_mask=SCREAMING_SNAKE_CASE__    ,       token_type_ids=SCREAMING_SNAKE_CASE__    ,       labels=SCREAMING_SNAKE_CASE__    )
					self.parent.assertEqual(result.logits.shape    ,       (self.batch_size, self.num_labels)    )

		def    __lowerCAmelCase  (					self		:    Optional[Any]    ,       SCREAMING_SNAKE_CASE__		:    Any    ,       SCREAMING_SNAKE_CASE__		:    Union[str, Any]    ,       SCREAMING_SNAKE_CASE__		:    List[str]    ,       SCREAMING_SNAKE_CASE__		:    Optional[Any]    ,       SCREAMING_SNAKE_CASE__		:    Union[str, Any]    ,       SCREAMING_SNAKE_CASE__		:    Tuple    ,       SCREAMING_SNAKE_CASE__		:    Tuple    ):



					'''simple docstring'''



					__a						:  Any									=     self.num_labels
					__a						:  Tuple									=     NezhaForTokenClassification(config=SCREAMING_SNAKE_CASE__    )
					model.to(SCREAMING_SNAKE_CASE__    )
					model.eval()
					__a						:  Optional[Any]									=     model(SCREAMING_SNAKE_CASE__    ,       attention_mask=SCREAMING_SNAKE_CASE__    ,       token_type_ids=SCREAMING_SNAKE_CASE__    ,       labels=SCREAMING_SNAKE_CASE__    )
					self.parent.assertEqual(result.logits.shape    ,       (self.batch_size, self.seq_length, self.num_labels)    )

		def    __lowerCAmelCase  (					self		:    Optional[Any]    ,       SCREAMING_SNAKE_CASE__		:    Optional[Any]    ,       SCREAMING_SNAKE_CASE__		:    int    ,       SCREAMING_SNAKE_CASE__		:    int    ,       SCREAMING_SNAKE_CASE__		:    Optional[int]    ,       SCREAMING_SNAKE_CASE__		:    Any    ,       SCREAMING_SNAKE_CASE__		:    Dict    ,       SCREAMING_SNAKE_CASE__		:    Union[str, Any]    ):



					'''simple docstring'''



					__a						:  List[str]									=     self.num_choices
					__a						:  str									=     NezhaForMultipleChoice(config=SCREAMING_SNAKE_CASE__    )
					model.to(SCREAMING_SNAKE_CASE__    )
					model.eval()
					__a						:  Dict									=     input_ids.unsqueeze(1    ).expand(-1    ,       self.num_choices    ,       -1    ).contiguous()
					__a						:  Tuple									=     token_type_ids.unsqueeze(1    ).expand(-1    ,       self.num_choices    ,       -1    ).contiguous()
					__a						:  Any									=     input_mask.unsqueeze(1    ).expand(-1    ,       self.num_choices    ,       -1    ).contiguous()
					__a						:  str									=     model(
					    SCREAMING_SNAKE_CASE__    ,       attention_mask=SCREAMING_SNAKE_CASE__    ,       token_type_ids=SCREAMING_SNAKE_CASE__    ,       labels=SCREAMING_SNAKE_CASE__    ,       )
					self.parent.assertEqual(result.logits.shape    ,       (self.batch_size, self.num_choices)    )



		def    __lowerCAmelCase  (					self		:    List[Any]    ):



					'''simple docstring'''



					__a						:  Tuple									=     self.prepare_config_and_inputs()
					(
					    (
					    __a
					)						,					(
					    __a
					)						,					(
					    __a
					)						,					(
					    __a
					)						,					(
					    __a
					)						,					(
					    __a
					)						,					(
					    __a
					)						,					
					)						:  int									=     config_and_inputs
					__a						:  List[Any]									=     {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
					return config, inputs_dict






@require_torch
class 			_UpperCamelCase(       __lowerCamelCase		,				__lowerCamelCase		,				__lowerCamelCase		,				unittest.TestCase		):
		__SCREAMING_SNAKE_CASE  :       str							=							(
		    (
		        NezhaModel,
		        NezhaForMaskedLM,
		        NezhaForMultipleChoice,
		        NezhaForNextSentencePrediction,
		        NezhaForPreTraining,
		        NezhaForQuestionAnswering,
		        NezhaForSequenceClassification,
		        NezhaForTokenClassification,
		    )
		    if is_torch_available()
		    else ()
		)
		__SCREAMING_SNAKE_CASE  :       Dict							=							(
		    {
		        '''feature-extraction''': NezhaModel,
		        '''fill-mask''': NezhaForMaskedLM,
		        '''question-answering''': NezhaForQuestionAnswering,
		        '''text-classification''': NezhaForSequenceClassification,
		        '''token-classification''': NezhaForTokenClassification,
		        '''zero-shot''': NezhaForSequenceClassification,
		    }
		    if is_torch_available()
		    else {}
		)
		__SCREAMING_SNAKE_CASE  :       Optional[Any]							=							True

		def    __lowerCAmelCase  (					self		:    Optional[Any]    ,       SCREAMING_SNAKE_CASE__		:    Union[str, Any]    ,       SCREAMING_SNAKE_CASE__		:    Optional[Any]    ,       SCREAMING_SNAKE_CASE__		:    str=False    ):



					'''simple docstring'''



					__a						:  List[Any]									=     super()._prepare_for_class(SCREAMING_SNAKE_CASE__    ,       SCREAMING_SNAKE_CASE__    ,       return_labels=SCREAMING_SNAKE_CASE__    )

					if return_labels:
								if model_class in get_values(SCREAMING_SNAKE_CASE__    ):
											__a						:  List[str]									=     torch.zeros(
											    (self.model_tester.batch_size, self.model_tester.seq_length)    ,       dtype=torch.long    ,       device=SCREAMING_SNAKE_CASE__    )
											__a						:  Optional[int]									=     torch.zeros(
											    self.model_tester.batch_size    ,       dtype=torch.long    ,       device=SCREAMING_SNAKE_CASE__    )
					return inputs_dict

		def    __lowerCAmelCase  (					self		:    str    ):



					'''simple docstring'''



					__a						:  int									=     NezhaModelTester(self    )
					__a						:  List[Any]									=     ConfigTester(self    ,       config_class=SCREAMING_SNAKE_CASE__    ,       hidden_size=3_7    )

		def    __lowerCAmelCase  (					self		:    Tuple    ):



					'''simple docstring'''



					self.config_tester.run_common_tests()

		def    __lowerCAmelCase  (					self		:    Tuple    ):



					'''simple docstring'''



					__a						:  Dict									=     self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE__    )

		def    __lowerCAmelCase  (					self		:    List[Any]    ):



					'''simple docstring'''



					__a						:  str									=     self.model_tester.prepare_config_and_inputs_for_decoder()
					self.model_tester.create_and_check_model_as_decoder(*SCREAMING_SNAKE_CASE__    )

		def    __lowerCAmelCase  (					self		:    int    ):



					'''simple docstring'''



					(
					    (
					    __a
					)						,					(
					    __a
					)						,					(
					    __a
					)						,					(
					    __a
					)						,					(
					    __a
					)						,					(
					    __a
					)						,					(
					    __a
					)						,					(
					    __a
					)						,					(
					    __a
					)						,					
					)						:  List[Any]									=     self.model_tester.prepare_config_and_inputs_for_decoder()

					__a						:  Dict									=     None

					self.model_tester.create_and_check_model_as_decoder(
					    SCREAMING_SNAKE_CASE__    ,       SCREAMING_SNAKE_CASE__    ,       SCREAMING_SNAKE_CASE__    ,       SCREAMING_SNAKE_CASE__    ,       SCREAMING_SNAKE_CASE__    ,       SCREAMING_SNAKE_CASE__    ,       SCREAMING_SNAKE_CASE__    ,       SCREAMING_SNAKE_CASE__    ,       SCREAMING_SNAKE_CASE__    ,       )

		def    __lowerCAmelCase  (					self		:    Optional[Any]    ):



					'''simple docstring'''



					__a						:  Optional[int]									=     self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_masked_lm(*SCREAMING_SNAKE_CASE__    )

		def    __lowerCAmelCase  (					self		:    List[str]    ):



					'''simple docstring'''



					__a						:  Union[str, Any]									=     self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_multiple_choice(*SCREAMING_SNAKE_CASE__    )

		def    __lowerCAmelCase  (					self		:    Union[str, Any]    ):



					'''simple docstring'''



					__a						:  Any									=     self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_next_sequence_prediction(*SCREAMING_SNAKE_CASE__    )

		def    __lowerCAmelCase  (					self		:    Any    ):



					'''simple docstring'''



					__a						:  Optional[int]									=     self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_pretraining(*SCREAMING_SNAKE_CASE__    )

		def    __lowerCAmelCase  (					self		:    Optional[Any]    ):



					'''simple docstring'''



					__a						:  Any									=     self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_question_answering(*SCREAMING_SNAKE_CASE__    )

		def    __lowerCAmelCase  (					self		:    int    ):



					'''simple docstring'''



					__a						:  Optional[Any]									=     self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_sequence_classification(*SCREAMING_SNAKE_CASE__    )

		def    __lowerCAmelCase  (					self		:    Dict    ):



					'''simple docstring'''



					__a						:  Optional[int]									=     self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_token_classification(*SCREAMING_SNAKE_CASE__    )

		@slow
		def    __lowerCAmelCase  (					self		:    List[Any]    ):



					'''simple docstring'''



					for model_name in NEZHA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
								__a						:  Optional[Any]									=     NezhaModel.from_pretrained(SCREAMING_SNAKE_CASE__    )
								self.assertIsNotNone(SCREAMING_SNAKE_CASE__    )



		@slow
		@require_torch_gpu
		def    __lowerCAmelCase  (					self		:    Tuple    ):



					'''simple docstring'''



					__a						,					__a						:  Union[str, Any]									=     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

								__a						:  Union[str, Any]									=     True
								__a						:  Tuple									=     model_class(config=SCREAMING_SNAKE_CASE__    )

								__a						:  Optional[Any]									=     self._prepare_for_class(SCREAMING_SNAKE_CASE__    ,       SCREAMING_SNAKE_CASE__    )
								__a						:  Tuple									=     torch.jit.trace(
								    SCREAMING_SNAKE_CASE__    ,       (inputs_dict['input_ids'].to('cpu'    ), inputs_dict['attention_mask'].to('cpu'    ))    )

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






@require_torch
class 			_UpperCamelCase(       unittest.TestCase		):

		@slow
		def    __lowerCAmelCase  (					self		:    Optional[int]    ):



					'''simple docstring'''



					__a						:  List[str]									=     NezhaModel.from_pretrained('sijunhe/nezha-cn-base'    )
					__a						:  Dict									=     torch.tensor([[0, 1, 2, 3, 4, 5]]    )
					__a						:  Optional[int]									=     torch.tensor([[0, 1, 1, 1, 1, 1]]    )
					with torch.no_grad():
								__a						:  List[str]									=     model(SCREAMING_SNAKE_CASE__    ,       attention_mask=SCREAMING_SNAKE_CASE__    )[0]
					__a						:  Dict									=     torch.Size((1, 6, 7_6_8)    )
					self.assertEqual(output.shape    ,       SCREAMING_SNAKE_CASE__    )
					__a						:  Union[str, Any]									=     torch.tensor([[[0.0_685, 0.2_441, 0.1_102], [0.0_600, 0.1_906, 0.1_349], [0.0_221, 0.0_819, 0.0_586]]]    )

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



		@slow
		def    __lowerCAmelCase  (					self		:    Dict    ):



					'''simple docstring'''



					__a						:  Any									=     NezhaForMaskedLM.from_pretrained('sijunhe/nezha-cn-base'    )
					__a						:  Optional[Any]									=     torch.tensor([[0, 1, 2, 3, 4, 5]]    )
					__a						:  int									=     torch.tensor([[1, 1, 1, 1, 1, 1]]    )
					with torch.no_grad():
								__a						:  Dict									=     model(SCREAMING_SNAKE_CASE__    ,       attention_mask=SCREAMING_SNAKE_CASE__    )[0]
					__a						:  int									=     torch.Size((1, 6, 2_1_1_2_8)    )
					self.assertEqual(output.shape    ,       SCREAMING_SNAKE_CASE__    )
					__a						:  str									=     torch.tensor(
					    [[-2.7_939, -1.7_902, -2.2_189], [-2.8_585, -1.8_908, -2.3_723], [-2.6_499, -1.7_750, -2.2_558]]    )

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









from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_torch_available,
)


SCREAMING_SNAKE_CASE						:str			=  {'''configuration_unispeech''': ['''UNISPEECH_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''UniSpeechConfig''']}

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   SCREAMING_SNAKE_CASE						:List[str]			=  [
       '''UNISPEECH_PRETRAINED_MODEL_ARCHIVE_LIST''',
       '''UniSpeechForCTC''',
       '''UniSpeechForPreTraining''',
       '''UniSpeechForSequenceClassification''',
       '''UniSpeechModel''',
       '''UniSpeechPreTrainedModel''',
   ]

if TYPE_CHECKING:
   from .configuration_unispeech import UNISPEECH_PRETRAINED_CONFIG_ARCHIVE_MAP, UniSpeechConfig

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_unispeech import (
          UNISPEECH_PRETRAINED_MODEL_ARCHIVE_LIST,
          UniSpeechForCTC,
          UniSpeechForPreTraining,
          UniSpeechForSequenceClassification,
          UniSpeechModel,
          UniSpeechPreTrainedModel,
      )

else:
   import sys

   SCREAMING_SNAKE_CASE						:List[str]			=  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)




