


'''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      ,	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      ,	):

            '''simple docstring'''

            _lowerCAmelCase    :							int   			=       parent
            _lowerCAmelCase    :							Optional[int]   			=       batch_size
            _lowerCAmelCase    :							List[str]   			=       seq_length
            _lowerCAmelCase    :							List[Any]   			=       is_training
            _lowerCAmelCase    :							Dict   			=       use_input_mask
            _lowerCAmelCase    :							List[Any]   			=       use_token_type_ids
            _lowerCAmelCase    :							Any   			=       use_labels
            _lowerCAmelCase    :							Any   			=       vocab_size
            _lowerCAmelCase    :							str   			=       hidden_size
            _lowerCAmelCase    :							str   			=       num_hidden_layers
            _lowerCAmelCase    :							int   			=       num_attention_heads
            _lowerCAmelCase    :							Any   			=       intermediate_size
            _lowerCAmelCase    :							Dict   			=       hidden_act
            _lowerCAmelCase    :							str   			=       hidden_dropout_prob
            _lowerCAmelCase    :							Tuple   			=       attention_probs_dropout_prob
            _lowerCAmelCase    :							Optional[int]   			=       max_position_embeddings
            _lowerCAmelCase    :							Tuple   			=       type_vocab_size
            _lowerCAmelCase    :							List[str]   			=       type_sequence_label_size
            _lowerCAmelCase    :							Tuple   			=       initializer_range
            _lowerCAmelCase    :							Union[str, Any]   			=       num_labels
            _lowerCAmelCase    :							Any   			=       num_choices
            _lowerCAmelCase    :							Optional[int]   			=       relative_attention
            _lowerCAmelCase    :							Optional[int]   			=       position_biased_input
            _lowerCAmelCase    :							List[str]   			=       pos_att_type
            _lowerCAmelCase    :							List[str]   			=       scope







     def a	( self   ):

            '''simple docstring'''

            _lowerCAmelCase    :							List[Any]   			=       ids_tensor([self.batch_size, self.seq_length]      ,	self.vocab_size   )

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

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

            _lowerCAmelCase    :							Optional[int]   			=       None
            _lowerCAmelCase    :							Optional[Any]   			=       None
            _lowerCAmelCase    :							Optional[int]   			=       None
            if self.use_labels:
                   _lowerCAmelCase    :							Optional[Any]   			=       ids_tensor([self.batch_size]      ,	self.type_sequence_label_size   )
                   _lowerCAmelCase    :							Dict   			=       ids_tensor([self.batch_size, self.seq_length]      ,	self.num_labels   )
                   _lowerCAmelCase    :							List[Any]   			=       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   ):

            '''simple docstring'''

            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      ,	snake_case__   ):

            '''simple docstring'''

            self.parent.assertListEqual(list(result.loss.size()   )      ,	[]   )







     def a	( self      ,	snake_case__      ,	snake_case__      ,	snake_case__      ,	snake_case__      ,	snake_case__      ,	snake_case__      ,	snake_case__   ):

            '''simple docstring'''

            _lowerCAmelCase    :							Any   			=       DebertaVaModel(config=snake_case__   )
            model.to(snake_case__   )
            model.eval()
            _lowerCAmelCase    :							int   			=       model(snake_case__      ,	attention_mask=snake_case__      ,	token_type_ids=snake_case__   )[0]
            _lowerCAmelCase    :							Any   			=       model(snake_case__      ,	token_type_ids=snake_case__   )[0]
            _lowerCAmelCase    :							Optional[int]   			=       model(snake_case__   )[0]

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







     def a	( self      ,	snake_case__      ,	snake_case__      ,	snake_case__      ,	snake_case__      ,	snake_case__      ,	snake_case__      ,	snake_case__   ):

            '''simple docstring'''

            _lowerCAmelCase    :							Tuple   			=       DebertaVaForMaskedLM(config=snake_case__   )
            model.to(snake_case__   )
            model.eval()
            _lowerCAmelCase    :							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 a	( self      ,	snake_case__      ,	snake_case__      ,	snake_case__      ,	snake_case__      ,	snake_case__      ,	snake_case__      ,	snake_case__   ):

            '''simple docstring'''

            _lowerCAmelCase    :							Tuple   			=       self.num_labels
            _lowerCAmelCase    :							Union[str, Any]   			=       DebertaVaForSequenceClassification(snake_case__   )
            model.to(snake_case__   )
            model.eval()
            _lowerCAmelCase    :							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 a	( self      ,	snake_case__      ,	snake_case__      ,	snake_case__      ,	snake_case__      ,	snake_case__      ,	snake_case__      ,	snake_case__   ):

            '''simple docstring'''

            _lowerCAmelCase    :							Any   			=       self.num_labels
            _lowerCAmelCase    :							int   			=       DebertaVaForTokenClassification(config=snake_case__   )
            model.to(snake_case__   )
            model.eval()
            _lowerCAmelCase    :							str   			=       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 a	( self      ,	snake_case__      ,	snake_case__      ,	snake_case__      ,	snake_case__      ,	snake_case__      ,	snake_case__      ,	snake_case__   ):

            '''simple docstring'''

            _lowerCAmelCase    :							str   			=       DebertaVaForQuestionAnswering(config=snake_case__   )
            model.to(snake_case__   )
            model.eval()
            _lowerCAmelCase    :							Tuple   			=       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 a	( self      ,	snake_case__      ,	snake_case__      ,	snake_case__      ,	snake_case__      ,	snake_case__      ,	snake_case__      ,	snake_case__   ):

            '''simple docstring'''

            _lowerCAmelCase    :							Tuple   			=       DebertaVaForMultipleChoice(config=snake_case__   )
            model.to(snake_case__   )
            model.eval()
            _lowerCAmelCase    :							Optional[int]   			=       input_ids.unsqueeze(1   ).expand(-1      ,	self.num_choices      ,	-1   ).contiguous()
            _lowerCAmelCase    :							str   			=       token_type_ids.unsqueeze(1   ).expand(-1      ,	self.num_choices      ,	-1   ).contiguous()
            _lowerCAmelCase    :							int   			=       input_mask.unsqueeze(1   ).expand(-1      ,	self.num_choices      ,	-1   ).contiguous()
            _lowerCAmelCase    :							str   			=       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.num_choices)   )







     def a	( self   ):

            '''simple docstring'''

            _lowerCAmelCase    :							Optional[int]   			=       self.prepare_config_and_inputs()
            (
                (
                _lowerCAmelCase
            )			,     (
                _lowerCAmelCase
            )			,     (
                _lowerCAmelCase
            )			,     (
                _lowerCAmelCase
            )			,     (
                _lowerCAmelCase
            )			,     (
                _lowerCAmelCase
            )			,     (
                _lowerCAmelCase
            )			,     
            )    :							Union[str, Any]   			=       config_and_inputs
            _lowerCAmelCase    :							Optional[int]   			=       {'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"""






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

     __magic_name__    			=    True
     __magic_name__    			=    False
     __magic_name__    			=    False
     __magic_name__    			=    False
     __magic_name__    			=    False







     def a	( self   ):

            '''simple docstring'''

            _lowerCAmelCase    :							Tuple   			=       DebertaVaModelTester(self   )
            _lowerCAmelCase    :							List[Any]   			=       ConfigTester(self      ,	config_class=snake_case__      ,	hidden_size=37   )







     def a	( self   ):

            '''simple docstring'''

            self.config_tester.run_common_tests()







     def a	( self   ):

            '''simple docstring'''

            _lowerCAmelCase    :							List[Any]   			=       self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_deberta_model(*snake_case__   )







     def a	( self   ):

            '''simple docstring'''

            _lowerCAmelCase    :							Optional[int]   			=       self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_deberta_for_sequence_classification(*snake_case__   )







     def a	( self   ):

            '''simple docstring'''

            _lowerCAmelCase    :							Optional[int]   			=       self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_deberta_for_masked_lm(*snake_case__   )







     def a	( self   ):

            '''simple docstring'''

            _lowerCAmelCase    :							Tuple   			=       self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_deberta_for_question_answering(*snake_case__   )







     def a	( self   ):

            '''simple docstring'''

            _lowerCAmelCase    :							List[Any]   			=       self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_deberta_for_token_classification(*snake_case__   )







     def a	( self   ):

            '''simple docstring'''

            _lowerCAmelCase    :							List[str]   			=       self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_deberta_for_multiple_choice(*snake_case__   )







     @slow
     def a	( self   ):

            '''simple docstring'''

            for model_name in DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                   _lowerCAmelCase    :							Dict   			=       DebertaVaModel.from_pretrained(snake_case__   )
                   self.assertIsNotNone(snake_case__   )
@require_torch
@require_sentencepiece
@require_tokenizers
class 	UpperCamelCase__					( unittest.TestCase	):



     """simple docstring"""






     @unittest.skip(reason='Model not available yet'   )
     def a	( self   ):

            '''simple docstring'''

            pass







     @slow
     def a	( self   ):

            '''simple docstring'''

            _lowerCAmelCase    :							str   			=       DebertaVaModel.from_pretrained('microsoft/deberta-v2-xlarge'   )

            _lowerCAmelCase    :							int   			=       torch.tensor([[0, 3_1414, 232, 328, 740, 1140, 1_2695, 69, 4_6078, 1588, 2]]   )
            _lowerCAmelCase    :							Any   			=       torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]   )
            with torch.no_grad():
                   _lowerCAmelCase    :							Optional[int]   			=       model(snake_case__      ,	attention_mask=snake_case__   )[0]
            # compare the actual values for a slice.
            _lowerCAmelCase    :							Any   			=       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]      ,	snake_case__      ,	atol=1E-4   )      ,	F'{output[:, 1:4, 1:4]}'   )





'''simple docstring'''







from typing import TYPE_CHECKING

from ....utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowerCAmelCase    :     Optional[int]					=						{
    """configuration_mctct""": ["""MCTCT_PRETRAINED_CONFIG_ARCHIVE_MAP""", """MCTCTConfig"""],
    """feature_extraction_mctct""": ["""MCTCTFeatureExtractor"""],
    """processing_mctct""": ["""MCTCTProcessor"""],
}


try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       lowerCAmelCase    :     List[str]					=						[
           """MCTCT_PRETRAINED_MODEL_ARCHIVE_LIST""",
           """MCTCTForCTC""",
           """MCTCTModel""",
           """MCTCTPreTrainedModel""",
       ]


if TYPE_CHECKING:
       from .configuration_mctct import MCTCT_PRETRAINED_CONFIG_ARCHIVE_MAP, MCTCTConfig
       from .feature_extraction_mctct import MCTCTFeatureExtractor
       from .processing_mctct import MCTCTProcessor

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_mctct import MCTCT_PRETRAINED_MODEL_ARCHIVE_LIST, MCTCTForCTC, MCTCTModel, MCTCTPreTrainedModel

else:
       import sys

       lowerCAmelCase    :     Tuple					=						_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)

