'''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			:       int  ,							UpperCAmelCase__			:       Any  ,							UpperCAmelCase__			:       Any=13  ,							UpperCAmelCase__			:       Any=7  ,							UpperCAmelCase__			:       List[str]=True  ,							UpperCAmelCase__			:       Tuple=True  ,							UpperCAmelCase__			:       Union[str, Any]=True  ,							UpperCAmelCase__			:       Optional[Any]=True  ,							UpperCAmelCase__			:       int=99  ,							UpperCAmelCase__			:       Optional[int]=32  ,							UpperCAmelCase__			:       Optional[int]=5  ,							UpperCAmelCase__			:       Dict=4  ,							UpperCAmelCase__			:       Dict=37  ,							UpperCAmelCase__			:       Optional[Any]="gelu"  ,							UpperCAmelCase__			:       Optional[Any]=0.1  ,							UpperCAmelCase__			:       Union[str, Any]=0.1  ,							UpperCAmelCase__			:       Optional[int]=128  ,							UpperCAmelCase__			:       Optional[int]=32  ,							UpperCAmelCase__			:       Tuple=16  ,							UpperCAmelCase__			:       int=2  ,							UpperCAmelCase__			:       List[Any]=0.02  ,							UpperCAmelCase__			:       Optional[Any]=3  ,							UpperCAmelCase__			:       Optional[Any]=4  ,							UpperCAmelCase__			:       int=None  ,							)				->Dict:
        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  lowerCAmelCase__ (      self			:       Any  )				->Tuple:
        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  lowerCAmelCase__ (      self			:       Any  )				->Optional[Any]:
        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=UpperCAmelCase__  ,							initializer_range=self.initializer_range  ,							)






  def  lowerCAmelCase__ (      self			:       List[str]  )				->List[str]:
        (
            (
            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  lowerCAmelCase__ (      self			:       Optional[int]  ,							UpperCAmelCase__			:       List[str]  ,							UpperCAmelCase__			:       List[Any]  ,							UpperCAmelCase__			:       Tuple  ,							UpperCAmelCase__			:       str  ,							UpperCAmelCase__			:       int  ,							UpperCAmelCase__			:       str  ,							UpperCAmelCase__			:       List[str]  )				->Optional[Any]:
        UpperCAmelCase_            =  NezhaModel(config=UpperCAmelCase__  )
        model.to(UpperCAmelCase__  )
        model.eval()
        UpperCAmelCase_            =  model(UpperCAmelCase__  ,							attention_mask=UpperCAmelCase__  ,							token_type_ids=UpperCAmelCase__  )
        UpperCAmelCase_            =  model(UpperCAmelCase__  ,							token_type_ids=UpperCAmelCase__  )
        UpperCAmelCase_            =  model(UpperCAmelCase__  )
        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			:       int  ,							UpperCAmelCase__			:       Dict  ,							UpperCAmelCase__			:       List[Any]  ,							UpperCAmelCase__			:       str  ,							UpperCAmelCase__			:       Tuple  ,							UpperCAmelCase__			:       Tuple  ,							UpperCAmelCase__			:       Tuple  ,							UpperCAmelCase__			:       Optional[Any]  ,							UpperCAmelCase__			:       Optional[Any]  ,							UpperCAmelCase__			:       int  ,							)				->Tuple:
        UpperCAmelCase_            =  True
        UpperCAmelCase_            =  NezhaModel(UpperCAmelCase__  )
        model.to(UpperCAmelCase__  )
        model.eval()
        UpperCAmelCase_            =  model(
            UpperCAmelCase__  ,							attention_mask=UpperCAmelCase__  ,							token_type_ids=UpperCAmelCase__  ,							encoder_hidden_states=UpperCAmelCase__  ,							encoder_attention_mask=UpperCAmelCase__  ,							)
        UpperCAmelCase_            =  model(
            UpperCAmelCase__  ,							attention_mask=UpperCAmelCase__  ,							token_type_ids=UpperCAmelCase__  ,							encoder_hidden_states=UpperCAmelCase__  ,							)
        UpperCAmelCase_            =  model(UpperCAmelCase__  ,							attention_mask=UpperCAmelCase__  ,							token_type_ids=UpperCAmelCase__  )
        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			:       int  ,							UpperCAmelCase__			:       List[Any]  ,							UpperCAmelCase__			:       Optional[int]  ,							UpperCAmelCase__			:       Optional[int]  ,							UpperCAmelCase__			:       Optional[Any]  ,							UpperCAmelCase__			:       List[str]  ,							UpperCAmelCase__			:       Any  ,							UpperCAmelCase__			:       List[str]  )				->Any:
        UpperCAmelCase_            =  NezhaForMaskedLM(config=UpperCAmelCase__  )
        model.to(UpperCAmelCase__  )
        model.eval()
        UpperCAmelCase_            =  model(UpperCAmelCase__  ,							attention_mask=UpperCAmelCase__  ,							token_type_ids=UpperCAmelCase__  ,							labels=UpperCAmelCase__  )
        self.parent.assertEqual(result.logits.shape  ,							(self.batch_size, self.seq_length, self.vocab_size)  )






  def  lowerCAmelCase__ (      self			:       List[str]  ,							UpperCAmelCase__			:       List[str]  ,							UpperCAmelCase__			:       Tuple  ,							UpperCAmelCase__			:       Optional[Any]  ,							UpperCAmelCase__			:       Any  ,							UpperCAmelCase__			:       Dict  ,							UpperCAmelCase__			:       Tuple  ,							UpperCAmelCase__			:       Dict  )				->List[Any]:
        UpperCAmelCase_            =  NezhaForNextSentencePrediction(config=UpperCAmelCase__  )
        model.to(UpperCAmelCase__  )
        model.eval()
        UpperCAmelCase_            =  model(
            UpperCAmelCase__  ,							attention_mask=UpperCAmelCase__  ,							token_type_ids=UpperCAmelCase__  ,							labels=UpperCAmelCase__  ,							)
        self.parent.assertEqual(result.logits.shape  ,							(self.batch_size, 2)  )






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






  def  lowerCAmelCase__ (      self			:       str  ,							UpperCAmelCase__			:       int  ,							UpperCAmelCase__			:       Optional[int]  ,							UpperCAmelCase__			:       List[Any]  ,							UpperCAmelCase__			:       str  ,							UpperCAmelCase__			:       Tuple  ,							UpperCAmelCase__			:       Any  ,							UpperCAmelCase__			:       List[str]  )				->str:
        UpperCAmelCase_            =  self.num_labels
        UpperCAmelCase_            =  NezhaForTokenClassification(config=UpperCAmelCase__  )
        model.to(UpperCAmelCase__  )
        model.eval()
        UpperCAmelCase_            =  model(UpperCAmelCase__  ,							attention_mask=UpperCAmelCase__  ,							token_type_ids=UpperCAmelCase__  ,							labels=UpperCAmelCase__  )
        self.parent.assertEqual(result.logits.shape  ,							(self.batch_size, self.seq_length, self.num_labels)  )






  def  lowerCAmelCase__ (      self			:       Tuple  ,							UpperCAmelCase__			:       Optional[int]  ,							UpperCAmelCase__			:       Dict  ,							UpperCAmelCase__			:       List[Any]  ,							UpperCAmelCase__			:       Any  ,							UpperCAmelCase__			:       List[Any]  ,							UpperCAmelCase__			:       Optional[Any]  ,							UpperCAmelCase__			:       str  )				->List[str]:
        UpperCAmelCase_            =  self.num_choices
        UpperCAmelCase_            =  NezhaForMultipleChoice(config=UpperCAmelCase__  )
        model.to(UpperCAmelCase__  )
        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(
            UpperCAmelCase__  ,							attention_mask=UpperCAmelCase__  ,							token_type_ids=UpperCAmelCase__  ,							labels=UpperCAmelCase__  ,							)
        self.parent.assertEqual(result.logits.shape  ,							(self.batch_size, self.num_choices)  )






  def  lowerCAmelCase__ (      self			:       List[Any]  )				->Union[str, Any]:
        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							(	lowerCamelCase     ,		lowerCamelCase     ,		lowerCamelCase     ,		unittest.TestCase					):




  '''simple docstring'''



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






  def  lowerCAmelCase__ (      self			:       Optional[Any]  ,							UpperCAmelCase__			:       str  ,							UpperCAmelCase__			:       Any  ,							UpperCAmelCase__			:       int=False  )				->List[str]:
        UpperCAmelCase_            =  super()._prepare_for_class(UpperCAmelCase__  ,							UpperCAmelCase__  ,							return_labels=UpperCAmelCase__  )

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






  def  lowerCAmelCase__ (      self			:       Optional[Any]  )				->Optional[Any]:
        UpperCAmelCase_            =  NezhaModelTester(self  )
        UpperCAmelCase_            =  ConfigTester(self  ,							config_class=UpperCAmelCase__  ,							hidden_size=37  )






  def  lowerCAmelCase__ (      self			:       List[str]  )				->List[str]:
        self.config_tester.run_common_tests()






  def  lowerCAmelCase__ (      self			:       Tuple  )				->Any:
        UpperCAmelCase_            =  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*UpperCAmelCase__  )






  def  lowerCAmelCase__ (      self			:       Optional[int]  )				->List[Any]:
        UpperCAmelCase_            =  self.model_tester.prepare_config_and_inputs_for_decoder()
        self.model_tester.create_and_check_model_as_decoder(*UpperCAmelCase__  )






  def  lowerCAmelCase__ (      self			:       str  )				->str:
        # This regression test was failing with PyTorch < 1.3
        (
            (
            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(
            UpperCAmelCase__  ,							UpperCAmelCase__  ,							UpperCAmelCase__  ,							UpperCAmelCase__  ,							UpperCAmelCase__  ,							UpperCAmelCase__  ,							UpperCAmelCase__  ,							UpperCAmelCase__  ,							UpperCAmelCase__  ,							)






  def  lowerCAmelCase__ (      self			:       Optional[int]  )				->int:
        UpperCAmelCase_            =  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_masked_lm(*UpperCAmelCase__  )






  def  lowerCAmelCase__ (      self			:       Tuple  )				->Optional[Any]:
        UpperCAmelCase_            =  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_multiple_choice(*UpperCAmelCase__  )






  def  lowerCAmelCase__ (      self			:       int  )				->List[Any]:
        UpperCAmelCase_            =  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_next_sequence_prediction(*UpperCAmelCase__  )






  def  lowerCAmelCase__ (      self			:       Tuple  )				->Optional[int]:
        UpperCAmelCase_            =  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_pretraining(*UpperCAmelCase__  )






  def  lowerCAmelCase__ (      self			:       Optional[int]  )				->List[Any]:
        UpperCAmelCase_            =  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_question_answering(*UpperCAmelCase__  )






  def  lowerCAmelCase__ (      self			:       List[Any]  )				->Union[str, Any]:
        UpperCAmelCase_            =  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_sequence_classification(*UpperCAmelCase__  )






  def  lowerCAmelCase__ (      self			:       int  )				->Any:
        UpperCAmelCase_            =  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_token_classification(*UpperCAmelCase__  )






  @slow
  def  lowerCAmelCase__ (      self			:       List[Any]  )				->Dict:
        for model_name in NEZHA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              UpperCAmelCase_            =  NezhaModel.from_pretrained(UpperCAmelCase__  )
              self.assertIsNotNone(UpperCAmelCase__  )






  @slow
  @require_torch_gpu
  def  lowerCAmelCase__ (      self			:       Dict  )				->Any:
        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=UpperCAmelCase__  )

              UpperCAmelCase_            =  self._prepare_for_class(UpperCAmelCase__  ,							UpperCAmelCase__  )
              UpperCAmelCase_            =  torch.jit.trace(
                  UpperCAmelCase__  ,							(inputs_dict['''input_ids'''].to('''cpu'''  ), inputs_dict['''attention_mask'''].to('''cpu'''  ))  )

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







@require_torch
class lowerCamelCase							(	unittest.TestCase					):




  '''simple docstring'''



  @slow
  def  lowerCAmelCase__ (      self			:       Tuple  )				->Union[str, Any]:
        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(UpperCAmelCase__  ,							attention_mask=UpperCAmelCase__  )[0]
        UpperCAmelCase_            =  torch.Size((1, 6, 768)  )
        self.assertEqual(output.shape  ,							UpperCAmelCase__  )
        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]  ,							UpperCAmelCase__  ,							atol=1e-4  )  )






  @slow
  def  lowerCAmelCase__ (      self			:       List[Any]  )				->Optional[int]:
        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(UpperCAmelCase__  ,							attention_mask=UpperCAmelCase__  )[0]
        UpperCAmelCase_            =  torch.Size((1, 6, 2_1128)  )
        self.assertEqual(output.shape  ,							UpperCAmelCase__  )
        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]  ,							UpperCAmelCase__  ,							atol=1e-4  )  )






'''simple docstring'''
lowercase__  :      Union[str, Any]        =					"\n# Transformers 설치 방법\n! pip install transformers datasets\n# 마지막 릴리스 대신 소스에서 설치하려면, 위 명령을 주석으로 바꾸고 아래 명령을 해제하세요.\n# ! pip install git+https://github.com/huggingface/transformers.git\n"

lowercase__  :      str        =					[{"type": "code", "content": INSTALL_CONTENT}]
lowercase__  :      Any        =					{
    "{processor_class}": "FakeProcessorClass",
    "{model_class}": "FakeModelClass",
    "{object_class}": "FakeObjectClass",
}





