




'''simple docstring'''





from __future__ import annotations

import unittest

from transformers import DebertaVaConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
		import tensorflow as tf

		from transformers import (
		    TFDebertaVaForMaskedLM,
		    TFDebertaVaForQuestionAnswering,
		    TFDebertaVaForSequenceClassification,
		    TFDebertaVaForTokenClassification,
		    TFDebertaVaModel,
		)




class  _snake_case		:




			def __init__(					self				,							a__				,							a__=13				,							a__=7				,							a__=True				,							a__=True				,							a__=True				,							a__=True				,							a__=99				,							a__=32				,							a__=2				,							a__=4				,							a__=37				,							a__="gelu"				,							a__=0.1				,							a__=0.1				,							a__=512				,							a__=16				,							a__=2				,							a__=0.0_2				,							a__=False				,							a__=True				,							a__="None"				,							a__=3				,							a__=4				,							a__=None				,							)				->				int:

										'''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    lowerCAmelCase__				(					self							)				->				Union[str, Any]:

										'''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_						=      random_attention_mask([self.batch_size, self.seq_length]							)

										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_						=      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				,							relative_attention=self.relative_attention				,							position_biased_input=self.position_biased_input				,							initializer_range=self.initializer_range				,							return_dict=a__				,							)

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




			def    lowerCAmelCase__				(					self				,							a__				,							a__				,							a__				,							a__				,							a__				,							a__				,							a__							)				->				str:

										'''simple docstring'''




										snake_case_						=      TFDebertaVaModel(config=a__							)
										snake_case_						=      {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}

										snake_case_						=      [input_ids, input_mask]
										snake_case_						=      model(a__							)

										snake_case_						=      model(a__							)

										self.parent.assertEqual(result.last_hidden_state.shape				,							(self.batch_size, self.seq_length, self.hidden_size)							)




			def    lowerCAmelCase__				(					self				,							a__				,							a__				,							a__				,							a__				,							a__				,							a__				,							a__							)				->				Optional[int]:

										'''simple docstring'''




										snake_case_						=      TFDebertaVaForMaskedLM(config=a__							)
										snake_case_						=      {
										    "input_ids": input_ids,
										    "attention_mask": input_mask,
										    "token_type_ids": token_type_ids,
										}
										snake_case_						=      model(a__							)
										self.parent.assertEqual(result.logits.shape				,							(self.batch_size, self.seq_length, self.vocab_size)							)




			def    lowerCAmelCase__				(					self				,							a__				,							a__				,							a__				,							a__				,							a__				,							a__				,							a__							)				->				Any:

										'''simple docstring'''




										snake_case_						=      self.num_labels
										snake_case_						=      TFDebertaVaForSequenceClassification(config=a__							)
										snake_case_						=      {
										    "input_ids": input_ids,
										    "attention_mask": input_mask,
										    "token_type_ids": token_type_ids,
										}

										snake_case_						=      model(a__							)
										self.parent.assertEqual(result.logits.shape				,							(self.batch_size, self.num_labels)							)




			def    lowerCAmelCase__				(					self				,							a__				,							a__				,							a__				,							a__				,							a__				,							a__				,							a__							)				->				Optional[Any]:

										'''simple docstring'''




										snake_case_						=      self.num_labels
										snake_case_						=      TFDebertaVaForTokenClassification(config=a__							)
										snake_case_						=      {
										    "input_ids": input_ids,
										    "attention_mask": input_mask,
										    "token_type_ids": token_type_ids,
										}
										snake_case_						=      model(a__							)
										self.parent.assertEqual(result.logits.shape				,							(self.batch_size, self.seq_length, self.num_labels)							)




			def    lowerCAmelCase__				(					self				,							a__				,							a__				,							a__				,							a__				,							a__				,							a__				,							a__							)				->				Any:

										'''simple docstring'''




										snake_case_						=      TFDebertaVaForQuestionAnswering(config=a__							)
										snake_case_						=      {
										    "input_ids": input_ids,
										    "attention_mask": input_mask,
										    "token_type_ids": token_type_ids,
										}

										snake_case_						=      model(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    lowerCAmelCase__				(					self							)				->				Optional[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_tf
class  _snake_case		(	lowercase_						,						lowercase_						,						unittest.TestCase							):
			lowerCAmelCase_     :      str						       =    (
			    (
			        TFDebertaVaModel,
			        TFDebertaVaForMaskedLM,
			        TFDebertaVaForQuestionAnswering,
			        TFDebertaVaForSequenceClassification,
			        TFDebertaVaForTokenClassification,
			    )
			    if is_tf_available()
			    else ()
			)
			lowerCAmelCase_     :      Optional[int]						       =    (
			    {
			        "feature-extraction": TFDebertaVaModel,
			        "fill-mask": TFDebertaVaForMaskedLM,
			        "question-answering": TFDebertaVaForQuestionAnswering,
			        "text-classification": TFDebertaVaForSequenceClassification,
			        "token-classification": TFDebertaVaForTokenClassification,
			        "zero-shot": TFDebertaVaForSequenceClassification,
			    }
			    if is_tf_available()
			    else {}
			)

			lowerCAmelCase_     :      Optional[Any]						       =    False
			lowerCAmelCase_     :      Optional[int]						       =    False




			def    lowerCAmelCase__				(					self							)				->				int:

										'''simple docstring'''




										snake_case_						=      TFDebertaVaModelTester(self							)
										snake_case_						=      ConfigTester(self				,							config_class=a__				,							hidden_size=37							)




			def    lowerCAmelCase__				(					self							)				->				List[Any]:

										'''simple docstring'''




										self.config_tester.run_common_tests()




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

										'''simple docstring'''




										snake_case_						=      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*a__							)




			def    lowerCAmelCase__				(					self							)				->				List[Any]:

										'''simple docstring'''




										snake_case_						=      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_masked_lm(*a__							)




			def    lowerCAmelCase__				(					self							)				->				List[str]:

										'''simple docstring'''




										snake_case_						=      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_question_answering(*a__							)




			def    lowerCAmelCase__				(					self							)				->				Dict:

										'''simple docstring'''




										snake_case_						=      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_sequence_classification(*a__							)




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

										'''simple docstring'''




										snake_case_						=      self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_token_classification(*a__							)




			@slow
			def    lowerCAmelCase__				(					self							)				->				Tuple:

										'''simple docstring'''




										snake_case_						=      TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge"							)
										self.assertIsNotNone(a__							)




@require_tf
class  _snake_case		(	unittest.TestCase							):




			@unittest.skip(reason="Model not available yet"							)
			def    lowerCAmelCase__				(					self							)				->				Dict:

										'''simple docstring'''




										pass




			@slow
			def    lowerCAmelCase__				(					self							)				->				str:

										'''simple docstring'''




										snake_case_						=      TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge"							)
										snake_case_						=      tf.constant([[0, 31_414, 232, 328, 740, 1_140, 12_695, 69, 46_078, 1_588, 2]]							)
										snake_case_						=      tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]							)
										snake_case_						=      model(a__				,							attention_mask=a__							)[0]

										snake_case_						=      tf.constant(
										    [[[0.2_3_5_6, 0.1_9_4_8, 0.0_3_6_9], [-0.1_0_6_3, 0.3_5_8_6, -0.5_1_5_2], [-0.6_3_9_9, -0.0_2_5_9, -0.2_5_2_5]]]							)
										tf.debugging.assert_near(output[:, 1:4, 1:4]				,							a__				,							atol=1e-4							)







from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


lowerCAmelCase_       	=	{'''configuration_opt''': ['''OPT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''OPTConfig''']}

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					lowerCAmelCase_       	=	[
					    '''OPT_PRETRAINED_MODEL_ARCHIVE_LIST''',
					    '''OPTForCausalLM''',
					    '''OPTModel''',
					    '''OPTPreTrainedModel''',
					    '''OPTForSequenceClassification''',
					    '''OPTForQuestionAnswering''',
					]

try:
					if not is_tf_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					lowerCAmelCase_       	=	['''TFOPTForCausalLM''', '''TFOPTModel''', '''TFOPTPreTrainedModel''']

try:
					if not is_flax_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					lowerCAmelCase_       	=	[
					    '''FlaxOPTForCausalLM''',
					    '''FlaxOPTModel''',
					    '''FlaxOPTPreTrainedModel''',
					]


if TYPE_CHECKING:
					from .configuration_opt import OPT_PRETRAINED_CONFIG_ARCHIVE_MAP, OPTConfig

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_opt import (
										    OPT_PRETRAINED_MODEL_ARCHIVE_LIST,
										    OPTForCausalLM,
										    OPTForQuestionAnswering,
										    OPTForSequenceClassification,
										    OPTModel,
										    OPTPreTrainedModel,
										)

					try:
										if not is_tf_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_tf_opt import TFOPTForCausalLM, TFOPTModel, TFOPTPreTrainedModel

					try:
										if not is_flax_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_flax_opt import FlaxOPTForCausalLM, FlaxOPTModel, FlaxOPTPreTrainedModel

else:
					import sys

					lowerCAmelCase_       	=	_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)