





"""simple docstring"""


import unittest

from transformers import DebertaConfig, 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 (
		    DebertaForMaskedLM,
		    DebertaForQuestionAnswering,
		    DebertaForSequenceClassification,
		    DebertaForTokenClassification,
		    DebertaModel,
		)
		from transformers.models.deberta.modeling_deberta import DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST






class 							lowercase__			(   __SCREAMING_SNAKE_CASE	):

			"""simple docstring"""







			def __init__(      self						,   _A						,   _A=1_3						,   _A=7						,   _A=True						,   _A=True						,   _A=True						,   _A=True						,   _A=9_9						,   _A=3_2						,   _A=5						,   _A=4						,   _A=3_7						,   _A="gelu"						,   _A=0.1						,   _A=0.1						,   _A=5_1_2						,   _A=1_6						,   _A=2						,   _A=0.02						,   _A=False						,   _A=True						,   _A="None"						,   _A=3						,   _A=4						,   _A=None						,   ):






									'''simple docstring'''







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







			def   _a      (      self    ):






									'''simple docstring'''







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

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

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

									UpperCamelCase				:		Union[str, Any]				   =			None
									UpperCamelCase				:		int				   =			None
									UpperCamelCase				:		Optional[Any]				   =			None
									if self.use_labels:
															UpperCamelCase				:		Tuple				   =			ids_tensor([self.batch_size]						,   self.type_sequence_label_size    )
															UpperCamelCase				:		str				   =			ids_tensor([self.batch_size, self.seq_length]						,   self.num_labels    )
															UpperCamelCase				:		Dict				   =			ids_tensor([self.batch_size]						,   self.num_choices    )

									UpperCamelCase				:		int				   =			self.get_config()

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







			def   _a      (      self    ):






									'''simple docstring'''







									return DebertaConfig(
									    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   _a      (      self    ):






									'''simple docstring'''







									UpperCamelCase				:		Any				   =			self.get_config()
									UpperCamelCase				:		Union[str, Any]				   =			3_0_0
									return config







			def   _a      (      self						,   _A    ):






									'''simple docstring'''







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







			def   _a      (      self						,   _A						,   _A						,   _A						,   _A						,   _A						,   _A						,   _A    ):






									'''simple docstring'''







									UpperCamelCase				:		Union[str, Any]				   =			DebertaModel(config=_A    )
									model.to(_A    )
									model.eval()
									UpperCamelCase				:		Tuple				   =			model(_A						,   attention_mask=_A						,   token_type_ids=_A    )[0]
									UpperCamelCase				:		str				   =			model(_A						,   token_type_ids=_A    )[0]
									UpperCamelCase				:		Optional[Any]				   =			model(_A    )[0]

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







			def   _a      (      self						,   _A						,   _A						,   _A						,   _A						,   _A						,   _A						,   _A    ):






									'''simple docstring'''







									UpperCamelCase				:		Optional[int]				   =			DebertaForMaskedLM(config=_A    )
									model.to(_A    )
									model.eval()
									UpperCamelCase				:		int				   =			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   _a      (      self						,   _A						,   _A						,   _A						,   _A						,   _A						,   _A						,   _A    ):






									'''simple docstring'''







									UpperCamelCase				:		int				   =			self.num_labels
									UpperCamelCase				:		Union[str, Any]				   =			DebertaForSequenceClassification(_A    )
									model.to(_A    )
									model.eval()
									UpperCamelCase				:		Optional[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   _a      (      self						,   _A						,   _A						,   _A						,   _A						,   _A						,   _A						,   _A    ):






									'''simple docstring'''







									UpperCamelCase				:		List[Any]				   =			self.num_labels
									UpperCamelCase				:		Optional[int]				   =			DebertaForTokenClassification(config=_A    )
									model.to(_A    )
									model.eval()
									UpperCamelCase				:		Optional[Any]				   =			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   _a      (      self						,   _A						,   _A						,   _A						,   _A						,   _A						,   _A						,   _A    ):






									'''simple docstring'''







									UpperCamelCase				:		List[Any]				   =			DebertaForQuestionAnswering(config=_A    )
									model.to(_A    )
									model.eval()
									UpperCamelCase				:		Optional[int]				   =			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   _a      (      self    ):






									'''simple docstring'''







									UpperCamelCase				:		str				   =			self.prepare_config_and_inputs()
									(
									    (
									    UpperCamelCase
									)   ,						(
									    UpperCamelCase
									)   ,						(
									    UpperCamelCase
									)   ,						(
									    UpperCamelCase
									)   ,						(
									    UpperCamelCase
									)   ,						(
									    UpperCamelCase
									)   ,						(
									    UpperCamelCase
									)   ,						
									)				:		List[str]				   =			config_and_inputs
									UpperCamelCase				:		Any				   =			{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
									return config, inputs_dict






@require_torch
class 							lowercase__			(   __SCREAMING_SNAKE_CASE					,     __SCREAMING_SNAKE_CASE					,     unittest.TestCase	):

			"""simple docstring"""
			__lowerCAmelCase     :				Optional[Any]										=  (
			    (
			        DebertaModel,
			        DebertaForMaskedLM,
			        DebertaForSequenceClassification,
			        DebertaForTokenClassification,
			        DebertaForQuestionAnswering,
			    )
			    if is_torch_available()
			    else ()
			)
			__lowerCAmelCase     :				int										=  (
			    {
			        """feature-extraction""": DebertaModel,
			        """fill-mask""": DebertaForMaskedLM,
			        """question-answering""": DebertaForQuestionAnswering,
			        """text-classification""": DebertaForSequenceClassification,
			        """token-classification""": DebertaForTokenClassification,
			        """zero-shot""": DebertaForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)

			__lowerCAmelCase     :				Tuple										=  True
			__lowerCAmelCase     :				int										=  False
			__lowerCAmelCase     :				int										=  False
			__lowerCAmelCase     :				Optional[int]										=  False
			__lowerCAmelCase     :				Tuple										=  False







			def   _a      (      self    ):






									'''simple docstring'''







									UpperCamelCase				:		Optional[int]				   =			DebertaModelTester(self    )
									UpperCamelCase				:		Tuple				   =			ConfigTester(self						,   config_class=_A						,   hidden_size=3_7    )







			def   _a      (      self    ):






									'''simple docstring'''







									self.config_tester.run_common_tests()







			def   _a      (      self    ):






									'''simple docstring'''







									UpperCamelCase				:		Any				   =			self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_deberta_model(*_A    )







			def   _a      (      self    ):






									'''simple docstring'''







									UpperCamelCase				:		Optional[Any]				   =			self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_deberta_for_sequence_classification(*_A    )







			def   _a      (      self    ):






									'''simple docstring'''







									UpperCamelCase				:		Any				   =			self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_deberta_for_masked_lm(*_A    )







			def   _a      (      self    ):






									'''simple docstring'''







									UpperCamelCase				:		Dict				   =			self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_deberta_for_question_answering(*_A    )







			def   _a      (      self    ):






									'''simple docstring'''







									UpperCamelCase				:		Dict				   =			self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_deberta_for_token_classification(*_A    )







			@slow
			def   _a      (      self    ):






									'''simple docstring'''







									for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															UpperCamelCase				:		int				   =			DebertaModel.from_pretrained(_A    )
															self.assertIsNotNone(_A    )






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

			"""simple docstring"""







			@unittest.skip(reason="""Model not available yet"""    )
			def   _a      (      self    ):






									'''simple docstring'''







									pass







			@slow
			def   _a      (      self    ):






									'''simple docstring'''







									UpperCamelCase				:		Optional[int]				   =			DebertaModel.from_pretrained("""microsoft/deberta-base"""    )

									UpperCamelCase				:		Tuple				   =			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]]    )
									UpperCamelCase				:		Optional[int]				   =			torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]    )
									with torch.no_grad():
															UpperCamelCase				:		List[Any]				   =			model(_A						,   attention_mask=_A    )[0]
									# compare the actual values for a slice.
									UpperCamelCase				:		int				   =			torch.tensor(
									    [[[-0.59_86, -0.80_55, -0.84_62], [1.44_84, -0.93_48, -0.80_59], [0.31_23, 0.00_32, -1.41_31]]]    )
									self.assertTrue(torch.allclose(output[:, 1:4, 1:4]						,   _A						,   atol=1e-4    )						,   f"""{output[:, 1:4, 1:4]}"""    )










"""simple docstring"""


import os

def      UpperCamelCase							():
						UpperCamelCase				:		Union[str, Any]				   =			os.path.join(os.path.dirname(SCREAMING_SNAKE_CASE     )							,     """num.txt"""     )
						with open(SCREAMING_SNAKE_CASE     ) as file_hand:
												return str(sum(int(SCREAMING_SNAKE_CASE     ) for line in file_hand     )     )[:10]


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



