


import inspect
import unittest

from transformers import ConvNextVaConfig
from transformers.models.auto import get_values
from transformers.models.auto.modeling_auto import MODEL_FOR_BACKBONE_MAPPING_NAMES, MODEL_MAPPING_NAMES
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
			import torch

			from transformers import ConvNextVaBackbone, ConvNextVaForImageClassification, ConvNextVaModel
			from transformers.models.convnextva.modeling_convnextva import CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
			from PIL import Image

			from transformers import AutoImageProcessor

class 							a						:




							"""simple docstring"""


							def __init__(				self			:    Union[str, Any]       ,      lowerCamelCase			:    Any       ,      lowerCamelCase			:    Any=13       ,      lowerCamelCase			:    Union[str, Any]=32       ,      lowerCamelCase			:    Tuple=3       ,      lowerCamelCase			:    Any=4       ,      lowerCamelCase			:    Optional[int]=[10, 20, 30, 40]       ,      lowerCamelCase			:    int=[2, 2, 3, 2]       ,      lowerCamelCase			:    str=True       ,      lowerCamelCase			:    Any=True       ,      lowerCamelCase			:    Union[str, Any]=37       ,      lowerCamelCase			:    List[str]="gelu"       ,      lowerCamelCase			:    Optional[int]=10       ,      lowerCamelCase			:    Optional[Any]=0.02       ,      lowerCamelCase			:    List[Any]=["stage2", "stage3", "stage4"]       ,      lowerCamelCase			:    Union[str, Any]=[2, 3, 4]       ,      lowerCamelCase			:    Dict=None       ,      )      ->       List[str]:
														__snake_case						:     int									=  parent
														__snake_case						:     int									=  batch_size
														__snake_case						:     List[Any]									=  image_size
														__snake_case						:     Any									=  num_channels
														__snake_case						:     Optional[int]									=  num_stages
														__snake_case						:     Union[str, Any]									=  hidden_sizes
														__snake_case						:     List[str]									=  depths
														__snake_case						:     Any									=  is_training
														__snake_case						:     Tuple									=  use_labels
														__snake_case						:     Dict									=  intermediate_size
														__snake_case						:     Any									=  hidden_act
														__snake_case						:     Optional[Any]									=  num_labels
														__snake_case						:     int									=  initializer_range
														__snake_case						:     Any									=  out_features
														__snake_case						:     int									=  out_indices
														__snake_case						:     Optional[Any]									=  scope

							def        __snake_case   (				self			:    Optional[int]							)      ->       List[str]:
														__snake_case						:     Tuple									=  floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]							)

														__snake_case						:     Any									=  None
														if self.use_labels:
																					__snake_case						:     Optional[Any]									=  ids_tensor([self.batch_size]       ,      self.num_labels							)

														__snake_case						:     str									=  self.get_config()

														return config, pixel_values, labels

							def        __snake_case   (				self			:    str							)      ->       List[Any]:
														return ConvNextVaConfig(
														    num_channels=self.num_channels       ,      hidden_sizes=self.hidden_sizes       ,      depths=self.depths       ,      num_stages=self.num_stages       ,      hidden_act=self.hidden_act       ,      is_decoder=lowerCamelCase       ,      initializer_range=self.initializer_range       ,      out_features=self.out_features       ,      out_indices=self.out_indices       ,      num_labels=self.num_labels       ,      )

							def        __snake_case   (				self			:    Tuple       ,      lowerCamelCase			:    Optional[Any]       ,      lowerCamelCase			:    Tuple       ,      lowerCamelCase			:    str							)      ->       Any:
														__snake_case						:     Any									=  ConvNextVaModel(config=lowerCamelCase							)
														model.to(lowerCamelCase							)
														model.eval()
														__snake_case						:     Optional[Any]									=  model(lowerCamelCase							)
														# expected last hidden states: B, C, H // 32, W // 32
														self.parent.assertEqual(
														    result.last_hidden_state.shape       ,      (self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32)       ,      )

							def        __snake_case   (				self			:    List[str]       ,      lowerCamelCase			:    List[str]       ,      lowerCamelCase			:    Tuple       ,      lowerCamelCase			:    str							)      ->       List[str]:
														__snake_case						:     Any									=  ConvNextVaForImageClassification(lowerCamelCase							)
														model.to(lowerCamelCase							)
														model.eval()
														__snake_case						:     int									=  model(lowerCamelCase       ,      labels=lowerCamelCase							)
														self.parent.assertEqual(result.logits.shape       ,      (self.batch_size, self.num_labels)							)

							def        __snake_case   (				self			:    List[Any]       ,      lowerCamelCase			:    str       ,      lowerCamelCase			:    Dict       ,      lowerCamelCase			:    List[Any]							)      ->       Dict:
														__snake_case						:     Optional[int]									=  ConvNextVaBackbone(config=lowerCamelCase							)
														model.to(lowerCamelCase							)
														model.eval()
														__snake_case						:     Optional[Any]									=  model(lowerCamelCase							)

														# verify hidden states
														self.parent.assertEqual(len(result.feature_maps							)       ,      len(config.out_features							)							)
														self.parent.assertListEqual(list(result.feature_maps[0].shape							)       ,      [self.batch_size, self.hidden_sizes[1], 4, 4]							)

														# verify channels
														self.parent.assertEqual(len(model.channels							)       ,      len(config.out_features							)							)
														self.parent.assertListEqual(model.channels       ,      config.hidden_sizes[1:]							)

														# verify backbone works with out_features=None
														__snake_case						:     Union[str, Any]									=  None
														__snake_case						:     Optional[int]									=  ConvNextVaBackbone(config=lowerCamelCase							)
														model.to(lowerCamelCase							)
														model.eval()
														__snake_case						:     Optional[Any]									=  model(lowerCamelCase							)

														# verify feature maps
														self.parent.assertEqual(len(result.feature_maps							)       ,      1							)
														self.parent.assertListEqual(list(result.feature_maps[0].shape							)       ,      [self.batch_size, self.hidden_sizes[-1], 1, 1]							)

														# verify channels
														self.parent.assertEqual(len(model.channels							)       ,      1							)
														self.parent.assertListEqual(model.channels       ,      [config.hidden_sizes[-1]]							)

							def        __snake_case   (				self			:    List[str]							)      ->       Union[str, Any]:
														__snake_case						:     Optional[Any]									=  self.prepare_config_and_inputs()
														__snake_case					,     __snake_case					,     __snake_case						:     List[str]									=  config_and_inputs
														__snake_case						:     Optional[int]									=  {"pixel_values": pixel_values}
														return config, inputs_dict






							def        __snake_case   (				self			:    str							)      ->       Union[str, Any]:
														__snake_case						:     str									=  self.prepare_config_and_inputs()
														__snake_case					,     __snake_case					,     __snake_case						:     int									=  config_and_inputs
														__snake_case						:     List[Any]									=  {"pixel_values": pixel_values, "labels": labels}
														return config, inputs_dict

@require_torch
class 							a						(_lowerCAmelCase	,							_lowerCAmelCase	,							unittest.TestCase ):




							"""simple docstring"""


							__UpperCAmelCase       :				Any	    =    (
							    (
							        ConvNextVaModel,
							        ConvNextVaForImageClassification,
							        ConvNextVaBackbone,
							    )
							    if is_torch_available()
							    else ()
							)
							__UpperCAmelCase       :				Union[str, Any]	    =    (
							    {"feature-extraction": ConvNextVaModel, "image-classification": ConvNextVaForImageClassification}
							    if is_torch_available()
							    else {}
							)

							__UpperCAmelCase       :				str	    =    False
							__UpperCAmelCase       :				List[str]	    =    False
							__UpperCAmelCase       :				Optional[Any]	    =    False
							__UpperCAmelCase       :				List[Any]	    =    False
							__UpperCAmelCase       :				Optional[int]	    =    False

							def        __snake_case   (				self			:    Optional[int]							)      ->       List[Any]:
														__snake_case						:     Union[str, Any]									=  ConvNextVaModelTester(self							)
														__snake_case						:     Any									=  ConfigTester(self       ,      config_class=lowerCamelCase       ,      has_text_modality=lowerCamelCase       ,      hidden_size=37							)

							def        __snake_case   (				self			:    Optional[Any]							)      ->       Optional[Any]:
														self.create_and_test_config_common_properties()
														self.config_tester.create_and_test_config_to_json_string()
														self.config_tester.create_and_test_config_to_json_file()
														self.config_tester.create_and_test_config_from_and_save_pretrained()
														self.config_tester.create_and_test_config_with_num_labels()
														self.config_tester.check_config_can_be_init_without_params()
														self.config_tester.check_config_arguments_init()

							def        __snake_case   (				self			:    str							)      ->       Dict:
														return

							@unittest.skip(reason="ConvNextV2 does not use inputs_embeds"							)
							def        __snake_case   (				self			:    str							)      ->       str:
														pass

							@unittest.skip(reason="ConvNextV2 does not support input and output embeddings"							)
							def        __snake_case   (				self			:    Optional[int]							)      ->       str:
														pass

							@unittest.skip(reason="ConvNextV2 does not use feedforward chunking"							)
							def        __snake_case   (				self			:    Tuple							)      ->       Tuple:
														pass

							def        __snake_case   (				self			:    Tuple							)      ->       Optional[int]:
														if not self.model_tester.is_training:
																					return

														for model_class in self.all_model_classes:
																					__snake_case					,     __snake_case						:     Union[str, Any]									=  self.model_tester.prepare_config_and_inputs_with_labels()
																					__snake_case						:     Optional[int]									=  True

																					if model_class.__name__ in [
																					    *get_values(lowerCamelCase							),
																					    *get_values(lowerCamelCase							),
																					]:
																												continue

																					__snake_case						:     Optional[int]									=  model_class(lowerCamelCase							)
																					model.to(lowerCamelCase							)
																					model.train()
																					__snake_case						:     List[Any]									=  self._prepare_for_class(lowerCamelCase       ,      lowerCamelCase       ,      return_labels=lowerCamelCase							)
																					__snake_case						:     List[Any]									=  model(**lowerCamelCase							).loss
																					loss.backward()

							def        __snake_case   (				self			:    str							)      ->       Optional[Any]:
														if not self.model_tester.is_training:
																					return

														for model_class in self.all_model_classes:
																					__snake_case					,     __snake_case						:     str									=  self.model_tester.prepare_config_and_inputs_with_labels()
																					__snake_case						:     Tuple									=  False
																					__snake_case						:     List[str]									=  True

																					if (
																					    model_class.__name__
																					    in [*get_values(lowerCamelCase							), *get_values(lowerCamelCase							)]
																					    or not model_class.supports_gradient_checkpointing
																					):
																												continue

																					__snake_case						:     Dict									=  model_class(lowerCamelCase							)
																					model.to(lowerCamelCase							)
																					model.gradient_checkpointing_enable()
																					model.train()
																					__snake_case						:     int									=  self._prepare_for_class(lowerCamelCase       ,      lowerCamelCase       ,      return_labels=lowerCamelCase							)
																					__snake_case						:     List[str]									=  model(**lowerCamelCase							).loss
																					loss.backward()

							def        __snake_case   (				self			:    Optional[int]							)      ->       Tuple:
														__snake_case					,     __snake_case						:     List[str]									=  self.model_tester.prepare_config_and_inputs_for_common()

														for model_class in self.all_model_classes:
																					__snake_case						:     Dict									=  model_class(lowerCamelCase							)
																					__snake_case						:     List[str]									=  inspect.signature(model.forward							)
																					# signature.parameters is an OrderedDict => so arg_names order is deterministic
																					__snake_case						:     Dict									=  [*signature.parameters.keys()]

																					__snake_case						:     int									=  ["pixel_values"]
																					self.assertListEqual(arg_names[:1]       ,      lowerCamelCase							)

							def        __snake_case   (				self			:    Optional[Any]							)      ->       str:
														__snake_case						:     List[str]									=  self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_model(*lowerCamelCase							)

							def        __snake_case   (				self			:    Dict							)      ->       Dict:
														def check_hidden_states_output(lowerCamelCase			:    Any       ,      lowerCamelCase			:    List[str]       ,      lowerCamelCase			:    List[Any]							):
																					__snake_case						:     str									=  model_class(lowerCamelCase							)
																					model.to(lowerCamelCase							)
																					model.eval()

																					with torch.no_grad():
																												__snake_case						:     Tuple									=  model(**self._prepare_for_class(lowerCamelCase       ,      lowerCamelCase							)							)

																					__snake_case						:     Union[str, Any]									=  outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

																					__snake_case						:     int									=  self.model_tester.num_stages
																					self.assertEqual(len(lowerCamelCase							)       ,      expected_num_stages + 1							)

																					# ConvNextV2's feature maps are of shape (batch_size, num_channels, height, width)
																					self.assertListEqual(
																					    list(hidden_states[0].shape[-2:]							)       ,      [self.model_tester.image_size // 4, self.model_tester.image_size // 4]       ,      )

														__snake_case					,     __snake_case						:     int									=  self.model_tester.prepare_config_and_inputs_for_common()

														for model_class in self.all_model_classes:
																					__snake_case						:     Optional[Any]									=  True
																					check_hidden_states_output(lowerCamelCase       ,      lowerCamelCase       ,      lowerCamelCase							)

																					# check that output_hidden_states also work using config
																					del inputs_dict["output_hidden_states"]
																					__snake_case						:     Dict									=  True

																					check_hidden_states_output(lowerCamelCase       ,      lowerCamelCase       ,      lowerCamelCase							)

							def        __snake_case   (				self			:    int							)      ->       str:
														__snake_case						:     int									=  self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_image_classification(*lowerCamelCase							)






							@slow
							def        __snake_case   (				self			:    Tuple							)      ->       str:
														for model_name in CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																					__snake_case						:     int									=  ConvNextVaModel.from_pretrained(lowerCamelCase							)
																					self.assertIsNotNone(lowerCamelCase							)







def 							lowerCAmelCase_	(   ):
							__snake_case						:     Union[str, Any]									=  Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"      )
							return image

@require_torch
@require_vision
class 							a						(unittest.TestCase ):




							"""simple docstring"""


							@cached_property
							def        __snake_case   (				self			:    Optional[int]							)      ->       List[str]:
														return AutoImageProcessor.from_pretrained("facebook/convnextv2-tiny-1k-224"							) if is_vision_available() else None






							@slow
							def        __snake_case   (				self			:    int							)      ->       List[str]:
														__snake_case						:     int									=  ConvNextVaForImageClassification.from_pretrained("facebook/convnextv2-tiny-1k-224"							).to(lowerCamelCase							)

														__snake_case						:     Union[str, Any]									=  self.default_image_processor
														__snake_case						:     Optional[Any]									=  prepare_img()
														__snake_case						:     List[Any]									=  preprocessor(images=lowerCamelCase       ,      return_tensors="pt"							).to(lowerCamelCase							)

														# forward pass
														with torch.no_grad():
																					__snake_case						:     int									=  model(**lowerCamelCase							)

														# verify the logits
														__snake_case						:     List[str]									=  torch.Size((1, 1000)							)
														self.assertEqual(outputs.logits.shape       ,      lowerCamelCase							)

														__snake_case						:     Optional[int]									=  torch.tensor([0.99_96, 0.19_66, -0.43_86]							).to(lowerCamelCase							)
														self.assertTrue(torch.allclose(outputs.logits[0, :3]       ,      lowerCamelCase       ,      atol=1E-4							)							)









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

  '''simple docstring'''







  def __init__(      self		:			Union[str, Any]       ,				lowerCamelCase		:			str       ,				lowerCamelCase		:			Optional[Any]=13       ,				lowerCamelCase		:			List[Any]=7       ,				lowerCamelCase		:			List[Any]=True       ,				lowerCamelCase		:			str=True       ,				lowerCamelCase		:			List[str]=True       ,				lowerCamelCase		:			List[str]=True       ,				lowerCamelCase		:			Optional[int]=99       ,				lowerCamelCase		:			int=32       ,				lowerCamelCase		:			str=5       ,				lowerCamelCase		:			str=4       ,				lowerCamelCase		:			List[str]=37       ,				lowerCamelCase		:			str="gelu"       ,				lowerCamelCase		:			Dict=0.1       ,				lowerCamelCase		:			Any=0.1       ,				lowerCamelCase		:			Union[str, Any]=512       ,				lowerCamelCase		:			Optional[int]=16       ,				lowerCamelCase		:			Any=2       ,				lowerCamelCase		:			Any=0.02       ,				lowerCamelCase		:			List[Any]=False       ,				lowerCamelCase		:			Optional[Any]=True       ,				lowerCamelCase		:			Optional[int]="None"       ,				lowerCamelCase		:			Tuple=3       ,				lowerCamelCase		:			int=4       ,				lowerCamelCase		:			Optional[Any]=None       ,				)						->	Optional[int]:


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


  def  lowerCamelCase       (      self		:			str							)						->	Union[str, Any]:


         """simple docstring"""
         _UpperCAmelCase							=    ids_tensor([self.batch_size, self.seq_length]       ,				self.vocab_size							)

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

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

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

         _UpperCAmelCase							=    self.get_config()

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


  def  lowerCamelCase       (      self		:			Dict							)						->	Dict:


         """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  lowerCamelCase       (      self		:			Union[str, Any]       ,				lowerCamelCase		:			List[Any]							)						->	Union[str, Any]:


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


  def  lowerCamelCase       (      self		:			Optional[Any]       ,				lowerCamelCase		:			int       ,				lowerCamelCase		:			List[Any]       ,				lowerCamelCase		:			int       ,				lowerCamelCase		:			Union[str, Any]       ,				lowerCamelCase		:			List[str]       ,				lowerCamelCase		:			List[str]       ,				lowerCamelCase		:			Any							)						->	List[Any]:


         """simple docstring"""
         _UpperCAmelCase							=    DebertaVaModel(config=lowerCamelCase							)
         model.to(lowerCamelCase							)
         model.eval()
         _UpperCAmelCase							=    model(lowerCamelCase       ,				attention_mask=lowerCamelCase       ,				token_type_ids=lowerCamelCase							)[0]
         _UpperCAmelCase							=    model(lowerCamelCase       ,				token_type_ids=lowerCamelCase							)[0]
         _UpperCAmelCase							=    model(lowerCamelCase							)[0]

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


  def  lowerCamelCase       (      self		:			List[str]       ,				lowerCamelCase		:			Any       ,				lowerCamelCase		:			Optional[int]       ,				lowerCamelCase		:			int       ,				lowerCamelCase		:			Tuple       ,				lowerCamelCase		:			Optional[Any]       ,				lowerCamelCase		:			List[str]       ,				lowerCamelCase		:			List[Any]							)						->	List[str]:


         """simple docstring"""
         _UpperCAmelCase							=    DebertaVaForMaskedLM(config=lowerCamelCase							)
         model.to(lowerCamelCase							)
         model.eval()
         _UpperCAmelCase							=    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  lowerCamelCase       (      self		:			str       ,				lowerCamelCase		:			Optional[Any]       ,				lowerCamelCase		:			List[str]       ,				lowerCamelCase		:			Dict       ,				lowerCamelCase		:			List[Any]       ,				lowerCamelCase		:			List[str]       ,				lowerCamelCase		:			Optional[Any]       ,				lowerCamelCase		:			Any							)						->	Union[str, Any]:


         """simple docstring"""
         _UpperCAmelCase							=    self.num_labels
         _UpperCAmelCase							=    DebertaVaForSequenceClassification(lowerCamelCase							)
         model.to(lowerCamelCase							)
         model.eval()
         _UpperCAmelCase							=    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  lowerCamelCase       (      self		:			Dict       ,				lowerCamelCase		:			List[str]       ,				lowerCamelCase		:			int       ,				lowerCamelCase		:			Optional[Any]       ,				lowerCamelCase		:			Dict       ,				lowerCamelCase		:			Union[str, Any]       ,				lowerCamelCase		:			Optional[int]       ,				lowerCamelCase		:			Union[str, Any]							)						->	Tuple:


         """simple docstring"""
         _UpperCAmelCase							=    self.num_labels
         _UpperCAmelCase							=    DebertaVaForTokenClassification(config=lowerCamelCase							)
         model.to(lowerCamelCase							)
         model.eval()
         _UpperCAmelCase							=    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  lowerCamelCase       (      self		:			Any       ,				lowerCamelCase		:			Tuple       ,				lowerCamelCase		:			Any       ,				lowerCamelCase		:			str       ,				lowerCamelCase		:			Tuple       ,				lowerCamelCase		:			Optional[int]       ,				lowerCamelCase		:			Optional[Any]       ,				lowerCamelCase		:			str							)						->	Tuple:


         """simple docstring"""
         _UpperCAmelCase							=    DebertaVaForQuestionAnswering(config=lowerCamelCase							)
         model.to(lowerCamelCase							)
         model.eval()
         _UpperCAmelCase							=    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  lowerCamelCase       (      self		:			Dict       ,				lowerCamelCase		:			List[str]       ,				lowerCamelCase		:			str       ,				lowerCamelCase		:			Any       ,				lowerCamelCase		:			Tuple       ,				lowerCamelCase		:			Optional[Any]       ,				lowerCamelCase		:			Any       ,				lowerCamelCase		:			str							)						->	str:


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





  def  lowerCamelCase       (      self		:			List[str]							)						->	Optional[int]:


         """simple docstring"""
         _UpperCAmelCase							=    self.prepare_config_and_inputs()
         (
             (
             _UpperCAmelCase
         )	,			(
             _UpperCAmelCase
         )	,			(
             _UpperCAmelCase
         )	,			(
             _UpperCAmelCase
         )	,			(
             _UpperCAmelCase
         )	,			(
             _UpperCAmelCase
         )	,			(
             _UpperCAmelCase
         )	,			
         )							=    config_and_inputs
         _UpperCAmelCase							=    {"""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     ):

  '''simple docstring'''







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

  _lowerCamelCase    =  True
  _lowerCamelCase    =  False
  _lowerCamelCase    =  False
  _lowerCamelCase    =  False
  _lowerCamelCase    =  False


  def  lowerCamelCase       (      self		:			int							)						->	List[str]:


         """simple docstring"""
         _UpperCAmelCase							=    DebertaVaModelTester(self							)
         _UpperCAmelCase							=    ConfigTester(self       ,				config_class=lowerCamelCase       ,				hidden_size=37							)


  def  lowerCamelCase       (      self		:			Optional[int]							)						->	Tuple:


         """simple docstring"""
         self.config_tester.run_common_tests()


  def  lowerCamelCase       (      self		:			Tuple							)						->	Tuple:


         """simple docstring"""
         _UpperCAmelCase							=    self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_deberta_model(*lowerCamelCase							)


  def  lowerCamelCase       (      self		:			List[Any]							)						->	Any:


         """simple docstring"""
         _UpperCAmelCase							=    self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_deberta_for_sequence_classification(*lowerCamelCase							)


  def  lowerCamelCase       (      self		:			Union[str, Any]							)						->	List[str]:


         """simple docstring"""
         _UpperCAmelCase							=    self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_deberta_for_masked_lm(*lowerCamelCase							)


  def  lowerCamelCase       (      self		:			Tuple							)						->	Tuple:


         """simple docstring"""
         _UpperCAmelCase							=    self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_deberta_for_question_answering(*lowerCamelCase							)


  def  lowerCamelCase       (      self		:			Dict							)						->	List[str]:


         """simple docstring"""
         _UpperCAmelCase							=    self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_deberta_for_token_classification(*lowerCamelCase							)


  def  lowerCamelCase       (      self		:			int							)						->	List[Any]:


         """simple docstring"""
         _UpperCAmelCase							=    self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_deberta_for_multiple_choice(*lowerCamelCase							)





  @slow
  def  lowerCamelCase       (      self		:			Dict							)						->	Optional[int]:


         """simple docstring"""
         for model_name in DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                _UpperCAmelCase							=    DebertaVaModel.from_pretrained(lowerCamelCase							)
                self.assertIsNotNone(lowerCamelCase							)



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

  '''simple docstring'''







  @unittest.skip(reason="""Model not available yet"""							)
  def  lowerCamelCase       (      self		:			Any							)						->	Tuple:


         """simple docstring"""
         pass





  @slow
  def  lowerCamelCase       (      self		:			Union[str, Any]							)						->	int:


         """simple docstring"""
         _UpperCAmelCase							=    DebertaVaModel.from_pretrained("""microsoft/deberta-v2-xlarge"""							)

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