




import unittest

import numpy as np

from transformers import is_flax_available
from transformers.testing_utils import require_flax

from ..test_modeling_flax_common import ids_tensor


if is_flax_available():
		import jax
		import jax.numpy as jnp

		from transformers.generation import (
		    FlaxForcedBOSTokenLogitsProcessor,
		    FlaxForcedEOSTokenLogitsProcessor,
		    FlaxLogitsProcessorList,
		    FlaxMinLengthLogitsProcessor,
		    FlaxTemperatureLogitsWarper,
		    FlaxTopKLogitsWarper,
		    FlaxTopPLogitsWarper,
		)
@require_flax
class 						UpperCAmelCase  (							unittest.TestCase     ):







						'''simple docstring'''





						def 			snake_case__		(		self				:	Union[str, Any]			,      __lowercase				:	int			,      __lowercase				:	int		):






							"""simple docstring"""






							snake_case_						       =	jnp.ones((batch_size, length)		) / length
							return scores






						def 			snake_case__		(		self				:	str		):






							"""simple docstring"""






							snake_case_						       =	None
							snake_case_						       =	20

							snake_case_						       =	self._get_uniform_logits(batch_size=2			,      length=__lowercase		)

							# tweak scores to not be uniform anymore
							snake_case_						       =	scores.at[1, 5].set((1 / length) + 0.1		)  # peak, 1st batch
							snake_case_						       =	scores.at[1, 10].set((1 / length) - 0.4		)  # valley, 1st batch

							# compute softmax
							snake_case_						       =	jax.nn.softmax(__lowercase			,      axis=-1		)

							snake_case_						       =	FlaxTemperatureLogitsWarper(temperature=0.5		)
							snake_case_						       =	FlaxTemperatureLogitsWarper(temperature=1.3		)

							snake_case_						       =	jax.nn.softmax(temp_dist_warper_sharper(__lowercase			,      scores.copy()			,      cur_len=__lowercase		)			,      axis=-1		)
							snake_case_						       =	jax.nn.softmax(temp_dist_warper_smoother(__lowercase			,      scores.copy()			,      cur_len=__lowercase		)			,      axis=-1		)

							# uniform distribution stays uniform
							self.assertTrue(jnp.allclose(probs[0, :]			,      warped_prob_sharp[0, :]			,      atol=1E-3		)		)
							self.assertTrue(jnp.allclose(probs[0, :]			,      warped_prob_smooth[0, :]			,      atol=1E-3		)		)

							# sharp peaks get higher, valleys get lower
							self.assertLess(probs[1, :].max()			,      warped_prob_sharp[1, :].max()		)
							self.assertGreater(probs[1, :].min()			,      warped_prob_sharp[1, :].min()		)

							# smooth peaks get lower, valleys get higher
							self.assertGreater(probs[1, :].max()			,      warped_prob_smooth[1, :].max()		)
							self.assertLess(probs[1, :].min()			,      warped_prob_smooth[1, :].min()		)






						def 			snake_case__		(		self				:	Any		):






							"""simple docstring"""






							snake_case_						       =	None
							snake_case_						       =	10
							snake_case_						       =	2

							# create ramp distribution
							snake_case_						       =	np.broadcast_to(np.arange(__lowercase		)[None, :]			,      (batch_size, vocab_size)		).copy()
							snake_case_						       =	ramp_logits[1:, : vocab_size // 2] + vocab_size

							snake_case_						       =	FlaxTopKLogitsWarper(3		)

							snake_case_						       =	top_k_warp(__lowercase			,      __lowercase			,      cur_len=__lowercase		)

							# check that correct tokens are filtered
							self.assertListEqual(jnp.isinf(scores[0]		).tolist()			,      7 * [True] + 3 * [False]		)
							self.assertListEqual(jnp.isinf(scores[1]		).tolist()			,      2 * [True] + 3 * [False] + 5 * [True]		)

							# check special case
							snake_case_						       =	5
							snake_case_						       =	FlaxTopKLogitsWarper(top_k=1			,      filter_value=0.0			,      min_tokens_to_keep=3		)

							snake_case_						       =	np.broadcast_to(np.arange(__lowercase		)[None, :]			,      (batch_size, length)		).copy()
							snake_case_						       =	top_k_warp_safety_check(__lowercase			,      __lowercase			,      cur_len=__lowercase		)

							# min_tokens overwrites k: 3 tokens are kept => 2 tokens are nullified
							self.assertListEqual((scores == 0.0).sum(axis=-1		).tolist()			,      [2, 2]		)






						def 			snake_case__		(		self				:	List[Any]		):






							"""simple docstring"""






							snake_case_						       =	None
							snake_case_						       =	10
							snake_case_						       =	2

							# create distribution and take log (inverse to Softmax as taken in TopPLogitsWarper)
							snake_case_						       =	np.log(np.array([[0.3, 0.1, 0.1, 0.5], [0.15, 0.3, 0.3, 0.25]]		)		)

							snake_case_						       =	FlaxTopPLogitsWarper(0.8		)
							snake_case_						       =	np.exp(top_p_warp(__lowercase			,      __lowercase			,      cur_len=__lowercase		)		)

							# dist should be filtered to keep min num values so that sum is >= top_p
							# exp (-inf) => 0
							snake_case_						       =	np.array([[0.3, 0.0, 0.0, 0.5], [0.0, 0.3, 0.3, 0.25]]		)
							self.assertTrue(np.allclose(__lowercase			,      __lowercase			,      atol=1E-3		)		)

							# check edge cases with negative and extreme logits
							snake_case_						       =	np.broadcast_to(np.arange(__lowercase		)[None, :]			,      (batch_size, vocab_size)		).copy() - (
							    vocab_size // 2
							)

							# make ramp_logits more extreme
							snake_case_						       =	ramp_logits[1] * 100.0

							# make sure at least 2 tokens are kept
							snake_case_						       =	FlaxTopPLogitsWarper(0.9			,      min_tokens_to_keep=2			,      filter_value=0.0		)
							snake_case_						       =	top_p_warp(__lowercase			,      __lowercase			,      cur_len=__lowercase		)

							# first batch should keep three tokens, second batch would keep only 1, but due to `min_tokens_to_keep=2` keeps 2.
							self.assertListEqual((filtered_dist != 0.0).sum(axis=-1		).tolist()			,      [3, 2]		)






						def 			snake_case__		(		self				:	List[Any]		):






							"""simple docstring"""






							snake_case_						       =	20
							snake_case_						       =	4
							snake_case_						       =	0

							snake_case_						       =	FlaxMinLengthLogitsProcessor(min_length=10			,      eos_token_id=__lowercase		)

							# check that min length is applied at length 5
							snake_case_						       =	ids_tensor((batch_size, 20)			,      vocab_size=20		)
							snake_case_						       =	5
							snake_case_						       =	self._get_uniform_logits(__lowercase			,      __lowercase		)
							snake_case_						       =	min_dist_processor(__lowercase			,      __lowercase			,      cur_len=__lowercase		)
							self.assertListEqual(scores_before_min_length[:, eos_token_id].tolist()			,      4 * [-float("inf"		)]		)

							# check that min length is not applied anymore at length 15
							snake_case_						       =	self._get_uniform_logits(__lowercase			,      __lowercase		)
							snake_case_						       =	15
							snake_case_						       =	min_dist_processor(__lowercase			,      __lowercase			,      cur_len=__lowercase		)
							self.assertFalse(jnp.isinf(__lowercase		).any()		)






						def 			snake_case__		(		self				:	str		):






							"""simple docstring"""






							snake_case_						       =	20
							snake_case_						       =	4
							snake_case_						       =	0

							snake_case_						       =	FlaxForcedBOSTokenLogitsProcessor(bos_token_id=__lowercase		)

							# check that all scores are -inf except the bos_token_id score
							snake_case_						       =	ids_tensor((batch_size, 1)			,      vocab_size=20		)
							snake_case_						       =	1
							snake_case_						       =	self._get_uniform_logits(__lowercase			,      __lowercase		)
							snake_case_						       =	logits_processor(__lowercase			,      __lowercase			,      cur_len=__lowercase		)
							self.assertTrue(jnp.isneginf(scores[:, bos_token_id + 1 :]		).all()		)
							self.assertListEqual(scores[:, bos_token_id].tolist()			,      4 * [0]		)  # score for bos_token_id shold be zero

							# check that bos_token_id is not forced if current length is greater than 1
							snake_case_						       =	3
							snake_case_						       =	self._get_uniform_logits(__lowercase			,      __lowercase		)
							snake_case_						       =	logits_processor(__lowercase			,      __lowercase			,      cur_len=__lowercase		)
							self.assertFalse(jnp.isinf(__lowercase		).any()		)






						def 			snake_case__		(		self				:	Tuple		):






							"""simple docstring"""






							snake_case_						       =	20
							snake_case_						       =	4
							snake_case_						       =	0
							snake_case_						       =	5

							snake_case_						       =	FlaxForcedEOSTokenLogitsProcessor(max_length=__lowercase			,      eos_token_id=__lowercase		)

							# check that all scores are -inf except the eos_token_id when max_length is reached
							snake_case_						       =	ids_tensor((batch_size, 4)			,      vocab_size=20		)
							snake_case_						       =	4
							snake_case_						       =	self._get_uniform_logits(__lowercase			,      __lowercase		)
							snake_case_						       =	logits_processor(__lowercase			,      __lowercase			,      cur_len=__lowercase		)
							self.assertTrue(jnp.isneginf(scores[:, eos_token_id + 1 :]		).all()		)
							self.assertListEqual(scores[:, eos_token_id].tolist()			,      4 * [0]		)  # score for eos_token_id should be zero

							# check that eos_token_id is not forced if max_length is not reached
							snake_case_						       =	3
							snake_case_						       =	self._get_uniform_logits(__lowercase			,      __lowercase		)
							snake_case_						       =	logits_processor(__lowercase			,      __lowercase			,      cur_len=__lowercase		)
							self.assertFalse(jnp.isinf(__lowercase		).any()		)






						def 			snake_case__		(		self				:	int		):






							"""simple docstring"""






							snake_case_						       =	4
							snake_case_						       =	10
							snake_case_						       =	15
							snake_case_						       =	2
							snake_case_						       =	1
							snake_case_						       =	15

							# dummy input_ids and scores
							snake_case_						       =	ids_tensor((batch_size, sequence_length)			,      __lowercase		)
							snake_case_						       =	input_ids.copy()

							snake_case_						       =	self._get_uniform_logits(__lowercase			,      __lowercase		)
							snake_case_						       =	scores.copy()

							# instantiate all dist processors
							snake_case_						       =	FlaxTemperatureLogitsWarper(temperature=0.5		)
							snake_case_						       =	FlaxTopKLogitsWarper(3		)
							snake_case_						       =	FlaxTopPLogitsWarper(0.8		)

							# instantiate all logits processors
							snake_case_						       =	FlaxMinLengthLogitsProcessor(min_length=10			,      eos_token_id=__lowercase		)
							snake_case_						       =	FlaxForcedBOSTokenLogitsProcessor(bos_token_id=__lowercase		)
							snake_case_						       =	FlaxForcedEOSTokenLogitsProcessor(max_length=__lowercase			,      eos_token_id=__lowercase		)

							snake_case_						       =	10

							# no processor list
							snake_case_						       =	temp_dist_warp(__lowercase			,      __lowercase			,      cur_len=__lowercase		)
							snake_case_						       =	top_k_warp(__lowercase			,      __lowercase			,      cur_len=__lowercase		)
							snake_case_						       =	top_p_warp(__lowercase			,      __lowercase			,      cur_len=__lowercase		)
							snake_case_						       =	min_dist_proc(__lowercase			,      __lowercase			,      cur_len=__lowercase		)
							snake_case_						       =	bos_dist_proc(__lowercase			,      __lowercase			,      cur_len=__lowercase		)
							snake_case_						       =	eos_dist_proc(__lowercase			,      __lowercase			,      cur_len=__lowercase		)

							# with processor list
							snake_case_						       =	FlaxLogitsProcessorList(
							    [temp_dist_warp, top_k_warp, top_p_warp, min_dist_proc, bos_dist_proc, eos_dist_proc]		)
							snake_case_						       =	processor(__lowercase			,      __lowercase			,      cur_len=__lowercase		)

							# scores should be equal
							self.assertTrue(jnp.allclose(__lowercase			,      __lowercase			,      atol=1E-3		)		)

							# input_ids should never be changed
							self.assertListEqual(input_ids.tolist()			,      input_ids_comp.tolist()		)






						def 			snake_case__		(		self				:	Dict		):






							"""simple docstring"""






							snake_case_						       =	4
							snake_case_						       =	10
							snake_case_						       =	15
							snake_case_						       =	2
							snake_case_						       =	1
							snake_case_						       =	15

							# dummy input_ids and scores
							snake_case_						       =	ids_tensor((batch_size, sequence_length)			,      __lowercase		)
							snake_case_						       =	input_ids.copy()

							snake_case_						       =	self._get_uniform_logits(__lowercase			,      __lowercase		)
							snake_case_						       =	scores.copy()

							# instantiate all dist processors
							snake_case_						       =	FlaxTemperatureLogitsWarper(temperature=0.5		)
							snake_case_						       =	FlaxTopKLogitsWarper(3		)
							snake_case_						       =	FlaxTopPLogitsWarper(0.8		)

							# instantiate all logits processors
							snake_case_						       =	FlaxMinLengthLogitsProcessor(min_length=10			,      eos_token_id=__lowercase		)
							snake_case_						       =	FlaxForcedBOSTokenLogitsProcessor(bos_token_id=__lowercase		)
							snake_case_						       =	FlaxForcedEOSTokenLogitsProcessor(max_length=__lowercase			,      eos_token_id=__lowercase		)

							snake_case_						       =	10

							# no processor list
							def run_no_processor_list(__lowercase				:	str			,      __lowercase				:	Optional[int]			,      __lowercase				:	Optional[Any]		):
								snake_case_						       =	temp_dist_warp(__lowercase			,      __lowercase			,      cur_len=__lowercase		)
								snake_case_						       =	top_k_warp(__lowercase			,      __lowercase			,      cur_len=__lowercase		)
								snake_case_						       =	top_p_warp(__lowercase			,      __lowercase			,      cur_len=__lowercase		)
								snake_case_						       =	min_dist_proc(__lowercase			,      __lowercase			,      cur_len=__lowercase		)
								snake_case_						       =	bos_dist_proc(__lowercase			,      __lowercase			,      cur_len=__lowercase		)
								snake_case_						       =	eos_dist_proc(__lowercase			,      __lowercase			,      cur_len=__lowercase		)
								return scores

							# with processor list
							def run_processor_list(__lowercase				:	Union[str, Any]			,      __lowercase				:	Dict			,      __lowercase				:	Optional[int]		):
								snake_case_						       =	FlaxLogitsProcessorList(
								    [temp_dist_warp, top_k_warp, top_p_warp, min_dist_proc, bos_dist_proc, eos_dist_proc]		)
								snake_case_						       =	processor(__lowercase			,      __lowercase			,      cur_len=__lowercase		)
								return scores

							snake_case_						       =	jax.jit(__lowercase		)
							snake_case_						       =	jax.jit(__lowercase		)

							snake_case_						       =	jitted_run_no_processor_list(__lowercase			,      __lowercase			,      __lowercase		)
							snake_case_						       =	jitted_run_processor_list(__lowercase			,      __lowercase			,      __lowercase		)

							# scores should be equal
							self.assertTrue(jnp.allclose(__lowercase			,      __lowercase			,      atol=1E-3		)		)

							# input_ids should never be changed
							self.assertListEqual(input_ids.tolist()			,      input_ids_comp.tolist()		)






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







						'''simple docstring'''





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






							"""simple docstring"""






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






						def 			snake_case__		(		self				:	str		):






							"""simple docstring"""






							snake_case_						       =	ids_tensor([self.batch_size, self.seq_length]			,      self.vocab_size		)

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

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

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

							snake_case_						       =	self.get_config()

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






						def 			snake_case__		(		self				:	Optional[int]		):






							"""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 			snake_case__		(		self				:	int		):






							"""simple docstring"""






							snake_case_						       =	self.get_config()
							snake_case_						       =	3_00
							return config






						def 			snake_case__		(		self				:	List[Any]			,      __lowercase				:	List[Any]		):






							"""simple docstring"""






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






						def 			snake_case__		(		self				:	List[str]			,      __lowercase				:	Tuple			,      __lowercase				:	Union[str, Any]			,      __lowercase				:	Tuple			,      __lowercase				:	Dict			,      __lowercase				:	str			,      __lowercase				:	Optional[int]			,      __lowercase				:	int		):






							"""simple docstring"""






							snake_case_						       =	DebertaModel(config=__lowercase		)
							model.to(__lowercase		)
							model.eval()
							snake_case_						       =	model(__lowercase			,      attention_mask=__lowercase			,      token_type_ids=__lowercase		)[0]
							snake_case_						       =	model(__lowercase			,      token_type_ids=__lowercase		)[0]
							snake_case_						       =	model(__lowercase		)[0]

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






						def 			snake_case__		(		self				:	Any			,      __lowercase				:	Any			,      __lowercase				:	Dict			,      __lowercase				:	Any			,      __lowercase				:	Any			,      __lowercase				:	Tuple			,      __lowercase				:	Union[str, Any]			,      __lowercase				:	List[str]		):






							"""simple docstring"""






							snake_case_						       =	DebertaForMaskedLM(config=__lowercase		)
							model.to(__lowercase		)
							model.eval()
							snake_case_						       =	model(__lowercase			,      attention_mask=__lowercase			,      token_type_ids=__lowercase			,      labels=__lowercase		)

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






						def 			snake_case__		(		self				:	List[str]			,      __lowercase				:	Tuple			,      __lowercase				:	List[str]			,      __lowercase				:	Dict			,      __lowercase				:	str			,      __lowercase				:	Optional[Any]			,      __lowercase				:	Optional[Any]			,      __lowercase				:	Union[str, Any]		):






							"""simple docstring"""






							snake_case_						       =	self.num_labels
							snake_case_						       =	DebertaForSequenceClassification(__lowercase		)
							model.to(__lowercase		)
							model.eval()
							snake_case_						       =	model(__lowercase			,      attention_mask=__lowercase			,      token_type_ids=__lowercase			,      labels=__lowercase		)
							self.parent.assertListEqual(list(result.logits.size()		)			,      [self.batch_size, self.num_labels]		)
							self.check_loss_output(__lowercase		)






						def 			snake_case__		(		self				:	List[Any]			,      __lowercase				:	List[str]			,      __lowercase				:	Any			,      __lowercase				:	List[Any]			,      __lowercase				:	str			,      __lowercase				:	List[str]			,      __lowercase				:	Optional[Any]			,      __lowercase				:	Optional[int]		):






							"""simple docstring"""






							snake_case_						       =	self.num_labels
							snake_case_						       =	DebertaForTokenClassification(config=__lowercase		)
							model.to(__lowercase		)
							model.eval()
							snake_case_						       =	model(__lowercase			,      attention_mask=__lowercase			,      token_type_ids=__lowercase			,      labels=__lowercase		)
							self.parent.assertEqual(result.logits.shape			,      (self.batch_size, self.seq_length, self.num_labels)		)






						def 			snake_case__		(		self				:	List[str]			,      __lowercase				:	str			,      __lowercase				:	List[str]			,      __lowercase				:	Optional[int]			,      __lowercase				:	Optional[Any]			,      __lowercase				:	Optional[Any]			,      __lowercase				:	Optional[Any]			,      __lowercase				:	Union[str, Any]		):






							"""simple docstring"""






							snake_case_						       =	DebertaForQuestionAnswering(config=__lowercase		)
							model.to(__lowercase		)
							model.eval()
							snake_case_						       =	model(
							    __lowercase			,      attention_mask=__lowercase			,      token_type_ids=__lowercase			,      start_positions=__lowercase			,      end_positions=__lowercase			,      )
							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 			snake_case__		(		self				:	Tuple		):






							"""simple docstring"""






							snake_case_						       =	self.prepare_config_and_inputs()
							(
							    (
							    snake_case_
							)       , (
							    snake_case_
							)       , (
							    snake_case_
							)       , (
							    snake_case_
							)       , (
							    snake_case_
							)       , (
							    snake_case_
							)       , (
							    snake_case_
							)       , 
							)						       =	config_and_inputs
							snake_case_						       =	{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
							return config, inputs_dict







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







						'''simple docstring'''





						lowerCAmelCase_							=  (
						    (
						        DebertaModel,
						        DebertaForMaskedLM,
						        DebertaForSequenceClassification,
						        DebertaForTokenClassification,
						        DebertaForQuestionAnswering,
						    )
						    if is_torch_available()
						    else ()
						)
						lowerCAmelCase_							=  (
						    {
						        '''feature-extraction''': DebertaModel,
						        '''fill-mask''': DebertaForMaskedLM,
						        '''question-answering''': DebertaForQuestionAnswering,
						        '''text-classification''': DebertaForSequenceClassification,
						        '''token-classification''': DebertaForTokenClassification,
						        '''zero-shot''': DebertaForSequenceClassification,
						    }
						    if is_torch_available()
						    else {}
						)

						lowerCAmelCase_							=  True
						lowerCAmelCase_							=  False
						lowerCAmelCase_							=  False
						lowerCAmelCase_							=  False
						lowerCAmelCase_							=  False






						def 			snake_case__		(		self				:	int		):






							"""simple docstring"""






							snake_case_						       =	DebertaModelTester(self		)
							snake_case_						       =	ConfigTester(self			,      config_class=__lowercase			,      hidden_size=37		)






						def 			snake_case__		(		self				:	Optional[int]		):






							"""simple docstring"""






							self.config_tester.run_common_tests()






						def 			snake_case__		(		self				:	Dict		):






							"""simple docstring"""






							snake_case_						       =	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_deberta_model(*__lowercase		)






						def 			snake_case__		(		self				:	str		):






							"""simple docstring"""






							snake_case_						       =	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_deberta_for_sequence_classification(*__lowercase		)






						def 			snake_case__		(		self				:	str		):






							"""simple docstring"""






							snake_case_						       =	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_deberta_for_masked_lm(*__lowercase		)






						def 			snake_case__		(		self				:	Optional[Any]		):






							"""simple docstring"""






							snake_case_						       =	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_deberta_for_question_answering(*__lowercase		)






						def 			snake_case__		(		self				:	Optional[Any]		):






							"""simple docstring"""






							snake_case_						       =	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_deberta_for_token_classification(*__lowercase		)






						@slow
						def 			snake_case__		(		self				:	str		):






							"""simple docstring"""






							for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
								snake_case_						       =	DebertaModel.from_pretrained(__lowercase		)
								self.assertIsNotNone(__lowercase		)







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







						'''simple docstring'''





						@unittest.skip(reason="Model not available yet"		)
						def 			snake_case__		(		self				:	str		):






							"""simple docstring"""






							pass






						@slow
						def 			snake_case__		(		self				:	Optional[int]		):






							"""simple docstring"""






							snake_case_						       =	DebertaModel.from_pretrained("microsoft/deberta-base"		)

							snake_case_						       =	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_						       =	torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]		)
							with torch.no_grad():
								snake_case_						       =	model(__lowercase			,      attention_mask=__lowercase		)[0]
							# compare the actual values for a slice.
							snake_case_						       =	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]			,      __lowercase			,      atol=1E-4		)			,      f"{output[:, 1:4, 1:4]}"		)
