


'''simple docstring'''

from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxSeqaSeqConfigWithPast
from ...utils import logging


lowerCamelCase				:  Dict    		=      logging.get_logger(__name__)

lowerCamelCase				:  Dict    		=      {
    'google/umt5-small': 'https://huggingface.co/google/umt5-small/resolve/main/config.json',
    # See all umt5 models at https://huggingface.co/models?filter=umt5
}
class     __lowerCAmelCase		(SCREAMING_SNAKE_CASE_	):





      '''simple docstring'''






      lowerCAmelCase__   :	str       =				"""umt5"""
      lowerCAmelCase__   :	Union[str, Any]       =				["""past_key_values"""]



      def __init__(self       :       int  ,		UpperCamelCase       :       List[Any]=250112  ,		UpperCamelCase       :       Optional[Any]=512  ,		UpperCamelCase       :       Optional[Any]=64  ,		UpperCamelCase       :       List[str]=1024  ,		UpperCamelCase       :       Union[str, Any]=8  ,		UpperCamelCase       :       Optional[int]=None  ,		UpperCamelCase       :       Any=6  ,		UpperCamelCase       :       Any=32  ,		UpperCamelCase       :       Union[str, Any]=128  ,		UpperCamelCase       :       int=0.1  ,		UpperCamelCase       :       Optional[int]=1E-6  ,		UpperCamelCase       :       List[Any]=1.0  ,		UpperCamelCase       :       Any="gated-gelu"  ,		UpperCamelCase       :       Optional[Any]=True  ,		UpperCamelCase       :       str=True  ,		UpperCamelCase       :       Optional[Any]="T5Tokenizer"  ,		UpperCamelCase       :       List[Any]=True  ,		UpperCamelCase       :       Optional[Any]=0  ,		UpperCamelCase       :       List[Any]=1  ,		UpperCamelCase       :       List[Any]=0  ,		**UpperCamelCase       :       Dict  ,		):

             '''simple docstring'''







             super().__init__(
                 is_encoder_decoder=_a  ,		tokenizer_class=_a  ,		tie_word_embeddings=_a  ,		pad_token_id=_a  ,		eos_token_id=_a  ,		decoder_start_token_id=_a  ,		**_a  ,		)
             lowercase__      =					vocab_size
             lowercase__      =					d_model
             lowercase__      =					d_kv
             lowercase__      =					d_ff
             lowercase__      =					num_layers
             lowercase__      =					(
                 num_decoder_layers if num_decoder_layers is not None else self.num_layers
             )  # default = symmetry
             lowercase__      =					num_heads
             lowercase__      =					relative_attention_num_buckets
             lowercase__      =					relative_attention_max_distance
             lowercase__      =					dropout_rate
             lowercase__      =					layer_norm_epsilon
             lowercase__      =					initializer_factor
             lowercase__      =					feed_forward_proj
             lowercase__      =					use_cache

             lowercase__      =					self.feed_forward_proj.split('''-'''					)
             lowercase__      =					act_info[-1]
             lowercase__      =					act_info[0] == 'gated'

             if len(_a					) > 1 and act_info[0] != "gated" or len(_a					) > 2:
                    raise ValueError(
                        f"`feed_forward_proj`: {feed_forward_proj} is not a valid activation function of the dense layer."
                        '''Please make sure `feed_forward_proj` is of the format `gated-{ACT_FN}` or `{ACT_FN}`, e.g. '''
                        '''\'gated-gelu\' or \'relu\''''					)

             if feed_forward_proj == "gated-gelu":
                    lowercase__      =					'gelu_new'



      @property
      def  UpperCamelCase__						(self       :       List[str]					):

             '''simple docstring'''







             return self.d_model



      @property
      def  UpperCamelCase__						(self       :       Any					):

             '''simple docstring'''







             return self.num_heads






      @property
      def  UpperCamelCase__						(self       :       Optional[int]					):

             '''simple docstring'''







             return self.num_layers






class     __lowerCAmelCase		(SCREAMING_SNAKE_CASE_	):





      '''simple docstring'''






      @property
      # Copied from transformers.models.t5.configuration_t5.T5OnnxConfig.inputs
      def  UpperCamelCase__						(self       :       Tuple					):

             '''simple docstring'''







             lowercase__      =					{
                 'input_ids': {0: 'batch', 1: 'encoder_sequence'},
                 'attention_mask': {0: 'batch', 1: 'encoder_sequence'},
             }
             if self.use_past:
                    lowercase__      =					'past_encoder_sequence + sequence'
                    lowercase__      =					{0: 'batch'}
                    lowercase__      =					{0: 'batch', 1: 'past_decoder_sequence + sequence'}
             else:
                    lowercase__      =					{0: 'batch', 1: 'decoder_sequence'}
                    lowercase__      =					{0: 'batch', 1: 'decoder_sequence'}

             if self.use_past:
                    self.fill_with_past_key_values_(_a  ,		direction='''inputs'''					)

             return common_inputs



      @property
      # Copied from transformers.models.t5.configuration_t5.T5OnnxConfig.default_onnx_opset
      def  UpperCamelCase__						(self       :       Union[str, Any]					):

             '''simple docstring'''







             return 13






      @property
      def  UpperCamelCase__						(self       :       int					):

             '''simple docstring'''







             return 5E-4









'''simple docstring'''





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_       :
  """simple docstring"""




  def __init__(					self :      str     ,      _a :      Dict     ,      _a :      List[str]=13     ,      _a :      List[str]=7     ,      _a :      Union[str, Any]=True     ,      _a :      List[Any]=True     ,      _a :      Optional[Any]=True     ,      _a :      Any=True     ,      _a :      Optional[Any]=99     ,      _a :      List[str]=32     ,      _a :      Optional[Any]=5     ,      _a :      str=4     ,      _a :      str=37     ,      _a :      List[Any]="gelu"     ,      _a :      List[Any]=0.1     ,      _a :      Optional[int]=0.1     ,      _a :      Optional[Any]=128     ,      _a :      Tuple=32     ,      _a :      List[Any]=16     ,      _a :      Optional[int]=2     ,      _a :      List[str]=0.02     ,      _a :      List[str]=3     ,      _a :      Any=4     ,      _a :      List[str]=None     ,      )   ->   Any:
    __lowerCamelCase			:			Optional[Any]       			=					parent
    __lowerCamelCase			:			Optional[int]       			=					batch_size
    __lowerCamelCase			:			List[str]       			=					seq_length
    __lowerCamelCase			:			List[str]       			=					is_training
    __lowerCamelCase			:			Dict       			=					use_input_mask
    __lowerCamelCase			:			Optional[int]       			=					use_token_type_ids
    __lowerCamelCase			:			Union[str, Any]       			=					use_labels
    __lowerCamelCase			:			Tuple       			=					vocab_size
    __lowerCamelCase			:			Any       			=					hidden_size
    __lowerCamelCase			:			Tuple       			=					num_hidden_layers
    __lowerCamelCase			:			List[str]       			=					num_attention_heads
    __lowerCamelCase			:			str       			=					intermediate_size
    __lowerCamelCase			:			Tuple       			=					hidden_act
    __lowerCamelCase			:			List[str]       			=					hidden_dropout_prob
    __lowerCamelCase			:			List[Any]       			=					attention_probs_dropout_prob
    __lowerCamelCase			:			List[str]       			=					max_position_embeddings
    __lowerCamelCase			:			str       			=					type_vocab_size
    __lowerCamelCase			:			Optional[Any]       			=					type_sequence_label_size
    __lowerCamelCase			:			Optional[Any]       			=					initializer_range
    __lowerCamelCase			:			Tuple       			=					num_labels
    __lowerCamelCase			:			Tuple       			=					num_choices
    __lowerCamelCase			:			Optional[int]       			=					scope




  def 		_lowercase	(					self :      Optional[int]  )   ->   Dict:
    __lowerCamelCase			:			Tuple       			=					ids_tensor([self.batch_size, self.seq_length]     ,      self.vocab_size  )

    __lowerCamelCase			:			Optional[int]       			=					None
    if self.use_input_mask:
      __lowerCamelCase			:			Optional[int]       			=					random_attention_mask([self.batch_size, self.seq_length]  )

    __lowerCamelCase			:			Tuple       			=					None
    if self.use_token_type_ids:
      __lowerCamelCase			:			int       			=					ids_tensor([self.batch_size, self.seq_length]     ,      self.type_vocab_size  )

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

    __lowerCamelCase			:			List[Any]       			=					self.get_config()

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




  def 		_lowercase	(					self :      List[str]  )   ->   int:
    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 		_lowercase	(					self :      Tuple  )   ->   Optional[Any]:
    (
        (
        __lowerCamelCase
    )			,(
        __lowerCamelCase
    )			,(
        __lowerCamelCase
    )			,(
        __lowerCamelCase
    )			,(
        __lowerCamelCase
    )			,(
        __lowerCamelCase
    )			,(
        __lowerCamelCase
    )			,
    )			:			List[Any]       			=					self.prepare_config_and_inputs()

    __lowerCamelCase			:			Optional[Any]       			=					True
    __lowerCamelCase			:			Optional[int]       			=					floats_tensor([self.batch_size, self.seq_length, self.hidden_size]  )
    __lowerCamelCase			:			Optional[Any]       			=					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 		_lowercase	(					self :      Optional[int]     ,      _a :      List[Any]     ,      _a :      Dict     ,      _a :      Union[str, Any]     ,      _a :      Tuple     ,      _a :      Tuple     ,      _a :      Dict     ,      _a :      Any  )   ->   Tuple:
    __lowerCamelCase			:			List[Any]       			=					NezhaModel(config=_a  )
    model.to(_a  )
    model.eval()
    __lowerCamelCase			:			Any       			=					model(_a     ,      attention_mask=_a     ,      token_type_ids=_a  )
    __lowerCamelCase			:			int       			=					model(_a     ,      token_type_ids=_a  )
    __lowerCamelCase			:			Optional[Any]       			=					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 		_lowercase	(					self :      Optional[Any]     ,      _a :      List[str]     ,      _a :      Dict     ,      _a :      Optional[Any]     ,      _a :      int     ,      _a :      List[str]     ,      _a :      Optional[int]     ,      _a :      List[str]     ,      _a :      Optional[int]     ,      _a :      Any     ,      )   ->   Dict:
    __lowerCamelCase			:			Optional[Any]       			=					True
    __lowerCamelCase			:			Union[str, Any]       			=					NezhaModel(_a  )
    model.to(_a  )
    model.eval()
    __lowerCamelCase			:			Any       			=					model(
        _a     ,      attention_mask=_a     ,      token_type_ids=_a     ,      encoder_hidden_states=_a     ,      encoder_attention_mask=_a     ,      )
    __lowerCamelCase			:			Tuple       			=					model(
        _a     ,      attention_mask=_a     ,      token_type_ids=_a     ,      encoder_hidden_states=_a     ,      )
    __lowerCamelCase			:			str       			=					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 		_lowercase	(					self :      Union[str, Any]     ,      _a :      Optional[int]     ,      _a :      int     ,      _a :      Optional[Any]     ,      _a :      Any     ,      _a :      Tuple     ,      _a :      Optional[int]     ,      _a :      int  )   ->   List[Any]:
    __lowerCamelCase			:			int       			=					NezhaForMaskedLM(config=_a  )
    model.to(_a  )
    model.eval()
    __lowerCamelCase			:			Optional[Any]       			=					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 		_lowercase	(					self :      int     ,      _a :      Tuple     ,      _a :      List[Any]     ,      _a :      Any     ,      _a :      Optional[Any]     ,      _a :      Dict     ,      _a :      Dict     ,      _a :      List[Any]  )   ->   str:
    __lowerCamelCase			:			str       			=					NezhaForNextSentencePrediction(config=_a  )
    model.to(_a  )
    model.eval()
    __lowerCamelCase			:			str       			=					model(
        _a     ,      attention_mask=_a     ,      token_type_ids=_a     ,      labels=_a     ,      )
    self.parent.assertEqual(result.logits.shape     ,      (self.batch_size, 2)  )




  def 		_lowercase	(					self :      Any     ,      _a :      List[str]     ,      _a :      str     ,      _a :      List[Any]     ,      _a :      str     ,      _a :      Union[str, Any]     ,      _a :      int     ,      _a :      Tuple  )   ->   Dict:
    __lowerCamelCase			:			List[str]       			=					NezhaForPreTraining(config=_a  )
    model.to(_a  )
    model.eval()
    __lowerCamelCase			:			Optional[int]       			=					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 		_lowercase	(					self :      int     ,      _a :      Dict     ,      _a :      Any     ,      _a :      Any     ,      _a :      Tuple     ,      _a :      List[str]     ,      _a :      Any     ,      _a :      List[Any]  )   ->   List[Any]:
    __lowerCamelCase			:			Any       			=					NezhaForQuestionAnswering(config=_a  )
    model.to(_a  )
    model.eval()
    __lowerCamelCase			:			List[Any]       			=					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 		_lowercase	(					self :      Optional[int]     ,      _a :      str     ,      _a :      Tuple     ,      _a :      List[str]     ,      _a :      List[str]     ,      _a :      Any     ,      _a :      str     ,      _a :      Union[str, Any]  )   ->   int:
    __lowerCamelCase			:			Optional[int]       			=					self.num_labels
    __lowerCamelCase			:			List[str]       			=					NezhaForSequenceClassification(_a  )
    model.to(_a  )
    model.eval()
    __lowerCamelCase			:			Any       			=					model(_a     ,      attention_mask=_a     ,      token_type_ids=_a     ,      labels=_a  )
    self.parent.assertEqual(result.logits.shape     ,      (self.batch_size, self.num_labels)  )




  def 		_lowercase	(					self :      List[Any]     ,      _a :      List[Any]     ,      _a :      str     ,      _a :      Tuple     ,      _a :      Dict     ,      _a :      Dict     ,      _a :      Union[str, Any]     ,      _a :      List[Any]  )   ->   int:
    __lowerCamelCase			:			int       			=					self.num_labels
    __lowerCamelCase			:			int       			=					NezhaForTokenClassification(config=_a  )
    model.to(_a  )
    model.eval()
    __lowerCamelCase			:			List[str]       			=					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 		_lowercase	(					self :      List[str]     ,      _a :      Any     ,      _a :      List[str]     ,      _a :      Tuple     ,      _a :      Optional[Any]     ,      _a :      Optional[Any]     ,      _a :      str     ,      _a :      Optional[Any]  )   ->   int:
    __lowerCamelCase			:			List[Any]       			=					self.num_choices
    __lowerCamelCase			:			Optional[Any]       			=					NezhaForMultipleChoice(config=_a  )
    model.to(_a  )
    model.eval()
    __lowerCamelCase			:			Optional[Any]       			=					input_ids.unsqueeze(1  ).expand(-1     ,      self.num_choices     ,      -1  ).contiguous()
    __lowerCamelCase			:			Any       			=					token_type_ids.unsqueeze(1  ).expand(-1     ,      self.num_choices     ,      -1  ).contiguous()
    __lowerCamelCase			:			List[str]       			=					input_mask.unsqueeze(1  ).expand(-1     ,      self.num_choices     ,      -1  ).contiguous()
    __lowerCamelCase			:			str       			=					model(
        _a     ,      attention_mask=_a     ,      token_type_ids=_a     ,      labels=_a     ,      )
    self.parent.assertEqual(result.logits.shape     ,      (self.batch_size, self.num_choices)  )




  def 		_lowercase	(					self :      List[str]  )   ->   Any:
    __lowerCamelCase			:			Optional[Any]       			=					self.prepare_config_and_inputs()
    (
        (
        __lowerCamelCase
    )			,(
        __lowerCamelCase
    )			,(
        __lowerCamelCase
    )			,(
        __lowerCamelCase
    )			,(
        __lowerCamelCase
    )			,(
        __lowerCamelCase
    )			,(
        __lowerCamelCase
    )			,
    )			:			Optional[int]       			=					config_and_inputs
    __lowerCamelCase			:			List[Any]       			=					{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
    return config, inputs_dict






@require_torch
class    lowerCamelCase_       (							SCREAMING_SNAKE_CASE_  ,  SCREAMING_SNAKE_CASE_  ,  SCREAMING_SNAKE_CASE_  ,  unittest.TestCase	):
  """simple docstring"""




  a_				   =(
      (
          NezhaModel,
          NezhaForMaskedLM,
          NezhaForMultipleChoice,
          NezhaForNextSentencePrediction,
          NezhaForPreTraining,
          NezhaForQuestionAnswering,
          NezhaForSequenceClassification,
          NezhaForTokenClassification,
      )
      if is_torch_available()
      else ()
  )
  a_				   =(
      {
          """feature-extraction""": NezhaModel,
          """fill-mask""": NezhaForMaskedLM,
          """question-answering""": NezhaForQuestionAnswering,
          """text-classification""": NezhaForSequenceClassification,
          """token-classification""": NezhaForTokenClassification,
          """zero-shot""": NezhaForSequenceClassification,
      }
      if is_torch_available()
      else {}
  )
  a_				   =True




  def 		_lowercase	(					self :      List[str]     ,      _a :      Union[str, Any]     ,      _a :      Any     ,      _a :      List[Any]=False  )   ->   Optional[Any]:
    __lowerCamelCase			:			List[str]       			=					super()._prepare_for_class(_a     ,      _a     ,      return_labels=_a  )

    if return_labels:
      if model_class in get_values(_a  ):
        __lowerCamelCase			:			Tuple       			=					torch.zeros(
            (self.model_tester.batch_size, self.model_tester.seq_length)     ,      dtype=torch.long     ,      device=_a  )
        __lowerCamelCase			:			List[Any]       			=					torch.zeros(
            self.model_tester.batch_size     ,      dtype=torch.long     ,      device=_a  )
    return inputs_dict




  def 		_lowercase	(					self :      Optional[int]  )   ->   Any:
    __lowerCamelCase			:			Dict       			=					NezhaModelTester(self  )
    __lowerCamelCase			:			int       			=					ConfigTester(self     ,      config_class=_a     ,      hidden_size=37  )




  def 		_lowercase	(					self :      Optional[Any]  )   ->   List[Any]:
    self.config_tester.run_common_tests()




  def 		_lowercase	(					self :      int  )   ->   List[str]:
    __lowerCamelCase			:			str       			=					self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_model(*_a  )




  def 		_lowercase	(					self :      Optional[Any]  )   ->   Union[str, Any]:
    __lowerCamelCase			:			List[str]       			=					self.model_tester.prepare_config_and_inputs_for_decoder()
    self.model_tester.create_and_check_model_as_decoder(*_a  )




  def 		_lowercase	(					self :      str  )   ->   Any:
    # This regression test was failing with PyTorch < 1.3
    (
        (
        __lowerCamelCase
    )			,(
        __lowerCamelCase
    )			,(
        __lowerCamelCase
    )			,(
        __lowerCamelCase
    )			,(
        __lowerCamelCase
    )			,(
        __lowerCamelCase
    )			,(
        __lowerCamelCase
    )			,(
        __lowerCamelCase
    )			,(
        __lowerCamelCase
    )			,
    )			:			str       			=					self.model_tester.prepare_config_and_inputs_for_decoder()

    __lowerCamelCase			:			Dict       			=					None

    self.model_tester.create_and_check_model_as_decoder(
        _a     ,      _a     ,      _a     ,      _a     ,      _a     ,      _a     ,      _a     ,      _a     ,      _a     ,      )




  def 		_lowercase	(					self :      int  )   ->   Tuple:
    __lowerCamelCase			:			Any       			=					self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_masked_lm(*_a  )




  def 		_lowercase	(					self :      str  )   ->   str:
    __lowerCamelCase			:			str       			=					self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_multiple_choice(*_a  )




  def 		_lowercase	(					self :      List[str]  )   ->   int:
    __lowerCamelCase			:			int       			=					self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_next_sequence_prediction(*_a  )




  def 		_lowercase	(					self :      Any  )   ->   Any:
    __lowerCamelCase			:			Union[str, Any]       			=					self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_pretraining(*_a  )




  def 		_lowercase	(					self :      Union[str, Any]  )   ->   Optional[int]:
    __lowerCamelCase			:			Dict       			=					self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_question_answering(*_a  )




  def 		_lowercase	(					self :      Optional[int]  )   ->   str:
    __lowerCamelCase			:			Optional[Any]       			=					self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_sequence_classification(*_a  )




  def 		_lowercase	(					self :      Dict  )   ->   Any:
    __lowerCamelCase			:			str       			=					self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_token_classification(*_a  )




  @slow
  def 		_lowercase	(					self :      Optional[Any]  )   ->   Union[str, Any]:
    for model_name in NEZHA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
      __lowerCamelCase			:			List[str]       			=					NezhaModel.from_pretrained(_a  )
      self.assertIsNotNone(_a  )




  @slow
  @require_torch_gpu
  def 		_lowercase	(					self :      List[Any]  )   ->   str:
    __lowerCamelCase			,__lowerCamelCase			:			Optional[int]       			=					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

      __lowerCamelCase			:			List[str]       			=					True
      __lowerCamelCase			:			Dict       			=					model_class(config=_a  )

      __lowerCamelCase			:			List[str]       			=					self._prepare_for_class(_a     ,      _a  )
      __lowerCamelCase			:			Dict       			=					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'  )  )
        __lowerCamelCase			:			int       			=					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	):
  """simple docstring"""




  @slow
  def 		_lowercase	(					self :      Dict  )   ->   Optional[int]:
    __lowerCamelCase			:			Dict       			=					NezhaModel.from_pretrained('sijunhe/nezha-cn-base'  )
    __lowerCamelCase			:			int       			=					torch.tensor([[0, 1, 2, 3, 4, 5]]  )
    __lowerCamelCase			:			Dict       			=					torch.tensor([[0, 1, 1, 1, 1, 1]]  )
    with torch.no_grad():
      __lowerCamelCase			:			Tuple       			=					model(_a     ,      attention_mask=_a  )[0]
    __lowerCamelCase			:			Optional[int]       			=					torch.Size((1, 6, 768)  )
    self.assertEqual(output.shape     ,      _a  )
    __lowerCamelCase			:			Union[str, Any]       			=					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 		_lowercase	(					self :      Dict  )   ->   Dict:
    __lowerCamelCase			:			Dict       			=					NezhaForMaskedLM.from_pretrained('sijunhe/nezha-cn-base'  )
    __lowerCamelCase			:			Optional[Any]       			=					torch.tensor([[0, 1, 2, 3, 4, 5]]  )
    __lowerCamelCase			:			List[str]       			=					torch.tensor([[1, 1, 1, 1, 1, 1]]  )
    with torch.no_grad():
      __lowerCamelCase			:			Union[str, Any]       			=					model(_a     ,      attention_mask=_a  )[0]
    __lowerCamelCase			:			Optional[Any]       			=					torch.Size((1, 6, 2_1128)  )
    self.assertEqual(output.shape     ,      _a  )
    __lowerCamelCase			:			Optional[Any]       			=					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  )  )






