





'''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       UpperCAmelCase (						_lowercase  ):




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




		def 				UpperCAmelCase__   (self      :	Tuple				)					-> Any:
						lowercase         = ids_tensor([self.batch_size, self.seq_length]							,			self.vocab_size				)

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

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

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

						lowercase         = self.get_config()

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




		def 				UpperCAmelCase__   (self      :	Optional[Any]				)					-> Union[str, 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 				UpperCAmelCase__   (self      :	Tuple							,			A__      :	Dict				)					-> List[Any]:
						self.parent.assertListEqual(list(result.loss.size()				)							,			[]				)




		def 				UpperCAmelCase__   (self      :	List[Any]							,			A__      :	Any							,			A__      :	List[Any]							,			A__      :	Tuple							,			A__      :	str							,			A__      :	List[Any]							,			A__      :	Union[str, Any]							,			A__      :	Any				)					-> Optional[Any]:
						lowercase         = DebertaVaModel(config=A__				)
						model.to(A__				)
						model.eval()
						lowercase         = model(A__							,			attention_mask=A__							,			token_type_ids=A__				)[0]
						lowercase         = model(A__							,			token_type_ids=A__				)[0]
						lowercase         = model(A__				)[0]

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




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





		def 				UpperCAmelCase__   (self      :	str				)					-> Tuple:
						lowercase         = self.prepare_config_and_inputs()
						(
						    (
						    lowercase
						)   ,							(
						    lowercase
						)   ,							(
						    lowercase
						)   ,							(
						    lowercase
						)   ,							(
						    lowercase
						)   ,							(
						    lowercase
						)   ,							(
						    lowercase
						)   ,							
						)         = config_and_inputs
						lowercase         = {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
						return config, inputs_dict




@require_torch
class       UpperCAmelCase (						_lowercase			,       _lowercase			,       unittest.TestCase  ):
		UpperCAmelCase					:	str 			=		(
		    (
		        DebertaVaModel,
		        DebertaVaForMaskedLM,
		        DebertaVaForSequenceClassification,
		        DebertaVaForTokenClassification,
		        DebertaVaForQuestionAnswering,
		        DebertaVaForMultipleChoice,
		    )
		    if is_torch_available()
		    else ()
		)
		UpperCAmelCase					:	Any 			=		(
		    {
		        '''feature-extraction''': DebertaVaModel,
		        '''fill-mask''': DebertaVaForMaskedLM,
		        '''question-answering''': DebertaVaForQuestionAnswering,
		        '''text-classification''': DebertaVaForSequenceClassification,
		        '''token-classification''': DebertaVaForTokenClassification,
		        '''zero-shot''': DebertaVaForSequenceClassification,
		    }
		    if is_torch_available()
		    else {}
		)

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




		def 				UpperCAmelCase__   (self      :	str				)					-> Optional[int]:
						lowercase         = DebertaVaModelTester(self				)
						lowercase         = ConfigTester(self							,			config_class=A__							,			hidden_size=3_7				)




		def 				UpperCAmelCase__   (self      :	Dict				)					-> Optional[Any]:
						self.config_tester.run_common_tests()




		def 				UpperCAmelCase__   (self      :	Union[str, Any]				)					-> int:
						lowercase         = self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_model(*A__				)




		def 				UpperCAmelCase__   (self      :	str				)					-> Any:
						lowercase         = self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_sequence_classification(*A__				)




		def 				UpperCAmelCase__   (self      :	Dict				)					-> Any:
						lowercase         = self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_masked_lm(*A__				)




		def 				UpperCAmelCase__   (self      :	Union[str, Any]				)					-> int:
						lowercase         = self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_question_answering(*A__				)




		def 				UpperCAmelCase__   (self      :	Union[str, Any]				)					-> int:
						lowercase         = self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_token_classification(*A__				)




		def 				UpperCAmelCase__   (self      :	Tuple				)					-> Union[str, Any]:
						lowercase         = self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_multiple_choice(*A__				)





		@slow
		def 				UpperCAmelCase__   (self      :	List[str]				)					-> Any:
						for model_name in DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										lowercase         = 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 				UpperCAmelCase__   (self      :	str				)					-> Union[str, Any]:
						pass





		@slow
		def 				UpperCAmelCase__   (self      :	List[Any]				)					-> List[str]:
						lowercase         = DebertaVaModel.from_pretrained("microsoft/deberta-v2-xlarge"				)

						lowercase         = 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]]				)
						lowercase         = torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]				)
						with torch.no_grad():
										lowercase         = model(A__							,			attention_mask=A__				)[0]
						# compare the actual values for a slice.
						lowercase         = 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]}'				)











'''simple docstring'''

from functools import lru_cache







def 							UpperCAmelCase_    (	lowerCAmelCase_							):

				"""simple docstring"""






				lowercase         = 2
				lowercase         = set()
				while i * i <= n:
								if n % i:
												i += 1
								else:
												n //= i
												factors.add(lowerCAmelCase_							)
				if n > 1:
								factors.add(lowerCAmelCase_							)
				return factors







@lru_cache
def 							UpperCAmelCase_    (	lowerCAmelCase_							):

				"""simple docstring"""






				return len(unique_prime_factors(lowerCAmelCase_							)							)







def 							UpperCAmelCase_    (	lowerCAmelCase_							):

				"""simple docstring"""






				return len(set(lowerCAmelCase_							)							) in (0, 1)







def 							UpperCAmelCase_    (	lowerCAmelCase_							):

				"""simple docstring"""






				lowercase         = 2

				while True:
								# Increment each value of a generated range
								lowercase         = [base + i for i in range(lowerCAmelCase_							)]

								# Run elements through out unique_prime_factors function
								# Append our target number to the end.
								lowercase         = [upf_len(lowerCAmelCase_							) for x in group]
								checker.append(lowerCAmelCase_							)

								# If all numbers in the list are equal, return the group variable.
								if equality(lowerCAmelCase_							):
												return group

								# Increment our base variable by 1
								base += 1







def 							UpperCAmelCase_    (	lowerCAmelCase_ = 4							):

				"""simple docstring"""






				lowercase         = run(lowerCAmelCase_							)
				return results[0] if len(lowerCAmelCase_							) else None


if __name__ == "__main__":
			print(solution())




