
import inspect
import math
import tempfile
import unittest

import numpy as np

from transformers import ViTMAEConfig
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 torch import nn

						from transformers import ViTMAEForPreTraining, ViTMAEModel
						from transformers.models.vit.modeling_vit import VIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
						from PIL import Image

						from transformers import ViTImageProcessor
class 					lowercase__:



	"""simple docstring"""




	def __init__(			self    :     str			,				SCREAMING_SNAKE_CASE_    :     int			,				SCREAMING_SNAKE_CASE_    :     Union[str, Any]=1_3			,				SCREAMING_SNAKE_CASE_    :     str=3_0			,				SCREAMING_SNAKE_CASE_    :     Union[str, Any]=2			,				SCREAMING_SNAKE_CASE_    :     Union[str, Any]=3			,				SCREAMING_SNAKE_CASE_    :     int=True			,				SCREAMING_SNAKE_CASE_    :     List[str]=True			,				SCREAMING_SNAKE_CASE_    :     str=3_2			,				SCREAMING_SNAKE_CASE_    :     Any=5			,				SCREAMING_SNAKE_CASE_    :     Any=4			,				SCREAMING_SNAKE_CASE_    :     Optional[int]=3_7			,				SCREAMING_SNAKE_CASE_    :     List[Any]="gelu"			,				SCREAMING_SNAKE_CASE_    :     Dict=0.1			,				SCREAMING_SNAKE_CASE_    :     Any=0.1			,				SCREAMING_SNAKE_CASE_    :     str=1_0			,				SCREAMING_SNAKE_CASE_    :     Optional[int]=0.02			,				SCREAMING_SNAKE_CASE_    :     str=3			,				SCREAMING_SNAKE_CASE_    :     int=0.6			,				SCREAMING_SNAKE_CASE_    :     Optional[Any]=None			,				)			->	str:
					lowercase_	    =   parent
					lowercase_	    =   batch_size
					lowercase_	    =   image_size
					lowercase_	    =   patch_size
					lowercase_	    =   num_channels
					lowercase_	    =   is_training
					lowercase_	    =   use_labels
					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_	    =   type_sequence_label_size
					lowercase_	    =   initializer_range
					lowercase_	    =   mask_ratio
					lowercase_	    =   scope

					# in ViTMAE, the expected sequence length = (num_patches + 1) * (1 - config.mask_ratio), rounded above
					# (we add 1 for the [CLS] token)
					lowercase_	    =   (image_size // patch_size) ** 2
					lowercase_	    =   int(math.ceil((1 - mask_ratio) * (num_patches + 1)			)			)
	def 		_lowercase    (			self    :     List[Any]			)			->	Union[str, Any]:
					lowercase_	    =   floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]			)

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

					lowercase_	    =   self.get_config()

					return config, pixel_values, labels
	def 		_lowercase    (			self    :     Union[str, Any]			)			->	int:
					return ViTMAEConfig(
					    image_size=self.image_size			,				patch_size=self.patch_size			,				num_channels=self.num_channels			,				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			,				is_decoder=SCREAMING_SNAKE_CASE_			,				initializer_range=self.initializer_range			,				mask_ratio=self.mask_ratio			,				)
	def 		_lowercase    (			self    :     Tuple			,				SCREAMING_SNAKE_CASE_    :     str			,				SCREAMING_SNAKE_CASE_    :     Union[str, Any]			,				SCREAMING_SNAKE_CASE_    :     str			)			->	int:
					lowercase_	    =   ViTMAEModel(config=SCREAMING_SNAKE_CASE_			)
					model.to(SCREAMING_SNAKE_CASE_			)
					model.eval()
					lowercase_	    =   model(SCREAMING_SNAKE_CASE_			)
					self.parent.assertEqual(result.last_hidden_state.shape			,				(self.batch_size, self.seq_length, self.hidden_size)			)
	def 		_lowercase    (			self    :     int			,				SCREAMING_SNAKE_CASE_    :     Tuple			,				SCREAMING_SNAKE_CASE_    :     List[Any]			,				SCREAMING_SNAKE_CASE_    :     List[str]			)			->	Optional[Any]:
					lowercase_	    =   ViTMAEForPreTraining(SCREAMING_SNAKE_CASE_			)
					model.to(SCREAMING_SNAKE_CASE_			)
					model.eval()
					lowercase_	    =   model(SCREAMING_SNAKE_CASE_			)
					lowercase_	    =   (self.image_size // self.patch_size) ** 2
					lowercase_	    =   self.patch_size**2 * self.num_channels
					self.parent.assertEqual(result.logits.shape			,				(self.batch_size, num_patches, expected_num_channels)			)

					# test greyscale images
					lowercase_	    =   1
					lowercase_	    =   ViTMAEForPreTraining(SCREAMING_SNAKE_CASE_			)
					model.to(SCREAMING_SNAKE_CASE_			)
					model.eval()
					lowercase_	    =   floats_tensor([self.batch_size, 1, self.image_size, self.image_size]			)
					lowercase_	    =   model(SCREAMING_SNAKE_CASE_			)
					lowercase_	    =   self.patch_size**2
					self.parent.assertEqual(result.logits.shape			,				(self.batch_size, num_patches, expected_num_channels)			)




	def 		_lowercase    (			self    :     Tuple			)			->	str:
					lowercase_	    =   self.prepare_config_and_inputs()
					lowercase_    ,      lowercase_    ,      lowercase_	    =   config_and_inputs
					lowercase_	    =   {'''pixel_values''': pixel_values}
					return config, inputs_dict

@require_torch
class 					lowercase__(							UpperCAmelCase					,		UpperCAmelCase					,		unittest.TestCase				):



	"""simple docstring"""




	a     :Tuple       	=      (ViTMAEModel, ViTMAEForPreTraining) if is_torch_available() else ()
	a     :List[str]       	=      {'feature-extraction': ViTMAEModel} if is_torch_available() else {}

	a     :Any       	=      False
	a     :Optional[int]       	=      False
	a     :Union[str, Any]       	=      False
	a     :Any       	=      False
	def 		_lowercase    (			self    :     str			)			->	Optional[Any]:
					lowercase_	    =   ViTMAEModelTester(self			)
					lowercase_	    =   ConfigTester(self			,				config_class=SCREAMING_SNAKE_CASE_			,				has_text_modality=SCREAMING_SNAKE_CASE_			,				hidden_size=3_7			)
	def 		_lowercase    (			self    :     Dict			)			->	Optional[Any]:
					self.config_tester.run_common_tests()
	@unittest.skip(reason='''ViTMAE does not use inputs_embeds'''			)
	def 		_lowercase    (			self    :     int			)			->	Union[str, Any]:
					pass
	def 		_lowercase    (			self    :     Union[str, Any]			)			->	List[str]:
					lowercase_    ,      lowercase_	    =   self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
									lowercase_	    =   model_class(SCREAMING_SNAKE_CASE_			)
									self.assertIsInstance(model.get_input_embeddings()			,				(nn.Module)			)
									lowercase_	    =   model.get_output_embeddings()
									self.assertTrue(x is None or isinstance(SCREAMING_SNAKE_CASE_			,				nn.Linear			)			)
	def 		_lowercase    (			self    :     int			)			->	Tuple:
					lowercase_    ,      lowercase_	    =   self.model_tester.prepare_config_and_inputs_for_common()

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

									lowercase_	    =   ['''pixel_values''']
									self.assertListEqual(arg_names[:1]			,				SCREAMING_SNAKE_CASE_			)
	def 		_lowercase    (			self    :     Union[str, Any]			)			->	Optional[Any]:
					lowercase_	    =   self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE_			)
	def 		_lowercase    (			self    :     Union[str, Any]			)			->	Tuple:
					lowercase_	    =   self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_pretraining(*SCREAMING_SNAKE_CASE_			)
	def 		_lowercase    (			self    :     str			,				SCREAMING_SNAKE_CASE_    :     Union[str, Any]			,				SCREAMING_SNAKE_CASE_    :     List[Any]			,				SCREAMING_SNAKE_CASE_    :     Optional[Any]			)			->	List[str]:
					# make masks reproducible
					np.random.seed(2			)

					lowercase_	    =   int((pt_model.config.image_size // pt_model.config.patch_size) ** 2			)
					lowercase_	    =   np.random.uniform(size=(self.model_tester.batch_size, num_patches)			)
					lowercase_	    =   torch.from_numpy(SCREAMING_SNAKE_CASE_			)

					# Add `noise` argument.
					# PT inputs will be prepared in `super().check_pt_tf_models()` with this added `noise` argument
					lowercase_	    =   pt_noise

					super().check_pt_tf_models(SCREAMING_SNAKE_CASE_			,				SCREAMING_SNAKE_CASE_			,				SCREAMING_SNAKE_CASE_			)
	def 		_lowercase    (			self    :     str			)			->	Optional[Any]:
					lowercase_    ,      lowercase_	    =   self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
									lowercase_	    =   model_class(SCREAMING_SNAKE_CASE_			)
									model.to(SCREAMING_SNAKE_CASE_			)
									model.eval()
									# make random mask reproducible
									torch.manual_seed(2			)
									with torch.no_grad():
													lowercase_	    =   model(**self._prepare_for_class(SCREAMING_SNAKE_CASE_			,				SCREAMING_SNAKE_CASE_			)			)

									lowercase_	    =   outputs[0].cpu().numpy()
									lowercase_	    =   0

									with tempfile.TemporaryDirectory() as tmpdirname:
													model.save_pretrained(SCREAMING_SNAKE_CASE_			)
													lowercase_	    =   model_class.from_pretrained(SCREAMING_SNAKE_CASE_			)
													model.to(SCREAMING_SNAKE_CASE_			)
													# make random mask reproducible
													torch.manual_seed(2			)
													with torch.no_grad():
																	lowercase_	    =   model(**self._prepare_for_class(SCREAMING_SNAKE_CASE_			,				SCREAMING_SNAKE_CASE_			)			)

													# Make sure we don't have nans
													lowercase_	    =   after_outputs[0].cpu().numpy()
													lowercase_	    =   0
													lowercase_	    =   np.amax(np.abs(out_a - out_a			)			)
													self.assertLessEqual(SCREAMING_SNAKE_CASE_			,				1e-5			)
	@unittest.skip(
	    reason='''ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load
    to get deterministic results.'''			)
	def 		_lowercase    (			self    :     Dict			)			->	int:
					pass
	@unittest.skip(
	    reason='''ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load
    to get deterministic results.'''			)
	def 		_lowercase    (			self    :     int			)			->	Optional[int]:
					pass
	@unittest.skip(
	    reason='''ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load
    to get deterministic results.'''			)
	def 		_lowercase    (			self    :     Optional[Any]			)			->	List[Any]:
					pass
	@unittest.skip(reason='''ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load'''			)
	def 		_lowercase    (			self    :     Optional[Any]			)			->	Union[str, Any]:
					pass
	@unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''			)
	def 		_lowercase    (			self    :     List[Any]			)			->	Optional[Any]:
					pass




	@slow
	def 		_lowercase    (			self    :     Dict			)			->	List[str]:
					for model_name in VIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									lowercase_	    =   ViTMAEModel.from_pretrained(SCREAMING_SNAKE_CASE_			)
									self.assertIsNotNone(SCREAMING_SNAKE_CASE_			)




def 							a		(				):


				'''simple docstring'''
				lowercase_	    =   Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''   )
				return image


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



	"""simple docstring"""




	@cached_property
	def 		_lowercase    (			self    :     Any			)			->	Dict:
					return ViTImageProcessor.from_pretrained('''facebook/vit-mae-base'''			) if is_vision_available() else None




	@slow
	def 		_lowercase    (			self    :     Optional[int]			)			->	List[Any]:
					# make random mask reproducible across the PT and TF model
					np.random.seed(2			)

					lowercase_	    =   ViTMAEForPreTraining.from_pretrained('''facebook/vit-mae-base'''			).to(SCREAMING_SNAKE_CASE_			)

					lowercase_	    =   self.default_image_processor
					lowercase_	    =   prepare_img()
					lowercase_	    =   image_processor(images=SCREAMING_SNAKE_CASE_			,				return_tensors='''pt'''			).to(SCREAMING_SNAKE_CASE_			)

					# prepare a noise vector that will be also used for testing the TF model
					# (this way we can ensure that the PT and TF models operate on the same inputs)
					lowercase_	    =   ViTMAEConfig()
					lowercase_	    =   int((vit_mae_config.image_size // vit_mae_config.patch_size) ** 2			)
					lowercase_	    =   np.random.uniform(size=(1, num_patches)			)

					# forward pass
					with torch.no_grad():
									lowercase_	    =   model(**SCREAMING_SNAKE_CASE_			,				noise=torch.from_numpy(SCREAMING_SNAKE_CASE_			).to(device=SCREAMING_SNAKE_CASE_			)			)

					# verify the logits
					lowercase_	    =   torch.Size((1, 1_9_6, 7_6_8)			)
					self.assertEqual(outputs.logits.shape			,				SCREAMING_SNAKE_CASE_			)

					lowercase_	    =   torch.tensor(
					    [[-0.05_48, -1.70_23, -0.93_25], [0.37_21, -0.56_70, -0.22_33], [0.82_35, -1.38_78, -0.35_24]]			)

					self.assertTrue(torch.allclose(outputs.logits[0, :3, :3]			,				expected_slice.to(SCREAMING_SNAKE_CASE_			)			,				atol=1e-4			)			)






from __future__ import annotations

import unittest

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

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


if is_tf_available():
						import tensorflow as tf

						from transformers import (
						    TFDebertaVaForMaskedLM,
						    TFDebertaVaForQuestionAnswering,
						    TFDebertaVaForSequenceClassification,
						    TFDebertaVaForTokenClassification,
						    TFDebertaVaModel,
						)
class 					lowercase__:



	"""simple docstring"""




	def __init__(			self    :     Dict			,				SCREAMING_SNAKE_CASE_    :     str			,				SCREAMING_SNAKE_CASE_    :     str=1_3			,				SCREAMING_SNAKE_CASE_    :     Optional[Any]=7			,				SCREAMING_SNAKE_CASE_    :     Dict=True			,				SCREAMING_SNAKE_CASE_    :     Tuple=True			,				SCREAMING_SNAKE_CASE_    :     Optional[Any]=True			,				SCREAMING_SNAKE_CASE_    :     Tuple=True			,				SCREAMING_SNAKE_CASE_    :     Tuple=9_9			,				SCREAMING_SNAKE_CASE_    :     List[str]=3_2			,				SCREAMING_SNAKE_CASE_    :     int=2			,				SCREAMING_SNAKE_CASE_    :     Tuple=4			,				SCREAMING_SNAKE_CASE_    :     Union[str, Any]=3_7			,				SCREAMING_SNAKE_CASE_    :     Union[str, Any]="gelu"			,				SCREAMING_SNAKE_CASE_    :     Union[str, Any]=0.1			,				SCREAMING_SNAKE_CASE_    :     Union[str, Any]=0.1			,				SCREAMING_SNAKE_CASE_    :     Optional[int]=5_1_2			,				SCREAMING_SNAKE_CASE_    :     str=1_6			,				SCREAMING_SNAKE_CASE_    :     Union[str, Any]=2			,				SCREAMING_SNAKE_CASE_    :     List[Any]=0.02			,				SCREAMING_SNAKE_CASE_    :     List[Any]=False			,				SCREAMING_SNAKE_CASE_    :     List[Any]=True			,				SCREAMING_SNAKE_CASE_    :     Union[str, Any]="None"			,				SCREAMING_SNAKE_CASE_    :     Optional[Any]=3			,				SCREAMING_SNAKE_CASE_    :     List[Any]=4			,				SCREAMING_SNAKE_CASE_    :     str=None			,				)			->	str:
					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 		_lowercase    (			self    :     List[Any]			)			->	List[Any]:
					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
					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_	    =   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			,				relative_attention=self.relative_attention			,				position_biased_input=self.position_biased_input			,				initializer_range=self.initializer_range			,				return_dict=SCREAMING_SNAKE_CASE_			,				)

					return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
	def 		_lowercase    (			self    :     str			,				SCREAMING_SNAKE_CASE_    :     Any			,				SCREAMING_SNAKE_CASE_    :     Optional[int]			,				SCREAMING_SNAKE_CASE_    :     str			,				SCREAMING_SNAKE_CASE_    :     Tuple			,				SCREAMING_SNAKE_CASE_    :     Dict			,				SCREAMING_SNAKE_CASE_    :     Dict			,				SCREAMING_SNAKE_CASE_    :     List[Any]			)			->	List[Any]:
					lowercase_	    =   TFDebertaVaModel(config=SCREAMING_SNAKE_CASE_			)
					lowercase_	    =   {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}

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

					lowercase_	    =   model(SCREAMING_SNAKE_CASE_			)

					self.parent.assertEqual(result.last_hidden_state.shape			,				(self.batch_size, self.seq_length, self.hidden_size)			)
	def 		_lowercase    (			self    :     Tuple			,				SCREAMING_SNAKE_CASE_    :     Optional[Any]			,				SCREAMING_SNAKE_CASE_    :     str			,				SCREAMING_SNAKE_CASE_    :     Any			,				SCREAMING_SNAKE_CASE_    :     int			,				SCREAMING_SNAKE_CASE_    :     Dict			,				SCREAMING_SNAKE_CASE_    :     Any			,				SCREAMING_SNAKE_CASE_    :     Any			)			->	Union[str, Any]:
					lowercase_	    =   TFDebertaVaForMaskedLM(config=SCREAMING_SNAKE_CASE_			)
					lowercase_	    =   {
					    '''input_ids''': input_ids,
					    '''attention_mask''': input_mask,
					    '''token_type_ids''': token_type_ids,
					}
					lowercase_	    =   model(SCREAMING_SNAKE_CASE_			)
					self.parent.assertEqual(result.logits.shape			,				(self.batch_size, self.seq_length, self.vocab_size)			)
	def 		_lowercase    (			self    :     Optional[int]			,				SCREAMING_SNAKE_CASE_    :     Tuple			,				SCREAMING_SNAKE_CASE_    :     int			,				SCREAMING_SNAKE_CASE_    :     Tuple			,				SCREAMING_SNAKE_CASE_    :     str			,				SCREAMING_SNAKE_CASE_    :     List[Any]			,				SCREAMING_SNAKE_CASE_    :     Union[str, Any]			,				SCREAMING_SNAKE_CASE_    :     Union[str, Any]			)			->	List[str]:
					lowercase_	    =   self.num_labels
					lowercase_	    =   TFDebertaVaForSequenceClassification(config=SCREAMING_SNAKE_CASE_			)
					lowercase_	    =   {
					    '''input_ids''': input_ids,
					    '''attention_mask''': input_mask,
					    '''token_type_ids''': token_type_ids,
					}

					lowercase_	    =   model(SCREAMING_SNAKE_CASE_			)
					self.parent.assertEqual(result.logits.shape			,				(self.batch_size, self.num_labels)			)
	def 		_lowercase    (			self    :     Optional[int]			,				SCREAMING_SNAKE_CASE_    :     Tuple			,				SCREAMING_SNAKE_CASE_    :     List[Any]			,				SCREAMING_SNAKE_CASE_    :     List[Any]			,				SCREAMING_SNAKE_CASE_    :     Union[str, Any]			,				SCREAMING_SNAKE_CASE_    :     str			,				SCREAMING_SNAKE_CASE_    :     Any			,				SCREAMING_SNAKE_CASE_    :     Optional[int]			)			->	Optional[Any]:
					lowercase_	    =   self.num_labels
					lowercase_	    =   TFDebertaVaForTokenClassification(config=SCREAMING_SNAKE_CASE_			)
					lowercase_	    =   {
					    '''input_ids''': input_ids,
					    '''attention_mask''': input_mask,
					    '''token_type_ids''': token_type_ids,
					}
					lowercase_	    =   model(SCREAMING_SNAKE_CASE_			)
					self.parent.assertEqual(result.logits.shape			,				(self.batch_size, self.seq_length, self.num_labels)			)
	def 		_lowercase    (			self    :     Union[str, Any]			,				SCREAMING_SNAKE_CASE_    :     List[str]			,				SCREAMING_SNAKE_CASE_    :     List[Any]			,				SCREAMING_SNAKE_CASE_    :     int			,				SCREAMING_SNAKE_CASE_    :     Optional[Any]			,				SCREAMING_SNAKE_CASE_    :     List[Any]			,				SCREAMING_SNAKE_CASE_    :     List[Any]			,				SCREAMING_SNAKE_CASE_    :     Optional[int]			)			->	str:
					lowercase_	    =   TFDebertaVaForQuestionAnswering(config=SCREAMING_SNAKE_CASE_			)
					lowercase_	    =   {
					    '''input_ids''': input_ids,
					    '''attention_mask''': input_mask,
					    '''token_type_ids''': token_type_ids,
					}

					lowercase_	    =   model(SCREAMING_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 		_lowercase    (			self    :     List[str]			)			->	Optional[int]:
					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_tf
class 					lowercase__(							UpperCAmelCase					,		UpperCAmelCase					,		unittest.TestCase				):



	"""simple docstring"""




	a     :str       	=      (
	    (
	        TFDebertaVaModel,
	        TFDebertaVaForMaskedLM,
	        TFDebertaVaForQuestionAnswering,
	        TFDebertaVaForSequenceClassification,
	        TFDebertaVaForTokenClassification,
	    )
	    if is_tf_available()
	    else ()
	)
	a     :int       	=      (
	    {
	        'feature-extraction': TFDebertaVaModel,
	        'fill-mask': TFDebertaVaForMaskedLM,
	        'question-answering': TFDebertaVaForQuestionAnswering,
	        'text-classification': TFDebertaVaForSequenceClassification,
	        'token-classification': TFDebertaVaForTokenClassification,
	        'zero-shot': TFDebertaVaForSequenceClassification,
	    }
	    if is_tf_available()
	    else {}
	)

	a     :int       	=      False
	a     :Any       	=      False
	def 		_lowercase    (			self    :     Dict			)			->	str:
					lowercase_	    =   TFDebertaVaModelTester(self			)
					lowercase_	    =   ConfigTester(self			,				config_class=SCREAMING_SNAKE_CASE_			,				hidden_size=3_7			)
	def 		_lowercase    (			self    :     Tuple			)			->	Dict:
					self.config_tester.run_common_tests()
	def 		_lowercase    (			self    :     Union[str, Any]			)			->	int:
					lowercase_	    =   self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE_			)
	def 		_lowercase    (			self    :     Dict			)			->	List[Any]:
					lowercase_	    =   self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_masked_lm(*SCREAMING_SNAKE_CASE_			)
	def 		_lowercase    (			self    :     Optional[Any]			)			->	Optional[int]:
					lowercase_	    =   self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_question_answering(*SCREAMING_SNAKE_CASE_			)
	def 		_lowercase    (			self    :     Any			)			->	str:
					lowercase_	    =   self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_sequence_classification(*SCREAMING_SNAKE_CASE_			)
	def 		_lowercase    (			self    :     Union[str, Any]			)			->	Optional[Any]:
					lowercase_	    =   self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_token_classification(*SCREAMING_SNAKE_CASE_			)




	@slow
	def 		_lowercase    (			self    :     Tuple			)			->	Dict:
					lowercase_	    =   TFDebertaVaModel.from_pretrained('''kamalkraj/deberta-v2-xlarge'''			)
					self.assertIsNotNone(SCREAMING_SNAKE_CASE_			)

@require_tf
class 					lowercase__(							unittest.TestCase				):



	"""simple docstring"""




	@unittest.skip(reason='''Model not available yet'''			)
	def 		_lowercase    (			self    :     Optional[Any]			)			->	Union[str, Any]:
					pass




	@slow
	def 		_lowercase    (			self    :     List[Any]			)			->	Dict:
					lowercase_	    =   TFDebertaVaModel.from_pretrained('''kamalkraj/deberta-v2-xlarge'''			)
					lowercase_	    =   tf.constant([[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_	    =   tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]			)
					lowercase_	    =   model(SCREAMING_SNAKE_CASE_			,				attention_mask=SCREAMING_SNAKE_CASE_			)[0]

					lowercase_	    =   tf.constant(
					    [[[0.23_56, 0.19_48, 0.03_69], [-0.10_63, 0.35_86, -0.51_52], [-0.63_99, -0.02_59, -0.25_25]]]			)
					tf.debugging.assert_near(output[:, 1:4, 1:4]			,				SCREAMING_SNAKE_CASE_			,				atol=1e-4			)




