


"""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       (   _a			):







			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.02		,			UpperCamelCase__=False		,			UpperCamelCase__=True		,			UpperCamelCase__="None"		,			UpperCamelCase__=3		,			UpperCamelCase__=4		,			UpperCamelCase__=None		,			)			->	str:

							'''simple docstring'''




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







			def 				lowerCamelCase	(			self		)			->	Union[str, Any]:

							'''simple docstring'''




							snake_case					:   Tuple         =					ids_tensor([self.batch_size, self.seq_length]		,			self.vocab_size		)

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

							snake_case					:   Tuple         =					None
							if self.use_token_type_ids:
											snake_case					:   Optional[Any]         =					ids_tensor([self.batch_size, self.seq_length]		,			self.type_vocab_size		)

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

							snake_case					:   str         =					self.get_config()

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







			def 				lowerCamelCase	(			self		)			->	Tuple:

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

							'''simple docstring'''




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







			def 				lowerCamelCase	(			self		,			UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__		)			->	str:

							'''simple docstring'''




							snake_case					:   List[Any]         =					DebertaVaModel(config=snake_case_		)
							model.to(snake_case_		)
							model.eval()
							snake_case					:   List[Any]         =					model(snake_case_		,			attention_mask=snake_case_		,			token_type_ids=snake_case_		)[0]
							snake_case					:   List[str]         =					model(snake_case_		,			token_type_ids=snake_case_		)[0]
							snake_case					:   Any         =					model(snake_case_		)[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__		)			->	Optional[Any]:

							'''simple docstring'''




							snake_case					:   int         =					DebertaVaForMaskedLM(config=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.assertEqual(result.logits.shape		,			(self.batch_size, self.seq_length, self.vocab_size)		)







			def 				lowerCamelCase	(			self		,			UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__		)			->	Dict:

							'''simple docstring'''




							snake_case					:   Optional[Any]         =					self.num_labels
							snake_case					:   Tuple         =					DebertaVaForSequenceClassification(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.assertListEqual(list(result.logits.size()		)		,			[self.batch_size, self.num_labels]		)
							self.check_loss_output(snake_case_		)







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

							'''simple docstring'''




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

							'''simple docstring'''




							snake_case					:   Union[str, Any]         =					DebertaVaForQuestionAnswering(config=snake_case_		)
							model.to(snake_case_		)
							model.eval()
							snake_case					:   List[Any]         =					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 				lowerCamelCase	(			self		,			UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__		)			->	int:

							'''simple docstring'''




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







			def 				lowerCamelCase	(			self		)			->	Union[str, Any]:

							'''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						
							)      ,						
							)					:   Tuple         =					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       (   _a					,							_a					,							unittest.TestCase			):
			__UpperCAmelCase				: Any													=						(
			    (
			        DebertaVaModel,
			        DebertaVaForMaskedLM,
			        DebertaVaForSequenceClassification,
			        DebertaVaForTokenClassification,
			        DebertaVaForQuestionAnswering,
			        DebertaVaForMultipleChoice,
			    )
			    if is_torch_available()
			    else ()
			)
			__UpperCAmelCase				: Dict													=						(
			    {
			        """feature-extraction""": DebertaVaModel,
			        """fill-mask""": DebertaVaForMaskedLM,
			        """question-answering""": DebertaVaForQuestionAnswering,
			        """text-classification""": DebertaVaForSequenceClassification,
			        """token-classification""": DebertaVaForTokenClassification,
			        """zero-shot""": DebertaVaForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)

			__UpperCAmelCase				: Tuple													=						True
			__UpperCAmelCase				: Union[str, Any]													=						False
			__UpperCAmelCase				: Tuple													=						False
			__UpperCAmelCase				: Union[str, Any]													=						False
			__UpperCAmelCase				: Dict													=						False







			def 				lowerCamelCase	(			self		)			->	Any:

							'''simple docstring'''




							snake_case					:   Optional[Any]         =					DebertaVaModelTester(self		)
							snake_case					:   Union[str, Any]         =					ConfigTester(self		,			config_class=snake_case_		,			hidden_size=37		)







			def 				lowerCamelCase	(			self		)			->	Dict:

							'''simple docstring'''




							self.config_tester.run_common_tests()







			def 				lowerCamelCase	(			self		)			->	Tuple:

							'''simple docstring'''




							snake_case					:   Optional[int]         =					self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_deberta_model(*snake_case_		)







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

							'''simple docstring'''




							snake_case					:   List[Any]         =					self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_deberta_for_sequence_classification(*snake_case_		)







			def 				lowerCamelCase	(			self		)			->	Dict:

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

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

							'''simple docstring'''




							snake_case					:   int         =					self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_deberta_for_token_classification(*snake_case_		)







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

							'''simple docstring'''




							snake_case					:   int         =					self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_deberta_for_multiple_choice(*snake_case_		)







			@slow
			def 				lowerCamelCase	(			self		)			->	Dict:

							'''simple docstring'''




							for model_name in DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											snake_case					:   Union[str, Any]         =					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 				lowerCamelCase	(			self		)			->	Optional[Any]:

							'''simple docstring'''




							pass







			@slow
			def 				lowerCamelCase	(			self		)			->	Optional[Any]:

							'''simple docstring'''




							snake_case					:   List[str]         =					DebertaVaModel.from_pretrained("microsoft/deberta-v2-xlarge"		)

							snake_case					:   Any         =					torch.tensor([[0, 3_1414, 232, 328, 740, 1140, 1_2695, 69, 4_6078, 1588, 2]]		)
							snake_case					:   Optional[Any]         =					torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]		)
							with torch.no_grad():
											snake_case					:   str         =					model(snake_case_		,			attention_mask=snake_case_		)[0]
							# compare the actual values for a slice.
							snake_case					:   Optional[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]}'		)









"""simple docstring"""



# this script reports modified .py files under the desired list of top-level sub-dirs passed as a list of arguments, e.g.:
#   python ./utils/get_modified_files.py utils src tests examples
#
# it uses git to find the forking point and which files were modified - i.e. files not under git won't be considered
# since the output of this script is fed into Makefile commands it doesn't print a newline after the results

import re
import subprocess
import sys


__snake_case         =					subprocess.check_output("""git merge-base main HEAD""".split()).decode("""utf-8""")
__snake_case         =					(
    subprocess.check_output(F'''git diff --diff-filter=d --name-only {fork_point_sha}'''.split()).decode("""utf-8""").split()
)

__snake_case         =					"""|""".join(sys.argv[1:])
__snake_case         =					re.compile(RF'''^({joined_dirs}).*?\.py$''')

__snake_case         =					[x for x in modified_files if regex.match(x)]
print(""" """.join(relevant_modified_files), end="""""")





