
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  lowercase__(				lowerCamelCase_							):



	"""simple docstring"""




	def __init__(       self  :			int       ,							SCREAMING_SNAKE_CASE_  :			int       ,							SCREAMING_SNAKE_CASE_  :			str=1_3       ,							SCREAMING_SNAKE_CASE_  :			int=7       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]=True       ,							SCREAMING_SNAKE_CASE_  :			int=True       ,							SCREAMING_SNAKE_CASE_  :			Dict=True       ,							SCREAMING_SNAKE_CASE_  :			Tuple=True       ,							SCREAMING_SNAKE_CASE_  :			Dict=9_9       ,							SCREAMING_SNAKE_CASE_  :			Tuple=3_2       ,							SCREAMING_SNAKE_CASE_  :			str=5       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]=4       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]=3_7       ,							SCREAMING_SNAKE_CASE_  :			List[str]="gelu"       ,							SCREAMING_SNAKE_CASE_  :			List[Any]=0.1       ,							SCREAMING_SNAKE_CASE_  :			Tuple=0.1       ,							SCREAMING_SNAKE_CASE_  :			str=5_1_2       ,							SCREAMING_SNAKE_CASE_  :			Union[str, Any]=1_6       ,							SCREAMING_SNAKE_CASE_  :			List[str]=2       ,							SCREAMING_SNAKE_CASE_  :			Tuple=0.02       ,							SCREAMING_SNAKE_CASE_  :			List[Any]=False       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]=True       ,							SCREAMING_SNAKE_CASE_  :			Union[str, Any]="None"       ,							SCREAMING_SNAKE_CASE_  :			List[str]=3       ,							SCREAMING_SNAKE_CASE_  :			Union[str, Any]=4       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]=None       ,							)       ->     List[Any]:
					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  :			Optional[int]       )       ->     Optional[Any]:
					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 						_lowercase  (       self  :			Any       )       ->     Tuple:
					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  :			str       )       ->     Tuple:
					lowercase_       =					self.get_config()
					lowercase_       =					3_0_0
					return config
	def 						_lowercase  (       self  :			Dict       ,							SCREAMING_SNAKE_CASE_  :			Dict       )       ->     List[Any]:
					self.parent.assertListEqual(list(result.loss.size()       )       ,							[]       )
	def 						_lowercase  (       self  :			Tuple       ,							SCREAMING_SNAKE_CASE_  :			List[str]       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]       ,							SCREAMING_SNAKE_CASE_  :			List[Any]       ,							SCREAMING_SNAKE_CASE_  :			Any       ,							SCREAMING_SNAKE_CASE_  :			Tuple       ,							SCREAMING_SNAKE_CASE_  :			Dict       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]       )       ->     List[str]:
					lowercase_       =					DebertaModel(config=__snake_case       )
					model.to(__snake_case       )
					model.eval()
					lowercase_       =					model(__snake_case       ,							attention_mask=__snake_case       ,							token_type_ids=__snake_case       )[0]
					lowercase_       =					model(__snake_case       ,							token_type_ids=__snake_case       )[0]
					lowercase_       =					model(__snake_case       )[0]

					self.parent.assertListEqual(list(sequence_output.size()       )       ,							[self.batch_size, self.seq_length, self.hidden_size]       )
	def 						_lowercase  (       self  :			Tuple       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]       ,							SCREAMING_SNAKE_CASE_  :			int       ,							SCREAMING_SNAKE_CASE_  :			List[Any]       ,							SCREAMING_SNAKE_CASE_  :			Any       ,							SCREAMING_SNAKE_CASE_  :			Tuple       ,							SCREAMING_SNAKE_CASE_  :			Union[str, Any]       ,							SCREAMING_SNAKE_CASE_  :			Union[str, Any]       )       ->     str:
					lowercase_       =					DebertaForMaskedLM(config=__snake_case       )
					model.to(__snake_case       )
					model.eval()
					lowercase_       =					model(__snake_case       ,							attention_mask=__snake_case       ,							token_type_ids=__snake_case       ,							labels=__snake_case       )

					self.parent.assertEqual(result.logits.shape       ,							(self.batch_size, self.seq_length, self.vocab_size)       )
	def 						_lowercase  (       self  :			Any       ,							SCREAMING_SNAKE_CASE_  :			Any       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]       ,							SCREAMING_SNAKE_CASE_  :			Any       ,							SCREAMING_SNAKE_CASE_  :			Union[str, Any]       ,							SCREAMING_SNAKE_CASE_  :			Union[str, Any]       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]       ,							SCREAMING_SNAKE_CASE_  :			int       )       ->     Optional[Any]:
					lowercase_       =					self.num_labels
					lowercase_       =					DebertaForSequenceClassification(__snake_case       )
					model.to(__snake_case       )
					model.eval()
					lowercase_       =					model(__snake_case       ,							attention_mask=__snake_case       ,							token_type_ids=__snake_case       ,							labels=__snake_case       )
					self.parent.assertListEqual(list(result.logits.size()       )       ,							[self.batch_size, self.num_labels]       )
					self.check_loss_output(__snake_case       )
	def 						_lowercase  (       self  :			Union[str, Any]       ,							SCREAMING_SNAKE_CASE_  :			List[Any]       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]       ,							SCREAMING_SNAKE_CASE_  :			Dict       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]       ,							SCREAMING_SNAKE_CASE_  :			List[str]       ,							SCREAMING_SNAKE_CASE_  :			int       )       ->     List[Any]:
					lowercase_       =					self.num_labels
					lowercase_       =					DebertaForTokenClassification(config=__snake_case       )
					model.to(__snake_case       )
					model.eval()
					lowercase_       =					model(__snake_case       ,							attention_mask=__snake_case       ,							token_type_ids=__snake_case       ,							labels=__snake_case       )
					self.parent.assertEqual(result.logits.shape       ,							(self.batch_size, self.seq_length, self.num_labels)       )
	def 						_lowercase  (       self  :			List[str]       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]       ,							SCREAMING_SNAKE_CASE_  :			Any       ,							SCREAMING_SNAKE_CASE_  :			Tuple       ,							SCREAMING_SNAKE_CASE_  :			List[Any]       ,							SCREAMING_SNAKE_CASE_  :			Any       ,							SCREAMING_SNAKE_CASE_  :			Tuple       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]       )       ->     Tuple:
					lowercase_       =					DebertaForQuestionAnswering(config=__snake_case       )
					model.to(__snake_case       )
					model.eval()
					lowercase_       =					model(
					    __snake_case       ,							attention_mask=__snake_case       ,							token_type_ids=__snake_case       ,							start_positions=__snake_case       ,							end_positions=__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[Any]       )       ->     List[Any]:
					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  lowercase__(				lowerCamelCase_ ,						lowerCamelCase_ ,						unittest.TestCase							):



	"""simple docstring"""




	a			:Optional[int]         =	(
	    (
	        DebertaModel,
	        DebertaForMaskedLM,
	        DebertaForSequenceClassification,
	        DebertaForTokenClassification,
	        DebertaForQuestionAnswering,
	    )
	    if is_torch_available()
	    else ()
	)
	a			:List[Any]         =	(
	    {
	        '''feature-extraction''': DebertaModel,
	        '''fill-mask''': DebertaForMaskedLM,
	        '''question-answering''': DebertaForQuestionAnswering,
	        '''text-classification''': DebertaForSequenceClassification,
	        '''token-classification''': DebertaForTokenClassification,
	        '''zero-shot''': DebertaForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)

	a			:Optional[Any]         =	True
	a			:Dict         =	False
	a			:int         =	False
	a			:Union[str, Any]         =	False
	a			:Optional[int]         =	False
	def 						_lowercase  (       self  :			str       )       ->     Optional[Any]:
					lowercase_       =					DebertaModelTester(self       )
					lowercase_       =					ConfigTester(self       ,							config_class=__snake_case       ,							hidden_size=3_7       )
	def 						_lowercase  (       self  :			Union[str, Any]       )       ->     Tuple:
					self.config_tester.run_common_tests()
	def 						_lowercase  (       self  :			Any       )       ->     int:
					lowercase_       =					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_deberta_model(*__snake_case       )
	def 						_lowercase  (       self  :			str       )       ->     str:
					lowercase_       =					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_deberta_for_sequence_classification(*__snake_case       )
	def 						_lowercase  (       self  :			Dict       )       ->     Union[str, Any]:
					lowercase_       =					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_deberta_for_masked_lm(*__snake_case       )
	def 						_lowercase  (       self  :			List[Any]       )       ->     Dict:
					lowercase_       =					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_deberta_for_question_answering(*__snake_case       )
	def 						_lowercase  (       self  :			List[Any]       )       ->     Tuple:
					lowercase_       =					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_deberta_for_token_classification(*__snake_case       )




	@slow
	def 						_lowercase  (       self  :			Tuple       )       ->     Tuple:
					for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									lowercase_       =					DebertaModel.from_pretrained(__snake_case       )
									self.assertIsNotNone(__snake_case       )

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



	"""simple docstring"""




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




	@slow
	def 						_lowercase  (       self  :			Any       )       ->     Optional[int]:
					lowercase_       =					DebertaModel.from_pretrained('''microsoft/deberta-base'''       )

					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(__snake_case       ,							attention_mask=__snake_case       )[0]
					# compare the actual values for a slice.
					lowercase_       =					torch.tensor(
					    [[[-0.59_86, -0.80_55, -0.84_62], [1.44_84, -0.93_48, -0.80_59], [0.31_23, 0.00_32, -1.41_31]]]       )
					self.assertTrue(torch.allclose(output[:, 1:4, 1:4]       ,							__snake_case       ,							atol=1e-4       )       ,							f'''{output[:, 1:4, 1:4]}'''       )








import copy
from dataclasses import dataclass, field
from typing import ClassVar, Dict

from ..features import Audio, ClassLabel, Features
from .base import TaskTemplate







@dataclass(frozen=lowerCamelCase_      )
class        snake_case_   (lowerCamelCase_      ):
					UpperCAmelCase__					:    str          =			field(default='''audio-classification'''	,						metadata={'''include_in_asdict_even_if_is_default''': True}      )
					UpperCAmelCase__					:    ClassVar[Features]          =			Features({'''audio''': Audio()}      )
					UpperCAmelCase__					:    ClassVar[Features]          =			Features({'''labels''': ClassLabel}      )
					UpperCAmelCase__					:    str          =			"audio"
					UpperCAmelCase__					:    str          =			"labels"
					def  lowerCamelCase__(      self   :Optional[int]			,__snake_case   :int      )					->    str:
												if self.label_column not in features:
																			raise ValueError(F'Column {self.label_column} is not present in features.'      )
												if not isinstance(features[self.label_column]			,__snake_case      ):
																			raise ValueError(F'Column {self.label_column} is not a ClassLabel.'      )
												a__             =     copy.deepcopy(self      )
												a__             =     self.label_schema.copy()
												a__             =     features[self.label_column]
												a__             =     label_schema
												return task_template



					@property
					def  lowerCamelCase__(      self   :Dict      )					->    Dict[str, str]:
												return {
												    self.audio_column: "audio",
												    self.label_column: "labels",
												}




