



'''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_				(							__magic_name__    ):





	def __init__(						self	,	A	,	A=13	,	A=7	,	A=True	,	A=True	,	A=True	,	A=True	,	A=99	,	A=32	,	A=5	,	A=4	,	A=37	,	A="gelu"	,	A=0.1	,	A=0.1	,	A=512	,	A=16	,	A=2	,	A=0.0_2	,	A=False	,	A=True	,	A="None"	,	A=3	,	A=4	,	A=None	,	)    ->    str:
								UpperCAmelCase  :	Optional[int]							  =	parent
								UpperCAmelCase  :	List[Any]							  =	batch_size
								UpperCAmelCase  :	str							  =	seq_length
								UpperCAmelCase  :	List[Any]							  =	is_training
								UpperCAmelCase  :	Any							  =	use_input_mask
								UpperCAmelCase  :	Dict							  =	use_token_type_ids
								UpperCAmelCase  :	Dict							  =	use_labels
								UpperCAmelCase  :	str							  =	vocab_size
								UpperCAmelCase  :	str							  =	hidden_size
								UpperCAmelCase  :	Optional[Any]							  =	num_hidden_layers
								UpperCAmelCase  :	List[Any]							  =	num_attention_heads
								UpperCAmelCase  :	Optional[int]							  =	intermediate_size
								UpperCAmelCase  :	str							  =	hidden_act
								UpperCAmelCase  :	str							  =	hidden_dropout_prob
								UpperCAmelCase  :	int							  =	attention_probs_dropout_prob
								UpperCAmelCase  :	str							  =	max_position_embeddings
								UpperCAmelCase  :	Optional[Any]							  =	type_vocab_size
								UpperCAmelCase  :	List[Any]							  =	type_sequence_label_size
								UpperCAmelCase  :	Tuple							  =	initializer_range
								UpperCAmelCase  :	List[str]							  =	num_labels
								UpperCAmelCase  :	List[Any]							  =	num_choices
								UpperCAmelCase  :	Optional[Any]							  =	relative_attention
								UpperCAmelCase  :	int							  =	position_biased_input
								UpperCAmelCase  :	Union[str, Any]							  =	pos_att_type
								UpperCAmelCase  :	Tuple							  =	scope





	def 				_lowercase(						self					)    ->    List[Any]:
								UpperCAmelCase  :	Any							  =	ids_tensor([self.batch_size, self.seq_length]	,	self.vocab_size					)

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

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

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

								UpperCAmelCase  :	Dict							  =	self.get_config()

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





	def 				_lowercase(						self					)    ->    List[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 				_lowercase(						self	,	A					)    ->    List[str]:
								self.parent.assertListEqual(list(result.loss.size()					)	,	[]					)





	def 				_lowercase(						self	,	A	,	A	,	A	,	A	,	A	,	A	,	A					)    ->    List[Any]:
								UpperCAmelCase  :	Tuple							  =	DebertaVaModel(config=A					)
								model.to(A					)
								model.eval()
								UpperCAmelCase  :	Union[str, Any]							  =	model(A	,	attention_mask=A	,	token_type_ids=A					)[0]
								UpperCAmelCase  :	List[str]							  =	model(A	,	token_type_ids=A					)[0]
								UpperCAmelCase  :	Union[str, Any]							  =	model(A					)[0]

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





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






	def 				_lowercase(						self					)    ->    List[str]:
								UpperCAmelCase  :	Optional[Any]							  =	self.prepare_config_and_inputs()
								(
								    (
								    UpperCAmelCase
								)  ,  (
								    UpperCAmelCase
								)  ,  (
								    UpperCAmelCase
								)  ,  (
								    UpperCAmelCase
								)  ,  (
								    UpperCAmelCase
								)  ,  (
								    UpperCAmelCase
								)  ,  (
								    UpperCAmelCase
								)  ,  
								)  :	int							  =	config_and_inputs
								UpperCAmelCase  :	List[Any]							  =	{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
								return config, inputs_dict




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

	lowercase    =				True
	lowercase    =				False
	lowercase    =				False
	lowercase    =				False
	lowercase    =				False





	def 				_lowercase(						self					)    ->    str:
								UpperCAmelCase  :	Dict							  =	DebertaVaModelTester(self					)
								UpperCAmelCase  :	List[str]							  =	ConfigTester(self	,	config_class=A	,	hidden_size=37					)





	def 				_lowercase(						self					)    ->    List[str]:
								self.config_tester.run_common_tests()





	def 				_lowercase(						self					)    ->    Optional[int]:
								UpperCAmelCase  :	Union[str, Any]							  =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_model(*A					)





	def 				_lowercase(						self					)    ->    Optional[int]:
								UpperCAmelCase  :	Union[str, Any]							  =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_sequence_classification(*A					)





	def 				_lowercase(						self					)    ->    Optional[int]:
								UpperCAmelCase  :	Any							  =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_masked_lm(*A					)





	def 				_lowercase(						self					)    ->    Optional[Any]:
								UpperCAmelCase  :	List[str]							  =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_question_answering(*A					)





	def 				_lowercase(						self					)    ->    Optional[Any]:
								UpperCAmelCase  :	int							  =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_token_classification(*A					)





	def 				_lowercase(						self					)    ->    str:
								UpperCAmelCase  :	List[str]							  =	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_multiple_choice(*A					)






	@slow
	def 				_lowercase(						self					)    ->    Tuple:
								for model_name in DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															UpperCAmelCase  :	Tuple							  =	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 				_lowercase(						self					)    ->    List[str]:
								pass






	@slow
	def 				_lowercase(						self					)    ->    Dict:
								UpperCAmelCase  :	List[Any]							  =	DebertaVaModel.from_pretrained("""microsoft/deberta-v2-xlarge"""					)

								UpperCAmelCase  :	Union[str, Any]							  =	torch.tensor([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]]					)
								UpperCAmelCase  :	Optional[Any]							  =	torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]					)
								with torch.no_grad():
															UpperCAmelCase  :	Union[str, Any]							  =	model(A	,	attention_mask=A					)[0]
								# compare the actual values for a slice.
								UpperCAmelCase  :	List[str]							  =	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'''




def    __lowerCamelCase						(      _lowercase = "The quick brown fox jumps over the lazy dog"			,       )   ->    bool:
							UpperCAmelCase  :	Union[str, Any]							  =	set()

							# Replace all the whitespace in our sentence
							UpperCAmelCase  :	List[str]							  =	input_str.replace(""" """			,       """"""	)
							for alpha in input_str:
														if "a" <= alpha.lower() <= "z":
																					frequency.add(alpha.lower()	)
							return len(_lowercase	) == 2_6



def    __lowerCamelCase						(      _lowercase = "The quick brown fox jumps over the lazy dog"			,       )   ->    bool:
							UpperCAmelCase  :	Tuple							  =	[False] * 2_6
							for char in input_str:
														if char.islower():
																					UpperCAmelCase  :	Any							  =	True
														elif char.isupper():
																					UpperCAmelCase  :	Union[str, Any]							  =	True
							return all(_lowercase	)



def    __lowerCamelCase						(      _lowercase = "The quick brown fox jumps over the lazy dog"			,       )   ->    bool:
							return len({char for char in input_str.lower() if char.isalpha()}	) == 2_6



def    __lowerCamelCase						(      )   ->    None:
							from timeit import timeit

							UpperCAmelCase  :	str							  =	"""from __main__ import is_pangram, is_pangram_faster, is_pangram_fastest"""
							print(timeit("""is_pangram()"""			,       setup=_lowercase	)	)
							print(timeit("""is_pangram_faster()"""			,       setup=_lowercase	)	)
							print(timeit("""is_pangram_fastest()"""			,       setup=_lowercase	)	)
							# 5.348480500048026, 2.6477354579837993, 1.8470395830227062
							# 5.036091582966037, 2.644472333951853,  1.8869528750656173


if __name__ == "__main__":
							import doctest

							doctest.testmod()
							benchmark()

