





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__				):






		'''simple docstring'''






		def __init__(							self,   snake_case__,   snake_case__=13,   snake_case__=7,   snake_case__=True,   snake_case__=True,   snake_case__=True,   snake_case__=True,   snake_case__=99,   snake_case__=32,   snake_case__=5,   snake_case__=4,   snake_case__=37,   snake_case__="gelu",   snake_case__=0.1,   snake_case__=0.1,   snake_case__=5_12,   snake_case__=16,   snake_case__=2,   snake_case__=0.02,   snake_case__=False,   snake_case__=True,   snake_case__="None",   snake_case__=3,   snake_case__=4,   snake_case__=None,   )       -> int:






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






		def 						snake_case__				(							self  )       -> Dict:






									"""simple docstring"""
									lowercase_	:   int  				=     ids_tensor([self.batch_size, self.seq_length],   self.vocab_size  )

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

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

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

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

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






		def 						snake_case__				(							self  )       -> str:






									"""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 						snake_case__				(							self,   snake_case__  )       -> Union[str, Any]:






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






		def 						snake_case__				(							self,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__  )       -> Any:






									"""simple docstring"""
									lowercase_	:   Tuple  				=     DebertaVaModel(config=snake_case__  )
									model.to(snake_case__  )
									model.eval()
									lowercase_	:   Any  				=     model(snake_case__,   attention_mask=snake_case__,   token_type_ids=snake_case__  )[0]
									lowercase_	:   Tuple  				=     model(snake_case__,   token_type_ids=snake_case__  )[0]
									lowercase_	:   str  				=     model(snake_case__  )[0]

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






		def 						snake_case__				(							self,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__  )       -> Optional[Any]:






									"""simple docstring"""
									lowercase_	:   Any  				=     DebertaVaForMaskedLM(config=snake_case__  )
									model.to(snake_case__  )
									model.eval()
									lowercase_	:   Any  				=     model(snake_case__,   attention_mask=snake_case__,   token_type_ids=snake_case__,   labels=snake_case__  )

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






		def 						snake_case__				(							self,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__  )       -> Optional[int]:






									"""simple docstring"""
									lowercase_	:   Optional[Any]  				=     self.num_labels
									lowercase_	:   Any  				=     DebertaVaForSequenceClassification(snake_case__  )
									model.to(snake_case__  )
									model.eval()
									lowercase_	:   Optional[Any]  				=     model(snake_case__,   attention_mask=snake_case__,   token_type_ids=snake_case__,   labels=snake_case__  )
									self.parent.assertListEqual(list(result.logits.size()  ),   [self.batch_size, self.num_labels]  )
									self.check_loss_output(snake_case__  )






		def 						snake_case__				(							self,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__  )       -> List[Any]:






									"""simple docstring"""
									lowercase_	:   Union[str, Any]  				=     self.num_labels
									lowercase_	:   Union[str, Any]  				=     DebertaVaForTokenClassification(config=snake_case__  )
									model.to(snake_case__  )
									model.eval()
									lowercase_	:   List[str]  				=     model(snake_case__,   attention_mask=snake_case__,   token_type_ids=snake_case__,   labels=snake_case__  )
									self.parent.assertEqual(result.logits.shape,   (self.batch_size, self.seq_length, self.num_labels)  )






		def 						snake_case__				(							self,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__  )       -> Dict:






									"""simple docstring"""
									lowercase_	:   Dict  				=     DebertaVaForQuestionAnswering(config=snake_case__  )
									model.to(snake_case__  )
									model.eval()
									lowercase_	:   List[str]  				=     model(
									    snake_case__,   attention_mask=snake_case__,   token_type_ids=snake_case__,   start_positions=snake_case__,   end_positions=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 						snake_case__				(							self,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__,   snake_case__  )       -> List[Any]:






									"""simple docstring"""
									lowercase_	:   Optional[Any]  				=     DebertaVaForMultipleChoice(config=snake_case__  )
									model.to(snake_case__  )
									model.eval()
									lowercase_	:   List[str]  				=     input_ids.unsqueeze(1  ).expand(-1,   self.num_choices,   -1  ).contiguous()
									lowercase_	:   str  				=     token_type_ids.unsqueeze(1  ).expand(-1,   self.num_choices,   -1  ).contiguous()
									lowercase_	:   Optional[Any]  				=     input_mask.unsqueeze(1  ).expand(-1,   self.num_choices,   -1  ).contiguous()
									lowercase_	:   Optional[int]  				=     model(
									    snake_case__,   attention_mask=snake_case__,   token_type_ids=snake_case__,   labels=snake_case__,   )
									self.parent.assertEqual(result.logits.shape,   (self.batch_size, self.num_choices)  )






		def 						snake_case__				(							self  )       -> List[Any]:






									"""simple docstring"""
									lowercase_	:   List[str]  				=     self.prepare_config_and_inputs()
									(
									    (
									    lowercase_
									)				,		(
									    lowercase_
									)				,		(
									    lowercase_
									)				,		(
									    lowercase_
									)				,		(
									    lowercase_
									)				,		(
									    lowercase_
									)				,		(
									    lowercase_
									)				,		
									)	:   Tuple  				=     config_and_inputs
									lowercase_	:   str  				=     {"""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				):






		'''simple docstring'''






		__a       :       Optional[Any]       =	(
		    (
		        DebertaVaModel,
		        DebertaVaForMaskedLM,
		        DebertaVaForSequenceClassification,
		        DebertaVaForTokenClassification,
		        DebertaVaForQuestionAnswering,
		        DebertaVaForMultipleChoice,
		    )
		    if is_torch_available()
		    else ()
		)
		__a       :       List[Any]       =	(
		    {
		        """feature-extraction""": DebertaVaModel,
		        """fill-mask""": DebertaVaForMaskedLM,
		        """question-answering""": DebertaVaForQuestionAnswering,
		        """text-classification""": DebertaVaForSequenceClassification,
		        """token-classification""": DebertaVaForTokenClassification,
		        """zero-shot""": DebertaVaForSequenceClassification,
		    }
		    if is_torch_available()
		    else {}
		)

		__a       :       Optional[int]       =	True
		__a       :       int       =	False
		__a       :       Optional[int]       =	False
		__a       :       Optional[Any]       =	False
		__a       :       List[str]       =	False






		def 						snake_case__				(							self  )       -> Optional[int]:






									"""simple docstring"""
									lowercase_	:   Optional[Any]  				=     DebertaVaModelTester(self  )
									lowercase_	:   Optional[int]  				=     ConfigTester(self,   config_class=snake_case__,   hidden_size=37  )






		def 						snake_case__				(							self  )       -> Any:






									"""simple docstring"""
									self.config_tester.run_common_tests()






		def 						snake_case__				(							self  )       -> Any:






									"""simple docstring"""
									lowercase_	:   Tuple  				=     self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_deberta_model(*snake_case__  )






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






									"""simple docstring"""
									lowercase_	:   Dict  				=     self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_deberta_for_sequence_classification(*snake_case__  )






		def 						snake_case__				(							self  )       -> Dict:






									"""simple docstring"""
									lowercase_	:   List[str]  				=     self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_deberta_for_masked_lm(*snake_case__  )






		def 						snake_case__				(							self  )       -> Any:






									"""simple docstring"""
									lowercase_	:   List[str]  				=     self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_deberta_for_question_answering(*snake_case__  )






		def 						snake_case__				(							self  )       -> Any:






									"""simple docstring"""
									lowercase_	:   List[str]  				=     self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_deberta_for_token_classification(*snake_case__  )






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






									"""simple docstring"""
									lowercase_	:   Tuple  				=     self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_deberta_for_multiple_choice(*snake_case__  )






		@slow
		def 						snake_case__				(							self  )       -> Optional[int]:






									"""simple docstring"""
									for model_name in DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																lowercase_	:   Any  				=     DebertaVaModel.from_pretrained(snake_case__  )
																self.assertIsNotNone(snake_case__  )




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






		'''simple docstring'''






		@unittest.skip(reason="""Model not available yet"""  )
		def 						snake_case__				(							self  )       -> Optional[Any]:






									"""simple docstring"""
									pass






		@slow
		def 						snake_case__				(							self  )       -> str:






									"""simple docstring"""
									lowercase_	:   Optional[int]  				=     DebertaVaModel.from_pretrained("""microsoft/deberta-v2-xlarge"""  )

									lowercase_	:   int  				=     torch.tensor([[0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 4_60_78, 15_88, 2]]  )
									lowercase_	:   Optional[int]  				=     torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]  )
									with torch.no_grad():
																lowercase_	:   Optional[Any]  				=     model(snake_case__,   attention_mask=snake_case__  )[0]
									# compare the actual values for a slice.
									lowercase_	:   int  				=     torch.tensor(
									    [[[0.2356, 0.1948, 0.0369], [-0.1063, 0.3586, -0.5152], [-0.6399, -0.0259, -0.2525]]]  )
									self.assertTrue(torch.allclose(output[:, 1:4, 1:4],   snake_case__,   atol=1E-4  ),   f"""{output[:, 1:4, 1:4]}"""  )






def  __magic_name__  (				lowercase = 100				)				-> int:

							"""simple docstring"""



							lowercase_	:   Dict  				=     (n * (n + 1) // 2) ** 2
							lowercase_	:   List[str]  				=     n * (n + 1) * (2 * n + 1) // 6
							return sum_cubes - sum_squares


if __name__ == "__main__":
							print(F'''{solution() = }''')