



'''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 						a_		(     snake_case    ):


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


							def    UpperCamelCase     (				self   :						Union[str, Any]			)			->					List[Any]:
										snake_case:    int      							=ids_tensor([self.batch_size, self.seq_length]      ,						self.vocab_size			)

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

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

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

										snake_case:    Tuple      							=self.get_config()

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


							def    UpperCamelCase     (				self   :						List[Any]			)			->					Tuple:
										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   :						Optional[Any]			)			->					Optional[Any]:
										snake_case:    Tuple      							=self.get_config()
										snake_case:    Any      							=3_0_0
										return config


							def    UpperCamelCase     (				self   :						List[str]      ,						a_   :						Optional[Any]			)			->					int:
										self.parent.assertListEqual(list(result.loss.size()			)      ,						[]			)


							def    UpperCamelCase     (				self   :						List[str]      ,						a_   :						Any      ,						a_   :						Tuple      ,						a_   :						Dict      ,						a_   :						int      ,						a_   :						Optional[Any]      ,						a_   :						Any      ,						a_   :						List[str]			)			->					List[Any]:
										snake_case:    List[str]      							=DebertaModel(config=a_			)
										model.to(a_			)
										model.eval()
										snake_case:    List[Any]      							=model(a_      ,						attention_mask=a_      ,						token_type_ids=a_			)[0]
										snake_case:    int      							=model(a_      ,						token_type_ids=a_			)[0]
										snake_case:    Any      							=model(a_			)[0]

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


							def    UpperCamelCase     (				self   :						Union[str, Any]      ,						a_   :						List[str]      ,						a_   :						Optional[Any]      ,						a_   :						List[str]      ,						a_   :						int      ,						a_   :						Union[str, Any]      ,						a_   :						List[Any]      ,						a_   :						Optional[int]			)			->					str:
										snake_case:    Tuple      							=DebertaForMaskedLM(config=a_			)
										model.to(a_			)
										model.eval()
										snake_case:    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    UpperCamelCase     (				self   :						Optional[Any]      ,						a_   :						int      ,						a_   :						Dict      ,						a_   :						int      ,						a_   :						Optional[Any]      ,						a_   :						Union[str, Any]      ,						a_   :						Union[str, Any]      ,						a_   :						Tuple			)			->					Any:
										snake_case:    str      							=self.num_labels
										snake_case:    Dict      							=DebertaForSequenceClassification(a_			)
										model.to(a_			)
										model.eval()
										snake_case:    int      							=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   :						Dict      ,						a_   :						int      ,						a_   :						Optional[Any]      ,						a_   :						Optional[Any]      ,						a_   :						Dict      ,						a_   :						List[Any]      ,						a_   :						Optional[Any]      ,						a_   :						Optional[Any]			)			->					str:
										snake_case:    Union[str, Any]      							=self.num_labels
										snake_case:    Dict      							=DebertaForTokenClassification(config=a_			)
										model.to(a_			)
										model.eval()
										snake_case:    Dict      							=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_   :						List[Any]      ,						a_   :						Tuple      ,						a_   :						Dict      ,						a_   :						str      ,						a_   :						Tuple      ,						a_   :						Tuple      ,						a_   :						str			)			->					Any:
										snake_case:    Dict      							=DebertaForQuestionAnswering(config=a_			)
										model.to(a_			)
										model.eval()
										snake_case:    Optional[Any]      							=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   :						int			)			->					Optional[Any]:
										snake_case:    int      							=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:    str      							={'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
										return config, inputs_dict






@require_torch
class 						a_		(     snake_case    ,   snake_case    ,   unittest.TestCase    ):
							UpperCAmelCase			:		Any        =				(
							    (
							        DebertaModel,
							        DebertaForMaskedLM,
							        DebertaForSequenceClassification,
							        DebertaForTokenClassification,
							        DebertaForQuestionAnswering,
							    )
							    if is_torch_available()
							    else ()
							)
							UpperCAmelCase			:		List[str]        =				(
							    {
							        """feature-extraction""": DebertaModel,
							        """fill-mask""": DebertaForMaskedLM,
							        """question-answering""": DebertaForQuestionAnswering,
							        """text-classification""": DebertaForSequenceClassification,
							        """token-classification""": DebertaForTokenClassification,
							        """zero-shot""": DebertaForSequenceClassification,
							    }
							    if is_torch_available()
							    else {}
							)

							UpperCAmelCase			:		List[Any]        =				True
							UpperCAmelCase			:		Any        =				False
							UpperCAmelCase			:		Dict        =				False
							UpperCAmelCase			:		Optional[int]        =				False
							UpperCAmelCase			:		str        =				False


							def    UpperCamelCase     (				self   :						Optional[int]			)			->					List[Any]:
										snake_case:    str      							=DebertaModelTester(self			)
										snake_case:    int      							=ConfigTester(self      ,						config_class=a_      ,						hidden_size=3_7			)


							def    UpperCamelCase     (				self   :						int			)			->					Tuple:
										self.config_tester.run_common_tests()


							def    UpperCamelCase     (				self   :						Dict			)			->					Union[str, Any]:
										snake_case:    Any      							=self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_deberta_model(*a_			)


							def    UpperCamelCase     (				self   :						List[Any]			)			->					str:
										snake_case:    List[str]      							=self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_deberta_for_sequence_classification(*a_			)


							def    UpperCamelCase     (				self   :						Tuple			)			->					str:
										snake_case:    Any      							=self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_deberta_for_masked_lm(*a_			)


							def    UpperCamelCase     (				self   :						List[Any]			)			->					str:
										snake_case:    Optional[Any]      							=self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_deberta_for_question_answering(*a_			)


							def    UpperCamelCase     (				self   :						str			)			->					Dict:
										snake_case:    List[str]      							=self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_deberta_for_token_classification(*a_			)




							@slow
							def    UpperCamelCase     (				self   :						Any			)			->					Tuple:
										for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													snake_case:    Dict      							=DebertaModel.from_pretrained(a_			)
													self.assertIsNotNone(a_			)






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


							@unittest.skip(reason='Model not available yet'			)
							def    UpperCamelCase     (				self   :						Any			)			->					Optional[int]:
										pass




							@slow
							def    UpperCamelCase     (				self   :						int			)			->					Dict:
										snake_case:    Any      							=DebertaModel.from_pretrained('microsoft/deberta-base'			)

										snake_case:    Optional[Any]      							=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]]			)
										snake_case:    Optional[int]      							=torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]			)
										with torch.no_grad():
													snake_case:    Optional[Any]      							=model(a_      ,						attention_mask=a_			)[0]
										# compare the actual values for a slice.
										snake_case:    int      							=torch.tensor(
										    [[[-0.5_9_8_6, -0.8_0_5_5, -0.8_4_6_2], [1.4_4_8_4, -0.9_3_4_8, -0.8_0_5_9], [0.3_1_2_3, 0.0_0_3_2, -1.4_1_3_1]]]			)
										self.assertTrue(torch.allclose(output[:, 1:4, 1:4]      ,						a_      ,						atol=1E-4			)      ,						F'''{output[:, 1:4, 1:4]}'''			)









'''simple docstring'''

from diffusers.utils.testing_utils import require_onnxruntime






@require_onnxruntime
class 						a_		:
							pass




