


import inspect
import tempfile
from collections import OrderedDict, UserDict
from collections.abc import MutableMapping
from contextlib import ExitStack, contextmanager
from dataclasses import fields
from enum import Enum
from typing import Any, ContextManager, List, Tuple

import numpy as np

from .import_utils import is_flax_available, is_tf_available, is_torch_available, is_torch_fx_proxy


if is_flax_available():
	import jax.numpy as jnp






class     UpperCamelCase(  _a   ):


					def __get__(						self	:		Optional[int]     ,    SCREAMING_SNAKE_CASE	:		int     ,    SCREAMING_SNAKE_CASE	:		Dict=None						)			->	Dict:




											'''simple docstring'''

											if obj is None:
																	return self
											if self.fget is None:
																	raise AttributeError("unreadable attribute"						)
											__snake_case				=		"__cached_" + self.fget.__name__
											__snake_case				=		getattr(SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE						)
											if cached is None:
																	__snake_case				=		self.fget(SCREAMING_SNAKE_CASE						)
																	setattr(SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE						)
											return cached





def 	_lowerCAmelCase       (    _lowerCAmelCase )						->	int:


						'''simple docstring'''






						__snake_case				=		val.lower()
						if val in {"y", "yes", "t", "true", "on", "1"}:
												return 1
						if val in {"n", "no", "f", "false", "off", "0"}:
												return 0
						raise ValueError(F'''invalid truth value {val!r}''' )





def 	_lowerCAmelCase       (    _lowerCAmelCase )						->	Optional[int]:


						'''simple docstring'''






						if is_torch_fx_proxy(_lowerCAmelCase ):
												return True
						if is_torch_available():
												import torch

												if isinstance(_lowerCAmelCase      ,	torch.Tensor ):
																		return True
						if is_tf_available():
												import tensorflow as tf

												if isinstance(_lowerCAmelCase      ,	tf.Tensor ):
																		return True

						if is_flax_available():
												import jax.numpy as jnp
												from jax.core import Tracer

												if isinstance(_lowerCAmelCase      ,	(jnp.ndarray, Tracer) ):
																		return True

						return isinstance(_lowerCAmelCase      ,	np.ndarray )





def 	_lowerCAmelCase       (    _lowerCAmelCase )						->	Dict:


						'''simple docstring'''






						return isinstance(_lowerCAmelCase      ,	np.ndarray )





def 	_lowerCAmelCase       (    _lowerCAmelCase )						->	List[str]:


						'''simple docstring'''






						return _is_numpy(_lowerCAmelCase )





def 	_lowerCAmelCase       (    _lowerCAmelCase )						->	int:


						'''simple docstring'''






						import torch

						return isinstance(_lowerCAmelCase      ,	torch.Tensor )





def 	_lowerCAmelCase       (    _lowerCAmelCase )						->	Union[str, Any]:


						'''simple docstring'''






						return False if not is_torch_available() else _is_torch(_lowerCAmelCase )





def 	_lowerCAmelCase       (    _lowerCAmelCase )						->	Any:


						'''simple docstring'''






						import torch

						return isinstance(_lowerCAmelCase      ,	torch.device )





def 	_lowerCAmelCase       (    _lowerCAmelCase )						->	List[Any]:


						'''simple docstring'''






						return False if not is_torch_available() else _is_torch_device(_lowerCAmelCase )





def 	_lowerCAmelCase       (    _lowerCAmelCase )						->	Optional[Any]:


						'''simple docstring'''






						import torch

						if isinstance(_lowerCAmelCase      ,	_lowerCAmelCase ):
												if hasattr(_lowerCAmelCase      ,	_lowerCAmelCase ):
																		__snake_case				=		getattr(_lowerCAmelCase      ,	_lowerCAmelCase )
												else:
																		return False
						return isinstance(_lowerCAmelCase      ,	torch.dtype )





def 	_lowerCAmelCase       (    _lowerCAmelCase )						->	Optional[int]:


						'''simple docstring'''






						return False if not is_torch_available() else _is_torch_dtype(_lowerCAmelCase )





def 	_lowerCAmelCase       (    _lowerCAmelCase )						->	List[str]:


						'''simple docstring'''






						import tensorflow as tf

						return isinstance(_lowerCAmelCase      ,	tf.Tensor )





def 	_lowerCAmelCase       (    _lowerCAmelCase )						->	Any:


						'''simple docstring'''






						return False if not is_tf_available() else _is_tensorflow(_lowerCAmelCase )





def 	_lowerCAmelCase       (    _lowerCAmelCase )						->	List[str]:


						'''simple docstring'''






						import tensorflow as tf

						# the `is_symbolic_tensor` predicate is only available starting with TF 2.14
						if hasattr(_lowerCAmelCase      ,	"is_symbolic_tensor" ):
												return tf.is_symbolic_tensor(_lowerCAmelCase )
						return type(_lowerCAmelCase ) == tf.Tensor





def 	_lowerCAmelCase       (    _lowerCAmelCase )						->	str:


						'''simple docstring'''






						return False if not is_tf_available() else _is_tf_symbolic_tensor(_lowerCAmelCase )





def 	_lowerCAmelCase       (    _lowerCAmelCase )						->	int:


						'''simple docstring'''






						import jax.numpy as jnp  # noqa: F811

						return isinstance(_lowerCAmelCase      ,	jnp.ndarray )





def 	_lowerCAmelCase       (    _lowerCAmelCase )						->	Any:


						'''simple docstring'''






						return False if not is_flax_available() else _is_jax(_lowerCAmelCase )





def 	_lowerCAmelCase       (    _lowerCAmelCase )						->	Optional[int]:


						'''simple docstring'''






						if isinstance(_lowerCAmelCase      ,	(dict, UserDict) ):
												return {k: to_py_obj(_lowerCAmelCase ) for k, v in obj.items()}
						elif isinstance(_lowerCAmelCase      ,	(list, tuple) ):
												return [to_py_obj(_lowerCAmelCase ) for o in obj]
						elif is_tf_tensor(_lowerCAmelCase ):
												return obj.numpy().tolist()
						elif is_torch_tensor(_lowerCAmelCase ):
												return obj.detach().cpu().tolist()
						elif is_jax_tensor(_lowerCAmelCase ):
												return np.asarray(_lowerCAmelCase ).tolist()
						elif isinstance(_lowerCAmelCase      ,	(np.ndarray, np.number) ):  # tolist also works on 0d np arrays
												return obj.tolist()
						else:
												return obj





def 	_lowerCAmelCase       (    _lowerCAmelCase )						->	List[str]:


						'''simple docstring'''






						if isinstance(_lowerCAmelCase      ,	(dict, UserDict) ):
												return {k: to_numpy(_lowerCAmelCase ) for k, v in obj.items()}
						elif isinstance(_lowerCAmelCase      ,	(list, tuple) ):
												return np.array(_lowerCAmelCase )
						elif is_tf_tensor(_lowerCAmelCase ):
												return obj.numpy()
						elif is_torch_tensor(_lowerCAmelCase ):
												return obj.detach().cpu().numpy()
						elif is_jax_tensor(_lowerCAmelCase ):
												return np.asarray(_lowerCAmelCase )
						else:
												return obj






class     UpperCamelCase(  _a   ):


					def 							SCREAMING_SNAKE_CASE_  (						self	:		List[str]						)			->	Tuple:




											'''simple docstring'''

											__snake_case				=		fields(self						)

											# Safety and consistency checks
											if not len(SCREAMING_SNAKE_CASE						):
																	raise ValueError(f'''{self.__class__.__name__} has no fields.'''						)
											if not all(field.default is None for field in class_fields[1:]						):
																	raise ValueError(f'''{self.__class__.__name__} should not have more than one required field.'''						)

											__snake_case				=		getattr(self     ,    class_fields[0].name						)
											__snake_case				=		all(getattr(self     ,    field.name						) is None for field in class_fields[1:]						)

											if other_fields_are_none and not is_tensor(SCREAMING_SNAKE_CASE						):
																	if isinstance(SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE						):
																							__snake_case				=		first_field.items()
																							__snake_case				=		True
																	else:
																							try:
																													__snake_case				=		iter(SCREAMING_SNAKE_CASE						)
																													__snake_case				=		True
																							except TypeError:
																													__snake_case				=		False

            # if we provided an iterator as first field and the iterator is a (key, value) iterator
            # set the associated fields
																	if first_field_iterator:
																							for idx, element in enumerate(SCREAMING_SNAKE_CASE						):
																													if (
																													    not isinstance(SCREAMING_SNAKE_CASE     ,    (list, tuple)						)
																													    or not len(SCREAMING_SNAKE_CASE						) == 2
																													    or not isinstance(element[0]     ,    SCREAMING_SNAKE_CASE						)
																													):
																																			if idx == 0:
																																									# If we do not have an iterator of key/values, set it as attribute
																																									__snake_case				=		first_field
																																			else:
																																									# If we have a mixed iterator, raise an error
																																									raise ValueError(
																																									    f'''Cannot set key/value for {element}. It needs to be a tuple (key, value).'''						)
																																			break
																													setattr(self     ,    element[0]     ,    element[1]						)
																													if element[1] is not None:
																																			__snake_case				=		element[1]
																	elif first_field is not None:
																							__snake_case				=		first_field
											else:
																	for field in class_fields:
																							__snake_case				=		getattr(self     ,    field.name						)
																							if v is not None:
																													__snake_case				=		v


					def __delitem__(						self	:		Any     ,    *SCREAMING_SNAKE_CASE	:		int     ,    **SCREAMING_SNAKE_CASE	:		Any						)			->	Tuple:




											'''simple docstring'''

											raise Exception(f'''You cannot use ``__delitem__`` on a {self.__class__.__name__} instance.'''						)


					def 							SCREAMING_SNAKE_CASE_  (						self	:		List[Any]     ,    *SCREAMING_SNAKE_CASE	:		List[str]     ,    **SCREAMING_SNAKE_CASE	:		Any						)			->	List[str]:




											'''simple docstring'''

											raise Exception(f'''You cannot use ``setdefault`` on a {self.__class__.__name__} instance.'''						)


					def 							SCREAMING_SNAKE_CASE_  (						self	:		Dict     ,    *SCREAMING_SNAKE_CASE	:		Optional[int]     ,    **SCREAMING_SNAKE_CASE	:		Dict						)			->	Optional[Any]:




											'''simple docstring'''

											raise Exception(f'''You cannot use ``pop`` on a {self.__class__.__name__} instance.'''						)


					def 							SCREAMING_SNAKE_CASE_  (						self	:		List[str]     ,    *SCREAMING_SNAKE_CASE	:		List[Any]     ,    **SCREAMING_SNAKE_CASE	:		Any						)			->	Optional[int]:




											'''simple docstring'''

											raise Exception(f'''You cannot use ``update`` on a {self.__class__.__name__} instance.'''						)


					def __getitem__(						self	:		List[Any]     ,    SCREAMING_SNAKE_CASE	:		Dict						)			->	List[str]:




											'''simple docstring'''

											if isinstance(SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE						):
																	__snake_case				=		dict(self.items()						)
																	return inner_dict[k]
											else:
																	return self.to_tuple()[k]


					def __setattr__(						self	:		List[str]     ,    SCREAMING_SNAKE_CASE	:		Optional[int]     ,    SCREAMING_SNAKE_CASE	:		Union[str, Any]						)			->	Dict:




											'''simple docstring'''

											if name in self.keys() and value is not None:
																	# Don't call self.__setitem__ to avoid recursion errors
																	super().__setitem__(SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE						)
											super().__setattr__(SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE						)


					def __setitem__(						self	:		int     ,    SCREAMING_SNAKE_CASE	:		Optional[Any]     ,    SCREAMING_SNAKE_CASE	:		Any						)			->	Tuple:




											'''simple docstring'''

											super().__setitem__(SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE						)
											# Don't call self.__setattr__ to avoid recursion errors
											super().__setattr__(SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE						)






					def 							SCREAMING_SNAKE_CASE_  (						self	:		Optional[int]						)			->	Tuple[Any]:




											'''simple docstring'''

											return tuple(self[k] for k in self.keys()						)






class     UpperCamelCase(  _a     ,							_a   ):


					@classmethod
					def 							SCREAMING_SNAKE_CASE_  (						cls	:		List[str]     ,    SCREAMING_SNAKE_CASE	:		int						)			->	int:




											'''simple docstring'''

											raise ValueError(
											    f'''{value} is not a valid {cls.__name__}, please select one of {list(cls._valueamember_map_.keys()						)}'''						)






class     UpperCamelCase(  _a   ):
					snake_case_		:				Optional[Any]										=	"""longest"""
					snake_case_		:				List[str]										=	"""max_length"""
					snake_case_		:				List[Any]										=	"""do_not_pad"""






class     UpperCamelCase(  _a   ):
					snake_case_		:				Dict										=	"""pt"""
					snake_case_		:				Any										=	"""tf"""
					snake_case_		:				Any										=	"""np"""
					snake_case_		:				List[Any]										=	"""jax"""






class     UpperCamelCase:


					def __init__(						self	:		str     ,    SCREAMING_SNAKE_CASE	:		List[ContextManager]						)			->	Dict:




											'''simple docstring'''

											__snake_case				=		context_managers
											__snake_case				=		ExitStack()


					def __enter__(						self	:		Any						)			->	Optional[int]:




											'''simple docstring'''

											for context_manager in self.context_managers:
																	self.stack.enter_context(SCREAMING_SNAKE_CASE						)






					def __exit__(						self	:		List[str]     ,    *SCREAMING_SNAKE_CASE	:		Tuple     ,    **SCREAMING_SNAKE_CASE	:		List[str]						)			->	int:




											'''simple docstring'''

											self.stack.__exit__(*SCREAMING_SNAKE_CASE     ,    **SCREAMING_SNAKE_CASE						)





def 	_lowerCAmelCase       (    _lowerCAmelCase )						->	Optional[int]:


						'''simple docstring'''






						__snake_case				=		infer_framework(_lowerCAmelCase )
						if framework == "tf":
												__snake_case				=		inspect.signature(model_class.call )  # TensorFlow models
						elif framework == "pt":
												__snake_case				=		inspect.signature(model_class.forward )  # PyTorch models
						else:
												__snake_case				=		inspect.signature(model_class.__call__ )  # Flax models

						for p in signature.parameters:
												if p == "return_loss" and signature.parameters[p].default is True:
																		return True

						return False





def 	_lowerCAmelCase       (    _lowerCAmelCase )						->	Any:


						'''simple docstring'''






						__snake_case				=		model_class.__name__
						__snake_case				=		infer_framework(_lowerCAmelCase )
						if framework == "tf":
												__snake_case				=		inspect.signature(model_class.call )  # TensorFlow models
						elif framework == "pt":
												__snake_case				=		inspect.signature(model_class.forward )  # PyTorch models
						else:
												__snake_case				=		inspect.signature(model_class.__call__ )  # Flax models

						if "QuestionAnswering" in model_name:
												return [p for p in signature.parameters if "label" in p or p in ("start_positions", "end_positions")]
						else:
												return [p for p in signature.parameters if "label" in p]





def 	_lowerCAmelCase       (    _lowerCAmelCase      ,	_lowerCAmelCase = ""      ,	_lowerCAmelCase = "." )						->	List[Any]:


						'''simple docstring'''






						def _flatten_dict(_lowerCAmelCase      ,	_lowerCAmelCase=""      ,	_lowerCAmelCase="." ):
												for k, v in d.items():
																		__snake_case				=		str(_lowerCAmelCase ) + delimiter + str(_lowerCAmelCase ) if parent_key else k
																		if v and isinstance(_lowerCAmelCase      ,	_lowerCAmelCase ):
																								yield from flatten_dict(_lowerCAmelCase      ,	_lowerCAmelCase      ,	delimiter=_lowerCAmelCase ).items()
																		else:
																								yield key, v

						return dict(_flatten_dict(_lowerCAmelCase      ,	_lowerCAmelCase      ,	_lowerCAmelCase ) )





@contextmanager
def 	_lowerCAmelCase       (    _lowerCAmelCase      ,	_lowerCAmelCase = False )						->	List[str]:


						'''simple docstring'''






						if use_temp_dir:
												with tempfile.TemporaryDirectory() as tmp_dir:
																		yield tmp_dir
						else:
												yield working_dir





def 	_lowerCAmelCase       (    _lowerCAmelCase      ,	_lowerCAmelCase=None )						->	str:


						'''simple docstring'''






						if is_numpy_array(_lowerCAmelCase ):
												return np.transpose(_lowerCAmelCase      ,	axes=_lowerCAmelCase )
						elif is_torch_tensor(_lowerCAmelCase ):
												return array.T if axes is None else array.permute(*_lowerCAmelCase )
						elif is_tf_tensor(_lowerCAmelCase ):
												import tensorflow as tf

												return tf.transpose(_lowerCAmelCase      ,	perm=_lowerCAmelCase )
						elif is_jax_tensor(_lowerCAmelCase ):
												return jnp.transpose(_lowerCAmelCase      ,	axes=_lowerCAmelCase )
						else:
												raise ValueError(F'''Type not supported for transpose: {type(_lowerCAmelCase )}.''' )





def 	_lowerCAmelCase       (    _lowerCAmelCase      ,	_lowerCAmelCase )						->	Tuple:


						'''simple docstring'''






						if is_numpy_array(_lowerCAmelCase ):
												return np.reshape(_lowerCAmelCase      ,	_lowerCAmelCase )
						elif is_torch_tensor(_lowerCAmelCase ):
												return array.reshape(*_lowerCAmelCase )
						elif is_tf_tensor(_lowerCAmelCase ):
												import tensorflow as tf

												return tf.reshape(_lowerCAmelCase      ,	_lowerCAmelCase )
						elif is_jax_tensor(_lowerCAmelCase ):
												return jnp.reshape(_lowerCAmelCase      ,	_lowerCAmelCase )
						else:
												raise ValueError(F'''Type not supported for reshape: {type(_lowerCAmelCase )}.''' )





def 	_lowerCAmelCase       (    _lowerCAmelCase      ,	_lowerCAmelCase=None )						->	Optional[int]:


						'''simple docstring'''






						if is_numpy_array(_lowerCAmelCase ):
												return np.squeeze(_lowerCAmelCase      ,	axis=_lowerCAmelCase )
						elif is_torch_tensor(_lowerCAmelCase ):
												return array.squeeze() if axis is None else array.squeeze(dim=_lowerCAmelCase )
						elif is_tf_tensor(_lowerCAmelCase ):
												import tensorflow as tf

												return tf.squeeze(_lowerCAmelCase      ,	axis=_lowerCAmelCase )
						elif is_jax_tensor(_lowerCAmelCase ):
												return jnp.squeeze(_lowerCAmelCase      ,	axis=_lowerCAmelCase )
						else:
												raise ValueError(F'''Type not supported for squeeze: {type(_lowerCAmelCase )}.''' )





def 	_lowerCAmelCase       (    _lowerCAmelCase      ,	_lowerCAmelCase )						->	Union[str, Any]:


						'''simple docstring'''






						if is_numpy_array(_lowerCAmelCase ):
												return np.expand_dims(_lowerCAmelCase      ,	_lowerCAmelCase )
						elif is_torch_tensor(_lowerCAmelCase ):
												return array.unsqueeze(dim=_lowerCAmelCase )
						elif is_tf_tensor(_lowerCAmelCase ):
												import tensorflow as tf

												return tf.expand_dims(_lowerCAmelCase      ,	axis=_lowerCAmelCase )
						elif is_jax_tensor(_lowerCAmelCase ):
												return jnp.expand_dims(_lowerCAmelCase      ,	axis=_lowerCAmelCase )
						else:
												raise ValueError(F'''Type not supported for expand_dims: {type(_lowerCAmelCase )}.''' )





def 	_lowerCAmelCase       (    _lowerCAmelCase )						->	Dict:


						'''simple docstring'''






						if is_numpy_array(_lowerCAmelCase ):
												return np.size(_lowerCAmelCase )
						elif is_torch_tensor(_lowerCAmelCase ):
												return array.numel()
						elif is_tf_tensor(_lowerCAmelCase ):
												import tensorflow as tf

												return tf.size(_lowerCAmelCase )
						elif is_jax_tensor(_lowerCAmelCase ):
												return array.size
						else:
												raise ValueError(F'''Type not supported for expand_dims: {type(_lowerCAmelCase )}.''' )





def 	_lowerCAmelCase       (    _lowerCAmelCase      ,	_lowerCAmelCase )						->	Tuple:


						'''simple docstring'''






						for key, value in auto_map.items():
												if isinstance(_lowerCAmelCase      ,	(tuple, list) ):
																		__snake_case				=		[F'''{repo_id}--{v}''' if (v is not None and "--" not in v) else v for v in value]
												elif value is not None and "--" not in value:
																		__snake_case				=		F'''{repo_id}--{value}'''

						return auto_map





def 	_lowerCAmelCase       (    _lowerCAmelCase )						->	List[str]:


						'''simple docstring'''






						for base_class in inspect.getmro(_lowerCAmelCase ):
												__snake_case				=		base_class.__module__
												__snake_case				=		base_class.__name__
												if module.startswith("tensorflow" ) or module.startswith("keras" ) or name == "TFPreTrainedModel":
																		return "tf"
												elif module.startswith("torch" ) or name == "PreTrainedModel":
																		return "pt"
												elif module.startswith("flax" ) or module.startswith("jax" ) or name == "FlaxPreTrainedModel":
																		return "flax"
						else:
												raise TypeError(F'''Could not infer framework from class {model_class}.''' )









import unittest

from transformers import DebertaVaConfig, 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 (
	    DebertaVaForMaskedLM,
	    DebertaVaForMultipleChoice,
	    DebertaVaForQuestionAnswering,
	    DebertaVaForSequenceClassification,
	    DebertaVaForTokenClassification,
	    DebertaVaModel,
	)
	from transformers.models.deberta_va.modeling_deberta_va import DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST






class     UpperCamelCase(  _a   ):


					def __init__(						self	:		Dict     ,    SCREAMING_SNAKE_CASE	:		Dict     ,    SCREAMING_SNAKE_CASE	:		Dict=1_3     ,    SCREAMING_SNAKE_CASE	:		str=7     ,    SCREAMING_SNAKE_CASE	:		Optional[int]=True     ,    SCREAMING_SNAKE_CASE	:		str=True     ,    SCREAMING_SNAKE_CASE	:		Union[str, Any]=True     ,    SCREAMING_SNAKE_CASE	:		Dict=True     ,    SCREAMING_SNAKE_CASE	:		Dict=9_9     ,    SCREAMING_SNAKE_CASE	:		str=3_2     ,    SCREAMING_SNAKE_CASE	:		Optional[int]=5     ,    SCREAMING_SNAKE_CASE	:		Dict=4     ,    SCREAMING_SNAKE_CASE	:		Optional[Any]=3_7     ,    SCREAMING_SNAKE_CASE	:		Optional[Any]="gelu"     ,    SCREAMING_SNAKE_CASE	:		Optional[int]=0.1     ,    SCREAMING_SNAKE_CASE	:		int=0.1     ,    SCREAMING_SNAKE_CASE	:		int=5_1_2     ,    SCREAMING_SNAKE_CASE	:		Optional[Any]=1_6     ,    SCREAMING_SNAKE_CASE	:		Union[str, Any]=2     ,    SCREAMING_SNAKE_CASE	:		Optional[int]=0.02     ,    SCREAMING_SNAKE_CASE	:		str=False     ,    SCREAMING_SNAKE_CASE	:		Union[str, Any]=True     ,    SCREAMING_SNAKE_CASE	:		Tuple="None"     ,    SCREAMING_SNAKE_CASE	:		List[str]=3     ,    SCREAMING_SNAKE_CASE	:		str=4     ,    SCREAMING_SNAKE_CASE	:		List[str]=None     ,    )			->	Tuple:




											'''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 							SCREAMING_SNAKE_CASE_  (						self	:		List[Any]						)			->	Dict:




											'''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 							SCREAMING_SNAKE_CASE_  (						self	:		Any						)			->	int:




											'''simple docstring'''

											return 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     ,    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 							SCREAMING_SNAKE_CASE_  (						self	:		Optional[int]     ,    SCREAMING_SNAKE_CASE	:		str						)			->	Any:




											'''simple docstring'''

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


					def 							SCREAMING_SNAKE_CASE_  (						self	:		List[Any]     ,    SCREAMING_SNAKE_CASE	:		Optional[Any]     ,    SCREAMING_SNAKE_CASE	:		Dict     ,    SCREAMING_SNAKE_CASE	:		Dict     ,    SCREAMING_SNAKE_CASE	:		Optional[int]     ,    SCREAMING_SNAKE_CASE	:		List[str]     ,    SCREAMING_SNAKE_CASE	:		Dict     ,    SCREAMING_SNAKE_CASE	:		str						)			->	List[str]:




											'''simple docstring'''

											__snake_case				=		DebertaVaModel(config=SCREAMING_SNAKE_CASE						)
											model.to(SCREAMING_SNAKE_CASE						)
											model.eval()
											__snake_case				=		model(SCREAMING_SNAKE_CASE     ,    attention_mask=SCREAMING_SNAKE_CASE     ,    token_type_ids=SCREAMING_SNAKE_CASE						)[0]
											__snake_case				=		model(SCREAMING_SNAKE_CASE     ,    token_type_ids=SCREAMING_SNAKE_CASE						)[0]
											__snake_case				=		model(SCREAMING_SNAKE_CASE						)[0]

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


					def 							SCREAMING_SNAKE_CASE_  (						self	:		List[Any]     ,    SCREAMING_SNAKE_CASE	:		Dict     ,    SCREAMING_SNAKE_CASE	:		Optional[int]     ,    SCREAMING_SNAKE_CASE	:		Dict     ,    SCREAMING_SNAKE_CASE	:		Dict     ,    SCREAMING_SNAKE_CASE	:		Union[str, Any]     ,    SCREAMING_SNAKE_CASE	:		Any     ,    SCREAMING_SNAKE_CASE	:		Optional[Any]						)			->	str:




											'''simple docstring'''

											__snake_case				=		DebertaVaForMaskedLM(config=SCREAMING_SNAKE_CASE						)
											model.to(SCREAMING_SNAKE_CASE						)
											model.eval()
											__snake_case				=		model(SCREAMING_SNAKE_CASE     ,    attention_mask=SCREAMING_SNAKE_CASE     ,    token_type_ids=SCREAMING_SNAKE_CASE     ,    labels=SCREAMING_SNAKE_CASE						)

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


					def 							SCREAMING_SNAKE_CASE_  (						self	:		Union[str, Any]     ,    SCREAMING_SNAKE_CASE	:		Tuple     ,    SCREAMING_SNAKE_CASE	:		str     ,    SCREAMING_SNAKE_CASE	:		Union[str, Any]     ,    SCREAMING_SNAKE_CASE	:		int     ,    SCREAMING_SNAKE_CASE	:		Union[str, Any]     ,    SCREAMING_SNAKE_CASE	:		Any     ,    SCREAMING_SNAKE_CASE	:		Tuple						)			->	int:




											'''simple docstring'''

											__snake_case				=		self.num_labels
											__snake_case				=		DebertaVaForSequenceClassification(SCREAMING_SNAKE_CASE						)
											model.to(SCREAMING_SNAKE_CASE						)
											model.eval()
											__snake_case				=		model(SCREAMING_SNAKE_CASE     ,    attention_mask=SCREAMING_SNAKE_CASE     ,    token_type_ids=SCREAMING_SNAKE_CASE     ,    labels=SCREAMING_SNAKE_CASE						)
											self.parent.assertListEqual(list(result.logits.size()						)     ,    [self.batch_size, self.num_labels]						)
											self.check_loss_output(SCREAMING_SNAKE_CASE						)


					def 							SCREAMING_SNAKE_CASE_  (						self	:		Dict     ,    SCREAMING_SNAKE_CASE	:		Any     ,    SCREAMING_SNAKE_CASE	:		Dict     ,    SCREAMING_SNAKE_CASE	:		Union[str, Any]     ,    SCREAMING_SNAKE_CASE	:		int     ,    SCREAMING_SNAKE_CASE	:		str     ,    SCREAMING_SNAKE_CASE	:		Optional[Any]     ,    SCREAMING_SNAKE_CASE	:		List[Any]						)			->	Union[str, Any]:




											'''simple docstring'''

											__snake_case				=		self.num_labels
											__snake_case				=		DebertaVaForTokenClassification(config=SCREAMING_SNAKE_CASE						)
											model.to(SCREAMING_SNAKE_CASE						)
											model.eval()
											__snake_case				=		model(SCREAMING_SNAKE_CASE     ,    attention_mask=SCREAMING_SNAKE_CASE     ,    token_type_ids=SCREAMING_SNAKE_CASE     ,    labels=SCREAMING_SNAKE_CASE						)
											self.parent.assertEqual(result.logits.shape     ,    (self.batch_size, self.seq_length, self.num_labels)						)


					def 							SCREAMING_SNAKE_CASE_  (						self	:		Dict     ,    SCREAMING_SNAKE_CASE	:		Optional[int]     ,    SCREAMING_SNAKE_CASE	:		Dict     ,    SCREAMING_SNAKE_CASE	:		int     ,    SCREAMING_SNAKE_CASE	:		str     ,    SCREAMING_SNAKE_CASE	:		int     ,    SCREAMING_SNAKE_CASE	:		int     ,    SCREAMING_SNAKE_CASE	:		Union[str, Any]						)			->	int:




											'''simple docstring'''

											__snake_case				=		DebertaVaForQuestionAnswering(config=SCREAMING_SNAKE_CASE						)
											model.to(SCREAMING_SNAKE_CASE						)
											model.eval()
											__snake_case				=		model(
											    SCREAMING_SNAKE_CASE     ,    attention_mask=SCREAMING_SNAKE_CASE     ,    token_type_ids=SCREAMING_SNAKE_CASE     ,    start_positions=SCREAMING_SNAKE_CASE     ,    end_positions=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 							SCREAMING_SNAKE_CASE_  (						self	:		Tuple     ,    SCREAMING_SNAKE_CASE	:		List[Any]     ,    SCREAMING_SNAKE_CASE	:		str     ,    SCREAMING_SNAKE_CASE	:		List[str]     ,    SCREAMING_SNAKE_CASE	:		List[str]     ,    SCREAMING_SNAKE_CASE	:		Optional[Any]     ,    SCREAMING_SNAKE_CASE	:		Any     ,    SCREAMING_SNAKE_CASE	:		Optional[int]						)			->	Union[str, Any]:




											'''simple docstring'''

											__snake_case				=		DebertaVaForMultipleChoice(config=SCREAMING_SNAKE_CASE						)
											model.to(SCREAMING_SNAKE_CASE						)
											model.eval()
											__snake_case				=		input_ids.unsqueeze(1						).expand(-1     ,    self.num_choices     ,    -1						).contiguous()
											__snake_case				=		token_type_ids.unsqueeze(1						).expand(-1     ,    self.num_choices     ,    -1						).contiguous()
											__snake_case				=		input_mask.unsqueeze(1						).expand(-1     ,    self.num_choices     ,    -1						).contiguous()
											__snake_case				=		model(
											    SCREAMING_SNAKE_CASE     ,    attention_mask=SCREAMING_SNAKE_CASE     ,    token_type_ids=SCREAMING_SNAKE_CASE     ,    labels=SCREAMING_SNAKE_CASE     ,    )
											self.parent.assertEqual(result.logits.shape     ,    (self.batch_size, self.num_choices)						)






					def 							SCREAMING_SNAKE_CASE_  (						self	:		Union[str, Any]						)			->	List[Any]:




											'''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(  _a     ,							_a     ,							unittest.TestCase   ):
					snake_case_		:				Union[str, Any]										=	(
					    (
					        DebertaVaModel,
					        DebertaVaForMaskedLM,
					        DebertaVaForSequenceClassification,
					        DebertaVaForTokenClassification,
					        DebertaVaForQuestionAnswering,
					        DebertaVaForMultipleChoice,
					    )
					    if is_torch_available()
					    else ()
					)
					snake_case_		:				Optional[Any]										=	(
					    {
					        """feature-extraction""": DebertaVaModel,
					        """fill-mask""": DebertaVaForMaskedLM,
					        """question-answering""": DebertaVaForQuestionAnswering,
					        """text-classification""": DebertaVaForSequenceClassification,
					        """token-classification""": DebertaVaForTokenClassification,
					        """zero-shot""": DebertaVaForSequenceClassification,
					    }
					    if is_torch_available()
					    else {}
					)

					snake_case_		:				Dict										=	True
					snake_case_		:				Union[str, Any]										=	False
					snake_case_		:				Tuple										=	False
					snake_case_		:				List[str]										=	False
					snake_case_		:				List[Any]										=	False


					def 							SCREAMING_SNAKE_CASE_  (						self	:		Dict						)			->	Dict:




											'''simple docstring'''

											__snake_case				=		DebertaVaModelTester(self						)
											__snake_case				=		ConfigTester(self     ,    config_class=SCREAMING_SNAKE_CASE     ,    hidden_size=3_7						)


					def 							SCREAMING_SNAKE_CASE_  (						self	:		Any						)			->	Dict:




											'''simple docstring'''

											self.config_tester.run_common_tests()


					def 							SCREAMING_SNAKE_CASE_  (						self	:		Any						)			->	str:




											'''simple docstring'''

											__snake_case				=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_deberta_model(*SCREAMING_SNAKE_CASE						)


					def 							SCREAMING_SNAKE_CASE_  (						self	:		Union[str, Any]						)			->	str:




											'''simple docstring'''

											__snake_case				=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_deberta_for_sequence_classification(*SCREAMING_SNAKE_CASE						)


					def 							SCREAMING_SNAKE_CASE_  (						self	:		Any						)			->	Optional[Any]:




											'''simple docstring'''

											__snake_case				=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_deberta_for_masked_lm(*SCREAMING_SNAKE_CASE						)


					def 							SCREAMING_SNAKE_CASE_  (						self	:		Tuple						)			->	List[str]:




											'''simple docstring'''

											__snake_case				=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_deberta_for_question_answering(*SCREAMING_SNAKE_CASE						)


					def 							SCREAMING_SNAKE_CASE_  (						self	:		Optional[Any]						)			->	str:




											'''simple docstring'''

											__snake_case				=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_deberta_for_token_classification(*SCREAMING_SNAKE_CASE						)


					def 							SCREAMING_SNAKE_CASE_  (						self	:		int						)			->	Dict:




											'''simple docstring'''

											__snake_case				=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_deberta_for_multiple_choice(*SCREAMING_SNAKE_CASE						)






					@slow
					def 							SCREAMING_SNAKE_CASE_  (						self	:		str						)			->	Union[str, Any]:




											'''simple docstring'''

											for model_name in DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	__snake_case				=		DebertaVaModel.from_pretrained(SCREAMING_SNAKE_CASE						)
																	self.assertIsNotNone(SCREAMING_SNAKE_CASE						)






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


					@unittest.skip(reason="Model not available yet"						)
					def 							SCREAMING_SNAKE_CASE_  (						self	:		Optional[int]						)			->	str:




											'''simple docstring'''

											pass






					@slow
					def 							SCREAMING_SNAKE_CASE_  (						self	:		str						)			->	Tuple:




											'''simple docstring'''

											__snake_case				=		DebertaVaModel.from_pretrained("microsoft/deberta-v2-xlarge"						)

											__snake_case				=		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]]						)
											__snake_case				=		torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]						)
											with torch.no_grad():
																	__snake_case				=		model(SCREAMING_SNAKE_CASE     ,    attention_mask=SCREAMING_SNAKE_CASE						)[0]
											# compare the actual values for a slice.
											__snake_case				=		torch.tensor(
											    [[[0.2356, 0.1948, 0.0369], [-0.1063, 0.3586, -0.5152], [-0.6399, -0.0259, -0.2525]]]						)
											self.assertTrue(torch.allclose(output[:, 1:4, 1:4]     ,    SCREAMING_SNAKE_CASE     ,    atol=1e-4						)     ,    f'''{output[:, 1:4, 1:4]}'''						)





