

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


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


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

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

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

								UpperCAmelCase_		:      Optional[int]       	=					None
								UpperCAmelCase_		:      Any       	=					None
								UpperCAmelCase_		:      Optional[Any]       	=					None
								if self.use_labels:
									UpperCAmelCase_		:      Dict       	=					ids_tensor([self.batch_size]    ,			self.type_sequence_label_size)
									UpperCAmelCase_		:      str       	=					ids_tensor([self.batch_size, self.seq_length]    ,			self.num_labels)
									UpperCAmelCase_		:      Union[str, 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 						_snake_case							(			self)							->				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 						_snake_case							(			self)							->				Optional[Any]:
								UpperCAmelCase_		:      Tuple       	=					self.get_config()
								UpperCAmelCase_		:      List[str]       	=					300
								return config


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


							def 						_snake_case							(			self    ,			_snake_case    ,			_snake_case    ,			_snake_case    ,			_snake_case    ,			_snake_case    ,			_snake_case    ,			_snake_case)							->				Dict:
								UpperCAmelCase_		:      List[Any]       	=					DebertaModel(config=_snake_case)
								model.to(_snake_case)
								model.eval()
								UpperCAmelCase_		:      int       	=					model(_snake_case    ,			attention_mask=_snake_case    ,			token_type_ids=_snake_case)[0]
								UpperCAmelCase_		:      Optional[Any]       	=					model(_snake_case    ,			token_type_ids=_snake_case)[0]
								UpperCAmelCase_		:      Any       	=					model(_snake_case)[0]

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


							def 						_snake_case							(			self    ,			_snake_case    ,			_snake_case    ,			_snake_case    ,			_snake_case    ,			_snake_case    ,			_snake_case    ,			_snake_case)							->				List[Any]:
								UpperCAmelCase_		:      Tuple       	=					DebertaForMaskedLM(config=_snake_case)
								model.to(_snake_case)
								model.eval()
								UpperCAmelCase_		:      Union[str, Any]       	=					model(_snake_case    ,			attention_mask=_snake_case    ,			token_type_ids=_snake_case    ,			labels=_snake_case)

								self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.seq_length, self.vocab_size))


							def 						_snake_case							(			self    ,			_snake_case    ,			_snake_case    ,			_snake_case    ,			_snake_case    ,			_snake_case    ,			_snake_case    ,			_snake_case)							->				Optional[int]:
								UpperCAmelCase_		:      str       	=					self.num_labels
								UpperCAmelCase_		:      str       	=					DebertaForSequenceClassification(_snake_case)
								model.to(_snake_case)
								model.eval()
								UpperCAmelCase_		:      List[str]       	=					model(_snake_case    ,			attention_mask=_snake_case    ,			token_type_ids=_snake_case    ,			labels=_snake_case)
								self.parent.assertListEqual(list(result.logits.size())    ,			[self.batch_size, self.num_labels])
								self.check_loss_output(_snake_case)


							def 						_snake_case							(			self    ,			_snake_case    ,			_snake_case    ,			_snake_case    ,			_snake_case    ,			_snake_case    ,			_snake_case    ,			_snake_case)							->				int:
								UpperCAmelCase_		:      Optional[Any]       	=					self.num_labels
								UpperCAmelCase_		:      List[Any]       	=					DebertaForTokenClassification(config=_snake_case)
								model.to(_snake_case)
								model.eval()
								UpperCAmelCase_		:      int       	=					model(_snake_case    ,			attention_mask=_snake_case    ,			token_type_ids=_snake_case    ,			labels=_snake_case)
								self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.seq_length, self.num_labels))


							def 						_snake_case							(			self    ,			_snake_case    ,			_snake_case    ,			_snake_case    ,			_snake_case    ,			_snake_case    ,			_snake_case    ,			_snake_case)							->				Dict:
								UpperCAmelCase_		:      Union[str, Any]       	=					DebertaForQuestionAnswering(config=_snake_case)
								model.to(_snake_case)
								model.eval()
								UpperCAmelCase_		:      Optional[Any]       	=					model(
								    _snake_case    ,			attention_mask=_snake_case    ,			token_type_ids=_snake_case    ,			start_positions=_snake_case    ,			end_positions=_snake_case    ,			)
								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 						_snake_case							(			self)							->				Union[str, Any]:
								UpperCAmelCase_		:      List[str]       	=					self.prepare_config_and_inputs()
								(
								    (
								    UpperCAmelCase_
								)	,    (
								    UpperCAmelCase_
								)	,    (
								    UpperCAmelCase_
								)	,    (
								    UpperCAmelCase_
								)	,    (
								    UpperCAmelCase_
								)	,    (
								    UpperCAmelCase_
								)	,    (
								    UpperCAmelCase_
								)	,    
								)		:      Optional[Any]       	=					config_and_inputs
								UpperCAmelCase_		:      List[str]       	=					{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
								return config, inputs_dict



@require_torch
class 					lowercase						(  a_,					a_,					unittest.TestCase ):
							_lowerCamelCase		:      Optional[int]=   (
							    (
							        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		:      Optional[int]=   True
							_lowerCamelCase		:      List[str]=   False
							_lowerCamelCase		:      Union[str, Any]=   False
							_lowerCamelCase		:      Any=   False
							_lowerCamelCase		:      Optional[Any]=   False


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


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


							def 						_snake_case							(			self)							->				Any:
								UpperCAmelCase_		:      Tuple       	=					self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_model(*_snake_case)


							def 						_snake_case							(			self)							->				Optional[Any]:
								UpperCAmelCase_		:      Tuple       	=					self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_sequence_classification(*_snake_case)


							def 						_snake_case							(			self)							->				Any:
								UpperCAmelCase_		:      Dict       	=					self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_masked_lm(*_snake_case)


							def 						_snake_case							(			self)							->				Optional[Any]:
								UpperCAmelCase_		:      str       	=					self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_question_answering(*_snake_case)


							def 						_snake_case							(			self)							->				List[str]:
								UpperCAmelCase_		:      Tuple       	=					self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_token_classification(*_snake_case)





							@slow
							def 						_snake_case							(			self)							->				List[Any]:
								for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									UpperCAmelCase_		:      Tuple       	=					DebertaModel.from_pretrained(_snake_case)
									self.assertIsNotNone(_snake_case)



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


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





							@slow
							def 						_snake_case							(			self)							->				Any:
								UpperCAmelCase_		:      Union[str, Any]       	=					DebertaModel.from_pretrained('microsoft/deberta-base')

								UpperCAmelCase_		:      Union[str, Any]       	=					torch.tensor([[0, 3_1414, 232, 328, 740, 1140, 1_2695, 69, 4_6078, 1588, 2]])
								UpperCAmelCase_		:      List[str]       	=					torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
								with torch.no_grad():
									UpperCAmelCase_		:      Optional[Any]       	=					model(_snake_case    ,			attention_mask=_snake_case)[0]
								# compare the actual values for a slice.
								UpperCAmelCase_		:      Any       	=					torch.tensor(
								    [[[-0.5_986, -0.8_055, -0.8_462], [1.4_484, -0.9_348, -0.8_059], [0.3_123, 0.0_032, -1.4_131]]])
								self.assertTrue(torch.allclose(output[:, 1:4, 1:4]    ,			_snake_case    ,			atol=1e-4)    ,			F"""{output[:, 1:4, 1:4]}""")









'''simple docstring'''


from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


lowerCAmelCase__										= logging.get_logger(__name__)

lowerCAmelCase__										= {
    "facebook/xlm-roberta-xl": "https://huggingface.co/facebook/xlm-roberta-xl/resolve/main/config.json",
    "facebook/xlm-roberta-xxl": "https://huggingface.co/facebook/xlm-roberta-xxl/resolve/main/config.json",
    # See all XLM-RoBERTa-XL models at https://huggingface.co/models?filter=xlm-roberta-xl
}



class 					lowercase						(  a_ ):
							_lowerCamelCase		:      Any=   "xlm-roberta-xl"


							def __init__(			self    ,			_snake_case=25_0880    ,			_snake_case=2560    ,			_snake_case=36    ,			_snake_case=32    ,			_snake_case=1_0240    ,			_snake_case="gelu"    ,			_snake_case=0.1    ,			_snake_case=0.1    ,			_snake_case=514    ,			_snake_case=1    ,			_snake_case=0.02    ,			_snake_case=1e-05    ,			_snake_case=1    ,			_snake_case=0    ,			_snake_case=2    ,			_snake_case="absolute"    ,			_snake_case=True    ,			_snake_case=None    ,			**_snake_case    ,			)							->				Optional[Any]:
								super().__init__(pad_token_id=_snake_case    ,			bos_token_id=_snake_case    ,			eos_token_id=_snake_case    ,			**_snake_case)
								UpperCAmelCase_		:      List[str]       	=					vocab_size
								UpperCAmelCase_		:      int       	=					hidden_size
								UpperCAmelCase_		:      List[Any]       	=					num_hidden_layers
								UpperCAmelCase_		:      Optional[int]       	=					num_attention_heads
								UpperCAmelCase_		:      Union[str, Any]       	=					hidden_act
								UpperCAmelCase_		:      int       	=					intermediate_size
								UpperCAmelCase_		:      Tuple       	=					hidden_dropout_prob
								UpperCAmelCase_		:      List[str]       	=					attention_probs_dropout_prob
								UpperCAmelCase_		:      str       	=					max_position_embeddings
								UpperCAmelCase_		:      Union[str, Any]       	=					type_vocab_size
								UpperCAmelCase_		:      str       	=					initializer_range
								UpperCAmelCase_		:      List[str]       	=					layer_norm_eps
								UpperCAmelCase_		:      Dict       	=					position_embedding_type
								UpperCAmelCase_		:      int       	=					use_cache
								UpperCAmelCase_		:      List[Any]       	=					classifier_dropout



class 					lowercase						(  a_ ):


							@property
							def 						_snake_case							(			self)							->				Mapping[str, Mapping[int, str]]:
								if self.task == "multiple-choice":
									UpperCAmelCase_		:      Any       	=					{0: 'batch', 1: 'choice', 2: 'sequence'}
								else:
									UpperCAmelCase_		:      Optional[int]       	=					{0: 'batch', 1: 'sequence'}
								return OrderedDict(
								    [
								        ('input_ids', dynamic_axis),
								        ('attention_mask', dynamic_axis),
								    ])






