






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




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




 def        __magic_name__		( self		:							int )		->  Union[str, Any]:
       SCREAMING_SNAKE_CASE__       :			str													=ids_tensor([self.batch_size, self.seq_length]   , self.vocab_size )

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

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

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

       SCREAMING_SNAKE_CASE__       :			Tuple													=self.get_config()

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




 def        __magic_name__		( self		:							List[Any] )		->  Tuple:
       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        __magic_name__		( self		:							Optional[int]   , __lowercase		:							Any )		->  Any:
       self.parent.assertListEqual(list(result.loss.size() )   , [] )




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

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




 def        __magic_name__		( self		:							Dict   , __lowercase		:							str   , __lowercase		:							int   , __lowercase		:							List[str]   , __lowercase		:							Tuple   , __lowercase		:							Any   , __lowercase		:							Union[str, Any]   , __lowercase		:							List[Any] )		->  Union[str, Any]:
       SCREAMING_SNAKE_CASE__       :			List[str]													=DebertaVaForMaskedLM(config=__lowercase )
       model.to(__lowercase )
       model.eval()
       SCREAMING_SNAKE_CASE__       :			str													=model(__lowercase   , attention_mask=__lowercase   , token_type_ids=__lowercase   , labels=__lowercase )

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




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




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




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




 def        __magic_name__		( self		:							Union[str, Any] )		->  List[Any]:
       SCREAMING_SNAKE_CASE__       :			Tuple													=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__
       )						,		
       )       :			Tuple													=config_and_inputs
       SCREAMING_SNAKE_CASE__       :			List[Any]													={'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
       return config, inputs_dict






@require_torch
class        __SCREAMING_SNAKE_CASE (     lowerCamelCase		,			lowerCamelCase		,			unittest.TestCase			):
 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        __magic_name__		( self		:							Union[str, Any] )		->  List[Any]:
       SCREAMING_SNAKE_CASE__       :			List[Any]													=DebertaVaModelTester(self )
       SCREAMING_SNAKE_CASE__       :			Dict													=ConfigTester(self   , config_class=__lowercase   , hidden_size=37 )




 def        __magic_name__		( self		:							str )		->  int:
       self.config_tester.run_common_tests()




 def        __magic_name__		( self		:							Dict )		->  Optional[Any]:
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_deberta_model(*__lowercase )




 def        __magic_name__		( self		:							int )		->  str:
       SCREAMING_SNAKE_CASE__       :			Tuple													=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_deberta_for_sequence_classification(*__lowercase )




 def        __magic_name__		( self		:							List[Any] )		->  Dict:
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_deberta_for_masked_lm(*__lowercase )




 def        __magic_name__		( self		:							List[str] )		->  Optional[Any]:
       SCREAMING_SNAKE_CASE__       :			int													=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_deberta_for_question_answering(*__lowercase )




 def        __magic_name__		( self		:							Optional[Any] )		->  Optional[Any]:
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_deberta_for_token_classification(*__lowercase )




 def        __magic_name__		( self		:							Dict )		->  str:
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_deberta_for_multiple_choice(*__lowercase )




 @slow
 def        __magic_name__		( self		:							int )		->  Optional[int]:
       for model_name in DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             SCREAMING_SNAKE_CASE__       :			str													=DebertaVaModel.from_pretrained(__lowercase )
             self.assertIsNotNone(__lowercase )






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




 @unittest.skip(reason='''Model not available yet''' )
 def        __magic_name__		( self		:							Any )		->  List[Any]:
       pass




 @slow
 def        __magic_name__		( self		:							List[Any] )		->  Dict:
       SCREAMING_SNAKE_CASE__       :			Any													=DebertaVaModel.from_pretrained('''microsoft/deberta-v2-xlarge''' )

       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=torch.tensor([[0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 4_60_78, 15_88, 2]] )
       SCREAMING_SNAKE_CASE__       :			Dict													=torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]] )
       with torch.no_grad():
             SCREAMING_SNAKE_CASE__       :			int													=model(__lowercase   , attention_mask=__lowercase )[0]
       # compare the actual values for a slice.
       SCREAMING_SNAKE_CASE__       :			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]   , __lowercase   , atol=1e-4 )   , F"{output[:, 1:4, 1:4]}" )







'''simple docstring'''
from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


a_					=	{
    'configuration_lxmert': ['LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'LxmertConfig'],
    'tokenization_lxmert': ['LxmertTokenizer'],
}

try:
  if not is_tokenizers_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  a_					=	['LxmertTokenizerFast']

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  a_					=	[
      'LxmertEncoder',
      'LxmertForPreTraining',
      'LxmertForQuestionAnswering',
      'LxmertModel',
      'LxmertPreTrainedModel',
      'LxmertVisualFeatureEncoder',
      'LxmertXLayer',
  ]

try:
  if not is_tf_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  a_					=	[
      'TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST',
      'TFLxmertForPreTraining',
      'TFLxmertMainLayer',
      'TFLxmertModel',
      'TFLxmertPreTrainedModel',
      'TFLxmertVisualFeatureEncoder',
  ]


if TYPE_CHECKING:
  from .configuration_lxmert import LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP, LxmertConfig
  from .tokenization_lxmert import LxmertTokenizer

  try:
    if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .tokenization_lxmert_fast import LxmertTokenizerFast

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_lxmert import (
        LxmertEncoder,
        LxmertForPreTraining,
        LxmertForQuestionAnswering,
        LxmertModel,
        LxmertPreTrainedModel,
        LxmertVisualFeatureEncoder,
        LxmertXLayer,
    )

  try:
    if not is_tf_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_tf_lxmert import (
        TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST,
        TFLxmertForPreTraining,
        TFLxmertMainLayer,
        TFLxmertModel,
        TFLxmertPreTrainedModel,
        TFLxmertVisualFeatureEncoder,
    )

else:
  import sys

  a_					=	_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)