






import json
import os
import re
import shutil
import tempfile
import unittest
from typing import Tuple

from transformers import AddedToken, BatchEncoding, ByTaTokenizer
from transformers.utils import cached_property, is_tf_available, is_torch_available

from ...test_tokenization_common import TokenizerTesterMixin


if is_torch_available():
			_UpperCAmelCase      :		Any 					=     "pt"
elif is_tf_available():
			_UpperCAmelCase      :		Tuple 					=     "tf"
else:
			_UpperCAmelCase      :		Tuple 					=     "jax"
class 			lowerCAmelCase_							(					snake_case__  ,     unittest.TestCase       ):
							UpperCamelCase_		:List[str]		   =     ByTaTokenizer
							UpperCamelCase_		:Optional[int]		   =     False




							def     __snake_case       ( self  : List[Any]						):
											super().setUp()
											lowerCAmelCase__         =    ByTaTokenizer()
											tokenizer.save_pretrained(self.tmpdirname						)




							@cached_property
							def     __snake_case       ( self  : str						):
											return ByTaTokenizer.from_pretrained('''google/byt5-small'''						)




							def     __snake_case       ( self  : str			,				**SCREAMING_SNAKE_CASE_  : List[Any]						):
											return self.tokenizer_class.from_pretrained(self.tmpdirname			,				**SCREAMING_SNAKE_CASE_						)




							def     __snake_case       ( self  : Union[str, Any]			,				SCREAMING_SNAKE_CASE_  : int			,				SCREAMING_SNAKE_CASE_  : List[str]=False			,				SCREAMING_SNAKE_CASE_  : Dict=20			,				SCREAMING_SNAKE_CASE_  : Tuple=5						):
											# XXX The default common tokenizer tests assume that every ID is decodable on its own.
											# This assumption is invalid for ByT5 because single bytes might not be
											# valid utf-8 (byte 128 for instance).
											# Here we're overriding the smallest possible method to provide
											# a clean sequence without making the same assumption.

											lowerCAmelCase__         =    []
											for i in range(len(SCREAMING_SNAKE_CASE_						)						):
															try:
																			lowerCAmelCase__         =    tokenizer.decode([i]			,				clean_up_tokenization_spaces=SCREAMING_SNAKE_CASE_						)
															except UnicodeDecodeError:
																			pass
															toks.append((i, tok)						)

											lowerCAmelCase__         =    list(filter(lambda SCREAMING_SNAKE_CASE_						: re.match(R'''^[ a-zA-Z]+$'''			,				t[1]						)			,				SCREAMING_SNAKE_CASE_						)						)
											lowerCAmelCase__         =    list(filter(lambda SCREAMING_SNAKE_CASE_						: [t[0]] == tokenizer.encode(t[1]			,				add_special_tokens=SCREAMING_SNAKE_CASE_						)			,				SCREAMING_SNAKE_CASE_						)						)
											if max_length is not None and len(SCREAMING_SNAKE_CASE_						) > max_length:
															lowerCAmelCase__         =    toks[:max_length]
											if min_length is not None and len(SCREAMING_SNAKE_CASE_						) < min_length and len(SCREAMING_SNAKE_CASE_						) > 0:
															while len(SCREAMING_SNAKE_CASE_						) < min_length:
																			lowerCAmelCase__         =    toks + toks
        # toks_str = [t[1] for t in toks]
											lowerCAmelCase__         =    [t[0] for t in toks]

											# Ensure consistency
											lowerCAmelCase__         =    tokenizer.decode(SCREAMING_SNAKE_CASE_			,				clean_up_tokenization_spaces=SCREAMING_SNAKE_CASE_						)
											if " " not in output_txt and len(SCREAMING_SNAKE_CASE_						) > 1:
															lowerCAmelCase__         =    (
															    tokenizer.decode([toks_ids[0]]			,				clean_up_tokenization_spaces=SCREAMING_SNAKE_CASE_						)
															    + ''' '''
															    + tokenizer.decode(toks_ids[1:]			,				clean_up_tokenization_spaces=SCREAMING_SNAKE_CASE_						)
															)
											if with_prefix_space:
															lowerCAmelCase__         =    ''' ''' + output_txt
											lowerCAmelCase__         =    tokenizer.encode(SCREAMING_SNAKE_CASE_			,				add_special_tokens=SCREAMING_SNAKE_CASE_						)
											return output_txt, output_ids




							def     __snake_case       ( self  : Union[str, Any]						):
											lowerCAmelCase__         =    self.ta_base_tokenizer
											lowerCAmelCase__         =    tokenizer(['''hi</s>''', '''I went to the gym</s>''', '''</s>''']						)
											lowerCAmelCase__         =    tokenizer(['''hi''', '''I went to the gym''', '''''']						)
											self.assertListEqual(batch_with_eos_added['''input_ids''']			,				batch_without_eos_added['''input_ids''']						)




							def     __snake_case       ( self  : Dict						):
											lowerCAmelCase__         =    self.ta_base_tokenizer
											lowerCAmelCase__         =    '''Unicode €.'''
											lowerCAmelCase__         =    tokenizer(SCREAMING_SNAKE_CASE_						)
											lowerCAmelCase__         =    [88, 113, 108, 102, 114, 103, 104, 35, 229, 133, 175, 49, 1]
											self.assertEqual(encoded['''input_ids''']			,				SCREAMING_SNAKE_CASE_						)

											# decoding
											lowerCAmelCase__         =    tokenizer.decode(SCREAMING_SNAKE_CASE_						)
											self.assertEqual(SCREAMING_SNAKE_CASE_			,				'''Unicode €.</s>'''						)

											lowerCAmelCase__         =    tokenizer('''e è é ê ë'''						)
											lowerCAmelCase__         =    [104, 35, 198, 171, 35, 198, 172, 35, 198, 173, 35, 198, 174, 1]
											self.assertEqual(encoded['''input_ids''']			,				SCREAMING_SNAKE_CASE_						)
											# decoding
											lowerCAmelCase__         =    tokenizer.decode(SCREAMING_SNAKE_CASE_						)
											self.assertEqual(SCREAMING_SNAKE_CASE_			,				'''e è é ê ë</s>'''						)

											# encode/decode, but with `encode` instead of `__call__`
											self.assertEqual(tokenizer.decode(tokenizer.encode('''e è é ê ë'''						)						)			,				'''e è é ê ë</s>'''						)




							def     __snake_case       ( self  : int						):
											lowerCAmelCase__         =    self.ta_base_tokenizer
											lowerCAmelCase__         =    ['''A long paragraph for summarization.''', '''Another paragraph for summarization.''']
											# fmt: off
											lowerCAmelCase__         =    [68, 35, 111, 114, 113, 106, 35, 115, 100, 117, 100, 106, 117, 100, 115, 107, 35, 105, 114, 117, 35, 118, 120, 112, 112, 100, 117, 108, 125, 100, 119, 108, 114, 113, 49, 1, 0]
											# fmt: on
											lowerCAmelCase__         =    tokenizer(SCREAMING_SNAKE_CASE_			,				padding=SCREAMING_SNAKE_CASE_			,				return_tensors=SCREAMING_SNAKE_CASE_						)
											self.assertIsInstance(SCREAMING_SNAKE_CASE_			,				SCREAMING_SNAKE_CASE_						)

											if FRAMEWORK != "jax":
															lowerCAmelCase__         =    list(batch.input_ids.numpy()[0]						)
											else:
															lowerCAmelCase__         =    list(batch.input_ids.tolist()[0]						)

											self.assertListEqual(SCREAMING_SNAKE_CASE_			,				SCREAMING_SNAKE_CASE_						)

											self.assertEqual((2, 37)			,				batch.input_ids.shape						)
											self.assertEqual((2, 37)			,				batch.attention_mask.shape						)




							def     __snake_case       ( self  : int						):
											lowerCAmelCase__         =    self.ta_base_tokenizer
											lowerCAmelCase__         =    ['''A long paragraph for summarization.''', '''Another paragraph for summarization.''']
											lowerCAmelCase__         =    tokenizer(SCREAMING_SNAKE_CASE_			,				padding=SCREAMING_SNAKE_CASE_			,				return_tensors=SCREAMING_SNAKE_CASE_						)
											# check if input_ids are returned and no decoder_input_ids
											self.assertIn('''input_ids'''			,				SCREAMING_SNAKE_CASE_						)
											self.assertIn('''attention_mask'''			,				SCREAMING_SNAKE_CASE_						)
											self.assertNotIn('''decoder_input_ids'''			,				SCREAMING_SNAKE_CASE_						)
											self.assertNotIn('''decoder_attention_mask'''			,				SCREAMING_SNAKE_CASE_						)




							def     __snake_case       ( self  : List[str]						):
											lowerCAmelCase__         =    self.ta_base_tokenizer
											lowerCAmelCase__         =    [
											    '''Summary of the text.''',
											    '''Another summary.''',
											]
											lowerCAmelCase__         =    tokenizer(
											    text_target=SCREAMING_SNAKE_CASE_			,				max_length=32			,				padding='''max_length'''			,				truncation=SCREAMING_SNAKE_CASE_			,				return_tensors=SCREAMING_SNAKE_CASE_						)
											self.assertEqual(32			,				targets['''input_ids'''].shape[1]						)




							def     __snake_case       ( self  : int						):
											lowerCAmelCase__         =    self.ta_base_tokenizer
											lowerCAmelCase__         =    ['''A long paragraph for summarization. </s>''']
											lowerCAmelCase__         =    ['''Summary of the text. </s>''']
											# fmt: off
											lowerCAmelCase__         =    [68, 35, 111, 114, 113, 106, 35, 115, 100, 117, 100, 106, 117, 100, 115, 107, 35, 105, 114, 117, 35, 118, 120, 112, 112, 100, 117, 108, 125, 100, 119, 108, 114, 113, 49, 35, 1]
											lowerCAmelCase__         =    [86, 120, 112, 112, 100, 117, 124, 35, 114, 105, 35, 119, 107, 104, 35, 119, 104, 123, 119, 49, 35, 1]
											# fmt: on

											lowerCAmelCase__         =    tokenizer(SCREAMING_SNAKE_CASE_			,				text_target=SCREAMING_SNAKE_CASE_						)

											self.assertEqual(SCREAMING_SNAKE_CASE_			,				batch['''input_ids'''][0]						)
											self.assertEqual(SCREAMING_SNAKE_CASE_			,				batch['''labels'''][0]						)




							def     __snake_case       ( self  : List[str]						):
											# safety check on max_len default value so we are sure the test works
											lowerCAmelCase__         =    self.get_tokenizers()
											for tokenizer in tokenizers:
															with self.subTest(f'{tokenizer.__class__.__name__}'						):
																			self.assertNotEqual(tokenizer.model_max_length			,				42						)

        # Now let's start the test
											lowerCAmelCase__         =    self.get_tokenizers()
											for tokenizer in tokenizers:
															with self.subTest(f'{tokenizer.__class__.__name__}'						):
																			# Isolate this from the other tests because we save additional tokens/etc
																			lowerCAmelCase__         =    tempfile.mkdtemp()

																			lowerCAmelCase__         =    ''' He is very happy, UNwant\u00E9d,running'''
																			lowerCAmelCase__         =    tokenizer.encode(SCREAMING_SNAKE_CASE_			,				add_special_tokens=SCREAMING_SNAKE_CASE_						)
																			tokenizer.save_pretrained(SCREAMING_SNAKE_CASE_						)

																			lowerCAmelCase__         =    tokenizer.__class__.from_pretrained(SCREAMING_SNAKE_CASE_						)
																			lowerCAmelCase__         =    after_tokenizer.encode(SCREAMING_SNAKE_CASE_			,				add_special_tokens=SCREAMING_SNAKE_CASE_						)
																			self.assertListEqual(SCREAMING_SNAKE_CASE_			,				SCREAMING_SNAKE_CASE_						)

																			shutil.rmtree(SCREAMING_SNAKE_CASE_						)

											lowerCAmelCase__         =    self.get_tokenizers(model_max_length=42						)
											for tokenizer in tokenizers:
															with self.subTest(f'{tokenizer.__class__.__name__}'						):
																			# Isolate this from the other tests because we save additional tokens/etc
																			lowerCAmelCase__         =    tempfile.mkdtemp()

																			lowerCAmelCase__         =    ''' He is very happy, UNwant\u00E9d,running'''
																			tokenizer.add_tokens(['''bim''', '''bambam''']						)
																			lowerCAmelCase__         =    tokenizer.additional_special_tokens
																			additional_special_tokens.append('''new_additional_special_token'''						)
																			tokenizer.add_special_tokens({'''additional_special_tokens''': additional_special_tokens}						)
																			lowerCAmelCase__         =    tokenizer.encode(SCREAMING_SNAKE_CASE_			,				add_special_tokens=SCREAMING_SNAKE_CASE_						)
																			tokenizer.save_pretrained(SCREAMING_SNAKE_CASE_						)

																			lowerCAmelCase__         =    tokenizer.__class__.from_pretrained(SCREAMING_SNAKE_CASE_						)
																			lowerCAmelCase__         =    after_tokenizer.encode(SCREAMING_SNAKE_CASE_			,				add_special_tokens=SCREAMING_SNAKE_CASE_						)
																			self.assertListEqual(SCREAMING_SNAKE_CASE_			,				SCREAMING_SNAKE_CASE_						)
																			self.assertIn('''new_additional_special_token'''			,				after_tokenizer.additional_special_tokens						)
																			self.assertEqual(after_tokenizer.model_max_length			,				42						)

																			lowerCAmelCase__         =    tokenizer.__class__.from_pretrained(SCREAMING_SNAKE_CASE_			,				model_max_length=43						)
																			self.assertEqual(tokenizer.model_max_length			,				43						)

																			shutil.rmtree(SCREAMING_SNAKE_CASE_						)




							def     __snake_case       ( self  : List[Any]						):
											lowerCAmelCase__         =    []
											if self.test_slow_tokenizer:
															tokenizer_list.append((self.tokenizer_class, self.get_tokenizer())						)

											if self.test_rust_tokenizer:
															tokenizer_list.append((self.rust_tokenizer_class, self.get_rust_tokenizer())						)

											for tokenizer_class, tokenizer_utils in tokenizer_list:
															with tempfile.TemporaryDirectory() as tmp_dir:
																			tokenizer_utils.save_pretrained(SCREAMING_SNAKE_CASE_						)

																			with open(os.path.join(SCREAMING_SNAKE_CASE_			,				'''special_tokens_map.json'''						)			,				encoding='''utf-8'''						) as json_file:
																							lowerCAmelCase__         =    json.load(SCREAMING_SNAKE_CASE_						)

																			with open(os.path.join(SCREAMING_SNAKE_CASE_			,				'''tokenizer_config.json'''						)			,				encoding='''utf-8'''						) as json_file:
																							lowerCAmelCase__         =    json.load(SCREAMING_SNAKE_CASE_						)

																			lowerCAmelCase__         =    [f'<extra_id_{i}>' for i in range(125						)]

																			lowerCAmelCase__         =    added_tokens_extra_ids + [
																			    '''an_additional_special_token'''
																			]
																			lowerCAmelCase__         =    added_tokens_extra_ids + [
																			    '''an_additional_special_token'''
																			]

																			with open(os.path.join(SCREAMING_SNAKE_CASE_			,				'''special_tokens_map.json'''						)			,				'''w'''			,				encoding='''utf-8'''						) as outfile:
																							json.dump(SCREAMING_SNAKE_CASE_			,				SCREAMING_SNAKE_CASE_						)
																			with open(os.path.join(SCREAMING_SNAKE_CASE_			,				'''tokenizer_config.json'''						)			,				'''w'''			,				encoding='''utf-8'''						) as outfile:
																							json.dump(SCREAMING_SNAKE_CASE_			,				SCREAMING_SNAKE_CASE_						)

																			# the following checks allow us to verify that our test works as expected, i.e. that the tokenizer takes
																			# into account the new value of additional_special_tokens given in the "tokenizer_config.json" and
																			# "special_tokens_map.json" files
																			lowerCAmelCase__         =    tokenizer_class.from_pretrained(
																			    SCREAMING_SNAKE_CASE_			,				)
																			self.assertIn(
																			    '''an_additional_special_token'''			,				tokenizer_without_change_in_init.additional_special_tokens						)
																			# self.assertIn("an_additional_special_token",tokenizer_without_change_in_init.get_vocab()) # ByT5Tokenization no vocab
																			self.assertEqual(
																			    ['''an_additional_special_token''']			,				tokenizer_without_change_in_init.convert_ids_to_tokens(
																			        tokenizer_without_change_in_init.convert_tokens_to_ids(['''an_additional_special_token''']						)						)			,				)

																			# Now we test that we can change the value of additional_special_tokens in the from_pretrained
																			lowerCAmelCase__         =    added_tokens_extra_ids + [AddedToken('''a_new_additional_special_token'''			,				lstrip=SCREAMING_SNAKE_CASE_						)]
																			lowerCAmelCase__         =    tokenizer_class.from_pretrained(
																			    SCREAMING_SNAKE_CASE_			,				additional_special_tokens=SCREAMING_SNAKE_CASE_			,				)

																			self.assertIn('''a_new_additional_special_token'''			,				tokenizer.additional_special_tokens						)
																			self.assertEqual(
																			    ['''a_new_additional_special_token''']			,				tokenizer.convert_ids_to_tokens(
																			        tokenizer.convert_tokens_to_ids(['''a_new_additional_special_token''']						)						)			,				)




							def     __snake_case       ( self  : Union[str, Any]						):
											lowerCAmelCase__         =    []
											if self.test_slow_tokenizer:
															tokenizer_list.append((self.tokenizer_class, self.get_tokenizer())						)

											if self.test_rust_tokenizer:
															tokenizer_list.append((self.rust_tokenizer_class, self.get_rust_tokenizer())						)

											for tokenizer_class, tokenizer_utils in tokenizer_list:
															with tempfile.TemporaryDirectory() as tmp_dir:
																			tokenizer_utils.save_pretrained(SCREAMING_SNAKE_CASE_						)

																			lowerCAmelCase__         =    tokenizer_class.from_pretrained(SCREAMING_SNAKE_CASE_						)

																			self.assertTrue(tokenizer.decode([255]						) == ''''''						)




							def     __snake_case       ( self  : List[Any]						):
											pass




							def     __snake_case       ( self  : Union[str, Any]						):
											pass




							def     __snake_case       ( self  : Optional[Any]						):
											pass




							def     __snake_case       ( self  : Optional[int]						):
											pass




							def     __snake_case       ( self  : str						):
											# The default common tokenizer tests uses invalid tokens for ByT5 that can only accept one-character strings
											# and special added tokens as tokens
											lowerCAmelCase__         =    self.get_tokenizers(fast=SCREAMING_SNAKE_CASE_			,				do_lower_case=SCREAMING_SNAKE_CASE_						)
											for tokenizer in tokenizers:
															with self.subTest(f'{tokenizer.__class__.__name__}'						):
																			lowerCAmelCase__         =    ['''t''', '''h''', '''i''', '''s''', ''' ''', '''i''', '''s''', ''' ''', '''a''', ''' ''', '''t''', '''e''', '''x''', '''t''', '''</s>''']
																			lowerCAmelCase__         =    tokenizer.convert_tokens_to_string(SCREAMING_SNAKE_CASE_						)

																			self.assertIsInstance(SCREAMING_SNAKE_CASE_			,				SCREAMING_SNAKE_CASE_						)




							def     __snake_case       ( self  : str						):
											lowerCAmelCase__         =    self.get_tokenizers()
											for tokenizer in tokenizers:
															with self.subTest(f'{tokenizer.__class__.__name__}'						):
																			lowerCAmelCase__         =    [
																			    '''bos_token''',
																			    '''eos_token''',
																			    '''unk_token''',
																			    '''sep_token''',
																			    '''pad_token''',
																			    '''cls_token''',
																			    '''mask_token''',
																			]

																			lowerCAmelCase__         =    0
																			lowerCAmelCase__         =    tokenizer.convert_ids_to_tokens(
																			    SCREAMING_SNAKE_CASE_			,				skip_special_tokens=SCREAMING_SNAKE_CASE_						)

																			for attr in attributes_list:
																							setattr(SCREAMING_SNAKE_CASE_			,				attr + '''_id'''			,				SCREAMING_SNAKE_CASE_						)
																							self.assertEqual(getattr(SCREAMING_SNAKE_CASE_			,				SCREAMING_SNAKE_CASE_						)			,				SCREAMING_SNAKE_CASE_						)
																							self.assertEqual(getattr(SCREAMING_SNAKE_CASE_			,				attr + '''_id'''						)			,				SCREAMING_SNAKE_CASE_						)

																							setattr(SCREAMING_SNAKE_CASE_			,				attr + '''_id'''			,				SCREAMING_SNAKE_CASE_						)
																							self.assertEqual(getattr(SCREAMING_SNAKE_CASE_			,				SCREAMING_SNAKE_CASE_						)			,				SCREAMING_SNAKE_CASE_						)
																							self.assertEqual(getattr(SCREAMING_SNAKE_CASE_			,				attr + '''_id'''						)			,				SCREAMING_SNAKE_CASE_						)

																			setattr(SCREAMING_SNAKE_CASE_			,				'''additional_special_tokens_ids'''			,				[]						)
																			self.assertListEqual(getattr(SCREAMING_SNAKE_CASE_			,				'''additional_special_tokens'''						)			,				[]						)
																			self.assertListEqual(getattr(SCREAMING_SNAKE_CASE_			,				'''additional_special_tokens_ids'''						)			,				[]						)

																			setattr(SCREAMING_SNAKE_CASE_			,				'''additional_special_tokens_ids'''			,				[token_id_to_test_setters]						)
																			self.assertListEqual(getattr(SCREAMING_SNAKE_CASE_			,				'''additional_special_tokens'''						)			,				[token_to_test_setters]						)
																			self.assertListEqual(getattr(SCREAMING_SNAKE_CASE_			,				'''additional_special_tokens_ids'''						)			,				[token_id_to_test_setters]						)







from __future__ import annotations

import unittest

from transformers import DebertaVaConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
						import tensorflow as tf

						from transformers import (
						    TFDebertaVaForMaskedLM,
						    TFDebertaVaForQuestionAnswering,
						    TFDebertaVaForSequenceClassification,
						    TFDebertaVaForTokenClassification,
						    TFDebertaVaModel,
						)
class 					lowercase__:



	"""simple docstring"""




	def __init__(			self    :     Dict			,				SCREAMING_SNAKE_CASE_    :     str			,				SCREAMING_SNAKE_CASE_    :     str=1_3			,				SCREAMING_SNAKE_CASE_    :     Optional[Any]=7			,				SCREAMING_SNAKE_CASE_    :     Dict=True			,				SCREAMING_SNAKE_CASE_    :     Tuple=True			,				SCREAMING_SNAKE_CASE_    :     Optional[Any]=True			,				SCREAMING_SNAKE_CASE_    :     Tuple=True			,				SCREAMING_SNAKE_CASE_    :     Tuple=9_9			,				SCREAMING_SNAKE_CASE_    :     List[str]=3_2			,				SCREAMING_SNAKE_CASE_    :     int=2			,				SCREAMING_SNAKE_CASE_    :     Tuple=4			,				SCREAMING_SNAKE_CASE_    :     Union[str, Any]=3_7			,				SCREAMING_SNAKE_CASE_    :     Union[str, Any]="gelu"			,				SCREAMING_SNAKE_CASE_    :     Union[str, Any]=0.1			,				SCREAMING_SNAKE_CASE_    :     Union[str, Any]=0.1			,				SCREAMING_SNAKE_CASE_    :     Optional[int]=5_1_2			,				SCREAMING_SNAKE_CASE_    :     str=1_6			,				SCREAMING_SNAKE_CASE_    :     Union[str, Any]=2			,				SCREAMING_SNAKE_CASE_    :     List[Any]=0.02			,				SCREAMING_SNAKE_CASE_    :     List[Any]=False			,				SCREAMING_SNAKE_CASE_    :     List[Any]=True			,				SCREAMING_SNAKE_CASE_    :     Union[str, Any]="None"			,				SCREAMING_SNAKE_CASE_    :     Optional[Any]=3			,				SCREAMING_SNAKE_CASE_    :     List[Any]=4			,				SCREAMING_SNAKE_CASE_    :     str=None			,				)			->	str:
					lowercase_	    =   parent
					lowercase_	    =   batch_size
					lowercase_	    =   seq_length
					lowercase_	    =   is_training
					lowercase_	    =   use_input_mask
					lowercase_	    =   use_token_type_ids
					lowercase_	    =   use_labels
					lowercase_	    =   vocab_size
					lowercase_	    =   hidden_size
					lowercase_	    =   num_hidden_layers
					lowercase_	    =   num_attention_heads
					lowercase_	    =   intermediate_size
					lowercase_	    =   hidden_act
					lowercase_	    =   hidden_dropout_prob
					lowercase_	    =   attention_probs_dropout_prob
					lowercase_	    =   max_position_embeddings
					lowercase_	    =   type_vocab_size
					lowercase_	    =   type_sequence_label_size
					lowercase_	    =   initializer_range
					lowercase_	    =   num_labels
					lowercase_	    =   num_choices
					lowercase_	    =   relative_attention
					lowercase_	    =   position_biased_input
					lowercase_	    =   pos_att_type
					lowercase_	    =   scope
	def 		_lowercase    (			self    :     List[Any]			)			->	List[Any]:
					lowercase_	    =   ids_tensor([self.batch_size, self.seq_length]			,				self.vocab_size			)

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

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

					lowercase_	    =   None
					lowercase_	    =   None
					lowercase_	    =   None
					if self.use_labels:
									lowercase_	    =   ids_tensor([self.batch_size]			,				self.type_sequence_label_size			)
									lowercase_	    =   ids_tensor([self.batch_size, self.seq_length]			,				self.num_labels			)

					lowercase_	    =   DebertaVaConfig(
					    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			,				relative_attention=self.relative_attention			,				position_biased_input=self.position_biased_input			,				initializer_range=self.initializer_range			,				return_dict=SCREAMING_SNAKE_CASE_			,				)

					return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
	def 		_lowercase    (			self    :     str			,				SCREAMING_SNAKE_CASE_    :     Any			,				SCREAMING_SNAKE_CASE_    :     Optional[int]			,				SCREAMING_SNAKE_CASE_    :     str			,				SCREAMING_SNAKE_CASE_    :     Tuple			,				SCREAMING_SNAKE_CASE_    :     Dict			,				SCREAMING_SNAKE_CASE_    :     Dict			,				SCREAMING_SNAKE_CASE_    :     List[Any]			)			->	List[Any]:
					lowercase_	    =   TFDebertaVaModel(config=SCREAMING_SNAKE_CASE_			)
					lowercase_	    =   {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}

					lowercase_	    =   [input_ids, input_mask]
					lowercase_	    =   model(SCREAMING_SNAKE_CASE_			)

					lowercase_	    =   model(SCREAMING_SNAKE_CASE_			)

					self.parent.assertEqual(result.last_hidden_state.shape			,				(self.batch_size, self.seq_length, self.hidden_size)			)
	def 		_lowercase    (			self    :     Tuple			,				SCREAMING_SNAKE_CASE_    :     Optional[Any]			,				SCREAMING_SNAKE_CASE_    :     str			,				SCREAMING_SNAKE_CASE_    :     Any			,				SCREAMING_SNAKE_CASE_    :     int			,				SCREAMING_SNAKE_CASE_    :     Dict			,				SCREAMING_SNAKE_CASE_    :     Any			,				SCREAMING_SNAKE_CASE_    :     Any			)			->	Union[str, Any]:
					lowercase_	    =   TFDebertaVaForMaskedLM(config=SCREAMING_SNAKE_CASE_			)
					lowercase_	    =   {
					    '''input_ids''': input_ids,
					    '''attention_mask''': input_mask,
					    '''token_type_ids''': token_type_ids,
					}
					lowercase_	    =   model(SCREAMING_SNAKE_CASE_			)
					self.parent.assertEqual(result.logits.shape			,				(self.batch_size, self.seq_length, self.vocab_size)			)
	def 		_lowercase    (			self    :     Optional[int]			,				SCREAMING_SNAKE_CASE_    :     Tuple			,				SCREAMING_SNAKE_CASE_    :     int			,				SCREAMING_SNAKE_CASE_    :     Tuple			,				SCREAMING_SNAKE_CASE_    :     str			,				SCREAMING_SNAKE_CASE_    :     List[Any]			,				SCREAMING_SNAKE_CASE_    :     Union[str, Any]			,				SCREAMING_SNAKE_CASE_    :     Union[str, Any]			)			->	List[str]:
					lowercase_	    =   self.num_labels
					lowercase_	    =   TFDebertaVaForSequenceClassification(config=SCREAMING_SNAKE_CASE_			)
					lowercase_	    =   {
					    '''input_ids''': input_ids,
					    '''attention_mask''': input_mask,
					    '''token_type_ids''': token_type_ids,
					}

					lowercase_	    =   model(SCREAMING_SNAKE_CASE_			)
					self.parent.assertEqual(result.logits.shape			,				(self.batch_size, self.num_labels)			)
	def 		_lowercase    (			self    :     Optional[int]			,				SCREAMING_SNAKE_CASE_    :     Tuple			,				SCREAMING_SNAKE_CASE_    :     List[Any]			,				SCREAMING_SNAKE_CASE_    :     List[Any]			,				SCREAMING_SNAKE_CASE_    :     Union[str, Any]			,				SCREAMING_SNAKE_CASE_    :     str			,				SCREAMING_SNAKE_CASE_    :     Any			,				SCREAMING_SNAKE_CASE_    :     Optional[int]			)			->	Optional[Any]:
					lowercase_	    =   self.num_labels
					lowercase_	    =   TFDebertaVaForTokenClassification(config=SCREAMING_SNAKE_CASE_			)
					lowercase_	    =   {
					    '''input_ids''': input_ids,
					    '''attention_mask''': input_mask,
					    '''token_type_ids''': token_type_ids,
					}
					lowercase_	    =   model(SCREAMING_SNAKE_CASE_			)
					self.parent.assertEqual(result.logits.shape			,				(self.batch_size, self.seq_length, self.num_labels)			)
	def 		_lowercase    (			self    :     Union[str, Any]			,				SCREAMING_SNAKE_CASE_    :     List[str]			,				SCREAMING_SNAKE_CASE_    :     List[Any]			,				SCREAMING_SNAKE_CASE_    :     int			,				SCREAMING_SNAKE_CASE_    :     Optional[Any]			,				SCREAMING_SNAKE_CASE_    :     List[Any]			,				SCREAMING_SNAKE_CASE_    :     List[Any]			,				SCREAMING_SNAKE_CASE_    :     Optional[int]			)			->	str:
					lowercase_	    =   TFDebertaVaForQuestionAnswering(config=SCREAMING_SNAKE_CASE_			)
					lowercase_	    =   {
					    '''input_ids''': input_ids,
					    '''attention_mask''': input_mask,
					    '''token_type_ids''': token_type_ids,
					}

					lowercase_	    =   model(SCREAMING_SNAKE_CASE_			)
					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    :     List[str]			)			->	Optional[int]:
					lowercase_	    =   self.prepare_config_and_inputs()
					(
					    (
					    lowercase_
					)    ,      (
					    lowercase_
					)    ,      (
					    lowercase_
					)    ,      (
					    lowercase_
					)    ,      (
					    lowercase_
					)    ,      (
					    lowercase_
					)    ,      (
					    lowercase_
					)    ,      
					)	    =   config_and_inputs
					lowercase_	    =   {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
					return config, inputs_dict

@require_tf
class 					lowercase__(							UpperCAmelCase					,		UpperCAmelCase					,		unittest.TestCase				):



	"""simple docstring"""




	a     :str       	=      (
	    (
	        TFDebertaVaModel,
	        TFDebertaVaForMaskedLM,
	        TFDebertaVaForQuestionAnswering,
	        TFDebertaVaForSequenceClassification,
	        TFDebertaVaForTokenClassification,
	    )
	    if is_tf_available()
	    else ()
	)
	a     :int       	=      (
	    {
	        'feature-extraction': TFDebertaVaModel,
	        'fill-mask': TFDebertaVaForMaskedLM,
	        'question-answering': TFDebertaVaForQuestionAnswering,
	        'text-classification': TFDebertaVaForSequenceClassification,
	        'token-classification': TFDebertaVaForTokenClassification,
	        'zero-shot': TFDebertaVaForSequenceClassification,
	    }
	    if is_tf_available()
	    else {}
	)

	a     :int       	=      False
	a     :Any       	=      False
	def 		_lowercase    (			self    :     Dict			)			->	str:
					lowercase_	    =   TFDebertaVaModelTester(self			)
					lowercase_	    =   ConfigTester(self			,				config_class=SCREAMING_SNAKE_CASE_			,				hidden_size=3_7			)
	def 		_lowercase    (			self    :     Tuple			)			->	Dict:
					self.config_tester.run_common_tests()
	def 		_lowercase    (			self    :     Union[str, Any]			)			->	int:
					lowercase_	    =   self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE_			)
	def 		_lowercase    (			self    :     Dict			)			->	List[Any]:
					lowercase_	    =   self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_masked_lm(*SCREAMING_SNAKE_CASE_			)
	def 		_lowercase    (			self    :     Optional[Any]			)			->	Optional[int]:
					lowercase_	    =   self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_question_answering(*SCREAMING_SNAKE_CASE_			)
	def 		_lowercase    (			self    :     Any			)			->	str:
					lowercase_	    =   self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_sequence_classification(*SCREAMING_SNAKE_CASE_			)
	def 		_lowercase    (			self    :     Union[str, Any]			)			->	Optional[Any]:
					lowercase_	    =   self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_token_classification(*SCREAMING_SNAKE_CASE_			)




	@slow
	def 		_lowercase    (			self    :     Tuple			)			->	Dict:
					lowercase_	    =   TFDebertaVaModel.from_pretrained('''kamalkraj/deberta-v2-xlarge'''			)
					self.assertIsNotNone(SCREAMING_SNAKE_CASE_			)

@require_tf
class 					lowercase__(							unittest.TestCase				):



	"""simple docstring"""




	@unittest.skip(reason='''Model not available yet'''			)
	def 		_lowercase    (			self    :     Optional[Any]			)			->	Union[str, Any]:
					pass




	@slow
	def 		_lowercase    (			self    :     List[Any]			)			->	Dict:
					lowercase_	    =   TFDebertaVaModel.from_pretrained('''kamalkraj/deberta-v2-xlarge'''			)
					lowercase_	    =   tf.constant([[0, 3_1_4_1_4, 2_3_2, 3_2_8, 7_4_0, 1_1_4_0, 1_2_6_9_5, 6_9, 4_6_0_7_8, 1_5_8_8, 2]]			)
					lowercase_	    =   tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]			)
					lowercase_	    =   model(SCREAMING_SNAKE_CASE_			,				attention_mask=SCREAMING_SNAKE_CASE_			)[0]

					lowercase_	    =   tf.constant(
					    [[[0.23_56, 0.19_48, 0.03_69], [-0.10_63, 0.35_86, -0.51_52], [-0.63_99, -0.02_59, -0.25_25]]]			)
					tf.debugging.assert_near(output[:, 1:4, 1:4]			,				SCREAMING_SNAKE_CASE_			,				atol=1e-4			)




