



'''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 	lowerCAmelCase_(    SCREAMING_SNAKE_CASE_					):
		'''simple docstring'''




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




		def 							UpperCAmelCase_     (   self				)   ->		Dict:
						lowerCAmelCase__			:  Optional[Any]											= ids_tensor([self.batch_size, self.seq_length]  ,self.vocab_size				)

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

						lowerCAmelCase__			:  List[str]											= None
						if self.use_token_type_ids:
										lowerCAmelCase__			:  List[Any]											= ids_tensor([self.batch_size, self.seq_length]  ,self.type_vocab_size				)

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

						lowerCAmelCase__			:  Optional[int]											= self.get_config()

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




		def 							UpperCAmelCase_     (   self				)   ->		Optional[Any]:
						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				)   ->		Union[str, Any]:
						lowerCAmelCase__			:  Optional[int]											= self.get_config()
						lowerCAmelCase__			:  Union[str, Any]											= 300
						return config




		def 							UpperCAmelCase_     (   self  ,__UpperCAmelCase				)   ->		Optional[Any]:
						self.parent.assertListEqual(list(result.loss.size()				)  ,[]				)




		def 							UpperCAmelCase_     (   self  ,__UpperCAmelCase  ,__UpperCAmelCase  ,__UpperCAmelCase  ,__UpperCAmelCase  ,__UpperCAmelCase  ,__UpperCAmelCase  ,__UpperCAmelCase				)   ->		str:
						lowerCAmelCase__			:  Union[str, Any]											= DebertaModel(config=_a				)
						model.to(_a				)
						model.eval()
						lowerCAmelCase__			:  Tuple											= model(_a  ,attention_mask=_a  ,token_type_ids=_a				)[0]
						lowerCAmelCase__			:  List[str]											= model(_a  ,token_type_ids=_a				)[0]
						lowerCAmelCase__			:  Union[str, Any]											= model(_a				)[0]

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




		def 							UpperCAmelCase_     (   self  ,__UpperCAmelCase  ,__UpperCAmelCase  ,__UpperCAmelCase  ,__UpperCAmelCase  ,__UpperCAmelCase  ,__UpperCAmelCase  ,__UpperCAmelCase				)   ->		Optional[Any]:
						lowerCAmelCase__			:  List[Any]											= DebertaForMaskedLM(config=_a				)
						model.to(_a				)
						model.eval()
						lowerCAmelCase__			:  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.vocab_size)				)




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







@require_torch
class 	lowerCAmelCase_(    SCREAMING_SNAKE_CASE_						,			SCREAMING_SNAKE_CASE_						,			unittest.TestCase					):
		'''simple docstring'''




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

		__lowercase							:				List[str]           =				True
		__lowercase							:				List[Any]           =				False
		__lowercase							:				Optional[Any]           =				False
		__lowercase							:				Any           =				False
		__lowercase							:				List[str]           =				False




		def 							UpperCAmelCase_     (   self				)   ->		Tuple:
						lowerCAmelCase__			:  List[str]											= DebertaModelTester(self				)
						lowerCAmelCase__			:  List[str]											= ConfigTester(self  ,config_class=_a  ,hidden_size=37				)




		def 							UpperCAmelCase_     (   self				)   ->		str:
						self.config_tester.run_common_tests()




		def 							UpperCAmelCase_     (   self				)   ->		Tuple:
						lowerCAmelCase__			:  Dict											= self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_model(*_a				)




		def 							UpperCAmelCase_     (   self				)   ->		Dict:
						lowerCAmelCase__			:  Dict											= self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_sequence_classification(*_a				)




		def 							UpperCAmelCase_     (   self				)   ->		Optional[Any]:
						lowerCAmelCase__			:  Any											= self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_masked_lm(*_a				)




		def 							UpperCAmelCase_     (   self				)   ->		Optional[int]:
						lowerCAmelCase__			:  Any											= self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_question_answering(*_a				)




		def 							UpperCAmelCase_     (   self				)   ->		Optional[Any]:
						lowerCAmelCase__			:  int											= self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_token_classification(*_a				)






		@slow
		def 							UpperCAmelCase_     (   self				)   ->		Dict:
						for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										lowerCAmelCase__			:  List[str]											= DebertaModel.from_pretrained(_a				)
										self.assertIsNotNone(_a				)







@require_torch
@require_sentencepiece
@require_tokenizers
class 	lowerCAmelCase_(    unittest.TestCase					):
		'''simple docstring'''




		@unittest.skip(reason="""Model not available yet"""				)
		def 							UpperCAmelCase_     (   self				)   ->		List[str]:
						pass






		@slow
		def 							UpperCAmelCase_     (   self				)   ->		Optional[int]:
						lowerCAmelCase__			:  str											= DebertaModel.from_pretrained("""microsoft/deberta-base"""				)

						lowerCAmelCase__			:  Optional[int]											= torch.tensor([[0, 3_1414, 232, 328, 740, 1140, 1_2695, 69, 4_6078, 1588, 2]]				)
						lowerCAmelCase__			:  List[str]											= torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]				)
						with torch.no_grad():
										lowerCAmelCase__			:  int											= model(_a  ,attention_mask=_a				)[0]
						# compare the actual values for a slice.
						lowerCAmelCase__			:  List[str]											= 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'''





_lowerCAmelCase										=     '''Input must be a string of 8 numbers plus letter'''
_lowerCAmelCase										=     '''TRWAGMYFPDXBNJZSQVHLCKE'''
def        _SCREAMING_SNAKE_CASE  (	UpperCamelCase      ):



    """simple docstring"""





    if not isinstance(UpperCamelCase							,   UpperCamelCase      ):
        lowerCAmelCase__			:  List[Any]											= f"""Expected string as input, found {type(UpperCamelCase      ).__name__}"""
        raise TypeError(UpperCamelCase      )

    lowerCAmelCase__			:  Union[str, Any]											= spanish_id.replace("""-"""							,   """"""      ).upper()
    if len(UpperCamelCase      ) != 9:
        raise ValueError(UpperCamelCase      )

    try:
        lowerCAmelCase__			:  Optional[int]											= int(spanish_id_clean[0:8]      )
        lowerCAmelCase__			:  int											= spanish_id_clean[8]
    except ValueError as ex:
        raise ValueError(UpperCamelCase      ) from ex

    if letter.isdigit():
        raise ValueError(UpperCamelCase      )

    return letter == LOOKUP_LETTERS[number % 23]


if __name__ == "__main__":
 import doctest

 doctest.testmod()


