





'''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 				__SCREAMING_SNAKE_CASE  (lowerCamelCase_      ):






				"""simple docstring"""







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




				def   UpperCamelCase__   (  self     :					Optional[int]					):
								_a								= ids_tensor([self.batch_size, self.seq_length]					,				self.vocab_size					)

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

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

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

								_a								= self.get_config()

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




				def   UpperCamelCase__   (  self     :					Optional[int]					):
								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   UpperCamelCase__   (  self     :					Any					):
								_a								= self.get_config()
								_a								= 3_00
								return config




				def   UpperCamelCase__   (  self     :					List[str]					,				__a     :					Dict					):
								self.parent.assertListEqual(list(result.loss.size()					)					,				[]					)




				def   UpperCamelCase__   (  self     :					List[Any]					,				__a     :					int					,				__a     :					Dict					,				__a     :					Tuple					,				__a     :					str					,				__a     :					Union[str, Any]					,				__a     :					List[str]					,				__a     :					List[Any]					):
								_a								= DebertaModel(config=__a					)
								model.to(__a					)
								model.eval()
								_a								= model(__a					,				attention_mask=__a					,				token_type_ids=__a					)[0]
								_a								= model(__a					,				token_type_ids=__a					)[0]
								_a								= model(__a					)[0]

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




				def   UpperCamelCase__   (  self     :					str					,				__a     :					List[str]					,				__a     :					Optional[Any]					,				__a     :					Tuple					,				__a     :					List[Any]					,				__a     :					Dict					,				__a     :					Optional[Any]					,				__a     :					List[str]					):
								_a								= DebertaForMaskedLM(config=__a					)
								model.to(__a					)
								model.eval()
								_a								= 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     :					Optional[Any]					,				__a     :					int					,				__a     :					Optional[int]					,				__a     :					Dict					,				__a     :					int					,				__a     :					Optional[int]					,				__a     :					str					,				__a     :					Dict					):
								_a								= self.num_labels
								_a								= DebertaForSequenceClassification(__a					)
								model.to(__a					)
								model.eval()
								_a								= 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     :					List[str]					,				__a     :					int					,				__a     :					Dict					,				__a     :					Union[str, Any]					,				__a     :					Dict					,				__a     :					str					,				__a     :					Optional[Any]					,				__a     :					List[str]					):
								_a								= self.num_labels
								_a								= DebertaForTokenClassification(config=__a					)
								model.to(__a					)
								model.eval()
								_a								= 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     :					Optional[Any]					,				__a     :					List[Any]					,				__a     :					Dict					,				__a     :					List[str]					,				__a     :					Optional[int]					,				__a     :					Union[str, Any]					,				__a     :					int					,				__a     :					Optional[Any]					):
								_a								= DebertaForQuestionAnswering(config=__a					)
								model.to(__a					)
								model.eval()
								_a								= 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     :					List[str]					):
								_a								= self.prepare_config_and_inputs()
								(
								    (
								    _a
								)	,					(
								    _a
								)	,					(
								    _a
								)	,					(
								    _a
								)	,					(
								    _a
								)	,					(
								    _a
								)	,					(
								    _a
								)	,					
								)								= config_and_inputs
								_a								= {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
								return config, inputs_dict


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






				"""simple docstring"""







				__a            =(
				    (
				        DebertaModel,
				        DebertaForMaskedLM,
				        DebertaForSequenceClassification,
				        DebertaForTokenClassification,
				        DebertaForQuestionAnswering,
				    )
				    if is_torch_available()
				    else ()
				)
				__a            =(
				    {
				        'feature-extraction': DebertaModel,
				        'fill-mask': DebertaForMaskedLM,
				        'question-answering': DebertaForQuestionAnswering,
				        'text-classification': DebertaForSequenceClassification,
				        'token-classification': DebertaForTokenClassification,
				        'zero-shot': DebertaForSequenceClassification,
				    }
				    if is_torch_available()
				    else {}
				)

				__a            =True
				__a            =False
				__a            =False
				__a            =False
				__a            =False




				def   UpperCamelCase__   (  self     :					Tuple					):
								_a								= DebertaModelTester(self					)
								_a								= ConfigTester(self					,				config_class=__a					,				hidden_size=37					)




				def   UpperCamelCase__   (  self     :					Optional[int]					):
								self.config_tester.run_common_tests()




				def   UpperCamelCase__   (  self     :					str					):
								_a								= self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_model(*__a					)




				def   UpperCamelCase__   (  self     :					Any					):
								_a								= self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_sequence_classification(*__a					)




				def   UpperCamelCase__   (  self     :					List[str]					):
								_a								= self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_masked_lm(*__a					)




				def   UpperCamelCase__   (  self     :					List[Any]					):
								_a								= self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_question_answering(*__a					)




				def   UpperCamelCase__   (  self     :					Any					):
								_a								= self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_token_classification(*__a					)




				@slow
				def   UpperCamelCase__   (  self     :					List[str]					):
								for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
												_a								= DebertaModel.from_pretrained(__a					)
												self.assertIsNotNone(__a					)


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






				"""simple docstring"""







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




				@slow
				def   UpperCamelCase__   (  self     :					List[Any]					):
								_a								= DebertaModel.from_pretrained("microsoft/deberta-base"					)

								_a								= torch.tensor([[0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 4_60_78, 15_88, 2]]					)
								_a								= torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]					)
								with torch.no_grad():
												_a								= model(__a					,				attention_mask=__a					)[0]
								# compare the actual values for a slice.
								_a								= torch.tensor(
								    [[[-0.5986, -0.8055, -0.8462], [1.4484, -0.9348, -0.8059], [0.3123, 0.0032, -1.4131]]]					)
								self.assertTrue(torch.allclose(output[:, 1:4, 1:4]					,				__a					,				atol=1e-4					)					,				f'{output[:, 1:4, 1:4]}'					)




'''simple docstring'''

from __future__ import annotations

def _SCREAMING_SNAKE_CASE      (A       )       ->       bool:






       """simple docstring"""







       return len(set(A       )       ) == len(A       )


if __name__ == "__main__":
 import doctest

 doctest.testmod()




