

import json
import os
import shutil
import sys
import tempfile
import unittest
import unittest.mock as mock
from pathlib import Path

from huggingface_hub import HfFolder, delete_repo
from requests.exceptions import HTTPError

from transformers import AutoConfig, BertConfig, GPTaConfig
from transformers.configuration_utils import PretrainedConfig
from transformers.testing_utils import TOKEN, USER, is_staging_test


sys.path.append(str(Path(__file__).parent.parent / "utils"))

from test_module.custom_configuration import CustomConfig  # noqa E402


_lowerCamelCase    :       List[Any]        =							{
    "return_dict": False,
    "output_hidden_states": True,
    "output_attentions": True,
    "torchscript": True,
    "torch_dtype": "float16",
    "use_bfloat16": True,
    "tf_legacy_loss": True,
    "pruned_heads": {"a": 1},
    "tie_word_embeddings": False,
    "is_decoder": True,
    "cross_attention_hidden_size": 1_2_8,
    "add_cross_attention": True,
    "tie_encoder_decoder": True,
    "max_length": 5_0,
    "min_length": 3,
    "do_sample": True,
    "early_stopping": True,
    "num_beams": 3,
    "num_beam_groups": 3,
    "diversity_penalty": 0.5,
    "temperature": 2.0,
    "top_k": 1_0,
    "top_p": 0.7,
    "typical_p": 0.2,
    "repetition_penalty": 0.8,
    "length_penalty": 0.8,
    "no_repeat_ngram_size": 5,
    "encoder_no_repeat_ngram_size": 5,
    "bad_words_ids": [1, 2, 3],
    "num_return_sequences": 3,
    "chunk_size_feed_forward": 5,
    "output_scores": True,
    "return_dict_in_generate": True,
    "forced_bos_token_id": 2,
    "forced_eos_token_id": 3,
    "remove_invalid_values": True,
    "architectures": ["BertModel"],
    "finetuning_task": "translation",
    "id2label": {0: "label"},
    "label2id": {"label": "0"},
    "tokenizer_class": "BertTokenizerFast",
    "prefix": "prefix",
    "bos_token_id": 6,
    "pad_token_id": 7,
    "eos_token_id": 8,
    "sep_token_id": 9,
    "decoder_start_token_id": 1_0,
    "exponential_decay_length_penalty": (5, 1.0_1),
    "suppress_tokens": [0, 1],
    "begin_suppress_tokens": 2,
    "task_specific_params": {"translation": "some_params"},
    "problem_type": "regression",
}





@is_staging_test
class  __UpperCAmelCase					(	unittest.TestCase						):



			@classmethod
			def 	__magic_name__   (							cls							:					List[str]						):
					UpperCAmelCase	:							Any						=			TOKEN
					HfFolder.save_token(lowercase_						)



			@classmethod
			def 	__magic_name__   (							cls							:					Tuple						):

					try:
							delete_repo(token=cls._token,		repo_id='''test-config'''						)
					except HTTPError:
							pass

					try:
							delete_repo(token=cls._token,		repo_id='''valid_org/test-config-org'''						)
					except HTTPError:
							pass

					try:
							delete_repo(token=cls._token,		repo_id='''test-dynamic-config'''						)
					except HTTPError:
							pass



			def 	__magic_name__   (							self							:					List[Any]						):
					UpperCAmelCase	:							Tuple						=			BertConfig(
					    vocab_size=9_9,		hidden_size=3_2,		num_hidden_layers=5,		num_attention_heads=4,		intermediate_size=3_7						)
					config.push_to_hub('''test-config''',		use_auth_token=self._token						)

					UpperCAmelCase	:							List[Any]						=			BertConfig.from_pretrained(F'''{USER}/test-config'''						)
					for k, v in config.to_dict().items():
							if k != "transformers_version":
									self.assertEqual(lowercase_,		getattr(lowercase_,		lowercase_						)						)

        # Reset repo
					delete_repo(token=self._token,		repo_id='''test-config'''						)

					# Push to hub via save_pretrained
					with tempfile.TemporaryDirectory() as tmp_dir:
							config.save_pretrained(lowercase_,		repo_id='''test-config''',		push_to_hub=lowercase_,		use_auth_token=self._token						)

					UpperCAmelCase	:							Union[str, Any]						=			BertConfig.from_pretrained(F'''{USER}/test-config'''						)
					for k, v in config.to_dict().items():
							if k != "transformers_version":
									self.assertEqual(lowercase_,		getattr(lowercase_,		lowercase_						)						)



			def 	__magic_name__   (							self							:					List[str]						):
					UpperCAmelCase	:							List[Any]						=			BertConfig(
					    vocab_size=9_9,		hidden_size=3_2,		num_hidden_layers=5,		num_attention_heads=4,		intermediate_size=3_7						)
					config.push_to_hub('''valid_org/test-config-org''',		use_auth_token=self._token						)

					UpperCAmelCase	:							Optional[int]						=			BertConfig.from_pretrained('''valid_org/test-config-org'''						)
					for k, v in config.to_dict().items():
							if k != "transformers_version":
									self.assertEqual(lowercase_,		getattr(lowercase_,		lowercase_						)						)

        # Reset repo
					delete_repo(token=self._token,		repo_id='''valid_org/test-config-org'''						)

					# Push to hub via save_pretrained
					with tempfile.TemporaryDirectory() as tmp_dir:
							config.save_pretrained(
							    lowercase_,		repo_id='''valid_org/test-config-org''',		push_to_hub=lowercase_,		use_auth_token=self._token						)

					UpperCAmelCase	:							Any						=			BertConfig.from_pretrained('''valid_org/test-config-org'''						)
					for k, v in config.to_dict().items():
							if k != "transformers_version":
									self.assertEqual(lowercase_,		getattr(lowercase_,		lowercase_						)						)





			def 	__magic_name__   (							self							:					List[str]						):
					CustomConfig.register_for_auto_class()
					UpperCAmelCase	:							Optional[Any]						=			CustomConfig(attribute=4_2						)

					config.push_to_hub('''test-dynamic-config''',		use_auth_token=self._token						)

					# This has added the proper auto_map field to the config
					self.assertDictEqual(config.auto_map,		{'''AutoConfig''': '''custom_configuration.CustomConfig'''}						)

					UpperCAmelCase	:							Optional[int]						=			AutoConfig.from_pretrained(F'''{USER}/test-dynamic-config''',		trust_remote_code=lowercase_						)
					# Can't make an isinstance check because the new_config is from the FakeConfig class of a dynamic module
					self.assertEqual(new_config.__class__.__name__,		'''CustomConfig'''						)
					self.assertEqual(new_config.attribute,		4_2						)






class  __UpperCAmelCase					(	unittest.TestCase						):



			def 	__magic_name__   (							self							:					Optional[Any]						):
					UpperCAmelCase	:							Tuple						=			GPTaConfig()

					# attempt to modify each of int/float/bool/str config records and verify they were updated
					UpperCAmelCase	:							List[str]						=			c.n_embd + 1  # int
					UpperCAmelCase	:							Dict						=			c.resid_pdrop + 1.0  # float
					UpperCAmelCase	:							str						=			not c.scale_attn_weights  # bool
					UpperCAmelCase	:							int						=			c.summary_type + '''foo'''  # str
					c.update_from_string(
					    F'''n_embd={n_embd},resid_pdrop={resid_pdrop},scale_attn_weights={scale_attn_weights},summary_type={summary_type}'''						)
					self.assertEqual(lowercase_,		c.n_embd,		'''mismatch for key: n_embd'''						)
					self.assertEqual(lowercase_,		c.resid_pdrop,		'''mismatch for key: resid_pdrop'''						)
					self.assertEqual(lowercase_,		c.scale_attn_weights,		'''mismatch for key: scale_attn_weights'''						)
					self.assertEqual(lowercase_,		c.summary_type,		'''mismatch for key: summary_type'''						)



			def 	__magic_name__   (							self							:					Optional[Any]						):
					UpperCAmelCase	:							List[Any]						=			PretrainedConfig()
					UpperCAmelCase	:							Union[str, Any]						=			[key for key in base_config.__dict__ if key not in config_common_kwargs]
					# If this part of the test fails, you have arguments to addin config_common_kwargs above.
					self.assertListEqual(
					    lowercase_,		['''is_encoder_decoder''', '''_name_or_path''', '''_commit_hash''', '''transformers_version''']						)
					UpperCAmelCase	:							Optional[int]						=			[key for key, value in config_common_kwargs.items() if value == getattr(lowercase_,		lowercase_						)]
					if len(lowercase_						) > 0:
							raise ValueError(
							    '''The following keys are set with the default values in'''
							    ''' `test_configuration_common.config_common_kwargs` pick another value for them:'''
							    F''' {", ".join(lowercase_						)}.'''						)



			def 	__magic_name__   (							self							:					Optional[Any]						):

					with self.assertRaises(lowercase_						):
							# config is in subfolder, the following should not work without specifying the subfolder
							UpperCAmelCase	:							Union[str, Any]						=			BertConfig.from_pretrained('''hf-internal-testing/tiny-random-bert-subfolder'''						)

					UpperCAmelCase	:							Dict						=			BertConfig.from_pretrained('''hf-internal-testing/tiny-random-bert-subfolder''',		subfolder='''bert'''						)

					self.assertIsNotNone(lowercase_						)



			def 	__magic_name__   (							self							:					List[str]						):
					UpperCAmelCase	:							Optional[int]						=			mock.Mock()
					UpperCAmelCase	:							List[str]						=			5_0_0
					UpperCAmelCase	:							Dict						=			{}
					UpperCAmelCase	:							List[str]						=			HTTPError
					UpperCAmelCase	:							Optional[int]						=			{}

					# Download this model to make sure it's in the cache.
					UpperCAmelCase	:							Optional[int]						=			BertConfig.from_pretrained('''hf-internal-testing/tiny-random-bert'''						)

					# Under the mock environment we get a 500 error when trying to reach the model.
					with mock.patch('''requests.Session.request''',		return_value=lowercase_						) as mock_head:
							UpperCAmelCase	:							Dict						=			BertConfig.from_pretrained('''hf-internal-testing/tiny-random-bert'''						)
							# This check we did call the fake head request
							mock_head.assert_called()



			def 	__magic_name__   (							self							:					Optional[int]						):
					UpperCAmelCase	:							Optional[Any]						=			BertConfig.from_pretrained(
					    '''https://huggingface.co/hf-internal-testing/tiny-random-bert/resolve/main/config.json'''						)



			def 	__magic_name__   (							self							:					Union[str, Any]						):
					UpperCAmelCase	:							Dict						=			AutoConfig.from_pretrained('''bert-base-cased'''						)
					UpperCAmelCase	:							Tuple						=			['''config.4.0.0.json''']

					with tempfile.TemporaryDirectory() as tmp_dir:
							configuration.save_pretrained(lowercase_						)
							UpperCAmelCase	:							Optional[Any]						=			2
							json.dump(configuration.to_dict(),		open(os.path.join(lowercase_,		'''config.4.0.0.json'''						),		'''w'''						)						)

							# This should pick the new configuration file as the version of Transformers is > 4.0.0
							UpperCAmelCase	:							Tuple						=			AutoConfig.from_pretrained(lowercase_						)
							self.assertEqual(new_configuration.hidden_size,		2						)

							# Will need to be adjusted if we reach v42 and this test is still here.
							# Should pick the old configuration file as the version of Transformers is < 4.42.0
							UpperCAmelCase	:							Dict						=			['''config.42.0.0.json''']
							UpperCAmelCase	:							List[Any]						=			7_6_8
							configuration.save_pretrained(lowercase_						)
							shutil.move(os.path.join(lowercase_,		'''config.4.0.0.json'''						),		os.path.join(lowercase_,		'''config.42.0.0.json'''						)						)
							UpperCAmelCase	:							Tuple						=			AutoConfig.from_pretrained(lowercase_						)
							self.assertEqual(new_configuration.hidden_size,		7_6_8						)





			def 	__magic_name__   (							self							:					Any						):
					UpperCAmelCase	:							Dict						=			'''hf-internal-testing/test-two-configs'''

					import transformers as new_transformers

					UpperCAmelCase	:							Any						=			'''v4.0.0'''
					UpperCAmelCase			,						UpperCAmelCase	:							Dict						=			new_transformers.models.auto.AutoConfig.from_pretrained(
					    lowercase_,		return_unused_kwargs=lowercase_						)
					self.assertEqual(new_configuration.hidden_size,		2						)
					# This checks `_configuration_file` ia not kept in the kwargs by mistake.
					self.assertDictEqual(lowercase_,		{}						)

					# Testing an older version by monkey-patching the version in the module it's used.
					import transformers as old_transformers

					UpperCAmelCase	:							Optional[Any]						=			'''v3.0.0'''
					UpperCAmelCase	:							Tuple						=			old_transformers.models.auto.AutoConfig.from_pretrained(lowercase_						)
					self.assertEqual(old_configuration.hidden_size,		7_6_8						)








import unittest

from transformers import DebertaVaConfig, 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 (
         DebertaVaForMaskedLM,
         DebertaVaForMultipleChoice,
         DebertaVaForQuestionAnswering,
         DebertaVaForSequenceClassification,
         DebertaVaForTokenClassification,
         DebertaVaModel,
     )
     from transformers.models.deberta_va.modeling_deberta_va import DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST





class  __UpperCAmelCase					(	lowerCamelCase__						):



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



   def 	__magic_name__   (							self							:					Union[str, Any]						):
     UpperCAmelCase	:							Union[str, Any]						=			ids_tensor([self.batch_size, self.seq_length],		self.vocab_size						)

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

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

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

     UpperCAmelCase	:							Union[str, Any]						=			self.get_config()

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



   def 	__magic_name__   (							self							:					Any						):
     return 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,		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 	__magic_name__   (							self							:					Dict,		__A							:					str						):
     self.parent.assertListEqual(list(result.loss.size()						),		[]						)



   def 	__magic_name__   (							self							:					List[str],		__A							:					Dict,		__A							:					int,		__A							:					str,		__A							:					List[str],		__A							:					Dict,		__A							:					str,		__A							:					int						):
     UpperCAmelCase	:							Optional[int]						=			DebertaVaModel(config=__A						)
     model.to(__A						)
     model.eval()
     UpperCAmelCase	:							Optional[int]						=			model(__A,		attention_mask=__A,		token_type_ids=__A						)[0]
     UpperCAmelCase	:							Optional[int]						=			model(__A,		token_type_ids=__A						)[0]
     UpperCAmelCase	:							int						=			model(__A						)[0]

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



   def 	__magic_name__   (							self							:					Dict,		__A							:					Union[str, Any],		__A							:					Optional[Any],		__A							:					Tuple,		__A							:					Optional[int],		__A							:					List[Any],		__A							:					List[Any],		__A							:					Optional[int]						):
     UpperCAmelCase	:							int						=			DebertaVaForMaskedLM(config=__A						)
     model.to(__A						)
     model.eval()
     UpperCAmelCase	:							int						=			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 	__magic_name__   (							self							:					List[str],		__A							:					str,		__A							:					Optional[Any],		__A							:					List[str],		__A							:					Optional[int],		__A							:					List[Any],		__A							:					int,		__A							:					Optional[int]						):
     UpperCAmelCase	:							int						=			self.num_labels
     UpperCAmelCase	:							Union[str, Any]						=			DebertaVaForSequenceClassification(__A						)
     model.to(__A						)
     model.eval()
     UpperCAmelCase	:							int						=			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 	__magic_name__   (							self							:					Any,		__A							:					Tuple,		__A							:					Any,		__A							:					str,		__A							:					List[Any],		__A							:					Dict,		__A							:					Optional[Any],		__A							:					List[str]						):
     UpperCAmelCase	:							Dict						=			self.num_labels
     UpperCAmelCase	:							int						=			DebertaVaForTokenClassification(config=__A						)
     model.to(__A						)
     model.eval()
     UpperCAmelCase	:							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 	__magic_name__   (							self							:					Tuple,		__A							:					List[str],		__A							:					Tuple,		__A							:					Tuple,		__A							:					int,		__A							:					Optional[Any],		__A							:					Tuple,		__A							:					Any						):
     UpperCAmelCase	:							Union[str, Any]						=			DebertaVaForQuestionAnswering(config=__A						)
     model.to(__A						)
     model.eval()
     UpperCAmelCase	:							Any						=			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 	__magic_name__   (							self							:					Dict,		__A							:					Optional[int],		__A							:					str,		__A							:					List[str],		__A							:					Dict,		__A							:					Optional[Any],		__A							:					Union[str, Any],		__A							:					int						):
     UpperCAmelCase	:							Union[str, Any]						=			DebertaVaForMultipleChoice(config=__A						)
     model.to(__A						)
     model.eval()
     UpperCAmelCase	:							Optional[Any]						=			input_ids.unsqueeze(1						).expand(-1,		self.num_choices,		-1						).contiguous()
     UpperCAmelCase	:							int						=			token_type_ids.unsqueeze(1						).expand(-1,		self.num_choices,		-1						).contiguous()
     UpperCAmelCase	:							Tuple						=			input_mask.unsqueeze(1						).expand(-1,		self.num_choices,		-1						).contiguous()
     UpperCAmelCase	:							int						=			model(
         __A,		attention_mask=__A,		token_type_ids=__A,		labels=__A,		)
     self.parent.assertEqual(result.logits.shape,		(self.batch_size, self.num_choices)						)





   def 	__magic_name__   (							self							:					List[str]						):
     UpperCAmelCase	:							Any						=			self.prepare_config_and_inputs()
     (
         (
         UpperCAmelCase
     )			,						(
         UpperCAmelCase
     )			,						(
         UpperCAmelCase
     )			,						(
         UpperCAmelCase
     )			,						(
         UpperCAmelCase
     )			,						(
         UpperCAmelCase
     )			,						(
         UpperCAmelCase
     )			,						
     )	:							List[str]						=			config_and_inputs
     UpperCAmelCase	:							int						=			{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
     return config, inputs_dict






@require_torch
class  __UpperCAmelCase					(	lowerCamelCase__      ,  lowerCamelCase__      ,  unittest.TestCase						):
   UpperCamelCase       					=					(
       (
           DebertaVaModel,
           DebertaVaForMaskedLM,
           DebertaVaForSequenceClassification,
           DebertaVaForTokenClassification,
           DebertaVaForQuestionAnswering,
           DebertaVaForMultipleChoice,
       )
       if is_torch_available()
       else ()
   )
   UpperCamelCase       					=					(
       {
           """feature-extraction""": DebertaVaModel,
           """fill-mask""": DebertaVaForMaskedLM,
           """question-answering""": DebertaVaForQuestionAnswering,
           """text-classification""": DebertaVaForSequenceClassification,
           """token-classification""": DebertaVaForTokenClassification,
           """zero-shot""": DebertaVaForSequenceClassification,
       }
       if is_torch_available()
       else {}
   )

   UpperCamelCase       					=					True
   UpperCamelCase       					=					False
   UpperCamelCase       					=					False
   UpperCamelCase       					=					False
   UpperCamelCase       					=					False



   def 	__magic_name__   (							self							:					Union[str, Any]						):
     UpperCAmelCase	:							str						=			DebertaVaModelTester(self						)
     UpperCAmelCase	:							Dict						=			ConfigTester(self,		config_class=__A,		hidden_size=3_7						)



   def 	__magic_name__   (							self							:					Any						):
     self.config_tester.run_common_tests()



   def 	__magic_name__   (							self							:					Union[str, Any]						):
     UpperCAmelCase	:							Any						=			self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_deberta_model(*__A						)



   def 	__magic_name__   (							self							:					List[Any]						):
     UpperCAmelCase	:							Dict						=			self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_deberta_for_sequence_classification(*__A						)



   def 	__magic_name__   (							self							:					Tuple						):
     UpperCAmelCase	:							List[Any]						=			self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_deberta_for_masked_lm(*__A						)



   def 	__magic_name__   (							self							:					Union[str, Any]						):
     UpperCAmelCase	:							Optional[int]						=			self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_deberta_for_question_answering(*__A						)



   def 	__magic_name__   (							self							:					List[str]						):
     UpperCAmelCase	:							Optional[Any]						=			self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_deberta_for_token_classification(*__A						)



   def 	__magic_name__   (							self							:					Any						):
     UpperCAmelCase	:							Optional[int]						=			self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_deberta_for_multiple_choice(*__A						)





   @slow
   def 	__magic_name__   (							self							:					Dict						):
     for model_name in DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
       UpperCAmelCase	:							str						=			DebertaVaModel.from_pretrained(__A						)
       self.assertIsNotNone(__A						)






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



   @unittest.skip(reason='''Model not available yet'''						)
   def 	__magic_name__   (							self							:					str						):
     pass





   @slow
   def 	__magic_name__   (							self							:					Optional[int]						):
     UpperCAmelCase	:							str						=			DebertaVaModel.from_pretrained('''microsoft/deberta-v2-xlarge'''						)

     UpperCAmelCase	:							Union[str, Any]						=			torch.tensor([[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]]						)
     UpperCAmelCase	:							Any						=			torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]						)
     with torch.no_grad():
       UpperCAmelCase	:							List[str]						=			model(__A,		attention_mask=__A						)[0]
     # compare the actual values for a slice.
     UpperCAmelCase	:							List[str]						=			torch.tensor(
         [[[0.2_3_5_6, 0.1_9_4_8, 0.0_3_6_9], [-0.1_0_6_3, 0.3_5_8_6, -0.5_1_5_2], [-0.6_3_9_9, -0.0_2_5_9, -0.2_5_2_5]]]						)
     self.assertTrue(torch.allclose(output[:, 1:4, 1:4],		__A,		atol=1E-4						),		F'''{output[:, 1:4, 1:4]}'''						)





