

"""simple docstring"""




import unittest

from transformers import DebertaVaConfig, 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 (
						    DebertaVaForMaskedLM,
						    DebertaVaForMultipleChoice,
						    DebertaVaForQuestionAnswering,
						    DebertaVaForSequenceClassification,
						    DebertaVaForTokenClassification,
						    DebertaVaModel,
						)
						from transformers.models.deberta_va.modeling_deberta_va import DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST





class  lowerCamelCase    (A__      ):

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

			def        SCREAMING_SNAKE_CASE					(       self					:    str							) ->     Optional[Any]:
						SCREAMING_SNAKE_CASE__										=   ids_tensor([self.batch_size, self.seq_length]     ,					self.vocab_size							)

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

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

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

						SCREAMING_SNAKE_CASE__										=   self.get_config()

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

			def        SCREAMING_SNAKE_CASE					(       self					:    Any							) ->     List[Any]:
						return DebertaVaConfig(
						    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        SCREAMING_SNAKE_CASE					(       self					:    Optional[int]     ,					__UpperCAmelCase					:    Union[str, Any]							) ->     Dict:
						self.parent.assertListEqual(list(result.loss.size()							)     ,					[]							)

			def        SCREAMING_SNAKE_CASE					(       self					:    str     ,					__UpperCAmelCase					:    Optional[int]     ,					__UpperCAmelCase					:    Optional[Any]     ,					__UpperCAmelCase					:    Optional[Any]     ,					__UpperCAmelCase					:    Any     ,					__UpperCAmelCase					:    List[str]     ,					__UpperCAmelCase					:    Optional[Any]     ,					__UpperCAmelCase					:    Optional[int]							) ->     Tuple:
						SCREAMING_SNAKE_CASE__										=   DebertaVaModel(config=__UpperCAmelCase							)
						model.to(__UpperCAmelCase							)
						model.eval()
						SCREAMING_SNAKE_CASE__										=   model(__UpperCAmelCase     ,					attention_mask=__UpperCAmelCase     ,					token_type_ids=__UpperCAmelCase							)[0]
						SCREAMING_SNAKE_CASE__										=   model(__UpperCAmelCase     ,					token_type_ids=__UpperCAmelCase							)[0]
						SCREAMING_SNAKE_CASE__										=   model(__UpperCAmelCase							)[0]

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

			def        SCREAMING_SNAKE_CASE					(       self					:    str     ,					__UpperCAmelCase					:    Optional[int]     ,					__UpperCAmelCase					:    str     ,					__UpperCAmelCase					:    int     ,					__UpperCAmelCase					:    Optional[int]     ,					__UpperCAmelCase					:    Dict     ,					__UpperCAmelCase					:    Optional[int]     ,					__UpperCAmelCase					:    Optional[Any]							) ->     Optional[int]:
						SCREAMING_SNAKE_CASE__										=   DebertaVaForMaskedLM(config=__UpperCAmelCase							)
						model.to(__UpperCAmelCase							)
						model.eval()
						SCREAMING_SNAKE_CASE__										=   model(__UpperCAmelCase     ,					attention_mask=__UpperCAmelCase     ,					token_type_ids=__UpperCAmelCase     ,					labels=__UpperCAmelCase							)

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

			def        SCREAMING_SNAKE_CASE					(       self					:    Any     ,					__UpperCAmelCase					:    Tuple     ,					__UpperCAmelCase					:    int     ,					__UpperCAmelCase					:    List[Any]     ,					__UpperCAmelCase					:    List[Any]     ,					__UpperCAmelCase					:    str     ,					__UpperCAmelCase					:    List[Any]     ,					__UpperCAmelCase					:    Any							) ->     Dict:
						SCREAMING_SNAKE_CASE__										=   self.num_labels
						SCREAMING_SNAKE_CASE__										=   DebertaVaForSequenceClassification(__UpperCAmelCase							)
						model.to(__UpperCAmelCase							)
						model.eval()
						SCREAMING_SNAKE_CASE__										=   model(__UpperCAmelCase     ,					attention_mask=__UpperCAmelCase     ,					token_type_ids=__UpperCAmelCase     ,					labels=__UpperCAmelCase							)
						self.parent.assertListEqual(list(result.logits.size()							)     ,					[self.batch_size, self.num_labels]							)
						self.check_loss_output(__UpperCAmelCase							)

			def        SCREAMING_SNAKE_CASE					(       self					:    List[str]     ,					__UpperCAmelCase					:    List[Any]     ,					__UpperCAmelCase					:    Union[str, Any]     ,					__UpperCAmelCase					:    Any     ,					__UpperCAmelCase					:    Any     ,					__UpperCAmelCase					:    Optional[int]     ,					__UpperCAmelCase					:    Union[str, Any]     ,					__UpperCAmelCase					:    Any							) ->     Union[str, Any]:
						SCREAMING_SNAKE_CASE__										=   self.num_labels
						SCREAMING_SNAKE_CASE__										=   DebertaVaForTokenClassification(config=__UpperCAmelCase							)
						model.to(__UpperCAmelCase							)
						model.eval()
						SCREAMING_SNAKE_CASE__										=   model(__UpperCAmelCase     ,					attention_mask=__UpperCAmelCase     ,					token_type_ids=__UpperCAmelCase     ,					labels=__UpperCAmelCase							)
						self.parent.assertEqual(result.logits.shape     ,					(self.batch_size, self.seq_length, self.num_labels)							)

			def        SCREAMING_SNAKE_CASE					(       self					:    Union[str, Any]     ,					__UpperCAmelCase					:    Dict     ,					__UpperCAmelCase					:    List[str]     ,					__UpperCAmelCase					:    Dict     ,					__UpperCAmelCase					:    Any     ,					__UpperCAmelCase					:    Optional[Any]     ,					__UpperCAmelCase					:    List[Any]     ,					__UpperCAmelCase					:    List[str]							) ->     Tuple:
						SCREAMING_SNAKE_CASE__										=   DebertaVaForQuestionAnswering(config=__UpperCAmelCase							)
						model.to(__UpperCAmelCase							)
						model.eval()
						SCREAMING_SNAKE_CASE__										=   model(
						    __UpperCAmelCase     ,					attention_mask=__UpperCAmelCase     ,					token_type_ids=__UpperCAmelCase     ,					start_positions=__UpperCAmelCase     ,					end_positions=__UpperCAmelCase     ,					)
						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        SCREAMING_SNAKE_CASE					(       self					:    Any     ,					__UpperCAmelCase					:    Dict     ,					__UpperCAmelCase					:    List[str]     ,					__UpperCAmelCase					:    str     ,					__UpperCAmelCase					:    Optional[Any]     ,					__UpperCAmelCase					:    List[str]     ,					__UpperCAmelCase					:    Union[str, Any]     ,					__UpperCAmelCase					:    Union[str, Any]							) ->     Any:
						SCREAMING_SNAKE_CASE__										=   DebertaVaForMultipleChoice(config=__UpperCAmelCase							)
						model.to(__UpperCAmelCase							)
						model.eval()
						SCREAMING_SNAKE_CASE__										=   input_ids.unsqueeze(1							).expand(-1     ,					self.num_choices     ,					-1							).contiguous()
						SCREAMING_SNAKE_CASE__										=   token_type_ids.unsqueeze(1							).expand(-1     ,					self.num_choices     ,					-1							).contiguous()
						SCREAMING_SNAKE_CASE__										=   input_mask.unsqueeze(1							).expand(-1     ,					self.num_choices     ,					-1							).contiguous()
						SCREAMING_SNAKE_CASE__										=   model(
						    __UpperCAmelCase     ,					attention_mask=__UpperCAmelCase     ,					token_type_ids=__UpperCAmelCase     ,					labels=__UpperCAmelCase     ,					)
						self.parent.assertEqual(result.logits.shape     ,					(self.batch_size, self.num_choices)							)





			def        SCREAMING_SNAKE_CASE					(       self					:    List[Any]							) ->     List[Any]:
						SCREAMING_SNAKE_CASE__										=   self.prepare_config_and_inputs()
						(
						    (
						    SCREAMING_SNAKE_CASE__
						)				,		(
						    SCREAMING_SNAKE_CASE__
						)				,		(
						    SCREAMING_SNAKE_CASE__
						)				,		(
						    SCREAMING_SNAKE_CASE__
						)				,		(
						    SCREAMING_SNAKE_CASE__
						)				,		(
						    SCREAMING_SNAKE_CASE__
						)				,		(
						    SCREAMING_SNAKE_CASE__
						)				,		
						)										=   config_and_inputs
						SCREAMING_SNAKE_CASE__										=   {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
						return config, inputs_dict





@require_torch
class  lowerCamelCase    (A__      ,A__      ,unittest.TestCase      ):
			lowerCamelCase__ :		List[str]       		=				(
			    (
			        DebertaVaModel,
			        DebertaVaForMaskedLM,
			        DebertaVaForSequenceClassification,
			        DebertaVaForTokenClassification,
			        DebertaVaForQuestionAnswering,
			        DebertaVaForMultipleChoice,
			    )
			    if is_torch_available()
			    else ()
			)
			lowerCamelCase__ :		Dict       		=				(
			    {
			        'feature-extraction': DebertaVaModel,
			        'fill-mask': DebertaVaForMaskedLM,
			        'question-answering': DebertaVaForQuestionAnswering,
			        'text-classification': DebertaVaForSequenceClassification,
			        'token-classification': DebertaVaForTokenClassification,
			        'zero-shot': DebertaVaForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)

			lowerCamelCase__ :		Dict       		=				True
			lowerCamelCase__ :		Any       		=				False
			lowerCamelCase__ :		Dict       		=				False
			lowerCamelCase__ :		Dict       		=				False
			lowerCamelCase__ :		Any       		=				False

			def        SCREAMING_SNAKE_CASE					(       self					:    Tuple							) ->     int:
						SCREAMING_SNAKE_CASE__										=   DebertaVaModelTester(self							)
						SCREAMING_SNAKE_CASE__										=   ConfigTester(self     ,					config_class=__UpperCAmelCase     ,					hidden_size=3_7							)

			def        SCREAMING_SNAKE_CASE					(       self					:    List[str]							) ->     Optional[int]:
						self.config_tester.run_common_tests()

			def        SCREAMING_SNAKE_CASE					(       self					:    List[str]							) ->     Union[str, Any]:
						SCREAMING_SNAKE_CASE__										=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_model(*__UpperCAmelCase							)

			def        SCREAMING_SNAKE_CASE					(       self					:    Dict							) ->     str:
						SCREAMING_SNAKE_CASE__										=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_sequence_classification(*__UpperCAmelCase							)

			def        SCREAMING_SNAKE_CASE					(       self					:    Optional[int]							) ->     int:
						SCREAMING_SNAKE_CASE__										=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_masked_lm(*__UpperCAmelCase							)

			def        SCREAMING_SNAKE_CASE					(       self					:    List[str]							) ->     Tuple:
						SCREAMING_SNAKE_CASE__										=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_question_answering(*__UpperCAmelCase							)

			def        SCREAMING_SNAKE_CASE					(       self					:    str							) ->     Tuple:
						SCREAMING_SNAKE_CASE__										=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_token_classification(*__UpperCAmelCase							)

			def        SCREAMING_SNAKE_CASE					(       self					:    Union[str, Any]							) ->     int:
						SCREAMING_SNAKE_CASE__										=   self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_multiple_choice(*__UpperCAmelCase							)





			@slow
			def        SCREAMING_SNAKE_CASE					(       self					:    Optional[Any]							) ->     List[Any]:
						for model_name in DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									SCREAMING_SNAKE_CASE__										=   DebertaVaModel.from_pretrained(__UpperCAmelCase							)
									self.assertIsNotNone(__UpperCAmelCase							)





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

			@unittest.skip(reason="""Model not available yet"""							)
			def        SCREAMING_SNAKE_CASE					(       self					:    Any							) ->     Union[str, Any]:
						pass





			@slow
			def        SCREAMING_SNAKE_CASE					(       self					:    Optional[int]							) ->     Union[str, Any]:
						SCREAMING_SNAKE_CASE__										=   DebertaVaModel.from_pretrained("""microsoft/deberta-v2-xlarge"""							)

						SCREAMING_SNAKE_CASE__										=   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]]							)
						SCREAMING_SNAKE_CASE__										=   torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]							)
						with torch.no_grad():
									SCREAMING_SNAKE_CASE__										=   model(__UpperCAmelCase     ,					attention_mask=__UpperCAmelCase							)[0]
						# compare the actual values for a slice.
						SCREAMING_SNAKE_CASE__										=   torch.tensor(
						    [[[0.2_356, 0.1_948, 0.0_369], [-0.1_063, 0.3_586, -0.5_152], [-0.6_399, -0.0_259, -0.2_525]]]							)
						self.assertTrue(torch.allclose(output[:, 1:4, 1:4]     ,					__UpperCAmelCase     ,					atol=1e-4							)     ,					F"""{output[:, 1:4, 1:4]}"""							)





"""simple docstring"""




import logging
from dataclasses import dataclass, field
from typing import Optional

from seqaseq_trainer import arg_to_scheduler

from transformers import TrainingArguments


A_				:      Optional[Any]           =			logging.getLogger(__name__)





@dataclass
class  lowerCamelCase    (A__      ):
			lowerCamelCase__ :		Optional[float]       		=				field(
			    default=0.0      ,metadata={'help': 'The label smoothing epsilon to apply (if not zero).'}      )
			lowerCamelCase__ :		bool       		=				field(default=A__      ,metadata={'help': 'Whether to SortishSamler or not.'}      )
			lowerCamelCase__ :		bool       		=				field(
			    default=A__      ,metadata={'help': 'Whether to use generate to calculate generative metrics (ROUGE, BLEU).'}      )
			lowerCamelCase__ :		bool       		=				field(default=A__      ,metadata={'help': 'whether to use adafactor'}      )
			lowerCamelCase__ :		Optional[float]       		=				field(
			    default=A__      ,metadata={'help': 'Encoder layer dropout probability. Goes into model.config.'}      )
			lowerCamelCase__ :		Optional[float]       		=				field(
			    default=A__      ,metadata={'help': 'Decoder layer dropout probability. Goes into model.config.'}      )
			lowerCamelCase__ :		Optional[float]       		=				field(default=A__      ,metadata={'help': 'Dropout probability. Goes into model.config.'}      )
			lowerCamelCase__ :		Optional[float]       		=				field(
			    default=A__      ,metadata={'help': 'Attention dropout probability. Goes into model.config.'}      )
			lowerCamelCase__ :		Optional[str]       		=				field(
			    default='linear'      ,metadata={'help': f"Which lr scheduler to use. Selected in {sorted(arg_to_scheduler.keys()      )}"}      ,)


