



'''simple docstring'''


import os
import unittest

from transformers import MobileBertTokenizer, MobileBertTokenizerFast
from transformers.models.bert.tokenization_bert import (
    VOCAB_FILES_NAMES,
    BasicTokenizer,
    WordpieceTokenizer,
    _is_control,
    _is_punctuation,
    _is_whitespace,
)
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin, filter_non_english
@require_tokenizers
class 				a_       (    lowerCamelCase_     ,						unittest.TestCase							):
     __A								=      MobileBertTokenizer
     __A								=      MobileBertTokenizerFast
     __A								=      True
     __A								=      True
     __A								=      filter_non_english
     __A								=      """google/mobilebert-uncased"""





     def 							lowercase__				(			self		: List[str]						):





        """simple docstring"""




        super().setUp()

        lowercase_      :Optional[int]         =			[
            "[UNK]",
            "[CLS]",
            "[SEP]",
            "[PAD]",
            "[MASK]",
            "want",
            "##want",
            "##ed",
            "wa",
            "un",
            "runn",
            "##ing",
            ",",
            "low",
            "lowest",
        ]
        lowercase_      :int         =			os.path.join(self.tmpdirname     ,				VOCAB_FILES_NAMES["vocab_file"]						)
        with open(self.vocab_file     ,				"w"     ,				encoding="utf-8"						) as vocab_writer:
           vocab_writer.write("".join([x + "\n" for x in vocab_tokens]						)						)

        lowercase_      :Any         =			[
            (tokenizer_def[0], self.pre_trained_model_path, tokenizer_def[2])  # else the 'google/' prefix is stripped
            for tokenizer_def in self.tokenizers_list
        ]





     def 							lowercase__				(			self		: str     ,				lowercase		: Dict						):





        """simple docstring"""




        lowercase_      :int         =			"UNwant\u00E9d,running"
        lowercase_      :List[str]         =			"unwanted, running"
        return input_text, output_text





     def 							lowercase__				(			self		: Optional[Any]						):





        """simple docstring"""




        lowercase_      :str         =			self.tokenizer_class(self.vocab_file						)

        lowercase_      :Union[str, Any]         =			tokenizer.tokenize("UNwant\u00E9d,running"						)
        self.assertListEqual(_UpperCAmelCase     ,				["un", "##want", "##ed", ",", "runn", "##ing"]						)
        self.assertListEqual(tokenizer.convert_tokens_to_ids(_UpperCAmelCase						)     ,				[9, 6, 7, 12, 10, 11]						)





     def 							lowercase__				(			self		: List[str]						):





        """simple docstring"""




        if not self.test_rust_tokenizer:
           return

        lowercase_      :Union[str, Any]         =			self.get_tokenizer()
        lowercase_      :Tuple         =			self.get_rust_tokenizer()

        lowercase_      :str         =			"UNwant\u00E9d,running"

        lowercase_      :List[Any]         =			tokenizer.tokenize(_UpperCAmelCase						)
        lowercase_      :Optional[int]         =			rust_tokenizer.tokenize(_UpperCAmelCase						)
        self.assertListEqual(_UpperCAmelCase     ,				_UpperCAmelCase						)

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

        lowercase_      :Any         =			self.get_rust_tokenizer()
        lowercase_      :Dict         =			tokenizer.encode(_UpperCAmelCase						)
        lowercase_      :List[str]         =			rust_tokenizer.encode(_UpperCAmelCase						)
        self.assertListEqual(_UpperCAmelCase     ,				_UpperCAmelCase						)

        # With lower casing
        lowercase_      :str         =			self.get_tokenizer(do_lower_case=_UpperCAmelCase						)
        lowercase_      :Tuple         =			self.get_rust_tokenizer(do_lower_case=_UpperCAmelCase						)

        lowercase_      :int         =			"UNwant\u00E9d,running"

        lowercase_      :int         =			tokenizer.tokenize(_UpperCAmelCase						)
        lowercase_      :int         =			rust_tokenizer.tokenize(_UpperCAmelCase						)
        self.assertListEqual(_UpperCAmelCase     ,				_UpperCAmelCase						)

        lowercase_      :int         =			tokenizer.encode(_UpperCAmelCase     ,				add_special_tokens=_UpperCAmelCase						)
        lowercase_      :int         =			rust_tokenizer.encode(_UpperCAmelCase     ,				add_special_tokens=_UpperCAmelCase						)
        self.assertListEqual(_UpperCAmelCase     ,				_UpperCAmelCase						)

        lowercase_      :Optional[Any]         =			self.get_rust_tokenizer()
        lowercase_      :int         =			tokenizer.encode(_UpperCAmelCase						)
        lowercase_      :Optional[Any]         =			rust_tokenizer.encode(_UpperCAmelCase						)
        self.assertListEqual(_UpperCAmelCase     ,				_UpperCAmelCase						)





     def 							lowercase__				(			self		: List[Any]						):





        """simple docstring"""




        lowercase_      :Tuple         =			BasicTokenizer()

        self.assertListEqual(tokenizer.tokenize("ah\u535A\u63A8zz"						)     ,				["ah", "\u535A", "\u63A8", "zz"]						)





     def 							lowercase__				(			self		: Any						):





        """simple docstring"""




        lowercase_      :Dict         =			BasicTokenizer(do_lower_case=_UpperCAmelCase						)

        self.assertListEqual(
            tokenizer.tokenize(" \tHeLLo!how  \n Are yoU?  "						)     ,				["hello", "!", "how", "are", "you", "?"]						)
        self.assertListEqual(tokenizer.tokenize("H\u00E9llo"						)     ,				["hello"]						)





     def 							lowercase__				(			self		: Dict						):





        """simple docstring"""




        lowercase_      :Optional[int]         =			BasicTokenizer(do_lower_case=_UpperCAmelCase     ,				strip_accents=_UpperCAmelCase						)

        self.assertListEqual(
            tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  "						)     ,				["hällo", "!", "how", "are", "you", "?"]						)
        self.assertListEqual(tokenizer.tokenize("H\u00E9llo"						)     ,				["h\u00E9llo"]						)





     def 							lowercase__				(			self		: Any						):





        """simple docstring"""




        lowercase_      :List[str]         =			BasicTokenizer(do_lower_case=_UpperCAmelCase     ,				strip_accents=_UpperCAmelCase						)

        self.assertListEqual(
            tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  "						)     ,				["hallo", "!", "how", "are", "you", "?"]						)
        self.assertListEqual(tokenizer.tokenize("H\u00E9llo"						)     ,				["hello"]						)





     def 							lowercase__				(			self		: Optional[int]						):





        """simple docstring"""




        lowercase_      :int         =			BasicTokenizer(do_lower_case=_UpperCAmelCase						)

        self.assertListEqual(
            tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  "						)     ,				["hallo", "!", "how", "are", "you", "?"]						)
        self.assertListEqual(tokenizer.tokenize("H\u00E9llo"						)     ,				["hello"]						)





     def 							lowercase__				(			self		: List[str]						):





        """simple docstring"""




        lowercase_      :List[Any]         =			BasicTokenizer(do_lower_case=_UpperCAmelCase						)

        self.assertListEqual(
            tokenizer.tokenize(" \tHeLLo!how  \n Are yoU?  "						)     ,				["HeLLo", "!", "how", "Are", "yoU", "?"]						)





     def 							lowercase__				(			self		: Dict						):





        """simple docstring"""




        lowercase_      :List[str]         =			BasicTokenizer(do_lower_case=_UpperCAmelCase     ,				strip_accents=_UpperCAmelCase						)

        self.assertListEqual(
            tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  "						)     ,				["HäLLo", "!", "how", "Are", "yoU", "?"]						)





     def 							lowercase__				(			self		: Tuple						):





        """simple docstring"""




        lowercase_      :Union[str, Any]         =			BasicTokenizer(do_lower_case=_UpperCAmelCase     ,				strip_accents=_UpperCAmelCase						)

        self.assertListEqual(
            tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  "						)     ,				["HaLLo", "!", "how", "Are", "yoU", "?"]						)





     def 							lowercase__				(			self		: Any						):





        """simple docstring"""




        lowercase_      :Tuple         =			BasicTokenizer(do_lower_case=_UpperCAmelCase     ,				never_split=["[UNK]"]						)

        self.assertListEqual(
            tokenizer.tokenize(" \tHeLLo!how  \n Are yoU? [UNK]"						)     ,				["HeLLo", "!", "how", "Are", "yoU", "?", "[UNK]"]						)





     def 							lowercase__				(			self		: List[str]						):





        """simple docstring"""




        lowercase_      :int         =			["[UNK]", "[CLS]", "[SEP]", "want", "##want", "##ed", "wa", "un", "runn", "##ing"]

        lowercase_      :List[Any]         =			{}
        for i, token in enumerate(_UpperCAmelCase						):
           lowercase_      :int         =			i
        lowercase_      :Tuple         =			WordpieceTokenizer(vocab=_UpperCAmelCase     ,				unk_token="[UNK]"						)

        self.assertListEqual(tokenizer.tokenize(""						)     ,				[]						)

        self.assertListEqual(tokenizer.tokenize("unwanted running"						)     ,				["un", "##want", "##ed", "runn", "##ing"]						)

        self.assertListEqual(tokenizer.tokenize("unwantedX running"						)     ,				["[UNK]", "runn", "##ing"]						)





     def 							lowercase__				(			self		: Optional[int]						):





        """simple docstring"""




        self.assertTrue(_is_whitespace(" "						)						)
        self.assertTrue(_is_whitespace("\t"						)						)
        self.assertTrue(_is_whitespace("\r"						)						)
        self.assertTrue(_is_whitespace("\n"						)						)
        self.assertTrue(_is_whitespace("\u00A0"						)						)

        self.assertFalse(_is_whitespace("A"						)						)
        self.assertFalse(_is_whitespace("-"						)						)





     def 							lowercase__				(			self		: int						):





        """simple docstring"""




        self.assertTrue(_is_control("\u0005"						)						)

        self.assertFalse(_is_control("A"						)						)
        self.assertFalse(_is_control(" "						)						)
        self.assertFalse(_is_control("\t"						)						)
        self.assertFalse(_is_control("\r"						)						)





     def 							lowercase__				(			self		: List[str]						):





        """simple docstring"""




        self.assertTrue(_is_punctuation("-"						)						)
        self.assertTrue(_is_punctuation("$"						)						)
        self.assertTrue(_is_punctuation("`"						)						)
        self.assertTrue(_is_punctuation("."						)						)

        self.assertFalse(_is_punctuation("A"						)						)
        self.assertFalse(_is_punctuation(" "						)						)





     def 							lowercase__				(			self		: List[Any]						):





        """simple docstring"""




        lowercase_      :Optional[int]         =			self.get_tokenizer()
        lowercase_      :Union[str, Any]         =			self.get_rust_tokenizer()

        # Example taken from the issue https://github.com/huggingface/tokenizers/issues/340
        self.assertListEqual([tokenizer.tokenize(_UpperCAmelCase						) for t in ["Test", "\xad", "test"]]     ,				[["[UNK]"], [], ["[UNK]"]]						)

        self.assertListEqual(
            [rust_tokenizer.tokenize(_UpperCAmelCase						) for t in ["Test", "\xad", "test"]]     ,				[["[UNK]"], [], ["[UNK]"]]						)





     @slow
     def 							lowercase__				(			self		: str						):





        """simple docstring"""




        lowercase_      :List[str]         =			self.tokenizer_class.from_pretrained("google/mobilebert-uncased"						)

        lowercase_      :Dict         =			tokenizer.encode("sequence builders"     ,				add_special_tokens=_UpperCAmelCase						)
        lowercase_      :Tuple         =			tokenizer.encode("multi-sequence build"     ,				add_special_tokens=_UpperCAmelCase						)

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

        assert encoded_sentence == [101] + text + [102]
        assert encoded_pair == [101] + text + [102] + text_a + [102]





     def 							lowercase__				(			self		: List[str]						):





        """simple docstring"""




        for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
           with self.subTest(F'{tokenizer.__class__.__name__} ({pretrained_name})'						):
              lowercase_      :Optional[Any]         =			self.rust_tokenizer_class.from_pretrained(_UpperCAmelCase     ,				**_UpperCAmelCase						)

              lowercase_      :List[Any]         =			F'A, naïve {tokenizer_r.mask_token} AllenNLP sentence.'
              lowercase_      :Union[str, Any]         =			tokenizer_r.encode_plus(
                  _UpperCAmelCase     ,				return_attention_mask=_UpperCAmelCase     ,				return_token_type_ids=_UpperCAmelCase     ,				return_offsets_mapping=_UpperCAmelCase     ,				add_special_tokens=_UpperCAmelCase     ,				)

              lowercase_      :str         =			tokenizer_r.do_lower_case if hasattr(_UpperCAmelCase     ,				"do_lower_case"						) else False
              lowercase_      :Optional[int]         =			(
                  [
                      ((0, 0), tokenizer_r.cls_token),
                      ((0, 1), "A"),
                      ((1, 2), ","),
                      ((3, 5), "na"),
                      ((5, 6), "##ï"),
                      ((6, 8), "##ve"),
                      ((9, 15), tokenizer_r.mask_token),
                      ((16, 21), "Allen"),
                      ((21, 23), "##NL"),
                      ((23, 24), "##P"),
                      ((25, 33), "sentence"),
                      ((33, 34), "."),
                      ((0, 0), tokenizer_r.sep_token),
                  ]
                  if not do_lower_case
                  else [
                      ((0, 0), tokenizer_r.cls_token),
                      ((0, 1), "a"),
                      ((1, 2), ","),
                      ((3, 8), "naive"),
                      ((9, 15), tokenizer_r.mask_token),
                      ((16, 21), "allen"),
                      ((21, 23), "##nl"),
                      ((23, 24), "##p"),
                      ((25, 33), "sentence"),
                      ((33, 34), "."),
                      ((0, 0), tokenizer_r.sep_token),
                  ]
              )

              self.assertEqual(
                  [e[1] for e in expected_results]     ,				tokenizer_r.convert_ids_to_tokens(tokens["input_ids"]						)						)
              self.assertEqual([e[0] for e in expected_results]     ,				tokens["offset_mapping"]						)







     def 							lowercase__				(			self		: str						):





        """simple docstring"""




        lowercase_      :Optional[int]         =			["的", "人", "有"]
        lowercase_      :List[Any]         =			"".join(_UpperCAmelCase						)
        for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
           with self.subTest(F'{tokenizer.__class__.__name__} ({pretrained_name})'						):
              lowercase_      :List[str]         =			True
              lowercase_      :Tuple         =			self.tokenizer_class.from_pretrained(_UpperCAmelCase     ,				**_UpperCAmelCase						)
              lowercase_      :Optional[Any]         =			self.rust_tokenizer_class.from_pretrained(_UpperCAmelCase     ,				**_UpperCAmelCase						)

              lowercase_      :Optional[int]         =			tokenizer_p.encode(_UpperCAmelCase     ,				add_special_tokens=_UpperCAmelCase						)
              lowercase_      :List[Any]         =			tokenizer_r.encode(_UpperCAmelCase     ,				add_special_tokens=_UpperCAmelCase						)

              lowercase_      :Optional[int]         =			tokenizer_r.convert_ids_to_tokens(_UpperCAmelCase						)
              lowercase_      :List[str]         =			tokenizer_p.convert_ids_to_tokens(_UpperCAmelCase						)

              # it is expected that each Chinese character is not preceded by "##"
              self.assertListEqual(_UpperCAmelCase     ,				_UpperCAmelCase						)
              self.assertListEqual(_UpperCAmelCase     ,				_UpperCAmelCase						)

              lowercase_      :Dict         =			False
              lowercase_      :Any         =			self.rust_tokenizer_class.from_pretrained(_UpperCAmelCase     ,				**_UpperCAmelCase						)
              lowercase_      :str         =			self.tokenizer_class.from_pretrained(_UpperCAmelCase     ,				**_UpperCAmelCase						)

              lowercase_      :List[Any]         =			tokenizer_r.encode(_UpperCAmelCase     ,				add_special_tokens=_UpperCAmelCase						)
              lowercase_      :Optional[Any]         =			tokenizer_p.encode(_UpperCAmelCase     ,				add_special_tokens=_UpperCAmelCase						)

              lowercase_      :Dict         =			tokenizer_r.convert_ids_to_tokens(_UpperCAmelCase						)
              lowercase_      :Optional[int]         =			tokenizer_p.convert_ids_to_tokens(_UpperCAmelCase						)

              # it is expected that only the first Chinese character is not preceded by "##".
              lowercase_      :str         =			[
                  F'##{token}' if idx != 0 else token for idx, token in enumerate(_UpperCAmelCase						)
              ]
              self.assertListEqual(_UpperCAmelCase     ,				_UpperCAmelCase						)
              self.assertListEqual(_UpperCAmelCase     ,				_UpperCAmelCase						)









'''simple docstring'''


import unittest

from transformers import DebertaConfig, is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
 import torch

 from transformers import (
     DebertaForMaskedLM,
     DebertaForQuestionAnswering,
     DebertaForSequenceClassification,
     DebertaForTokenClassification,
     DebertaModel,
 )
 from transformers.models.deberta.modeling_deberta import DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST
class 				a_       (    _lowerCAmelCase							):





     def __init__(			self		: Any     ,				lowercase		: int     ,				lowercase		: Union[str, Any]=13     ,				lowercase		: List[str]=7     ,				lowercase		: List[str]=True     ,				lowercase		: int=True     ,				lowercase		: Tuple=True     ,				lowercase		: int=True     ,				lowercase		: List[Any]=99     ,				lowercase		: Optional[int]=32     ,				lowercase		: Dict=5     ,				lowercase		: Optional[int]=4     ,				lowercase		: List[str]=37     ,				lowercase		: Tuple="gelu"     ,				lowercase		: List[Any]=0.1     ,				lowercase		: Tuple=0.1     ,				lowercase		: List[str]=512     ,				lowercase		: str=16     ,				lowercase		: Tuple=2     ,				lowercase		: List[Any]=0.02     ,				lowercase		: Dict=False     ,				lowercase		: Dict=True     ,				lowercase		: int="None"     ,				lowercase		: Optional[Any]=3     ,				lowercase		: Dict=4     ,				lowercase		: List[Any]=None     ,				):





        """simple docstring"""




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





     def 							lowercase__				(			self		: Dict						):





        """simple docstring"""




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

        lowercase_      :Union[str, Any]         =			None
        if self.use_input_mask:
           lowercase_      :int         =			ids_tensor([self.batch_size, self.seq_length]     ,				vocab_size=2						)

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

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

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

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





     def 							lowercase__				(			self		: Optional[Any]						):





        """simple docstring"""




        return DebertaConfig(
            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     ,				initializer_range=self.initializer_range     ,				relative_attention=self.relative_attention     ,				position_biased_input=self.position_biased_input     ,				pos_att_type=self.pos_att_type     ,				)





     def 							lowercase__				(			self		: Optional[int]						):





        """simple docstring"""




        lowercase_      :Dict         =			self.get_config()
        lowercase_      :Optional[Any]         =			300
        return config





     def 							lowercase__				(			self		: Optional[Any]     ,				lowercase		: Dict						):





        """simple docstring"""




        self.parent.assertListEqual(list(result.loss.size()						)     ,				[]						)





     def 							lowercase__				(			self		: Optional[Any]     ,				lowercase		: Union[str, Any]     ,				lowercase		: List[Any]     ,				lowercase		: List[Any]     ,				lowercase		: Tuple     ,				lowercase		: str     ,				lowercase		: Optional[Any]     ,				lowercase		: Optional[int]						):





        """simple docstring"""




        lowercase_      :str         =			DebertaModel(config=lowercase						)
        model.to(lowercase						)
        model.eval()
        lowercase_      :Optional[int]         =			model(lowercase     ,				attention_mask=lowercase     ,				token_type_ids=lowercase						)[0]
        lowercase_      :Union[str, Any]         =			model(lowercase     ,				token_type_ids=lowercase						)[0]
        lowercase_      :Dict         =			model(lowercase						)[0]

        self.parent.assertListEqual(list(sequence_output.size()						)     ,				[self.batch_size, self.seq_length, self.hidden_size]						)





     def 							lowercase__				(			self		: Dict     ,				lowercase		: Union[str, Any]     ,				lowercase		: Optional[int]     ,				lowercase		: Tuple     ,				lowercase		: Dict     ,				lowercase		: Dict     ,				lowercase		: str     ,				lowercase		: Tuple						):





        """simple docstring"""




        lowercase_      :Dict         =			DebertaForMaskedLM(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, self.seq_length, self.vocab_size)						)





     def 							lowercase__				(			self		: Optional[int]     ,				lowercase		: Union[str, Any]     ,				lowercase		: Union[str, Any]     ,				lowercase		: Union[str, Any]     ,				lowercase		: Dict     ,				lowercase		: List[Any]     ,				lowercase		: int     ,				lowercase		: Dict						):





        """simple docstring"""




        lowercase_      :Dict         =			self.num_labels
        lowercase_      :int         =			DebertaForSequenceClassification(lowercase						)
        model.to(lowercase						)
        model.eval()
        lowercase_      :Union[str, Any]         =			model(lowercase     ,				attention_mask=lowercase     ,				token_type_ids=lowercase     ,				labels=lowercase						)
        self.parent.assertListEqual(list(result.logits.size()						)     ,				[self.batch_size, self.num_labels]						)
        self.check_loss_output(lowercase						)





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





        """simple docstring"""




        lowercase_      :List[str]         =			self.num_labels
        lowercase_      :Optional[int]         =			DebertaForTokenClassification(config=lowercase						)
        model.to(lowercase						)
        model.eval()
        lowercase_      :Dict         =			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 							lowercase__				(			self		: Union[str, Any]     ,				lowercase		: Tuple     ,				lowercase		: Any     ,				lowercase		: List[Any]     ,				lowercase		: List[Any]     ,				lowercase		: Union[str, Any]     ,				lowercase		: Optional[int]     ,				lowercase		: List[Any]						):





        """simple docstring"""




        lowercase_      :Any         =			DebertaForQuestionAnswering(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 							lowercase__				(			self		: Any						):





        """simple docstring"""




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







@require_torch
class 				a_       (    _lowerCAmelCase     ,						_lowerCAmelCase     ,						unittest.TestCase							):
     __A								=      (
         (
             DebertaModel,
             DebertaForMaskedLM,
             DebertaForSequenceClassification,
             DebertaForTokenClassification,
             DebertaForQuestionAnswering,
         )
         if is_torch_available()
         else ()
     )
     __A								=      (
         {
             "feature-extraction": DebertaModel,
             "fill-mask": DebertaForMaskedLM,
             "question-answering": DebertaForQuestionAnswering,
             "text-classification": DebertaForSequenceClassification,
             "token-classification": DebertaForTokenClassification,
             "zero-shot": DebertaForSequenceClassification,
         }
         if is_torch_available()
         else {}
     )

     __A								=      True
     __A								=      False
     __A								=      False
     __A								=      False
     __A								=      False





     def 							lowercase__				(			self		: Optional[int]						):





        """simple docstring"""




        lowercase_      :List[Any]         =			DebertaModelTester(self						)
        lowercase_      :str         =			ConfigTester(self     ,				config_class=lowercase     ,				hidden_size=37						)





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





        """simple docstring"""




        self.config_tester.run_common_tests()





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





        """simple docstring"""




        lowercase_      :str         =			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_deberta_model(*lowercase						)





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





        """simple docstring"""




        lowercase_      :Optional[Any]         =			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_deberta_for_sequence_classification(*lowercase						)





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





        """simple docstring"""




        lowercase_      :Optional[int]         =			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_deberta_for_masked_lm(*lowercase						)





     def 							lowercase__				(			self		: int						):





        """simple docstring"""




        lowercase_      :Union[str, Any]         =			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_deberta_for_question_answering(*lowercase						)





     def 							lowercase__				(			self		: Tuple						):





        """simple docstring"""




        lowercase_      :Union[str, Any]         =			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_deberta_for_token_classification(*lowercase						)







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





        """simple docstring"""




        for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           lowercase_      :Tuple         =			DebertaModel.from_pretrained(lowercase						)
           self.assertIsNotNone(lowercase						)







@require_torch
@require_sentencepiece
@require_tokenizers
class 				a_       (    unittest.TestCase							):





     @unittest.skip(reason="Model not available yet"						)
     def 							lowercase__				(			self		: Dict						):





        """simple docstring"""




        pass







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





        """simple docstring"""




        lowercase_      :Optional[Any]         =			DebertaModel.from_pretrained("microsoft/deberta-base"						)

        lowercase_      :Dict         =			torch.tensor([[0, 31_414, 232, 328, 740, 1_140, 12_695, 69, 46_078, 1_588, 2]]						)
        lowercase_      :Optional[Any]         =			torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]						)
        with torch.no_grad():
           lowercase_      :Optional[int]         =			model(lowercase     ,				attention_mask=lowercase						)[0]
        # compare the actual values for a slice.
        lowercase_      :List[Any]         =			torch.tensor(
            [[[-0.59_86, -0.80_55, -0.84_62], [1.44_84, -0.93_48, -0.80_59], [0.31_23, 0.00_32, -1.41_31]]]						)
        self.assertTrue(torch.allclose(output[:, 1:4, 1:4]     ,				lowercase     ,				atol=1e-4						)     ,				F'{output[:, 1:4, 1:4]}'						)


