



"""simple docstring"""
from __future__ import annotations

import unittest

from transformers import EsmConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
       import numpy
       import tensorflow as tf

       from transformers.models.esm.modeling_tf_esm import (
           TF_ESM_PRETRAINED_MODEL_ARCHIVE_LIST,
           TFEsmForMaskedLM,
           TFEsmForSequenceClassification,
           TFEsmForTokenClassification,
           TFEsmModel,
       )


class    SCREAMING_SNAKE_CASE__ :

    def __init__(				self			:				List[Any] ,  lowerCAmelCase_			:				Optional[Any] ,  ):







      """simple docstring"""







      lowercase_								= parent
      lowercase_								= 1_3
      lowercase_								= 7
      lowercase_								= True
      lowercase_								= True
      lowercase_								= True
      lowercase_								= 9_9
      lowercase_								= 3_2
      lowercase_								= 2
      lowercase_								= 4
      lowercase_								= 3_7
      lowercase_								= """gelu"""
      lowercase_								= 0.1
      lowercase_								= 0.1
      lowercase_								= 5_1_2
      lowercase_								= 1_6
      lowercase_								= 2
      lowercase_								= 0.02
      lowercase_								= 3
      lowercase_								= 4
      lowercase_								= None

    def 					_UpperCAmelCase	(				self			:				Union[str, Any]):







      """simple docstring"""







      lowercase_								= ids_tensor([self.batch_size, self.seq_length] ,  self.vocab_size)

      lowercase_								= None
      if self.use_input_mask:
        lowercase_								= random_attention_mask([self.batch_size, self.seq_length])

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

      lowercase_								= EsmConfig(
          vocab_size=self.vocab_size ,  hidden_size=self.hidden_size ,  num_hidden_layers=self.num_hidden_layers ,  pad_token_id=1 ,  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 ,  )

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

    def 					_UpperCAmelCase	(				self			:				Union[str, Any]):







      """simple docstring"""







      (
          (
          lowercase_      
      )					,    (
          lowercase_      
      )					,    (
          lowercase_      
      )					,    (
          lowercase_      
      )					,    (
          lowercase_      
      )					,    (
          lowercase_      
      )					,          
      )								= self.prepare_config_and_inputs()

      lowercase_								= True
      lowercase_								= floats_tensor([self.batch_size, self.seq_length, self.hidden_size])
      lowercase_								= ids_tensor([self.batch_size, self.seq_length] ,  vocab_size=2)

      return (
          config,
          input_ids,
          input_mask,
          sequence_labels,
          token_labels,
          choice_labels,
          encoder_hidden_states,
          encoder_attention_mask,
      )

    def 					_UpperCAmelCase	(				self			:				Optional[int] ,  lowerCAmelCase_			:				int ,  lowerCAmelCase_			:				List[str] ,  lowerCAmelCase_			:				Optional[int] ,  lowerCAmelCase_			:				List[Any] ,  lowerCAmelCase_			:				Any ,  lowerCAmelCase_			:				Any):







      """simple docstring"""







      lowercase_								= TFEsmModel(config=A_)
      lowercase_								= {"""input_ids""": input_ids, """attention_mask""": input_mask}
      lowercase_								= model(A_)

      lowercase_								= [input_ids, input_mask]
      lowercase_								= model(A_)

      lowercase_								= model(A_)

      self.parent.assertEqual(result.last_hidden_state.shape ,  (self.batch_size, self.seq_length, self.hidden_size))

    def 					_UpperCAmelCase	(				self			:				Union[str, Any] ,  lowerCAmelCase_			:				Any ,  lowerCAmelCase_			:				Union[str, Any] ,  lowerCAmelCase_			:				Tuple ,  lowerCAmelCase_			:				int ,  lowerCAmelCase_			:				List[Any] ,  lowerCAmelCase_			:				Optional[int] ,  lowerCAmelCase_			:				Optional[Any] ,  lowerCAmelCase_			:				List[str] ,  ):







      """simple docstring"""







      lowercase_								= True

      lowercase_								= TFEsmModel(config=A_)
      lowercase_								= {
          """input_ids""": input_ids,
          """attention_mask""": input_mask,
          """encoder_hidden_states""": encoder_hidden_states,
          """encoder_attention_mask""": encoder_attention_mask,
      }
      lowercase_								= model(A_)

      lowercase_								= [input_ids, input_mask]
      lowercase_								= model(A_ ,  encoder_hidden_states=A_)

      # Also check the case where encoder outputs are not passed
      lowercase_								= model(A_ ,  attention_mask=A_)

      self.parent.assertEqual(result.last_hidden_state.shape ,  (self.batch_size, self.seq_length, self.hidden_size))

    def 					_UpperCAmelCase	(				self			:				str ,  lowerCAmelCase_			:				List[Any] ,  lowerCAmelCase_			:				List[Any] ,  lowerCAmelCase_			:				Optional[Any] ,  lowerCAmelCase_			:				Optional[int] ,  lowerCAmelCase_			:				Optional[Any] ,  lowerCAmelCase_			:				List[Any]):







      """simple docstring"""







      lowercase_								= TFEsmForMaskedLM(config=A_)
      lowercase_								= model([input_ids, input_mask])
      self.parent.assertEqual(result.logits.shape ,  (self.batch_size, self.seq_length, self.vocab_size))

    def 					_UpperCAmelCase	(				self			:				Any ,  lowerCAmelCase_			:				Optional[Any] ,  lowerCAmelCase_			:				str ,  lowerCAmelCase_			:				List[Any] ,  lowerCAmelCase_			:				int ,  lowerCAmelCase_			:				Tuple ,  lowerCAmelCase_			:				Optional[int]):







      """simple docstring"""







      lowercase_								= self.num_labels
      lowercase_								= TFEsmForTokenClassification(config=A_)
      lowercase_								= {"""input_ids""": input_ids, """attention_mask""": input_mask}
      lowercase_								= model(A_)
      self.parent.assertEqual(result.logits.shape ,  (self.batch_size, self.seq_length, self.num_labels))




    def 					_UpperCAmelCase	(				self			:				Any):







      """simple docstring"""







      lowercase_								= self.prepare_config_and_inputs()
      (
          (
          lowercase_      
      )					,    (
          lowercase_      
      )					,    (
          lowercase_      
      )					,    (
          lowercase_      
      )					,    (
          lowercase_      
      )					,    (
          lowercase_      
      )					,          
      )								= config_and_inputs
      lowercase_								= {"""input_ids""": input_ids, """attention_mask""": input_mask}
      return config, inputs_dict







@require_tf
class    SCREAMING_SNAKE_CASE__ (							_lowercase      ,  _lowercase      ,  unittest.TestCase   ):
    lowercase__      =   (
        (
            TFEsmModel,
            TFEsmForMaskedLM,
            TFEsmForSequenceClassification,
            TFEsmForTokenClassification,
        )
        if is_tf_available()
        else ()
    )
    lowercase__      =   (
        {
            '''feature-extraction''': TFEsmModel,
            '''fill-mask''': TFEsmForMaskedLM,
            '''text-classification''': TFEsmForSequenceClassification,
            '''token-classification''': TFEsmForTokenClassification,
            '''zero-shot''': TFEsmForSequenceClassification,
        }
        if is_tf_available()
        else {}
    )
    lowercase__      =   False
    lowercase__      =   False

    def 					_UpperCAmelCase	(				self			:				List[Any]):







      """simple docstring"""







      lowercase_								= TFEsmModelTester(self)
      lowercase_								= ConfigTester(self ,  config_class=A_ ,  hidden_size=3_7)

    def 					_UpperCAmelCase	(				self			:				Any):







      """simple docstring"""







      self.config_tester.run_common_tests()

    def 					_UpperCAmelCase	(				self			:				Union[str, Any]):







      """simple docstring"""







      lowercase_								= self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*A_)

    def 					_UpperCAmelCase	(				self			:				List[Any]):







      """simple docstring"""







      lowercase_								= self.model_tester.prepare_config_and_inputs_for_decoder()
      self.model_tester.create_and_check_model_as_decoder(*A_)

    def 					_UpperCAmelCase	(				self			:				str):







      """simple docstring"""







      lowercase_								= self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_masked_lm(*A_)

    def 					_UpperCAmelCase	(				self			:				List[Any]):







      """simple docstring"""







      lowercase_								= self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_token_classification(*A_)

    @slow
    def 					_UpperCAmelCase	(				self			:				Tuple):







      """simple docstring"""







      for model_name in TF_ESM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
        lowercase_								= TFEsmModel.from_pretrained(A_)
        self.assertIsNotNone(A_)

    @unittest.skip("""Protein models do not support embedding resizing.""")
    def 					_UpperCAmelCase	(				self			:				Optional[int]):







      """simple docstring"""







      pass

    @unittest.skip("""Protein models do not support embedding resizing.""")
    def 					_UpperCAmelCase	(				self			:				Tuple):







      """simple docstring"""







      pass




    def 					_UpperCAmelCase	(				self			:				str):







      """simple docstring"""







      lowercase_					,    lowercase_								= self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
        lowercase_								= model_class(A_)
        assert isinstance(model.get_input_embeddings() ,  tf.keras.layers.Layer)
        if model_class is TFEsmForMaskedLM:
          # Output embedding test differs from the main test because they're a matrix, not a layer
          lowercase_								= model.get_bias()
          assert isinstance(A_ ,  A_)
          for k, v in name.items():
            assert isinstance(A_ ,  tf.Variable)
        else:
          lowercase_								= model.get_output_embeddings()
          assert x is None
          lowercase_								= model.get_bias()
          assert name is None







@require_tf
class    SCREAMING_SNAKE_CASE__ (							unittest.TestCase   ):

    @slow
    def 					_UpperCAmelCase	(				self			:				Optional[Any]):







      """simple docstring"""







      lowercase_								= TFEsmForMaskedLM.from_pretrained("""facebook/esm2_t6_8M_UR50D""")

      lowercase_								= tf.constant([[0, 1, 2, 3, 4, 5]])
      lowercase_								= model(A_)[0]
      lowercase_								= [1, 6, 3_3]
      self.assertEqual(list(output.numpy().shape) ,  A_)
      # compare the actual values for a slice.
      lowercase_								= tf.constant(
          [
              [
                  [8.921_518, -10.589_814, -6.4_671_307],
                  [-6.3_967_156, -13.911_377, -1.1_211_915],
                  [-7.781_247, -13.951_557, -3.740_592],
              ]
          ])
      self.assertTrue(numpy.allclose(output[:, :3, :3].numpy() ,  expected_slice.numpy() ,  atol=1E-2))




    @slow
    def 					_UpperCAmelCase	(				self			:				Optional[Any]):







      """simple docstring"""







      lowercase_								= TFEsmModel.from_pretrained("""facebook/esm2_t6_8M_UR50D""")

      lowercase_								= tf.constant([[0, 6, 4, 1_3, 5, 4, 1_6, 1_2, 1_1, 7, 2]])
      lowercase_								= model(A_)[0]
      # compare the actual values for a slice.
      lowercase_								= tf.constant(
          [
              [
                  [0.14_443_092, 0.54_125_327, 0.3_247_739],
                  [0.30_340_484, 0.00_526_676, 0.31_077_722],
                  [0.32_278_043, -0.24_987_096, 0.3_414_628],
              ]
          ])
      self.assertTrue(numpy.allclose(output[:, :3, :3].numpy() ,  expected_slice.numpy() ,  atol=1E-4))






"""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__ (							__UpperCAmelCase   ):

    def __init__(				self			:				Union[str, Any] ,  lowerCAmelCase_			:				int ,  lowerCAmelCase_			:				Optional[int]=1_3 ,  lowerCAmelCase_			:				Union[str, Any]=7 ,  lowerCAmelCase_			:				int=True ,  lowerCAmelCase_			:				Optional[int]=True ,  lowerCAmelCase_			:				List[Any]=True ,  lowerCAmelCase_			:				Tuple=True ,  lowerCAmelCase_			:				Dict=9_9 ,  lowerCAmelCase_			:				List[str]=3_2 ,  lowerCAmelCase_			:				Tuple=5 ,  lowerCAmelCase_			:				str=4 ,  lowerCAmelCase_			:				List[str]=3_7 ,  lowerCAmelCase_			:				List[str]="gelu" ,  lowerCAmelCase_			:				Optional[Any]=0.1 ,  lowerCAmelCase_			:				Union[str, Any]=0.1 ,  lowerCAmelCase_			:				List[str]=5_1_2 ,  lowerCAmelCase_			:				Union[str, Any]=1_6 ,  lowerCAmelCase_			:				List[Any]=2 ,  lowerCAmelCase_			:				Dict=0.02 ,  lowerCAmelCase_			:				int=False ,  lowerCAmelCase_			:				Any=True ,  lowerCAmelCase_			:				Tuple="None" ,  lowerCAmelCase_			:				int=3 ,  lowerCAmelCase_			:				Union[str, Any]=4 ,  lowerCAmelCase_			:				Dict=None ,  ):







      """simple docstring"""







      lowercase_								= parent
      lowercase_								= batch_size
      lowercase_								= seq_length
      lowercase_								= is_training
      lowercase_								= use_input_mask
      lowercase_								= use_token_type_ids
      lowercase_								= use_labels
      lowercase_								= vocab_size
      lowercase_								= hidden_size
      lowercase_								= num_hidden_layers
      lowercase_								= num_attention_heads
      lowercase_								= intermediate_size
      lowercase_								= hidden_act
      lowercase_								= hidden_dropout_prob
      lowercase_								= attention_probs_dropout_prob
      lowercase_								= max_position_embeddings
      lowercase_								= type_vocab_size
      lowercase_								= type_sequence_label_size
      lowercase_								= initializer_range
      lowercase_								= num_labels
      lowercase_								= num_choices
      lowercase_								= relative_attention
      lowercase_								= position_biased_input
      lowercase_								= pos_att_type
      lowercase_								= scope

    def 					_UpperCAmelCase	(				self			:				Any):







      """simple docstring"""







      lowercase_								= ids_tensor([self.batch_size, self.seq_length] ,  self.vocab_size)

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

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

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

      lowercase_								= self.get_config()

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

    def 					_UpperCAmelCase	(				self			:				int):







      """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 					_UpperCAmelCase	(				self			:				Tuple ,  lowerCAmelCase_			:				Dict):







      """simple docstring"""







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

    def 					_UpperCAmelCase	(				self			:				Any ,  lowerCAmelCase_			:				int ,  lowerCAmelCase_			:				Optional[Any] ,  lowerCAmelCase_			:				List[Any] ,  lowerCAmelCase_			:				Dict ,  lowerCAmelCase_			:				Tuple ,  lowerCAmelCase_			:				Union[str, Any] ,  lowerCAmelCase_			:				List[str]):







      """simple docstring"""







      lowercase_								= DebertaVaModel(config=lowerCAmelCase_)
      model.to(lowerCAmelCase_)
      model.eval()
      lowercase_								= model(lowerCAmelCase_ ,  attention_mask=lowerCAmelCase_ ,  token_type_ids=lowerCAmelCase_)[0]
      lowercase_								= model(lowerCAmelCase_ ,  token_type_ids=lowerCAmelCase_)[0]
      lowercase_								= model(lowerCAmelCase_)[0]

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

    def 					_UpperCAmelCase	(				self			:				Optional[Any] ,  lowerCAmelCase_			:				str ,  lowerCAmelCase_			:				str ,  lowerCAmelCase_			:				int ,  lowerCAmelCase_			:				Tuple ,  lowerCAmelCase_			:				Dict ,  lowerCAmelCase_			:				List[str] ,  lowerCAmelCase_			:				Union[str, Any]):







      """simple docstring"""







      lowercase_								= DebertaVaForMaskedLM(config=lowerCAmelCase_)
      model.to(lowerCAmelCase_)
      model.eval()
      lowercase_								= model(lowerCAmelCase_ ,  attention_mask=lowerCAmelCase_ ,  token_type_ids=lowerCAmelCase_ ,  labels=lowerCAmelCase_)

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

    def 					_UpperCAmelCase	(				self			:				Any ,  lowerCAmelCase_			:				List[str] ,  lowerCAmelCase_			:				List[str] ,  lowerCAmelCase_			:				List[Any] ,  lowerCAmelCase_			:				Optional[Any] ,  lowerCAmelCase_			:				str ,  lowerCAmelCase_			:				Tuple ,  lowerCAmelCase_			:				Tuple):







      """simple docstring"""







      lowercase_								= self.num_labels
      lowercase_								= DebertaVaForSequenceClassification(lowerCAmelCase_)
      model.to(lowerCAmelCase_)
      model.eval()
      lowercase_								= model(lowerCAmelCase_ ,  attention_mask=lowerCAmelCase_ ,  token_type_ids=lowerCAmelCase_ ,  labels=lowerCAmelCase_)
      self.parent.assertListEqual(list(result.logits.size()) ,  [self.batch_size, self.num_labels])
      self.check_loss_output(lowerCAmelCase_)

    def 					_UpperCAmelCase	(				self			:				List[str] ,  lowerCAmelCase_			:				Any ,  lowerCAmelCase_			:				List[str] ,  lowerCAmelCase_			:				Union[str, Any] ,  lowerCAmelCase_			:				Tuple ,  lowerCAmelCase_			:				Optional[int] ,  lowerCAmelCase_			:				Union[str, Any] ,  lowerCAmelCase_			:				Any):







      """simple docstring"""







      lowercase_								= self.num_labels
      lowercase_								= DebertaVaForTokenClassification(config=lowerCAmelCase_)
      model.to(lowerCAmelCase_)
      model.eval()
      lowercase_								= model(lowerCAmelCase_ ,  attention_mask=lowerCAmelCase_ ,  token_type_ids=lowerCAmelCase_ ,  labels=lowerCAmelCase_)
      self.parent.assertEqual(result.logits.shape ,  (self.batch_size, self.seq_length, self.num_labels))

    def 					_UpperCAmelCase	(				self			:				str ,  lowerCAmelCase_			:				Tuple ,  lowerCAmelCase_			:				Union[str, Any] ,  lowerCAmelCase_			:				Dict ,  lowerCAmelCase_			:				List[str] ,  lowerCAmelCase_			:				str ,  lowerCAmelCase_			:				Tuple ,  lowerCAmelCase_			:				Dict):







      """simple docstring"""







      lowercase_								= DebertaVaForQuestionAnswering(config=lowerCAmelCase_)
      model.to(lowerCAmelCase_)
      model.eval()
      lowercase_								= model(
          lowerCAmelCase_ ,  attention_mask=lowerCAmelCase_ ,  token_type_ids=lowerCAmelCase_ ,  start_positions=lowerCAmelCase_ ,  end_positions=lowerCAmelCase_ ,  )
      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 					_UpperCAmelCase	(				self			:				Tuple ,  lowerCAmelCase_			:				Union[str, Any] ,  lowerCAmelCase_			:				Dict ,  lowerCAmelCase_			:				str ,  lowerCAmelCase_			:				str ,  lowerCAmelCase_			:				Optional[int] ,  lowerCAmelCase_			:				List[str] ,  lowerCAmelCase_			:				Optional[Any]):







      """simple docstring"""







      lowercase_								= DebertaVaForMultipleChoice(config=lowerCAmelCase_)
      model.to(lowerCAmelCase_)
      model.eval()
      lowercase_								= input_ids.unsqueeze(1).expand(-1 ,  self.num_choices ,  -1).contiguous()
      lowercase_								= token_type_ids.unsqueeze(1).expand(-1 ,  self.num_choices ,  -1).contiguous()
      lowercase_								= input_mask.unsqueeze(1).expand(-1 ,  self.num_choices ,  -1).contiguous()
      lowercase_								= model(
          lowerCAmelCase_ ,  attention_mask=lowerCAmelCase_ ,  token_type_ids=lowerCAmelCase_ ,  labels=lowerCAmelCase_ ,  )
      self.parent.assertEqual(result.logits.shape ,  (self.batch_size, self.num_choices))




    def 					_UpperCAmelCase	(				self			:				int):







      """simple docstring"""







      lowercase_								= self.prepare_config_and_inputs()
      (
          (
          lowercase_
      )					,    (
          lowercase_
      )					,    (
          lowercase_
      )					,    (
          lowercase_
      )					,    (
          lowercase_
      )					,    (
          lowercase_
      )					,    (
          lowercase_
      )					,    
      )								= config_and_inputs
      lowercase_								= {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
      return config, inputs_dict







@require_torch
class    SCREAMING_SNAKE_CASE__ (							__UpperCAmelCase      ,  __UpperCAmelCase      ,  unittest.TestCase   ):
    lowercase__      =   (
        (
            DebertaVaModel,
            DebertaVaForMaskedLM,
            DebertaVaForSequenceClassification,
            DebertaVaForTokenClassification,
            DebertaVaForQuestionAnswering,
            DebertaVaForMultipleChoice,
        )
        if is_torch_available()
        else ()
    )
    lowercase__      =   (
        {
            "feature-extraction": DebertaVaModel,
            "fill-mask": DebertaVaForMaskedLM,
            "question-answering": DebertaVaForQuestionAnswering,
            "text-classification": DebertaVaForSequenceClassification,
            "token-classification": DebertaVaForTokenClassification,
            "zero-shot": DebertaVaForSequenceClassification,
        }
        if is_torch_available()
        else {}
    )

    lowercase__      =   True
    lowercase__      =   False
    lowercase__      =   False
    lowercase__      =   False
    lowercase__      =   False

    def 					_UpperCAmelCase	(				self			:				Optional[Any]):







      """simple docstring"""







      lowercase_								= DebertaVaModelTester(self)
      lowercase_								= ConfigTester(self ,  config_class=lowerCAmelCase_ ,  hidden_size=3_7)

    def 					_UpperCAmelCase	(				self			:				Union[str, Any]):







      """simple docstring"""







      self.config_tester.run_common_tests()

    def 					_UpperCAmelCase	(				self			:				int):







      """simple docstring"""







      lowercase_								= self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_deberta_model(*lowerCAmelCase_)

    def 					_UpperCAmelCase	(				self			:				Union[str, Any]):







      """simple docstring"""







      lowercase_								= self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_deberta_for_sequence_classification(*lowerCAmelCase_)

    def 					_UpperCAmelCase	(				self			:				Dict):







      """simple docstring"""







      lowercase_								= self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_deberta_for_masked_lm(*lowerCAmelCase_)

    def 					_UpperCAmelCase	(				self			:				List[Any]):







      """simple docstring"""







      lowercase_								= self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_deberta_for_question_answering(*lowerCAmelCase_)

    def 					_UpperCAmelCase	(				self			:				str):







      """simple docstring"""







      lowercase_								= self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_deberta_for_token_classification(*lowerCAmelCase_)

    def 					_UpperCAmelCase	(				self			:				Union[str, Any]):







      """simple docstring"""







      lowercase_								= self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_deberta_for_multiple_choice(*lowerCAmelCase_)




    @slow
    def 					_UpperCAmelCase	(				self			:				Tuple):







      """simple docstring"""







      for model_name in DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
        lowercase_								= DebertaVaModel.from_pretrained(lowerCAmelCase_)
        self.assertIsNotNone(lowerCAmelCase_)







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

    @unittest.skip(reason="""Model not available yet""")
    def 					_UpperCAmelCase	(				self			:				Optional[int]):







      """simple docstring"""







      pass




    @slow
    def 					_UpperCAmelCase	(				self			:				int):







      """simple docstring"""







      lowercase_								= DebertaVaModel.from_pretrained("""microsoft/deberta-v2-xlarge""")

      lowercase_								= 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]])
      lowercase_								= torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
      with torch.no_grad():
        lowercase_								= model(lowerCAmelCase_ ,  attention_mask=lowerCAmelCase_)[0]
      # compare the actual values for a slice.
      lowercase_								= 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] ,  lowerCAmelCase_ ,  atol=1E-4) ,  F'''{output[:, 1:4, 1:4]}''')

