
'''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    lowerCAmelCase       (     UpperCamelCase_  ):


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

  lowerCAmelCase__     :   List[str]     		=	parent
  lowerCAmelCase__     :   Optional[int]     		=	batch_size
  lowerCAmelCase__     :   Dict     		=	seq_length
  lowerCAmelCase__     :   List[str]     		=	is_training
  lowerCAmelCase__     :   Dict     		=	use_input_mask
  lowerCAmelCase__     :   List[str]     		=	use_token_type_ids
  lowerCAmelCase__     :   Tuple     		=	use_labels
  lowerCAmelCase__     :   Optional[int]     		=	vocab_size
  lowerCAmelCase__     :   int     		=	hidden_size
  lowerCAmelCase__     :   List[str]     		=	num_hidden_layers
  lowerCAmelCase__     :   Tuple     		=	num_attention_heads
  lowerCAmelCase__     :   Any     		=	intermediate_size
  lowerCAmelCase__     :   List[str]     		=	hidden_act
  lowerCAmelCase__     :   Union[str, Any]     		=	hidden_dropout_prob
  lowerCAmelCase__     :   Dict     		=	attention_probs_dropout_prob
  lowerCAmelCase__     :   Optional[Any]     		=	max_position_embeddings
  lowerCAmelCase__     :   Tuple     		=	type_vocab_size
  lowerCAmelCase__     :   Dict     		=	type_sequence_label_size
  lowerCAmelCase__     :   int     		=	initializer_range
  lowerCAmelCase__     :   Tuple     		=	num_labels
  lowerCAmelCase__     :   List[str]     		=	num_choices
  lowerCAmelCase__     :   Union[str, Any]     		=	relative_attention
  lowerCAmelCase__     :   int     		=	position_biased_input
  lowerCAmelCase__     :   Dict     		=	pos_att_type
  lowerCAmelCase__     :   Optional[Any]     		=	scope


 def    _A	(    self  : List[Any]    ):
  '''simple docstring'''

  lowerCAmelCase__     :   List[str]     		=	ids_tensor([self.batch_size, self.seq_length]			,							self.vocab_size    )

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

  lowerCAmelCase__     :   Dict     		=	None
  if self.use_token_type_ids:
   lowerCAmelCase__     :   List[Any]     		=	ids_tensor([self.batch_size, self.seq_length]			,							self.type_vocab_size    )

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

  lowerCAmelCase__     :   Any     		=	self.get_config()

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


 def    _A	(    self  : Optional[Any]    ):
  '''simple docstring'''

  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    _A	(    self  : int    ):
  '''simple docstring'''

  lowerCAmelCase__     :   Any     		=	self.get_config()
  lowerCAmelCase__     :   int     		=	300
  return config


 def    _A	(    self  : List[Any]			,							a__  : Dict    ):
  '''simple docstring'''

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


 def    _A	(    self  : Tuple			,							a__  : Optional[Any]			,							a__  : int			,							a__  : Tuple			,							a__  : Any			,							a__  : List[Any]			,							a__  : str			,							a__  : Union[str, Any]    ):
  '''simple docstring'''

  lowerCAmelCase__     :   Any     		=	DebertaModel(config=a__    )
  model.to(a__    )
  model.eval()
  lowerCAmelCase__     :   List[str]     		=	model(a__			,							attention_mask=a__			,							token_type_ids=a__    )[0]
  lowerCAmelCase__     :   List[str]     		=	model(a__			,							token_type_ids=a__    )[0]
  lowerCAmelCase__     :   Tuple     		=	model(a__    )[0]

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


 def    _A	(    self  : Optional[Any]			,							a__  : Tuple			,							a__  : int			,							a__  : Union[str, Any]			,							a__  : List[Any]			,							a__  : str			,							a__  : Tuple			,							a__  : List[str]    ):
  '''simple docstring'''

  lowerCAmelCase__     :   int     		=	DebertaForMaskedLM(config=a__    )
  model.to(a__    )
  model.eval()
  lowerCAmelCase__     :   Any     		=	model(a__			,							attention_mask=a__			,							token_type_ids=a__			,							labels=a__    )

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


 def    _A	(    self  : Optional[Any]			,							a__  : Any			,							a__  : int			,							a__  : Optional[int]			,							a__  : int			,							a__  : Optional[int]			,							a__  : Tuple			,							a__  : str    ):
  '''simple docstring'''

  lowerCAmelCase__     :   Optional[Any]     		=	self.num_labels
  lowerCAmelCase__     :   Tuple     		=	DebertaForSequenceClassification(a__    )
  model.to(a__    )
  model.eval()
  lowerCAmelCase__     :   Union[str, Any]     		=	model(a__			,							attention_mask=a__			,							token_type_ids=a__			,							labels=a__    )
  self.parent.assertListEqual(list(result.logits.size()    )			,							[self.batch_size, self.num_labels]    )
  self.check_loss_output(a__    )


 def    _A	(    self  : List[str]			,							a__  : Any			,							a__  : List[str]			,							a__  : Dict			,							a__  : str			,							a__  : int			,							a__  : List[Any]			,							a__  : str    ):
  '''simple docstring'''

  lowerCAmelCase__     :   List[str]     		=	self.num_labels
  lowerCAmelCase__     :   List[Any]     		=	DebertaForTokenClassification(config=a__    )
  model.to(a__    )
  model.eval()
  lowerCAmelCase__     :   Tuple     		=	model(a__			,							attention_mask=a__			,							token_type_ids=a__			,							labels=a__    )
  self.parent.assertEqual(result.logits.shape			,							(self.batch_size, self.seq_length, self.num_labels)    )


 def    _A	(    self  : Optional[int]			,							a__  : List[str]			,							a__  : Dict			,							a__  : int			,							a__  : Any			,							a__  : Dict			,							a__  : List[str]			,							a__  : Dict    ):
  '''simple docstring'''

  lowerCAmelCase__     :   Optional[Any]     		=	DebertaForQuestionAnswering(config=a__    )
  model.to(a__    )
  model.eval()
  lowerCAmelCase__     :   Any     		=	model(
      a__			,							attention_mask=a__			,							token_type_ids=a__			,							start_positions=a__			,							end_positions=a__			,							)
  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    _A	(    self  : Dict    ):
  '''simple docstring'''

  lowerCAmelCase__     :   List[Any]     		=	self.prepare_config_and_inputs()
  (
      (
      lowerCAmelCase__
  )		,     (
      lowerCAmelCase__
  )		,     (
      lowerCAmelCase__
  )		,     (
      lowerCAmelCase__
  )		,     (
      lowerCAmelCase__
  )		,     (
      lowerCAmelCase__
  )		,     (
      lowerCAmelCase__
  )		,     
  )     :   Optional[Any]     		=	config_and_inputs
  lowerCAmelCase__     :   Optional[Any]     		=	{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
  return config, inputs_dict




@require_torch
class    lowerCAmelCase       (     UpperCamelCase_    ,  UpperCamelCase_    ,  unittest.TestCase  ):
 A_				:				Optional[Any]	=			(
     (
         DebertaModel,
         DebertaForMaskedLM,
         DebertaForSequenceClassification,
         DebertaForTokenClassification,
         DebertaForQuestionAnswering,
     )
     if is_torch_available()
     else ()
 )
 A_				:				int	=			(
     {
         """feature-extraction""": DebertaModel,
         """fill-mask""": DebertaForMaskedLM,
         """question-answering""": DebertaForQuestionAnswering,
         """text-classification""": DebertaForSequenceClassification,
         """token-classification""": DebertaForTokenClassification,
         """zero-shot""": DebertaForSequenceClassification,
     }
     if is_torch_available()
     else {}
 )

 A_				:				Dict	=			True
 A_				:				Any	=			False
 A_				:				Optional[int]	=			False
 A_				:				Optional[Any]	=			False
 A_				:				List[Any]	=			False


 def    _A	(    self  : Tuple    ):
  '''simple docstring'''

  lowerCAmelCase__     :   int     		=	DebertaModelTester(self    )
  lowerCAmelCase__     :   int     		=	ConfigTester(self			,							config_class=a__			,							hidden_size=37    )


 def    _A	(    self  : Optional[int]    ):
  '''simple docstring'''

  self.config_tester.run_common_tests()


 def    _A	(    self  : Any    ):
  '''simple docstring'''

  lowerCAmelCase__     :   Union[str, Any]     		=	self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_deberta_model(*a__    )


 def    _A	(    self  : List[Any]    ):
  '''simple docstring'''

  lowerCAmelCase__     :   int     		=	self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_deberta_for_sequence_classification(*a__    )


 def    _A	(    self  : List[Any]    ):
  '''simple docstring'''

  lowerCAmelCase__     :   int     		=	self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_deberta_for_masked_lm(*a__    )


 def    _A	(    self  : List[Any]    ):
  '''simple docstring'''

  lowerCAmelCase__     :   Dict     		=	self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_deberta_for_question_answering(*a__    )


 def    _A	(    self  : Optional[Any]    ):
  '''simple docstring'''

  lowerCAmelCase__     :   List[str]     		=	self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_deberta_for_token_classification(*a__    )


 @slow
 def    _A	(    self  : Optional[int]    ):
  '''simple docstring'''

  for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
   lowerCAmelCase__     :   str     		=	DebertaModel.from_pretrained(a__    )
   self.assertIsNotNone(a__    )




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


 @unittest.skip(reason="Model not available yet"    )
 def    _A	(    self  : List[Any]    ):
  '''simple docstring'''

  pass


 @slow
 def    _A	(    self  : str    ):
  '''simple docstring'''

  lowerCAmelCase__     :   Dict     		=	DebertaModel.from_pretrained("microsoft/deberta-base"    )

  lowerCAmelCase__     :   Any     		=	torch.tensor([[0, 3_1414, 232, 328, 740, 1140, 1_2695, 69, 4_6078, 1588, 2]]    )
  lowerCAmelCase__     :   Dict     		=	torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]    )
  with torch.no_grad():
   lowerCAmelCase__     :   Optional[Any]     		=	model(a__			,							attention_mask=a__    )[0]
  # compare the actual values for a slice.
  lowerCAmelCase__     :   List[str]     		=	torch.tensor(
      [[[-0.5986, -0.8055, -0.8462], [1.4484, -0.9348, -0.8059], [0.3123, 0.0032, -1.4131]]]    )
  self.assertTrue(torch.allclose(output[:, 1:4, 1:4]			,							a__			,							atol=1e-4    )			,							F'''{output[:, 1:4, 1:4]}'''    )







'''simple docstring'''

import warnings
from functools import wraps
from typing import Callable


def        UpperCAmelCase_ (  lowerCamelCase_			):







 """simple docstring"""


 @wraps(lowerCamelCase_			)
 def _inner_fn(*lowerCamelCase_      ,			**lowerCamelCase_			):
  warnings.warn(
      (f'''\'{fn.__name__}\' is experimental and might be subject to breaking changes in the future.''')      ,			lowerCamelCase_      ,			)
  return fn(*lowerCamelCase_      ,			**lowerCamelCase_			)

 return _inner_fn





