





'''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 			lowerCamelCase					(						__UpperCAmelCase  ):


					def __init__(					self	:  Union[str, Any]       ,     __snake_case	:  Optional[Any]       ,     __snake_case	:  Union[str, Any]=13       ,     __snake_case	:  str=7       ,     __snake_case	:  List[str]=True       ,     __snake_case	:  Any=True       ,     __snake_case	:  str=True       ,     __snake_case	:  Optional[Any]=True       ,     __snake_case	:  str=99       ,     __snake_case	:  Optional[Any]=32       ,     __snake_case	:  Any=5       ,     __snake_case	:  Any=4       ,     __snake_case	:  int=37       ,     __snake_case	:  Dict="gelu"       ,     __snake_case	:  Optional[int]=0.1       ,     __snake_case	:  List[str]=0.1       ,     __snake_case	:  Any=5_12       ,     __snake_case	:  Union[str, Any]=16       ,     __snake_case	:  Tuple=2       ,     __snake_case	:  Dict=0.02       ,     __snake_case	:  List[Any]=False       ,     __snake_case	:  Optional[int]=True       ,     __snake_case	:  Dict="None"       ,     __snake_case	:  Optional[int]=3       ,     __snake_case	:  List[str]=4       ,     __snake_case	:  Any=None       ,     ):





											'''simple docstring'''





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


					def    SCREAMING_SNAKE_CASE_		(					self	:  Dict       ):





											'''simple docstring'''





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

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

											_snake_case:   int  					=		None
											if self.use_token_type_ids:
																	_snake_case:   List[Any]  					=		ids_tensor([self.batch_size, self.seq_length]       ,     self.type_vocab_size       )

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

											_snake_case:   Tuple  					=		self.get_config()

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


					def    SCREAMING_SNAKE_CASE_		(					self	:  int       ):





											'''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    SCREAMING_SNAKE_CASE_		(					self	:  Optional[Any]       ,     __snake_case	:  Any       ):





											'''simple docstring'''





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


					def    SCREAMING_SNAKE_CASE_		(					self	:  str       ,     __snake_case	:  Tuple       ,     __snake_case	:  Tuple       ,     __snake_case	:  List[str]       ,     __snake_case	:  int       ,     __snake_case	:  Optional[Any]       ,     __snake_case	:  Union[str, Any]       ,     __snake_case	:  List[Any]       ):





											'''simple docstring'''





											_snake_case:   Any  					=		DebertaVaModel(config=__snake_case       )
											model.to(__snake_case       )
											model.eval()
											_snake_case:   int  					=		model(__snake_case       ,     attention_mask=__snake_case       ,     token_type_ids=__snake_case       )[0]
											_snake_case:   List[Any]  					=		model(__snake_case       ,     token_type_ids=__snake_case       )[0]
											_snake_case:   Dict  					=		model(__snake_case       )[0]

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


					def    SCREAMING_SNAKE_CASE_		(					self	:  Optional[Any]       ,     __snake_case	:  Union[str, Any]       ,     __snake_case	:  Union[str, Any]       ,     __snake_case	:  Tuple       ,     __snake_case	:  Tuple       ,     __snake_case	:  str       ,     __snake_case	:  Optional[Any]       ,     __snake_case	:  int       ):





											'''simple docstring'''





											_snake_case:   int  					=		DebertaVaForMaskedLM(config=__snake_case       )
											model.to(__snake_case       )
											model.eval()
											_snake_case:   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    SCREAMING_SNAKE_CASE_		(					self	:  Tuple       ,     __snake_case	:  List[Any]       ,     __snake_case	:  int       ,     __snake_case	:  str       ,     __snake_case	:  int       ,     __snake_case	:  Tuple       ,     __snake_case	:  List[str]       ,     __snake_case	:  str       ):





											'''simple docstring'''





											_snake_case:   Union[str, Any]  					=		self.num_labels
											_snake_case:   str  					=		DebertaVaForSequenceClassification(__snake_case       )
											model.to(__snake_case       )
											model.eval()
											_snake_case:   str  					=		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    SCREAMING_SNAKE_CASE_		(					self	:  int       ,     __snake_case	:  Tuple       ,     __snake_case	:  List[str]       ,     __snake_case	:  Optional[int]       ,     __snake_case	:  Optional[Any]       ,     __snake_case	:  List[str]       ,     __snake_case	:  Optional[int]       ,     __snake_case	:  List[str]       ):





											'''simple docstring'''





											_snake_case:   Optional[int]  					=		self.num_labels
											_snake_case:   Optional[Any]  					=		DebertaVaForTokenClassification(config=__snake_case       )
											model.to(__snake_case       )
											model.eval()
											_snake_case:   Union[str, 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.num_labels)       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Any       ,     __snake_case	:  List[Any]       ,     __snake_case	:  Any       ,     __snake_case	:  Any       ,     __snake_case	:  Any       ,     __snake_case	:  List[str]       ,     __snake_case	:  Dict       ,     __snake_case	:  List[str]       ):





											'''simple docstring'''





											_snake_case:   Optional[int]  					=		DebertaVaForQuestionAnswering(config=__snake_case       )
											model.to(__snake_case       )
											model.eval()
											_snake_case:   Optional[int]  					=		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    SCREAMING_SNAKE_CASE_		(					self	:  Union[str, Any]       ,     __snake_case	:  Union[str, Any]       ,     __snake_case	:  Optional[int]       ,     __snake_case	:  List[Any]       ,     __snake_case	:  Tuple       ,     __snake_case	:  Optional[int]       ,     __snake_case	:  int       ,     __snake_case	:  Tuple       ):





											'''simple docstring'''





											_snake_case:   Any  					=		DebertaVaForMultipleChoice(config=__snake_case       )
											model.to(__snake_case       )
											model.eval()
											_snake_case:   Any  					=		input_ids.unsqueeze(1       ).expand(-1       ,     self.num_choices       ,     -1       ).contiguous()
											_snake_case:   List[Any]  					=		token_type_ids.unsqueeze(1       ).expand(-1       ,     self.num_choices       ,     -1       ).contiguous()
											_snake_case:   Union[str, Any]  					=		input_mask.unsqueeze(1       ).expand(-1       ,     self.num_choices       ,     -1       ).contiguous()
											_snake_case:   Tuple  					=		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    SCREAMING_SNAKE_CASE_		(					self	:  List[str]       ):





											'''simple docstring'''





											_snake_case:   Optional[Any]  					=		self.prepare_config_and_inputs()
											(
											    (
											    _snake_case
											)					,						(
											    _snake_case
											)					,						(
											    _snake_case
											)					,						(
											    _snake_case
											)					,						(
											    _snake_case
											)					,						(
											    _snake_case
											)					,						(
											    _snake_case
											)					,						
											):   int  					=		config_and_inputs
											_snake_case:   Any  					=		{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
											return config, inputs_dict







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

					_SCREAMING_SNAKE_CASE							   =    True
					_SCREAMING_SNAKE_CASE							   =    False
					_SCREAMING_SNAKE_CASE							   =    False
					_SCREAMING_SNAKE_CASE							   =    False
					_SCREAMING_SNAKE_CASE							   =    False


					def    SCREAMING_SNAKE_CASE_		(					self	:  Optional[Any]       ):





											'''simple docstring'''





											_snake_case:   List[str]  					=		DebertaVaModelTester(self       )
											_snake_case:   Union[str, Any]  					=		ConfigTester(self       ,     config_class=__snake_case       ,     hidden_size=37       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Tuple       ):





											'''simple docstring'''





											self.config_tester.run_common_tests()


					def    SCREAMING_SNAKE_CASE_		(					self	:  Dict       ):





											'''simple docstring'''





											_snake_case:   Union[str, Any]  					=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_deberta_model(*__snake_case       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Dict       ):





											'''simple docstring'''





											_snake_case:   str  					=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_deberta_for_sequence_classification(*__snake_case       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  List[Any]       ):





											'''simple docstring'''





											_snake_case:   Optional[int]  					=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_deberta_for_masked_lm(*__snake_case       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Union[str, Any]       ):





											'''simple docstring'''





											_snake_case:   int  					=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_deberta_for_question_answering(*__snake_case       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  str       ):





											'''simple docstring'''





											_snake_case:   Union[str, Any]  					=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_deberta_for_token_classification(*__snake_case       )


					def    SCREAMING_SNAKE_CASE_		(					self	:  Union[str, Any]       ):





											'''simple docstring'''





											_snake_case:   str  					=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_deberta_for_multiple_choice(*__snake_case       )




					@slow
					def    SCREAMING_SNAKE_CASE_		(					self	:  Optional[int]       ):





											'''simple docstring'''





											for model_name in DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	_snake_case:   int  					=		DebertaVaModel.from_pretrained(__snake_case       )
																	self.assertIsNotNone(__snake_case       )







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


					@unittest.skip(reason='Model not available yet'       )
					def    SCREAMING_SNAKE_CASE_		(					self	:  List[Any]       ):





											'''simple docstring'''





											pass




					@slow
					def    SCREAMING_SNAKE_CASE_		(					self	:  Optional[Any]       ):





											'''simple docstring'''





											_snake_case:   List[Any]  					=		DebertaVaModel.from_pretrained('microsoft/deberta-v2-xlarge'       )

											_snake_case:   Dict  					=		torch.tensor([[0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 4_60_78, 15_88, 2]]       )
											_snake_case:   str  					=		torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]       )
											with torch.no_grad():
																	_snake_case:   Any  					=		model(__snake_case       ,     attention_mask=__snake_case       )[0]
											# compare the actual values for a slice.
											_snake_case:   List[Any]  					=		torch.tensor(
											    [[[0.2_356, 0.1_948, 0.0_369], [-0.1_063, 0.3_586, -0.5_152], [-0.6_399, -0.0_259, -0.2_525]]]       )
											self.assertTrue(torch.allclose(output[:, 1:4, 1:4]       ,     __snake_case       ,     atol=1e-4       )       ,     f'''{output[:, 1:4, 1:4]}'''       )












'''simple docstring'''






def       lowercase_      (		lowercase__ = 50						)   ->int:
						_snake_case:   Union[str, Any]  					=		[[0] * 3 for _ in range(length + 1						)]

						for row_length in range(length + 1						):
												for tile_length in range(2				,  5						):
																		for tile_start in range(row_length - tile_length + 1						):
																								different_colour_ways_number[row_length][tile_length - 2] += (
																								    different_colour_ways_number[row_length - tile_start - tile_length][
																								        tile_length - 2
																								    ]
																								    + 1
																								)

						return sum(different_colour_ways_number[length]						)


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





