"""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      _UpperCAmelCase						( __SCREAMING_SNAKE_CASE						):






    """simple docstring"""







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







    def 				a__					(			self					)	->	Optional[int]:
        _lowerCamelCase	: int       =       ids_tensor([self.batch_size, self.seq_length]    , self.vocab_size					)

        _lowerCamelCase	: List[str]       =       None
        if self.use_input_mask:
            _lowerCamelCase	: Union[str, Any]       =       ids_tensor([self.batch_size, self.seq_length]    , vocab_size=2					)

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

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

        _lowerCamelCase	: str       =       self.get_config()

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







    def 				a__					(			self					)	->	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 				a__					(			self    , _lowercase					)	->	Dict:
        self.parent.assertListEqual(list(result.loss.size()					)    , []					)







    def 				a__					(			self    , _lowercase    , _lowercase    , _lowercase    , _lowercase    , _lowercase    , _lowercase    , _lowercase					)	->	Union[str, Any]:
        _lowerCamelCase	: str       =       DebertaVaModel(config=A_					)
        model.to(A_					)
        model.eval()
        _lowerCamelCase	: Any       =       model(A_    , attention_mask=A_    , token_type_ids=A_					)[0]
        _lowerCamelCase	: int       =       model(A_    , token_type_ids=A_					)[0]
        _lowerCamelCase	: Optional[int]       =       model(A_					)[0]

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







    def 				a__					(			self    , _lowercase    , _lowercase    , _lowercase    , _lowercase    , _lowercase    , _lowercase    , _lowercase					)	->	str:
        _lowerCamelCase	: Any       =       DebertaVaForMaskedLM(config=A_					)
        model.to(A_					)
        model.eval()
        _lowerCamelCase	: str       =       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 				a__					(			self    , _lowercase    , _lowercase    , _lowercase    , _lowercase    , _lowercase    , _lowercase    , _lowercase					)	->	int:
        _lowerCamelCase	: Any       =       self.num_labels
        _lowerCamelCase	: List[str]       =       DebertaVaForSequenceClassification(A_					)
        model.to(A_					)
        model.eval()
        _lowerCamelCase	: Optional[Any]       =       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 				a__					(			self    , _lowercase    , _lowercase    , _lowercase    , _lowercase    , _lowercase    , _lowercase    , _lowercase					)	->	int:
        _lowerCamelCase	: Tuple       =       self.num_labels
        _lowerCamelCase	: Optional[Any]       =       DebertaVaForTokenClassification(config=A_					)
        model.to(A_					)
        model.eval()
        _lowerCamelCase	: Optional[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.num_labels)					)







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







    def 				a__					(			self					)	->	List[Any]:
        _lowerCamelCase	: str       =       self.prepare_config_and_inputs()
        (
            (
            _lowerCamelCase		
        ),					(
            _lowerCamelCase		
        ),					(
            _lowerCamelCase		
        ),					(
            _lowerCamelCase		
        ),					(
            _lowerCamelCase		
        ),					(
            _lowerCamelCase		
        ),					(
            _lowerCamelCase		
        ),							
        )	: str       =       config_and_inputs
        _lowerCamelCase	: Any       =       {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
        return config, inputs_dict





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






    """simple docstring"""
    __snake_case    =       (
        (
            DebertaVaModel,
            DebertaVaForMaskedLM,
            DebertaVaForSequenceClassification,
            DebertaVaForTokenClassification,
            DebertaVaForQuestionAnswering,
            DebertaVaForMultipleChoice,
        )
        if is_torch_available()
        else ()
    )
    __snake_case    =       (
        {
            """feature-extraction""": DebertaVaModel,
            """fill-mask""": DebertaVaForMaskedLM,
            """question-answering""": DebertaVaForQuestionAnswering,
            """text-classification""": DebertaVaForSequenceClassification,
            """token-classification""": DebertaVaForTokenClassification,
            """zero-shot""": DebertaVaForSequenceClassification,
        }
        if is_torch_available()
        else {}
    )

    __snake_case    =       True
    __snake_case    =       False
    __snake_case    =       False
    __snake_case    =       False
    __snake_case    =       False







    def 				a__					(			self					)	->	List[str]:
        _lowerCamelCase	: Union[str, Any]       =       DebertaVaModelTester(self					)
        _lowerCamelCase	: Optional[int]       =       ConfigTester(self    , config_class=A_    , hidden_size=37					)







    def 				a__					(			self					)	->	Optional[int]:
        self.config_tester.run_common_tests()







    def 				a__					(			self					)	->	str:
        _lowerCamelCase	: Tuple       =       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_deberta_model(*A_					)







    def 				a__					(			self					)	->	List[str]:
        _lowerCamelCase	: Dict       =       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_deberta_for_sequence_classification(*A_					)







    def 				a__					(			self					)	->	Any:
        _lowerCamelCase	: str       =       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_deberta_for_masked_lm(*A_					)







    def 				a__					(			self					)	->	str:
        _lowerCamelCase	: int       =       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_deberta_for_question_answering(*A_					)







    def 				a__					(			self					)	->	Optional[int]:
        _lowerCamelCase	: Optional[Any]       =       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_deberta_for_token_classification(*A_					)







    def 				a__					(			self					)	->	Optional[int]:
        _lowerCamelCase	: Any       =       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_deberta_for_multiple_choice(*A_					)







    @slow
    def 				a__					(			self					)	->	str:

        for model_name in DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
            _lowerCamelCase	: Union[str, Any]       =       DebertaVaModel.from_pretrained(A_					)
            self.assertIsNotNone(A_					)





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






    """simple docstring"""







    @unittest.skip(reason='''Model not available yet'''					)
    def 				a__					(			self					)	->	Tuple:
        pass







    @slow
    def 				a__					(			self					)	->	List[Any]:
        _lowerCamelCase	: Optional[int]       =       DebertaVaModel.from_pretrained('''microsoft/deberta-v2-xlarge'''					)

        _lowerCamelCase	: Union[str, Any]       =       torch.tensor([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]]					)
        _lowerCamelCase	: int       =       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	: int       =       torch.tensor(
            [[[0.2356, 0.1948, 0.0369], [-0.1063, 0.3586, -0.5152], [-0.6399, -0.0259, -0.2525]]]					)
        self.assertTrue(torch.allclose(output[:, 1:4, 1:4]    , A_    , atol=1E-4					)    , F'''{output[:, 1:4, 1:4]}'''					)









from dataclasses import dataclass, field
from typing import ClassVar, Dict

from ..features import Features, Value
from .base import TaskTemplate



@dataclass(frozen=__SCREAMING_SNAKE_CASE    )
class 					__snake_case	(  __SCREAMING_SNAKE_CASE    ):


    '''simple docstring'''







    lowerCamelCase__    :		str				=	field(default="""summarization"""			,     metadata={"""include_in_asdict_even_if_is_default""": True}    )
    lowerCamelCase__    :		ClassVar[Features]				=	Features({"""text""": Value("""string"""    )}    )
    lowerCamelCase__    :		ClassVar[Features]				=	Features({"""summary""": Value("""string"""    )}    )
    lowerCamelCase__    :		str				=	"text"
    lowerCamelCase__    :		str				=	"summary"



    @property
    def  lowercase_					(       self     ):





        '''simple docstring'''

        return {self.text_column: "text", self.summary_column: "summary"}
