


'''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 					lowercase_     :


    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=5_12  ,					a=16  ,					a=2  ,					a=0.02  ,					a=False  ,					a=True  ,					a="None"  ,					a=3  ,					a=4  ,					a=None  ,					):
          UpperCamelCase__										=				parent
          UpperCamelCase__										=				batch_size
          UpperCamelCase__										=				seq_length
          UpperCamelCase__										=				is_training
          UpperCamelCase__										=				use_input_mask
          UpperCamelCase__										=				use_token_type_ids
          UpperCamelCase__										=				use_labels
          UpperCamelCase__										=				vocab_size
          UpperCamelCase__										=				hidden_size
          UpperCamelCase__										=				num_hidden_layers
          UpperCamelCase__										=				num_attention_heads
          UpperCamelCase__										=				intermediate_size
          UpperCamelCase__										=				hidden_act
          UpperCamelCase__										=				hidden_dropout_prob
          UpperCamelCase__										=				attention_probs_dropout_prob
          UpperCamelCase__										=				max_position_embeddings
          UpperCamelCase__										=				type_vocab_size
          UpperCamelCase__										=				type_sequence_label_size
          UpperCamelCase__										=				initializer_range
          UpperCamelCase__										=				num_labels
          UpperCamelCase__										=				num_choices
          UpperCamelCase__										=				relative_attention
          UpperCamelCase__										=				position_biased_input
          UpperCamelCase__										=				pos_att_type
          UpperCamelCase__										=				scope


    def    __a							(     self    ):
          UpperCamelCase__										=				ids_tensor([self.batch_size, self.seq_length]  ,					self.vocab_size    )

          UpperCamelCase__										=				None
          if self.use_input_mask:
                UpperCamelCase__										=				random_attention_mask([self.batch_size, self.seq_length]    )

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

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

          UpperCamelCase__										=				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    __a							(     self  ,					a  ,					a  ,					a  ,					a  ,					a  ,					a  ,					a    ):
          UpperCamelCase__										=				TFDebertaVaModel(config=a    )
          UpperCamelCase__										=				{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}

          UpperCamelCase__										=				[input_ids, input_mask]
          UpperCamelCase__										=				model(a    )

          UpperCamelCase__										=				model(a    )

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


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


    def    __a							(     self  ,					a  ,					a  ,					a  ,					a  ,					a  ,					a  ,					a    ):
          UpperCamelCase__										=				self.num_labels
          UpperCamelCase__										=				TFDebertaVaForSequenceClassification(config=a    )
          UpperCamelCase__										=				{
              "input_ids": input_ids,
              "attention_mask": input_mask,
              "token_type_ids": token_type_ids,
          }

          UpperCamelCase__										=				model(a    )
          self.parent.assertEqual(result.logits.shape  ,					(self.batch_size, self.num_labels)    )


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


    def    __a							(     self  ,					a  ,					a  ,					a  ,					a  ,					a  ,					a  ,					a    ):
          UpperCamelCase__										=				TFDebertaVaForQuestionAnswering(config=a    )
          UpperCamelCase__										=				{
              "input_ids": input_ids,
              "attention_mask": input_mask,
              "token_type_ids": token_type_ids,
          }

          UpperCamelCase__										=				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    __a							(     self    ):
          UpperCamelCase__										=				self.prepare_config_and_inputs()
          (
              (
              UpperCamelCase__
          )					,	(
              UpperCamelCase__
          )					,	(
              UpperCamelCase__
          )					,	(
              UpperCamelCase__
          )					,	(
              UpperCamelCase__
          )					,	(
              UpperCamelCase__
          )					,	(
              UpperCamelCase__
          )					,	
          )										=				config_and_inputs
          UpperCamelCase__										=				{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
          return config, inputs_dict

@require_tf
class 					lowercase_     (    a__  ,						a__  ,						unittest.TestCase   ):
    __UpperCAmelCase   			=	(
        (
            TFDebertaVaModel,
            TFDebertaVaForMaskedLM,
            TFDebertaVaForQuestionAnswering,
            TFDebertaVaForSequenceClassification,
            TFDebertaVaForTokenClassification,
        )
        if is_tf_available()
        else ()
    )
    __UpperCAmelCase   			=	(
        {
            'feature-extraction': TFDebertaVaModel,
            'fill-mask': TFDebertaVaForMaskedLM,
            'question-answering': TFDebertaVaForQuestionAnswering,
            'text-classification': TFDebertaVaForSequenceClassification,
            'token-classification': TFDebertaVaForTokenClassification,
            'zero-shot': TFDebertaVaForSequenceClassification,
        }
        if is_tf_available()
        else {}
    )

    __UpperCAmelCase   			=	False
    __UpperCAmelCase   			=	False


    def    __a							(     self    ):
          UpperCamelCase__										=				TFDebertaVaModelTester(self    )
          UpperCamelCase__										=				ConfigTester(self  ,					config_class=a  ,					hidden_size=37    )


    def    __a							(     self    ):
          self.config_tester.run_common_tests()


    def    __a							(     self    ):
          UpperCamelCase__										=				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*a    )


    def    __a							(     self    ):
          UpperCamelCase__										=				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_masked_lm(*a    )


    def    __a							(     self    ):
          UpperCamelCase__										=				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_question_answering(*a    )


    def    __a							(     self    ):
          UpperCamelCase__										=				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_sequence_classification(*a    )


    def    __a							(     self    ):
          UpperCamelCase__										=				self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_token_classification(*a    )


    @slow
    def    __a							(     self    ):
          UpperCamelCase__										=				TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge"    )
          self.assertIsNotNone(a    )

@require_tf
class 					lowercase_     (    unittest.TestCase   ):


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


    @slow
    def    __a							(     self    ):
          UpperCamelCase__										=				TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge"    )
          UpperCamelCase__										=				tf.constant([[0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 4_60_78, 15_88, 2]]    )
          UpperCamelCase__										=				tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]    )
          UpperCamelCase__										=				model(a  ,					attention_mask=a    )[0]

          UpperCamelCase__										=				tf.constant(
              [[[0.2356, 0.1948, 0.0369], [-0.1063, 0.3586, -0.5152], [-0.6399, -0.0259, -0.2525]]]    )
          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,
)


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

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

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

try:
		if not is_flax_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		_a      	=  [
		    '''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

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