


"""simple docstring"""



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    __a						( __snake_case							):







				def __init__( self      ,	UpperCAmelCase      ,	UpperCAmelCase=13      ,	UpperCAmelCase=7      ,	UpperCAmelCase=True      ,	UpperCAmelCase=True      ,	UpperCAmelCase=True      ,	UpperCAmelCase=True      ,	UpperCAmelCase=99      ,	UpperCAmelCase=32      ,	UpperCAmelCase=5      ,	UpperCAmelCase=4      ,	UpperCAmelCase=37      ,	UpperCAmelCase="gelu"      ,	UpperCAmelCase=0.1      ,	UpperCAmelCase=0.1      ,	UpperCAmelCase=512      ,	UpperCAmelCase=16      ,	UpperCAmelCase=2      ,	UpperCAmelCase=0.0_2      ,	UpperCAmelCase=False      ,	UpperCAmelCase=True      ,	UpperCAmelCase="None"      ,	UpperCAmelCase=3      ,	UpperCAmelCase=4      ,	UpperCAmelCase=None      ,	):

					'''simple docstring'''






					lowerCAmelCase_      							=			parent
					lowerCAmelCase_      							=			batch_size
					lowerCAmelCase_      							=			seq_length
					lowerCAmelCase_      							=			is_training
					lowerCAmelCase_      							=			use_input_mask
					lowerCAmelCase_      							=			use_token_type_ids
					lowerCAmelCase_      							=			use_labels
					lowerCAmelCase_      							=			vocab_size
					lowerCAmelCase_      							=			hidden_size
					lowerCAmelCase_      							=			num_hidden_layers
					lowerCAmelCase_      							=			num_attention_heads
					lowerCAmelCase_      							=			intermediate_size
					lowerCAmelCase_      							=			hidden_act
					lowerCAmelCase_      							=			hidden_dropout_prob
					lowerCAmelCase_      							=			attention_probs_dropout_prob
					lowerCAmelCase_      							=			max_position_embeddings
					lowerCAmelCase_      							=			type_vocab_size
					lowerCAmelCase_      							=			type_sequence_label_size
					lowerCAmelCase_      							=			initializer_range
					lowerCAmelCase_      							=			num_labels
					lowerCAmelCase_      							=			num_choices
					lowerCAmelCase_      							=			relative_attention
					lowerCAmelCase_      							=			position_biased_input
					lowerCAmelCase_      							=			pos_att_type
					lowerCAmelCase_      							=			scope







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			ids_tensor([self.batch_size, self.seq_length]      ,	self.vocab_size   )

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

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

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

					lowerCAmelCase_      							=			self.get_config()

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







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					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      lowerCamelCase_     ( self      ,	UpperCAmelCase   ):

					'''simple docstring'''






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







				def      lowerCamelCase_     ( self      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			DebertaVaModel(config=UpperCAmelCase   )
					model.to(UpperCAmelCase   )
					model.eval()
					lowerCAmelCase_      							=			model(UpperCAmelCase      ,	attention_mask=UpperCAmelCase      ,	token_type_ids=UpperCAmelCase   )[0]
					lowerCAmelCase_      							=			model(UpperCAmelCase      ,	token_type_ids=UpperCAmelCase   )[0]
					lowerCAmelCase_      							=			model(UpperCAmelCase   )[0]

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







				def      lowerCamelCase_     ( self      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			DebertaVaForMaskedLM(config=UpperCAmelCase   )
					model.to(UpperCAmelCase   )
					model.eval()
					lowerCAmelCase_      							=			model(UpperCAmelCase      ,	attention_mask=UpperCAmelCase      ,	token_type_ids=UpperCAmelCase      ,	labels=UpperCAmelCase   )

					self.parent.assertEqual(result.logits.shape      ,	(self.batch_size, self.seq_length, self.vocab_size)   )







				def      lowerCamelCase_     ( self      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			self.num_labels
					lowerCAmelCase_      							=			DebertaVaForSequenceClassification(UpperCAmelCase   )
					model.to(UpperCAmelCase   )
					model.eval()
					lowerCAmelCase_      							=			model(UpperCAmelCase      ,	attention_mask=UpperCAmelCase      ,	token_type_ids=UpperCAmelCase      ,	labels=UpperCAmelCase   )
					self.parent.assertListEqual(list(result.logits.size()   )      ,	[self.batch_size, self.num_labels]   )
					self.check_loss_output(UpperCAmelCase   )







				def      lowerCamelCase_     ( self      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			self.num_labels
					lowerCAmelCase_      							=			DebertaVaForTokenClassification(config=UpperCAmelCase   )
					model.to(UpperCAmelCase   )
					model.eval()
					lowerCAmelCase_      							=			model(UpperCAmelCase      ,	attention_mask=UpperCAmelCase      ,	token_type_ids=UpperCAmelCase      ,	labels=UpperCAmelCase   )
					self.parent.assertEqual(result.logits.shape      ,	(self.batch_size, self.seq_length, self.num_labels)   )







				def      lowerCamelCase_     ( self      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			DebertaVaForQuestionAnswering(config=UpperCAmelCase   )
					model.to(UpperCAmelCase   )
					model.eval()
					lowerCAmelCase_      							=			model(
					    UpperCAmelCase      ,	attention_mask=UpperCAmelCase      ,	token_type_ids=UpperCAmelCase      ,	start_positions=UpperCAmelCase      ,	end_positions=UpperCAmelCase      ,	)
					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      lowerCamelCase_     ( self      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			DebertaVaForMultipleChoice(config=UpperCAmelCase   )
					model.to(UpperCAmelCase   )
					model.eval()
					lowerCAmelCase_      							=			input_ids.unsqueeze(1   ).expand(-1      ,	self.num_choices      ,	-1   ).contiguous()
					lowerCAmelCase_      							=			token_type_ids.unsqueeze(1   ).expand(-1      ,	self.num_choices      ,	-1   ).contiguous()
					lowerCAmelCase_      							=			input_mask.unsqueeze(1   ).expand(-1      ,	self.num_choices      ,	-1   ).contiguous()
					lowerCAmelCase_      							=			model(
					    UpperCAmelCase      ,	attention_mask=UpperCAmelCase      ,	token_type_ids=UpperCAmelCase      ,	labels=UpperCAmelCase      ,	)
					self.parent.assertEqual(result.logits.shape      ,	(self.batch_size, self.num_choices)   )







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






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







@require_torch
class    __a						( __snake_case					,			__snake_case					,			unittest.TestCase							):
				lowerCamelCase     :       Tuple			       =(
				    (
				        DebertaVaModel,
				        DebertaVaForMaskedLM,
				        DebertaVaForSequenceClassification,
				        DebertaVaForTokenClassification,
				        DebertaVaForQuestionAnswering,
				        DebertaVaForMultipleChoice,
				    )
				    if is_torch_available()
				    else ()
				)
				lowerCamelCase     :       Dict			       =(
				    {
				        'feature-extraction': DebertaVaModel,
				        'fill-mask': DebertaVaForMaskedLM,
				        'question-answering': DebertaVaForQuestionAnswering,
				        'text-classification': DebertaVaForSequenceClassification,
				        'token-classification': DebertaVaForTokenClassification,
				        'zero-shot': DebertaVaForSequenceClassification,
				    }
				    if is_torch_available()
				    else {}
				)

				lowerCamelCase     :       Any			       =True
				lowerCamelCase     :       int			       =False
				lowerCamelCase     :       Optional[int]			       =False
				lowerCamelCase     :       Optional[Any]			       =False
				lowerCamelCase     :       str			       =False







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			DebertaVaModelTester(self   )
					lowerCAmelCase_      							=			ConfigTester(self      ,	config_class=UpperCAmelCase      ,	hidden_size=37   )







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					self.config_tester.run_common_tests()







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_deberta_model(*UpperCAmelCase   )







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_deberta_for_sequence_classification(*UpperCAmelCase   )







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_deberta_for_masked_lm(*UpperCAmelCase   )







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_deberta_for_question_answering(*UpperCAmelCase   )







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_deberta_for_token_classification(*UpperCAmelCase   )







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_deberta_for_multiple_choice(*UpperCAmelCase   )







				@slow
				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					for model_name in DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
						lowerCAmelCase_      							=			DebertaVaModel.from_pretrained(UpperCAmelCase   )
						self.assertIsNotNone(UpperCAmelCase   )







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







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

					'''simple docstring'''






					pass







				@slow
				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			DebertaVaModel.from_pretrained('''microsoft/deberta-v2-xlarge'''   )

					lowerCAmelCase_      							=			torch.tensor([[0, 3_1414, 232, 328, 740, 1140, 1_2695, 69, 4_6078, 1588, 2]]   )
					lowerCAmelCase_      							=			torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]   )
					with torch.no_grad():
						lowerCAmelCase_      							=			model(UpperCAmelCase      ,	attention_mask=UpperCAmelCase   )[0]
					# compare the actual values for a slice.
					lowerCAmelCase_      							=			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]      ,	UpperCAmelCase      ,	atol=1E-4   )      ,	F"""{output[:, 1:4, 1:4]}"""   )



"""simple docstring"""



from diffusers.utils.testing_utils import require_onnxruntime







@require_onnxruntime
class    __a						:
				pass