"""simple docstring"""







import unittest

from transformers import DebertaConfig, 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 (
	    DebertaForMaskedLM,
	    DebertaForQuestionAnswering,
	    DebertaForSequenceClassification,
	    DebertaForTokenClassification,
	    DebertaModel,
	)
	from transformers.models.deberta.modeling_deberta import DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST

class 		UpperCamelCase      (   __a						):



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



				def  _lowercase					(self    :				Optional[Any])   ->     Optional[Any]:
					__snake_case      :							Any						=			ids_tensor([self.batch_size, self.seq_length]     ,  self.vocab_size)

					__snake_case      :							Union[str, Any]						=			None
					if self.use_input_mask:
						__snake_case      :							Tuple						=			ids_tensor([self.batch_size, self.seq_length]     ,  vocab_size=2)

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

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

					__snake_case      :							Optional[int]						=			self.get_config()

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



				def  _lowercase					(self    :				str)   ->     Optional[int]:
					return DebertaConfig(
					    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  _lowercase					(self    :				Union[str, Any])   ->     str:
					__snake_case      :							Union[str, Any]						=			self.get_config()
					__snake_case      :							Any						=			3_00
					return config



				def  _lowercase					(self    :				List[Any]     ,  _A    :				Any)   ->     str:
					self.parent.assertListEqual(list(result.loss.size())     ,  [])



				def  _lowercase					(self    :				str     ,  _A    :				List[str]     ,  _A    :				Any     ,  _A    :				Union[str, Any]     ,  _A    :				Union[str, Any]     ,  _A    :				List[str]     ,  _A    :				Optional[int]     ,  _A    :				int)   ->     str:
					__snake_case      :							Optional[int]						=			DebertaModel(config=UpperCamelCase__)
					model.to(UpperCamelCase__)
					model.eval()
					__snake_case      :							List[str]						=			model(UpperCamelCase__     ,  attention_mask=UpperCamelCase__     ,  token_type_ids=UpperCamelCase__)[0]
					__snake_case      :							Union[str, Any]						=			model(UpperCamelCase__     ,  token_type_ids=UpperCamelCase__)[0]
					__snake_case      :							int						=			model(UpperCamelCase__)[0]

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



				def  _lowercase					(self    :				Dict     ,  _A    :				Optional[int]     ,  _A    :				Union[str, Any]     ,  _A    :				Optional[int]     ,  _A    :				Optional[Any]     ,  _A    :				Optional[int]     ,  _A    :				Optional[Any]     ,  _A    :				str)   ->     Optional[Any]:
					__snake_case      :							str						=			DebertaForMaskedLM(config=UpperCamelCase__)
					model.to(UpperCamelCase__)
					model.eval()
					__snake_case      :							int						=			model(UpperCamelCase__     ,  attention_mask=UpperCamelCase__     ,  token_type_ids=UpperCamelCase__     ,  labels=UpperCamelCase__)

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



				def  _lowercase					(self    :				Dict     ,  _A    :				Optional[int]     ,  _A    :				Optional[int]     ,  _A    :				Tuple     ,  _A    :				Optional[int]     ,  _A    :				Union[str, Any]     ,  _A    :				Union[str, Any]     ,  _A    :				Union[str, Any])   ->     str:
					__snake_case      :							List[str]						=			self.num_labels
					__snake_case      :							int						=			DebertaForSequenceClassification(UpperCamelCase__)
					model.to(UpperCamelCase__)
					model.eval()
					__snake_case      :							Tuple						=			model(UpperCamelCase__     ,  attention_mask=UpperCamelCase__     ,  token_type_ids=UpperCamelCase__     ,  labels=UpperCamelCase__)
					self.parent.assertListEqual(list(result.logits.size())     ,  [self.batch_size, self.num_labels])
					self.check_loss_output(UpperCamelCase__)



				def  _lowercase					(self    :				Optional[Any]     ,  _A    :				str     ,  _A    :				Any     ,  _A    :				Optional[int]     ,  _A    :				Union[str, Any]     ,  _A    :				str     ,  _A    :				Optional[Any]     ,  _A    :				Union[str, Any])   ->     Dict:
					__snake_case      :							str						=			self.num_labels
					__snake_case      :							Optional[Any]						=			DebertaForTokenClassification(config=UpperCamelCase__)
					model.to(UpperCamelCase__)
					model.eval()
					__snake_case      :							int						=			model(UpperCamelCase__     ,  attention_mask=UpperCamelCase__     ,  token_type_ids=UpperCamelCase__     ,  labels=UpperCamelCase__)
					self.parent.assertEqual(result.logits.shape     ,  (self.batch_size, self.seq_length, self.num_labels))



				def  _lowercase					(self    :				Optional[int]     ,  _A    :				str     ,  _A    :				Dict     ,  _A    :				Optional[int]     ,  _A    :				Optional[int]     ,  _A    :				List[Any]     ,  _A    :				List[str]     ,  _A    :				List[Any])   ->     int:
					__snake_case      :							Optional[Any]						=			DebertaForQuestionAnswering(config=UpperCamelCase__)
					model.to(UpperCamelCase__)
					model.eval()
					__snake_case      :							Any						=			model(
					    UpperCamelCase__     ,  attention_mask=UpperCamelCase__     ,  token_type_ids=UpperCamelCase__     ,  start_positions=UpperCamelCase__     ,  end_positions=UpperCamelCase__     ,  )
					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    :				Optional[int])   ->     Any:
					__snake_case      :							List[Any]						=			self.prepare_config_and_inputs()
					(
					    (
					    __snake_case     
					)		,    (
					    __snake_case     
					)		,    (
					    __snake_case     
					)		,    (
					    __snake_case     
					)		,    (
					    __snake_case     
					)		,    (
					    __snake_case     
					)		,    (
					    __snake_case     
					)		,         
					)      :							Tuple						=			config_and_inputs
					__snake_case      :							Any						=			{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
					return config, inputs_dict







@require_torch
class 		UpperCamelCase      (   __a				,     __a				,     unittest.TestCase						):
				UpperCAmelCase    :				int   =		(
				    (
				        DebertaModel,
				        DebertaForMaskedLM,
				        DebertaForSequenceClassification,
				        DebertaForTokenClassification,
				        DebertaForQuestionAnswering,
				    )
				    if is_torch_available()
				    else ()
				)
				UpperCAmelCase    :				int   =		(
				    {
				        """feature-extraction""": DebertaModel,
				        """fill-mask""": DebertaForMaskedLM,
				        """question-answering""": DebertaForQuestionAnswering,
				        """text-classification""": DebertaForSequenceClassification,
				        """token-classification""": DebertaForTokenClassification,
				        """zero-shot""": DebertaForSequenceClassification,
				    }
				    if is_torch_available()
				    else {}
				)

				UpperCAmelCase    :				List[str]   =		True
				UpperCAmelCase    :				int   =		False
				UpperCAmelCase    :				Optional[int]   =		False
				UpperCAmelCase    :				Any   =		False
				UpperCAmelCase    :				Dict   =		False



				def  _lowercase					(self    :				int)   ->     Any:
					__snake_case      :							Optional[int]						=			DebertaModelTester(self)
					__snake_case      :							Any						=			ConfigTester(self     ,  config_class=UpperCamelCase__     ,  hidden_size=37)



				def  _lowercase					(self    :				Optional[Any])   ->     List[str]:
					self.config_tester.run_common_tests()



				def  _lowercase					(self    :				Union[str, Any])   ->     Tuple:
					__snake_case      :							Dict						=			self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_deberta_model(*UpperCamelCase__)



				def  _lowercase					(self    :				str)   ->     List[str]:
					__snake_case      :							Optional[int]						=			self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_deberta_for_sequence_classification(*UpperCamelCase__)



				def  _lowercase					(self    :				Dict)   ->     Optional[int]:
					__snake_case      :							int						=			self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_deberta_for_masked_lm(*UpperCamelCase__)



				def  _lowercase					(self    :				Optional[Any])   ->     Optional[int]:
					__snake_case      :							Optional[Any]						=			self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_deberta_for_question_answering(*UpperCamelCase__)



				def  _lowercase					(self    :				List[str])   ->     Optional[Any]:
					__snake_case      :							Optional[int]						=			self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_deberta_for_token_classification(*UpperCamelCase__)






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



					for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
						__snake_case      :							Dict						=			DebertaModel.from_pretrained(UpperCamelCase__)
						self.assertIsNotNone(UpperCamelCase__)







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



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






				@slow
				def  _lowercase					(self    :				Union[str, Any])   ->     Optional[Any]:
					__snake_case      :							str						=			DebertaModel.from_pretrained('microsoft/deberta-base')

					__snake_case      :							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]])
					__snake_case      :							Tuple						=			torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
					with torch.no_grad():
						__snake_case      :							List[Any]						=			model(UpperCamelCase__     ,  attention_mask=UpperCamelCase__)[0]
					# compare the actual values for a slice.
					__snake_case      :							Tuple						=			torch.tensor(
					    [[[-0.5_986, -0.8_055, -0.8_462], [1.4_484, -0.9_348, -0.8_059], [0.3_123, 0.0_032, -1.4_131]]])
					self.assertTrue(torch.allclose(output[:, 1:4, 1:4]     ,  UpperCamelCase__     ,  atol=1E-4)     ,  f"{output[:, 1:4, 1:4]}")

"""simple docstring"""







import warnings

from ...utils import logging
from .image_processing_videomae import VideoMAEImageProcessor


_a					:					Tuple=			logging.get_logger(__name__)

class 		UpperCamelCase      (   lowercase						):



				def __init__(self    :				int     ,  *_A    :				str     ,  **_A    :				List[str])   ->     None:
					warnings.warn(
					    'The class VideoMAEFeatureExtractor is deprecated and will be removed in version 5 of Transformers.'
					    ' Please use VideoMAEImageProcessor instead.'     ,  _A     ,  )
					super().__init__(*_A     ,  **_A)





