




"""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  UpperCamelCase	:
   def __init__(    self  ,__UpperCamelCase  ,__UpperCamelCase=13  ,__UpperCamelCase=7  ,__UpperCamelCase=True  ,__UpperCamelCase=True  ,__UpperCamelCase=True  ,__UpperCamelCase=True  ,__UpperCamelCase=99  ,__UpperCamelCase=32  ,__UpperCamelCase=5  ,__UpperCamelCase=4  ,__UpperCamelCase=37  ,__UpperCamelCase="gelu"  ,__UpperCamelCase=0.1  ,__UpperCamelCase=0.1  ,__UpperCamelCase=128  ,__UpperCamelCase=32  ,__UpperCamelCase=16  ,__UpperCamelCase=2  ,__UpperCamelCase=0.02  ,__UpperCamelCase=3  ,__UpperCamelCase=4  ,__UpperCamelCase=None  ,)			->   Dict:


        '''simple docstring'''


        lowercase_			:       List[str]									=			parent
        lowercase_			:       int									=			batch_size
        lowercase_			:       List[str]									=			seq_length
        lowercase_			:       List[Any]									=			is_training
        lowercase_			:       Optional[int]									=			use_input_mask
        lowercase_			:       int									=			use_token_type_ids
        lowercase_			:       List[Any]									=			use_labels
        lowercase_			:       List[str]									=			vocab_size
        lowercase_			:       Optional[Any]									=			hidden_size
        lowercase_			:       Optional[int]									=			num_hidden_layers
        lowercase_			:       Tuple									=			num_attention_heads
        lowercase_			:       Union[str, Any]									=			intermediate_size
        lowercase_			:       List[str]									=			hidden_act
        lowercase_			:       Any									=			hidden_dropout_prob
        lowercase_			:       List[str]									=			attention_probs_dropout_prob
        lowercase_			:       Dict									=			max_position_embeddings
        lowercase_			:       int									=			type_vocab_size
        lowercase_			:       Tuple									=			type_sequence_label_size
        lowercase_			:       Any									=			initializer_range
        lowercase_			:       List[str]									=			num_labels
        lowercase_			:       Optional[int]									=			num_choices
        lowercase_			:       List[str]									=			scope
   def     _UpperCAmelCase     (    self    )			->   int:


        '''simple docstring'''


        lowercase_			:       Tuple									=			ids_tensor([self.batch_size, self.seq_length]  ,self.vocab_size    )

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

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

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

        lowercase_			:       Dict									=			self.get_config()

        return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
   def     _UpperCAmelCase     (    self    )			->   str:


        '''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=_lowercase  ,initializer_range=self.initializer_range  ,)
   def     _UpperCAmelCase     (    self    )			->   Optional[Any]:


        '''simple docstring'''


        (
            lowercase_     
        )			:       Dict									=			self.prepare_config_and_inputs()

        lowercase_			:       Any									=			True
        lowercase_			:       Dict									=			floats_tensor([self.batch_size, self.seq_length, self.hidden_size]    )
        lowercase_			:       str									=			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     _UpperCAmelCase     (    self  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase    )			->   int:


        '''simple docstring'''


        lowercase_			:       List[Any]									=			NezhaModel(config=_lowercase    )
        model.to(_lowercase    )
        model.eval()
        lowercase_			:       Any									=			model(_lowercase  ,attention_mask=_lowercase  ,token_type_ids=_lowercase    )
        lowercase_			:       str									=			model(_lowercase  ,token_type_ids=_lowercase    )
        lowercase_			:       int									=			model(_lowercase    )
        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     _UpperCAmelCase     (    self  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,)			->   Dict:


        '''simple docstring'''


        lowercase_			:       Dict									=			True
        lowercase_			:       Tuple									=			NezhaModel(_lowercase    )
        model.to(_lowercase    )
        model.eval()
        lowercase_			:       List[Any]									=			model(
            _lowercase  ,attention_mask=_lowercase  ,token_type_ids=_lowercase  ,encoder_hidden_states=_lowercase  ,encoder_attention_mask=_lowercase  ,)
        lowercase_			:       Optional[Any]									=			model(
            _lowercase  ,attention_mask=_lowercase  ,token_type_ids=_lowercase  ,encoder_hidden_states=_lowercase  ,)
        lowercase_			:       List[str]									=			model(_lowercase  ,attention_mask=_lowercase  ,token_type_ids=_lowercase    )
        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     _UpperCAmelCase     (    self  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase    )			->   Optional[int]:


        '''simple docstring'''


        lowercase_			:       int									=			NezhaForMaskedLM(config=_lowercase    )
        model.to(_lowercase    )
        model.eval()
        lowercase_			:       Any									=			model(_lowercase  ,attention_mask=_lowercase  ,token_type_ids=_lowercase  ,labels=_lowercase    )
        self.parent.assertEqual(result.logits.shape  ,(self.batch_size, self.seq_length, self.vocab_size)    )
   def     _UpperCAmelCase     (    self  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase    )			->   Dict:


        '''simple docstring'''


        lowercase_			:       Any									=			NezhaForNextSentencePrediction(config=_lowercase    )
        model.to(_lowercase    )
        model.eval()
        lowercase_			:       Optional[Any]									=			model(
            _lowercase  ,attention_mask=_lowercase  ,token_type_ids=_lowercase  ,labels=_lowercase  ,)
        self.parent.assertEqual(result.logits.shape  ,(self.batch_size, 2)    )
   def     _UpperCAmelCase     (    self  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase    )			->   Optional[Any]:


        '''simple docstring'''


        lowercase_			:       Any									=			NezhaForPreTraining(config=_lowercase    )
        model.to(_lowercase    )
        model.eval()
        lowercase_			:       Any									=			model(
            _lowercase  ,attention_mask=_lowercase  ,token_type_ids=_lowercase  ,labels=_lowercase  ,next_sentence_label=_lowercase  ,)
        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     _UpperCAmelCase     (    self  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase    )			->   List[str]:


        '''simple docstring'''


        lowercase_			:       Any									=			NezhaForQuestionAnswering(config=_lowercase    )
        model.to(_lowercase    )
        model.eval()
        lowercase_			:       List[Any]									=			model(
            _lowercase  ,attention_mask=_lowercase  ,token_type_ids=_lowercase  ,start_positions=_lowercase  ,end_positions=_lowercase  ,)
        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     _UpperCAmelCase     (    self  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase    )			->   List[Any]:


        '''simple docstring'''


        lowercase_			:       Any									=			self.num_labels
        lowercase_			:       str									=			NezhaForSequenceClassification(_lowercase    )
        model.to(_lowercase    )
        model.eval()
        lowercase_			:       int									=			model(_lowercase  ,attention_mask=_lowercase  ,token_type_ids=_lowercase  ,labels=_lowercase    )
        self.parent.assertEqual(result.logits.shape  ,(self.batch_size, self.num_labels)    )
   def     _UpperCAmelCase     (    self  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase    )			->   Any:


        '''simple docstring'''


        lowercase_			:       int									=			self.num_labels
        lowercase_			:       Tuple									=			NezhaForTokenClassification(config=_lowercase    )
        model.to(_lowercase    )
        model.eval()
        lowercase_			:       int									=			model(_lowercase  ,attention_mask=_lowercase  ,token_type_ids=_lowercase  ,labels=_lowercase    )
        self.parent.assertEqual(result.logits.shape  ,(self.batch_size, self.seq_length, self.num_labels)    )
   def     _UpperCAmelCase     (    self  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase    )			->   int:


        '''simple docstring'''


        lowercase_			:       Union[str, Any]									=			self.num_choices
        lowercase_			:       str									=			NezhaForMultipleChoice(config=_lowercase    )
        model.to(_lowercase    )
        model.eval()
        lowercase_			:       List[Any]									=			input_ids.unsqueeze(1    ).expand(-1  ,self.num_choices  ,-1    ).contiguous()
        lowercase_			:       Optional[int]									=			token_type_ids.unsqueeze(1    ).expand(-1  ,self.num_choices  ,-1    ).contiguous()
        lowercase_			:       Optional[int]									=			input_mask.unsqueeze(1    ).expand(-1  ,self.num_choices  ,-1    ).contiguous()
        lowercase_			:       List[str]									=			model(
            _lowercase  ,attention_mask=_lowercase  ,token_type_ids=_lowercase  ,labels=_lowercase  ,)
        self.parent.assertEqual(result.logits.shape  ,(self.batch_size, self.num_choices)    )







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


        '''simple docstring'''


        lowercase_			:       Dict									=			self.prepare_config_and_inputs()
        (
            lowercase_     
        )			:       Optional[int]									=			config_and_inputs
        lowercase_			:       Union[str, Any]									=			{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
        return config, inputs_dict







@require_torch
class  UpperCamelCase	(    __snake_case		,   __snake_case		,   __snake_case		,   unittest.TestCase						):
   lowercase							=						(
       (
           NezhaModel,
           NezhaForMaskedLM,
           NezhaForMultipleChoice,
           NezhaForNextSentencePrediction,
           NezhaForPreTraining,
           NezhaForQuestionAnswering,
           NezhaForSequenceClassification,
           NezhaForTokenClassification,
       )
       if is_torch_available()
       else ()
   )
   lowercase							=						(
       {
           'feature-extraction': NezhaModel,
           'fill-mask': NezhaForMaskedLM,
           'question-answering': NezhaForQuestionAnswering,
           'text-classification': NezhaForSequenceClassification,
           'token-classification': NezhaForTokenClassification,
           'zero-shot': NezhaForSequenceClassification,
       }
       if is_torch_available()
       else {}
   )
   lowercase							=						True
   def     _UpperCAmelCase     (    self  ,__UpperCamelCase  ,__UpperCamelCase  ,__UpperCamelCase=False    )			->   Optional[int]:


        '''simple docstring'''


        lowercase_			:       Dict									=			super()._prepare_for_class(_lowercase  ,_lowercase  ,return_labels=_lowercase    )

        if return_labels:
             if model_class in get_values(_lowercase    ):
                  lowercase_			:       Any									=			torch.zeros(
                      (self.model_tester.batch_size, self.model_tester.seq_length)  ,dtype=torch.long  ,device=_lowercase    )
                  lowercase_			:       Union[str, Any]									=			torch.zeros(
                      self.model_tester.batch_size  ,dtype=torch.long  ,device=_lowercase    )
        return inputs_dict
   def     _UpperCAmelCase     (    self    )			->   Optional[int]:


        '''simple docstring'''


        lowercase_			:       Any									=			NezhaModelTester(self    )
        lowercase_			:       str									=			ConfigTester(self  ,config_class=_lowercase  ,hidden_size=37    )
   def     _UpperCAmelCase     (    self    )			->   List[Any]:


        '''simple docstring'''


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


        '''simple docstring'''


        lowercase_			:       List[Any]									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*_lowercase    )
   def     _UpperCAmelCase     (    self    )			->   Optional[int]:


        '''simple docstring'''


        lowercase_			:       Optional[int]									=			self.model_tester.prepare_config_and_inputs_for_decoder()
        self.model_tester.create_and_check_model_as_decoder(*_lowercase    )
   def     _UpperCAmelCase     (    self    )			->   Dict:


        '''simple docstring'''


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

        lowercase_			:       Optional[Any]									=			None

        self.model_tester.create_and_check_model_as_decoder(
            _lowercase  ,_lowercase  ,_lowercase  ,_lowercase  ,_lowercase  ,_lowercase  ,_lowercase  ,_lowercase  ,_lowercase  ,)
   def     _UpperCAmelCase     (    self    )			->   Optional[Any]:


        '''simple docstring'''


        lowercase_			:       Optional[int]									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_masked_lm(*_lowercase    )
   def     _UpperCAmelCase     (    self    )			->   Tuple:


        '''simple docstring'''


        lowercase_			:       List[Any]									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_multiple_choice(*_lowercase    )
   def     _UpperCAmelCase     (    self    )			->   Union[str, Any]:


        '''simple docstring'''


        lowercase_			:       List[Any]									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_next_sequence_prediction(*_lowercase    )
   def     _UpperCAmelCase     (    self    )			->   List[str]:


        '''simple docstring'''


        lowercase_			:       Optional[int]									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_pretraining(*_lowercase    )
   def     _UpperCAmelCase     (    self    )			->   Optional[int]:


        '''simple docstring'''


        lowercase_			:       int									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_question_answering(*_lowercase    )
   def     _UpperCAmelCase     (    self    )			->   List[str]:


        '''simple docstring'''


        lowercase_			:       Optional[int]									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_sequence_classification(*_lowercase    )
   def     _UpperCAmelCase     (    self    )			->   int:


        '''simple docstring'''


        lowercase_			:       List[Any]									=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_token_classification(*_lowercase    )
   @slow
   def     _UpperCAmelCase     (    self    )			->   Optional[Any]:


        '''simple docstring'''


        for model_name in NEZHA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             lowercase_			:       Union[str, Any]									=			NezhaModel.from_pretrained(_lowercase    )
             self.assertIsNotNone(_lowercase    )







   @slow
   @require_torch_gpu
   def     _UpperCAmelCase     (    self    )			->   Union[str, Any]:


        '''simple docstring'''


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

             lowercase_			:       int									=			True
             lowercase_			:       Dict									=			model_class(config=_lowercase    )

             lowercase_			:       Any									=			self._prepare_for_class(_lowercase  ,_lowercase    )
             lowercase_			:       Dict									=			torch.jit.trace(
                 _lowercase  ,(inputs_dict['input_ids'].to('cpu'    ), inputs_dict['attention_mask'].to('cpu'    ))    )

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







@require_torch
class  UpperCamelCase	(    unittest.TestCase						):
   @slow
   def     _UpperCAmelCase     (    self    )			->   Optional[Any]:


        '''simple docstring'''


        lowercase_			:       List[Any]									=			NezhaModel.from_pretrained('sijunhe/nezha-cn-base'    )
        lowercase_			:       Any									=			torch.tensor([[0, 1, 2, 3, 4, 5]]    )
        lowercase_			:       str									=			torch.tensor([[0, 1, 1, 1, 1, 1]]    )
        with torch.no_grad():
             lowercase_			:       List[str]									=			model(_lowercase  ,attention_mask=_lowercase    )[0]
        lowercase_			:       str									=			torch.Size((1, 6, 768)    )
        self.assertEqual(output.shape  ,_lowercase    )
        lowercase_			:       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]  ,_lowercase  ,atol=1e-4    )    )







   @slow
   def     _UpperCAmelCase     (    self    )			->   str:


        '''simple docstring'''


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


"""simple docstring"""







import unittest

from transformers import DebertaVaTokenizer, DebertaVaTokenizerFast
from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin


__SCREAMING_SNAKE_CASE								=get_tests_dir("fixtures/spiece.model")







@require_sentencepiece
@require_tokenizers
class  UpperCamelCase	(    lowercase_		,   unittest.TestCase						):
   lowercase							=						DebertaVaTokenizer
   lowercase							=						DebertaVaTokenizerFast
   lowercase							=						True
   lowercase							=						True
   def     _UpperCAmelCase     (    self    )			->   List[str]:


        '''simple docstring'''


        super().setUp()

        # We have a SentencePiece fixture for testing
        lowercase_			:       Any									=			DebertaVaTokenizer(__UpperCamelCase  ,unk_token='<unk>'    )
        tokenizer.save_pretrained(self.tmpdirname    )
   def     _UpperCAmelCase     (    self  ,__UpperCamelCase    )			->   Any:


        '''simple docstring'''


        lowercase_			:       Union[str, Any]									=			'this is a test'
        lowercase_			:       str									=			'this is a test'
        return input_text, output_text
   def     _UpperCAmelCase     (    self    )			->   Optional[Any]:


        '''simple docstring'''


        lowercase_			:       Optional[int]									=			'<pad>'
        lowercase_			:       str									=			0

        self.assertEqual(self.get_tokenizer()._convert_token_to_id(__UpperCamelCase    )  ,__UpperCamelCase    )
        self.assertEqual(self.get_tokenizer()._convert_id_to_token(__UpperCamelCase    )  ,__UpperCamelCase    )
   def     _UpperCAmelCase     (    self    )			->   Optional[int]:


        '''simple docstring'''


        lowercase_			:       Union[str, Any]									=			list(self.get_tokenizer().get_vocab().keys()    )
        self.assertEqual(vocab_keys[0]  ,'<pad>'    )
        self.assertEqual(vocab_keys[1]  ,'<unk>'    )
        self.assertEqual(vocab_keys[-1]  ,'[PAD]'    )
        self.assertEqual(len(__UpperCamelCase    )  ,3_0001    )
   def     _UpperCAmelCase     (    self    )			->   int:


        '''simple docstring'''


        self.assertEqual(self.get_tokenizer().vocab_size  ,3_0000    )
   def     _UpperCAmelCase     (    self    )			->   List[str]:


        '''simple docstring'''


        lowercase_			:       Optional[Any]									=			' \tHeLLo!how  \n Are yoU?  '
        lowercase_			:       Optional[int]									=			['▁hello', '!', 'how', '▁are', '▁you', '?']
        # fmt: on

        lowercase_			:       int									=			DebertaVaTokenizer(__UpperCamelCase  ,do_lower_case=__UpperCamelCase    )
        lowercase_			:       Optional[int]									=			tokenizer.convert_ids_to_tokens(tokenizer.encode(__UpperCamelCase  ,add_special_tokens=__UpperCamelCase    )    )

        self.assertListEqual(__UpperCamelCase  ,__UpperCamelCase    )

        lowercase_			:       Optional[Any]									=			DebertaVaTokenizerFast(__UpperCamelCase  ,do_lower_case=__UpperCamelCase    )
        lowercase_			:       Dict									=			rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(__UpperCamelCase  ,add_special_tokens=__UpperCamelCase    )    )

        self.assertListEqual(__UpperCamelCase  ,__UpperCamelCase    )
   @unittest.skip('There is an inconsistency between slow and fast tokenizer due to a bug in the fast one.'    )
   def     _UpperCAmelCase     (    self    )			->   Union[str, Any]:


        '''simple docstring'''


        pass
   @unittest.skip('There is an inconsistency between slow and fast tokenizer due to a bug in the fast one.'    )
   def     _UpperCAmelCase     (    self    )			->   Tuple:


        '''simple docstring'''


        pass
   def     _UpperCAmelCase     (    self    )			->   List[Any]:


        '''simple docstring'''


        lowercase_			:       Any									=			'I was born in 92000, and this is falsé.'
        lowercase_			:       Union[str, Any]									=			['▁', '<unk>', '▁was', '▁born', '▁in', '▁9', '2000', '▁', ',', '▁and', '▁this', '▁is', '▁fal', 's', '<unk>', '▁', '.', ]
        # fmt: on

        lowercase_			:       List[str]									=			DebertaVaTokenizer(__UpperCamelCase  ,split_by_punct=__UpperCamelCase    )
        lowercase_			:       Optional[Any]									=			tokenizer.convert_ids_to_tokens(tokenizer.encode(__UpperCamelCase  ,add_special_tokens=__UpperCamelCase    )    )

        self.assertListEqual(__UpperCamelCase  ,__UpperCamelCase    )

        lowercase_			:       Any									=			DebertaVaTokenizerFast(__UpperCamelCase  ,split_by_punct=__UpperCamelCase    )
        lowercase_			:       Tuple									=			rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(__UpperCamelCase  ,add_special_tokens=__UpperCamelCase    )    )

        self.assertListEqual(__UpperCamelCase  ,__UpperCamelCase    )
   def     _UpperCAmelCase     (    self    )			->   Tuple:


        '''simple docstring'''


        lowercase_			:       Any									=			'I was born in 92000, and this is falsé.'
        lowercase_			:       Tuple									=			['▁i', '▁was', '▁born', '▁in', '▁9', '2000', '▁', ',', '▁and', '▁this', '▁is', '▁fal', 's', '<unk>', '▁', '.', ]
        # fmt: on

        lowercase_			:       List[str]									=			DebertaVaTokenizer(__UpperCamelCase  ,do_lower_case=__UpperCamelCase  ,split_by_punct=__UpperCamelCase    )
        lowercase_			:       Dict									=			tokenizer.convert_ids_to_tokens(tokenizer.encode(__UpperCamelCase  ,add_special_tokens=__UpperCamelCase    )    )
        self.assertListEqual(__UpperCamelCase  ,__UpperCamelCase    )

        lowercase_			:       Tuple									=			DebertaVaTokenizerFast(__UpperCamelCase  ,do_lower_case=__UpperCamelCase  ,split_by_punct=__UpperCamelCase    )
        lowercase_			:       Dict									=			rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(__UpperCamelCase  ,add_special_tokens=__UpperCamelCase    )    )
        self.assertListEqual(__UpperCamelCase  ,__UpperCamelCase    )
   def     _UpperCAmelCase     (    self    )			->   Dict:


        '''simple docstring'''


        lowercase_			:       str									=			'I was born in 92000, and this is falsé.'
        lowercase_			:       Optional[Any]									=			['▁i', '▁was', '▁born', '▁in', '▁9', '2000', ',', '▁and', '▁this', '▁is', '▁fal', 's', '<unk>', '.', ]
        # fmt: on

        lowercase_			:       Union[str, Any]									=			DebertaVaTokenizer(__UpperCamelCase  ,do_lower_case=__UpperCamelCase  ,split_by_punct=__UpperCamelCase    )
        lowercase_			:       Dict									=			tokenizer.convert_ids_to_tokens(tokenizer.encode(__UpperCamelCase  ,add_special_tokens=__UpperCamelCase    )    )

        self.assertListEqual(__UpperCamelCase  ,__UpperCamelCase    )

        lowercase_			:       Tuple									=			DebertaVaTokenizerFast(__UpperCamelCase  ,do_lower_case=__UpperCamelCase  ,split_by_punct=__UpperCamelCase    )
        lowercase_			:       Tuple									=			rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(__UpperCamelCase  ,add_special_tokens=__UpperCamelCase    )    )

        self.assertListEqual(__UpperCamelCase  ,__UpperCamelCase    )
   def     _UpperCAmelCase     (    self    )			->   Dict:


        '''simple docstring'''


        lowercase_			:       Tuple									=			'I was born in 92000, and this is falsé.'
        lowercase_			:       Optional[int]									=			['▁', '<unk>', '▁was', '▁born', '▁in', '▁9', '2000', '▁', ',', '▁and', '▁this', '▁is', '▁fal', 's', '<unk>', '▁', '.', ]
        # fmt: on

        lowercase_			:       Optional[int]									=			DebertaVaTokenizer(__UpperCamelCase  ,do_lower_case=__UpperCamelCase  ,split_by_punct=__UpperCamelCase    )
        lowercase_			:       str									=			tokenizer.convert_ids_to_tokens(tokenizer.encode(__UpperCamelCase  ,add_special_tokens=__UpperCamelCase    )    )

        self.assertListEqual(__UpperCamelCase  ,__UpperCamelCase    )

        lowercase_			:       Union[str, Any]									=			DebertaVaTokenizerFast(__UpperCamelCase  ,do_lower_case=__UpperCamelCase  ,split_by_punct=__UpperCamelCase    )
        lowercase_			:       List[Any]									=			rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(__UpperCamelCase  ,add_special_tokens=__UpperCamelCase    )    )

        self.assertListEqual(__UpperCamelCase  ,__UpperCamelCase    )
   def     _UpperCAmelCase     (    self    )			->   Optional[Any]:


        '''simple docstring'''


        lowercase_			:       Tuple									=			' \tHeLLo!how  \n Are yoU?  '
        lowercase_			:       List[str]									=			['▁', '<unk>', 'e', '<unk>', 'o', '!', 'how', '▁', '<unk>', 're', '▁yo', '<unk>', '?']
        # fmt: on

        lowercase_			:       str									=			DebertaVaTokenizer(__UpperCamelCase  ,do_lower_case=__UpperCamelCase  ,split_by_punct=__UpperCamelCase    )
        lowercase_			:       int									=			tokenizer.convert_ids_to_tokens(tokenizer.encode(__UpperCamelCase  ,add_special_tokens=__UpperCamelCase    )    )

        self.assertListEqual(__UpperCamelCase  ,__UpperCamelCase    )

        lowercase_			:       Union[str, Any]									=			DebertaVaTokenizerFast(__UpperCamelCase  ,do_lower_case=__UpperCamelCase  ,split_by_punct=__UpperCamelCase    )
        lowercase_			:       List[Any]									=			rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(__UpperCamelCase  ,add_special_tokens=__UpperCamelCase    )    )

        self.assertListEqual(__UpperCamelCase  ,__UpperCamelCase    )
   def     _UpperCAmelCase     (    self    )			->   List[Any]:


        '''simple docstring'''


        lowercase_			:       Optional[int]									=			self.get_tokenizer()
        lowercase_			:       int									=			self.get_rust_tokenizer()

        lowercase_			:       Dict									=			'I was born in 92000, and this is falsé.'

        lowercase_			:       Any									=			tokenizer.convert_ids_to_tokens(tokenizer.encode(__UpperCamelCase  ,add_special_tokens=__UpperCamelCase    )    )
        lowercase_			:       Union[str, Any]									=			rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(__UpperCamelCase  ,add_special_tokens=__UpperCamelCase    )    )
        self.assertListEqual(__UpperCamelCase  ,__UpperCamelCase    )

        lowercase_			:       Optional[int]									=			tokenizer.encode(__UpperCamelCase  ,add_special_tokens=__UpperCamelCase    )
        lowercase_			:       str									=			rust_tokenizer.encode(__UpperCamelCase  ,add_special_tokens=__UpperCamelCase    )
        self.assertListEqual(__UpperCamelCase  ,__UpperCamelCase    )

        lowercase_			:       Optional[int]									=			self.get_rust_tokenizer()
        lowercase_			:       Optional[Any]									=			tokenizer.encode(__UpperCamelCase    )
        lowercase_			:       Dict									=			rust_tokenizer.encode(__UpperCamelCase    )
        self.assertListEqual(__UpperCamelCase  ,__UpperCamelCase    )
   def     _UpperCAmelCase     (    self    )			->   Dict:


        '''simple docstring'''


        lowercase_			:       Optional[int]									=			'This is a test'
        lowercase_			:       Any									=			[13, 1, 4398, 25, 21, 1289]
        lowercase_			:       Union[str, Any]									=			['▁', 'T', 'his', '▁is', '▁a', '▁test']
        lowercase_			:       str									=			['▁', '<unk>', 'his', '▁is', '▁a', '▁test']

        lowercase_			:       Optional[int]									=			DebertaVaTokenizer(__UpperCamelCase  ,keep_accents=__UpperCamelCase    )
        lowercase_			:       str									=			DebertaVaTokenizerFast(__UpperCamelCase  ,keep_accents=__UpperCamelCase    )

        lowercase_			:       Optional[int]									=			tokenizer.encode(__UpperCamelCase  ,add_special_tokens=__UpperCamelCase    )
        self.assertListEqual(__UpperCamelCase  ,__UpperCamelCase    )
        lowercase_			:       List[Any]									=			tokenizer.tokenize(__UpperCamelCase    )
        self.assertListEqual(__UpperCamelCase  ,__UpperCamelCase    )
        lowercase_			:       Any									=			tokenizer.convert_ids_to_tokens(__UpperCamelCase    )
        self.assertListEqual(__UpperCamelCase  ,__UpperCamelCase    )

        lowercase_			:       str									=			rust_tokenizer.encode(__UpperCamelCase  ,add_special_tokens=__UpperCamelCase    )
        self.assertListEqual(__UpperCamelCase  ,__UpperCamelCase    )
        lowercase_			:       Optional[int]									=			rust_tokenizer.tokenize(__UpperCamelCase    )
        self.assertListEqual(__UpperCamelCase  ,__UpperCamelCase    )
        lowercase_			:       str									=			rust_tokenizer.convert_ids_to_tokens(__UpperCamelCase    )
        self.assertListEqual(__UpperCamelCase  ,__UpperCamelCase    )

        # fmt: off
        lowercase_			:       List[Any]									=			'I was born in 92000, and this is falsé.'
        lowercase_			:       int									=			[13, 1, 23, 386, 19, 561, 3050, 15, 17, 48, 25, 8256, 18, 1, 9]
        lowercase_			:       List[str]									=			['▁', 'I', '▁was', '▁born', '▁in', '▁9', '2000', ',', '▁and', '▁this', '▁is', '▁fal', 's', 'é', '.', ]
        lowercase_			:       List[str]									=			['▁', '<unk>', '▁was', '▁born', '▁in', '▁9', '2000', ',', '▁and', '▁this', '▁is', '▁fal', 's', '<unk>', '.', ]
        # fmt: on

        lowercase_			:       List[str]									=			tokenizer.encode(__UpperCamelCase  ,add_special_tokens=__UpperCamelCase    )
        self.assertListEqual(__UpperCamelCase  ,__UpperCamelCase    )
        lowercase_			:       List[str]									=			tokenizer.tokenize(__UpperCamelCase    )
        self.assertListEqual(__UpperCamelCase  ,__UpperCamelCase    )
        lowercase_			:       List[Any]									=			tokenizer.convert_ids_to_tokens(__UpperCamelCase    )
        self.assertListEqual(__UpperCamelCase  ,__UpperCamelCase    )

        lowercase_			:       Tuple									=			rust_tokenizer.encode(__UpperCamelCase  ,add_special_tokens=__UpperCamelCase    )
        self.assertListEqual(__UpperCamelCase  ,__UpperCamelCase    )
        lowercase_			:       Optional[int]									=			rust_tokenizer.tokenize(__UpperCamelCase    )
        self.assertListEqual(__UpperCamelCase  ,__UpperCamelCase    )
        lowercase_			:       Dict									=			rust_tokenizer.convert_ids_to_tokens(__UpperCamelCase    )
        self.assertListEqual(__UpperCamelCase  ,__UpperCamelCase    )
   def     _UpperCAmelCase     (    self    )			->   Dict:


        '''simple docstring'''


        lowercase_			:       Dict									=			DebertaVaTokenizer(__UpperCamelCase    )

        lowercase_			:       int									=			tokenizer.encode('sequence builders'    )
        lowercase_			:       Tuple									=			tokenizer.encode('multi-sequence build'    )

        lowercase_			:       Dict									=			tokenizer.build_inputs_with_special_tokens(__UpperCamelCase    )
        lowercase_			:       Optional[int]									=			tokenizer.build_inputs_with_special_tokens(__UpperCamelCase  ,__UpperCamelCase    )

        self.assertEqual([tokenizer.cls_token_id] + text + [tokenizer.sep_token_id]  ,__UpperCamelCase    )
        self.assertEqual(
            [tokenizer.cls_token_id] + text + [tokenizer.sep_token_id] + text_a + [tokenizer.sep_token_id]  ,__UpperCamelCase  ,)







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


        '''simple docstring'''


        lowercase_			:       List[Any]									=			{'input_ids': [[1, 3_9867, 36, 1_9390, 486, 27, 3_5052, 8_1436, 18, 6_0685, 1225, 7, 3_5052, 8_1436, 18, 9367, 1_6899, 18, 1_5937, 53, 594, 773, 18, 1_6287, 3_0465, 36, 1_5937, 6, 4_1139, 38, 3_6979, 6_0763, 191, 6, 3_4132, 99, 6, 5_0538, 390, 4_3230, 6, 3_4132, 2779, 2_0850, 14, 699, 1072, 1194, 36, 382, 1_0901, 53, 7, 699, 1072, 2084, 36, 2_0422, 630, 53, 19, 105, 3049, 1896, 1053, 1_6899, 1506, 11, 3_7978, 4243, 7, 1237, 3_1869, 200, 1_6566, 654, 6, 3_5052, 8_1436, 7, 5_5630, 1_3593, 4, 2], [1, 26, 1_5011, 13, 667, 8, 1053, 18, 2_3611, 1237, 7_2356, 1_2820, 34, 10_4134, 1209, 35, 1_3313, 6627, 21, 202, 347, 7, 164, 2399, 11, 46, 4485, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 5, 1232, 2864, 1_5785, 1_4951, 105, 5, 8581, 1250, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], 'token_type_ids': [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], 'attention_mask': [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]}  # noqa: E501
        # fmt: on

        self.tokenizer_integration_test_util(
            expected_encoding=__UpperCamelCase  ,model_name='microsoft/deberta-v2-xlarge'  ,revision='ad6e42c1532ddf3a15c39246b63f5559d558b670'  ,)

