

import os
import unittest

from transformers import BertTokenizerFast
from transformers.models.bert.tokenization_bert import (
    VOCAB_FILES_NAMES,
    BasicTokenizer,
    BertTokenizer,
    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   __lowercase      (_UpperCAmelCase		,   unittest.TestCase ):
 _UpperCamelCase			  =  BertTokenizer
 _UpperCamelCase			  =  BertTokenizerFast
 _UpperCamelCase			  =  True
 _UpperCamelCase			  =  True
 _UpperCamelCase			  =  filter_non_english
 def 	UpperCamelCase__  (							self					)					->int:



       '''simple docstring'''





       super().setUp()

       __lowerCAmelCase					:						Any					=					[
           '''[UNK]''',
           '''[CLS]''',
           '''[SEP]''',
           '''[PAD]''',
           '''[MASK]''',
           '''want''',
           '''##want''',
           '''##ed''',
           '''wa''',
           '''un''',
           '''runn''',
           '''##ing''',
           ''',''',
           '''low''',
           '''lowest''',
       ]
       __lowerCAmelCase					:						Union[str, Any]					=					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]					)					)
 def 	UpperCamelCase__  (							self      ,							A_					)					->str:



       '''simple docstring'''





       __lowerCAmelCase					:						str					=					'''UNwant\u00E9d,running'''
       __lowerCAmelCase					:						Dict					=					'''unwanted, running'''
       return input_text, output_text
 def 	UpperCamelCase__  (							self					)					->Tuple:



       '''simple docstring'''





       __lowerCAmelCase					:						List[str]					=					self.tokenizer_class(self.vocab_file					)

       __lowerCAmelCase					:						Any					=					tokenizer.tokenize('''UNwant\u00E9d,running'''					)
       self.assertListEqual(A_      ,							['''un''', '''##want''', '''##ed''', ''',''', '''runn''', '''##ing''']					)
       self.assertListEqual(tokenizer.convert_tokens_to_ids(A_					)      ,							[9, 6, 7, 12, 10, 11]					)
 def 	UpperCamelCase__  (							self					)					->Union[str, Any]:



       '''simple docstring'''





       if not self.test_rust_tokenizer:
             return

       __lowerCAmelCase					:						List[Any]					=					self.get_tokenizer()
       __lowerCAmelCase					:						Tuple					=					self.get_rust_tokenizer()

       __lowerCAmelCase					:						List[Any]					=					'''UNwant\u00E9d,running'''

       __lowerCAmelCase					:						Dict					=					tokenizer.tokenize(A_					)
       __lowerCAmelCase					:						Union[str, Any]					=					rust_tokenizer.tokenize(A_					)
       self.assertListEqual(A_      ,							A_					)

       __lowerCAmelCase					:						int					=					tokenizer.encode(A_      ,							add_special_tokens=A_					)
       __lowerCAmelCase					:						Optional[Any]					=					rust_tokenizer.encode(A_      ,							add_special_tokens=A_					)
       self.assertListEqual(A_      ,							A_					)

       __lowerCAmelCase					:						Union[str, Any]					=					self.get_rust_tokenizer()
       __lowerCAmelCase					:						Tuple					=					tokenizer.encode(A_					)
       __lowerCAmelCase					:						Optional[int]					=					rust_tokenizer.encode(A_					)
       self.assertListEqual(A_      ,							A_					)

       # With lower casing
       __lowerCAmelCase					:						Optional[int]					=					self.get_tokenizer(do_lower_case=A_					)
       __lowerCAmelCase					:						Tuple					=					self.get_rust_tokenizer(do_lower_case=A_					)

       __lowerCAmelCase					:						Union[str, Any]					=					'''UNwant\u00E9d,running'''

       __lowerCAmelCase					:						Union[str, Any]					=					tokenizer.tokenize(A_					)
       __lowerCAmelCase					:						Optional[Any]					=					rust_tokenizer.tokenize(A_					)
       self.assertListEqual(A_      ,							A_					)

       __lowerCAmelCase					:						Tuple					=					tokenizer.encode(A_      ,							add_special_tokens=A_					)
       __lowerCAmelCase					:						List[str]					=					rust_tokenizer.encode(A_      ,							add_special_tokens=A_					)
       self.assertListEqual(A_      ,							A_					)

       __lowerCAmelCase					:						Tuple					=					self.get_rust_tokenizer()
       __lowerCAmelCase					:						Optional[Any]					=					tokenizer.encode(A_					)
       __lowerCAmelCase					:						Union[str, Any]					=					rust_tokenizer.encode(A_					)
       self.assertListEqual(A_      ,							A_					)
 def 	UpperCamelCase__  (							self					)					->Tuple:



       '''simple docstring'''





       __lowerCAmelCase					:						str					=					BasicTokenizer()

       self.assertListEqual(tokenizer.tokenize('''ah\u535A\u63A8zz'''					)      ,							['''ah''', '''\u535A''', '''\u63A8''', '''zz''']					)
 def 	UpperCamelCase__  (							self					)					->Optional[Any]:



       '''simple docstring'''





       __lowerCAmelCase					:						Union[str, Any]					=					BasicTokenizer(do_lower_case=A_					)

       self.assertListEqual(
           tokenizer.tokenize(''' \tHeLLo!how  \n Are yoU?  '''					)      ,							['''hello''', '''!''', '''how''', '''are''', '''you''', '''?''']					)
       self.assertListEqual(tokenizer.tokenize('''H\u00E9llo'''					)      ,							['''hello''']					)
 def 	UpperCamelCase__  (							self					)					->Optional[int]:



       '''simple docstring'''





       __lowerCAmelCase					:						Any					=					BasicTokenizer(do_lower_case=A_      ,							strip_accents=A_					)

       self.assertListEqual(
           tokenizer.tokenize(''' \tHäLLo!how  \n Are yoU?  '''					)      ,							['''hällo''', '''!''', '''how''', '''are''', '''you''', '''?''']					)
       self.assertListEqual(tokenizer.tokenize('''H\u00E9llo'''					)      ,							['''h\u00E9llo''']					)
 def 	UpperCamelCase__  (							self					)					->Tuple:



       '''simple docstring'''





       __lowerCAmelCase					:						Optional[Any]					=					BasicTokenizer(do_lower_case=A_      ,							strip_accents=A_					)

       self.assertListEqual(
           tokenizer.tokenize(''' \tHäLLo!how  \n Are yoU?  '''					)      ,							['''hallo''', '''!''', '''how''', '''are''', '''you''', '''?''']					)
       self.assertListEqual(tokenizer.tokenize('''H\u00E9llo'''					)      ,							['''hello''']					)
 def 	UpperCamelCase__  (							self					)					->Dict:



       '''simple docstring'''





       __lowerCAmelCase					:						Dict					=					BasicTokenizer(do_lower_case=A_					)

       self.assertListEqual(
           tokenizer.tokenize(''' \tHäLLo!how  \n Are yoU?  '''					)      ,							['''hallo''', '''!''', '''how''', '''are''', '''you''', '''?''']					)
       self.assertListEqual(tokenizer.tokenize('''H\u00E9llo'''					)      ,							['''hello''']					)
 def 	UpperCamelCase__  (							self					)					->List[Any]:



       '''simple docstring'''





       __lowerCAmelCase					:						Any					=					BasicTokenizer(do_lower_case=A_					)

       self.assertListEqual(
           tokenizer.tokenize(''' \tHeLLo!how  \n Are yoU?  '''					)      ,							['''HeLLo''', '''!''', '''how''', '''Are''', '''yoU''', '''?''']					)
 def 	UpperCamelCase__  (							self					)					->Optional[int]:



       '''simple docstring'''





       __lowerCAmelCase					:						Tuple					=					BasicTokenizer(do_lower_case=A_      ,							strip_accents=A_					)

       self.assertListEqual(
           tokenizer.tokenize(''' \tHäLLo!how  \n Are yoU?  '''					)      ,							['''HäLLo''', '''!''', '''how''', '''Are''', '''yoU''', '''?''']					)
 def 	UpperCamelCase__  (							self					)					->Optional[Any]:



       '''simple docstring'''





       __lowerCAmelCase					:						List[str]					=					BasicTokenizer(do_lower_case=A_      ,							strip_accents=A_					)

       self.assertListEqual(
           tokenizer.tokenize(''' \tHäLLo!how  \n Are yoU?  '''					)      ,							['''HaLLo''', '''!''', '''how''', '''Are''', '''yoU''', '''?''']					)
 def 	UpperCamelCase__  (							self					)					->Optional[Any]:



       '''simple docstring'''





       __lowerCAmelCase					:						Any					=					BasicTokenizer(do_lower_case=A_      ,							never_split=['''[UNK]''']					)

       self.assertListEqual(
           tokenizer.tokenize(''' \tHeLLo!how  \n Are yoU? [UNK]'''					)      ,							['''HeLLo''', '''!''', '''how''', '''Are''', '''yoU''', '''?''', '''[UNK]''']					)
 def 	UpperCamelCase__  (							self					)					->List[str]:



       '''simple docstring'''





       __lowerCAmelCase					:						Union[str, Any]					=					BasicTokenizer()
       __lowerCAmelCase					:						List[str]					=					'''a\n\'ll !!to?\'d of, can\'t.'''
       __lowerCAmelCase					:						Dict					=					['''a''', '''\'''', '''ll''', '''!''', '''!''', '''to''', '''?''', '''\'''', '''d''', '''of''', ''',''', '''can''', '''\'''', '''t''', '''.''']
       self.assertListEqual(tokenizer.tokenize(A_					)      ,							A_					)
 def 	UpperCamelCase__  (							self					)					->List[str]:



       '''simple docstring'''





       __lowerCAmelCase					:						Dict					=					['''[UNK]''', '''[CLS]''', '''[SEP]''', '''want''', '''##want''', '''##ed''', '''wa''', '''un''', '''runn''', '''##ing''']

       __lowerCAmelCase					:						List[str]					=					{}
       for i, token in enumerate(A_					):
             __lowerCAmelCase					:						Dict					=					i
       __lowerCAmelCase					:						List[Any]					=					WordpieceTokenizer(vocab=A_      ,							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 	UpperCamelCase__  (							self					)					->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 	UpperCamelCase__  (							self					)					->Tuple:



       '''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 	UpperCamelCase__  (							self					)					->Any:



       '''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 	UpperCamelCase__  (							self					)					->Tuple:



       '''simple docstring'''





       __lowerCAmelCase					:						str					=					self.get_tokenizer()
       __lowerCAmelCase					:						str					=					self.get_rust_tokenizer()

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

       self.assertListEqual(
           [rust_tokenizer.tokenize(A_					) for t in ['''Test''', '''\xad''', '''test''']]      ,							[['''[UNK]'''], [], ['''[UNK]''']]					)
 @slow
 def 	UpperCamelCase__  (							self					)					->Tuple:



       '''simple docstring'''





       __lowerCAmelCase					:						List[Any]					=					self.tokenizer_class.from_pretrained('''bert-base-uncased'''					)

       __lowerCAmelCase					:						Tuple					=					tokenizer.encode('''sequence builders'''      ,							add_special_tokens=A_					)
       __lowerCAmelCase					:						Any					=					tokenizer.encode('''multi-sequence build'''      ,							add_special_tokens=A_					)

       __lowerCAmelCase					:						Optional[Any]					=					tokenizer.build_inputs_with_special_tokens(A_					)
       __lowerCAmelCase					:						Tuple					=					tokenizer.build_inputs_with_special_tokens(A_      ,							A_					)

       assert encoded_sentence == [101] + text + [102]
       assert encoded_pair == [101] + text + [102] + text_a + [102]
 def 	UpperCamelCase__  (							self					)					->int:



       '''simple docstring'''





       for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
             with self.subTest(f"""{tokenizer.__class__.__name__} ({pretrained_name})"""					):
                   __lowerCAmelCase					:						Tuple					=					self.rust_tokenizer_class.from_pretrained(A_      ,							**A_					)

                   __lowerCAmelCase					:						Optional[int]					=					f"""A, naïve {tokenizer_r.mask_token} AllenNLP sentence."""
                   __lowerCAmelCase					:						Dict					=					tokenizer_r.encode_plus(
                       A_      ,							return_attention_mask=A_      ,							return_token_type_ids=A_      ,							return_offsets_mapping=A_      ,							add_special_tokens=A_      ,							)

                   __lowerCAmelCase					:						Optional[int]					=					tokenizer_r.do_lower_case if hasattr(A_      ,							'''do_lower_case'''					) else False
                   __lowerCAmelCase					:						Union[str, Any]					=					(
                       [
                           ((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 	UpperCamelCase__  (							self					)					->int:



       '''simple docstring'''





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

                   __lowerCAmelCase					:						Optional[Any]					=					tokenizer_p.encode(A_      ,							add_special_tokens=A_					)
                   __lowerCAmelCase					:						Optional[int]					=					tokenizer_r.encode(A_      ,							add_special_tokens=A_					)

                   __lowerCAmelCase					:						Union[str, Any]					=					tokenizer_r.convert_ids_to_tokens(A_					)
                   __lowerCAmelCase					:						List[str]					=					tokenizer_p.convert_ids_to_tokens(A_					)

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

                   __lowerCAmelCase					:						int					=					False
                   __lowerCAmelCase					:						Union[str, Any]					=					self.rust_tokenizer_class.from_pretrained(A_      ,							**A_					)
                   __lowerCAmelCase					:						Optional[int]					=					self.tokenizer_class.from_pretrained(A_      ,							**A_					)

                   __lowerCAmelCase					:						Dict					=					tokenizer_r.encode(A_      ,							add_special_tokens=A_					)
                   __lowerCAmelCase					:						str					=					tokenizer_p.encode(A_      ,							add_special_tokens=A_					)

                   __lowerCAmelCase					:						List[str]					=					tokenizer_r.convert_ids_to_tokens(A_					)
                   __lowerCAmelCase					:						List[str]					=					tokenizer_p.convert_ids_to_tokens(A_					)

                   # it is expected that only the first Chinese character is not preceded by "##".
                   __lowerCAmelCase					:						Any					=					[
                       f"""##{token}""" if idx != 0 else token for idx, token in enumerate(A_					)
                   ]
                   self.assertListEqual(A_      ,							A_					)
                   self.assertListEqual(A_      ,							A_					)





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   __lowercase      (_UpperCAmelCase ):
 def __init__(							self      ,							A_      ,							A_=13      ,							A_=7      ,							A_=True      ,							A_=True      ,							A_=True      ,							A_=True      ,							A_=99      ,							A_=32      ,							A_=5      ,							A_=4      ,							A_=37      ,							A_="gelu"      ,							A_=0.1      ,							A_=0.1      ,							A_=512      ,							A_=16      ,							A_=2      ,							A_=0.02      ,							A_=False      ,							A_=True      ,							A_="None"      ,							A_=3      ,							A_=4      ,							A_=None      ,							)					->List[Any]:



       '''simple docstring'''





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



       '''simple docstring'''





       __lowerCAmelCase					:						Dict					=					ids_tensor([self.batch_size, self.seq_length]      ,							self.vocab_size					)

       __lowerCAmelCase					:						int					=					None
       if self.use_input_mask:
             __lowerCAmelCase					:						List[Any]					=					ids_tensor([self.batch_size, self.seq_length]      ,							vocab_size=2					)

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

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

       __lowerCAmelCase					:						Tuple					=					self.get_config()

       return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
 def 	UpperCamelCase__  (							self					)					->List[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 	UpperCamelCase__  (							self					)					->str:



       '''simple docstring'''





       __lowerCAmelCase					:						str					=					self.get_config()
       __lowerCAmelCase					:						Dict					=					300
       return config
 def 	UpperCamelCase__  (							self      ,							A_					)					->Union[str, Any]:



       '''simple docstring'''





       self.parent.assertListEqual(list(result.loss.size()					)      ,							[]					)
 def 	UpperCamelCase__  (							self      ,							A_      ,							A_      ,							A_      ,							A_      ,							A_      ,							A_      ,							A_					)					->Any:



       '''simple docstring'''





       __lowerCAmelCase					:						Optional[Any]					=					DebertaModel(config=A_					)
       model.to(A_					)
       model.eval()
       __lowerCAmelCase					:						str					=					model(A_      ,							attention_mask=A_      ,							token_type_ids=A_					)[0]
       __lowerCAmelCase					:						Any					=					model(A_      ,							token_type_ids=A_					)[0]
       __lowerCAmelCase					:						List[str]					=					model(A_					)[0]

       self.parent.assertListEqual(list(sequence_output.size()					)      ,							[self.batch_size, self.seq_length, self.hidden_size]					)
 def 	UpperCamelCase__  (							self      ,							A_      ,							A_      ,							A_      ,							A_      ,							A_      ,							A_      ,							A_					)					->int:



       '''simple docstring'''





       __lowerCAmelCase					:						Tuple					=					DebertaForMaskedLM(config=A_					)
       model.to(A_					)
       model.eval()
       __lowerCAmelCase					:						Union[str, Any]					=					model(A_      ,							attention_mask=A_      ,							token_type_ids=A_      ,							labels=A_					)

       self.parent.assertEqual(result.logits.shape      ,							(self.batch_size, self.seq_length, self.vocab_size)					)
 def 	UpperCamelCase__  (							self      ,							A_      ,							A_      ,							A_      ,							A_      ,							A_      ,							A_      ,							A_					)					->Any:



       '''simple docstring'''





       __lowerCAmelCase					:						Any					=					self.num_labels
       __lowerCAmelCase					:						Tuple					=					DebertaForSequenceClassification(A_					)
       model.to(A_					)
       model.eval()
       __lowerCAmelCase					:						Union[str, Any]					=					model(A_      ,							attention_mask=A_      ,							token_type_ids=A_      ,							labels=A_					)
       self.parent.assertListEqual(list(result.logits.size()					)      ,							[self.batch_size, self.num_labels]					)
       self.check_loss_output(A_					)
 def 	UpperCamelCase__  (							self      ,							A_      ,							A_      ,							A_      ,							A_      ,							A_      ,							A_      ,							A_					)					->Dict:



       '''simple docstring'''





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



       '''simple docstring'''





       __lowerCAmelCase					:						List[str]					=					DebertaForQuestionAnswering(config=A_					)
       model.to(A_					)
       model.eval()
       __lowerCAmelCase					:						int					=					model(
           A_      ,							attention_mask=A_      ,							token_type_ids=A_      ,							start_positions=A_      ,							end_positions=A_      ,							)
       self.parent.assertEqual(result.start_logits.shape      ,							(self.batch_size, self.seq_length)					)
       self.parent.assertEqual(result.end_logits.shape      ,							(self.batch_size, self.seq_length)					)





 def 	UpperCamelCase__  (							self					)					->List[str]:



       '''simple docstring'''





       __lowerCAmelCase					:						Any					=					self.prepare_config_and_inputs()
       (
           (
           __lowerCAmelCase
       ),							(
           __lowerCAmelCase
       ),							(
           __lowerCAmelCase
       ),							(
           __lowerCAmelCase
       ),							(
           __lowerCAmelCase
       ),							(
           __lowerCAmelCase
       ),							(
           __lowerCAmelCase
       ),							
       )					:						Tuple					=					config_and_inputs
       __lowerCAmelCase					:						Tuple					=					{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
       return config, inputs_dict







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

 _UpperCamelCase			  =  True
 _UpperCamelCase			  =  False
 _UpperCamelCase			  =  False
 _UpperCamelCase			  =  False
 _UpperCamelCase			  =  False
 def 	UpperCamelCase__  (							self					)					->int:



       '''simple docstring'''





       __lowerCAmelCase					:						int					=					DebertaModelTester(self					)
       __lowerCAmelCase					:						List[Any]					=					ConfigTester(self      ,							config_class=A_      ,							hidden_size=37					)
 def 	UpperCamelCase__  (							self					)					->Optional[Any]:



       '''simple docstring'''





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



       '''simple docstring'''





       __lowerCAmelCase					:						Dict					=					self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_deberta_model(*A_					)
 def 	UpperCamelCase__  (							self					)					->int:



       '''simple docstring'''





       __lowerCAmelCase					:						Any					=					self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_deberta_for_sequence_classification(*A_					)
 def 	UpperCamelCase__  (							self					)					->int:



       '''simple docstring'''





       __lowerCAmelCase					:						Any					=					self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_deberta_for_masked_lm(*A_					)
 def 	UpperCamelCase__  (							self					)					->Optional[int]:



       '''simple docstring'''





       __lowerCAmelCase					:						List[Any]					=					self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_deberta_for_question_answering(*A_					)
 def 	UpperCamelCase__  (							self					)					->List[Any]:



       '''simple docstring'''





       __lowerCAmelCase					:						str					=					self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_deberta_for_token_classification(*A_					)





 @slow
 def 	UpperCamelCase__  (							self					)					->Tuple:



       '''simple docstring'''





       for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             __lowerCAmelCase					:						Optional[int]					=					DebertaModel.from_pretrained(A_					)
             self.assertIsNotNone(A_					)







@require_torch
@require_sentencepiece
@require_tokenizers
class   __lowercase      (unittest.TestCase ):
 @unittest.skip(reason='''Model not available yet'''					)
 def 	UpperCamelCase__  (							self					)					->Dict:



       '''simple docstring'''





       pass





 @slow
 def 	UpperCamelCase__  (							self					)					->Tuple:



       '''simple docstring'''





       __lowerCAmelCase					:						str					=					DebertaModel.from_pretrained('''microsoft/deberta-base'''					)

       __lowerCAmelCase					:						Tuple					=					torch.tensor([[0, 3_1414, 232, 328, 740, 1140, 1_2695, 69, 4_6078, 1588, 2]]					)
       __lowerCAmelCase					:						Union[str, Any]					=					torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]					)
       with torch.no_grad():
             __lowerCAmelCase					:						Optional[int]					=					model(A_      ,							attention_mask=A_					)[0]
       # compare the actual values for a slice.
       __lowerCAmelCase					:						Optional[Any]					=					torch.tensor(
           [[[-0.5_986, -0.8_055, -0.8_462], [1.4_484, -0.9_348, -0.8_059], [0.3_123, 0.0_032, -1.4_131]]]					)
       self.assertTrue(torch.allclose(output[:, 1:4, 1:4]      ,							A_      ,							atol=1e-4					)      ,							f"""{output[:, 1:4, 1:4]}"""					)


