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 		_lowerCamelCase		:
				def __init__(  self , lowerCAmelCase , lowerCAmelCase=13 , lowerCAmelCase=7 , lowerCAmelCase=True , lowerCAmelCase=True , lowerCAmelCase=True , lowerCAmelCase=True , lowerCAmelCase=99 , lowerCAmelCase=32 , lowerCAmelCase=2 , lowerCAmelCase=4 , lowerCAmelCase=37 , lowerCAmelCase="gelu" , lowerCAmelCase=0.1 , lowerCAmelCase=0.1 , lowerCAmelCase=512 , lowerCAmelCase=16 , lowerCAmelCase=2 , lowerCAmelCase=0.02 , lowerCAmelCase=False , lowerCAmelCase=True , lowerCAmelCase="None" , lowerCAmelCase=3 , lowerCAmelCase=4 , lowerCAmelCase=None , )       ->					Tuple:
					SCREAMING_SNAKE_CASE__:   Any=      parent
					SCREAMING_SNAKE_CASE__:   List[str]=      batch_size
					SCREAMING_SNAKE_CASE__:   str=      seq_length
					SCREAMING_SNAKE_CASE__:   Tuple=      is_training
					SCREAMING_SNAKE_CASE__:   Union[str, Any]=      use_input_mask
					SCREAMING_SNAKE_CASE__:   Optional[int]=      use_token_type_ids
					SCREAMING_SNAKE_CASE__:   Tuple=      use_labels
					SCREAMING_SNAKE_CASE__:   int=      vocab_size
					SCREAMING_SNAKE_CASE__:   Tuple=      hidden_size
					SCREAMING_SNAKE_CASE__:   List[str]=      num_hidden_layers
					SCREAMING_SNAKE_CASE__:   Dict=      num_attention_heads
					SCREAMING_SNAKE_CASE__:   Dict=      intermediate_size
					SCREAMING_SNAKE_CASE__:   List[Any]=      hidden_act
					SCREAMING_SNAKE_CASE__:   Optional[int]=      hidden_dropout_prob
					SCREAMING_SNAKE_CASE__:   Tuple=      attention_probs_dropout_prob
					SCREAMING_SNAKE_CASE__:   Dict=      max_position_embeddings
					SCREAMING_SNAKE_CASE__:   Union[str, Any]=      type_vocab_size
					SCREAMING_SNAKE_CASE__:   List[str]=      type_sequence_label_size
					SCREAMING_SNAKE_CASE__:   Optional[int]=      initializer_range
					SCREAMING_SNAKE_CASE__:   Dict=      num_labels
					SCREAMING_SNAKE_CASE__:   Union[str, Any]=      num_choices
					SCREAMING_SNAKE_CASE__:   int=      relative_attention
					SCREAMING_SNAKE_CASE__:   Tuple=      position_biased_input
					SCREAMING_SNAKE_CASE__:   List[str]=      pos_att_type
					SCREAMING_SNAKE_CASE__:   str=      scope
				def 						UpperCamelCase_				(  self   )       ->					str:
					SCREAMING_SNAKE_CASE__:   List[Any]=      ids_tensor([self.batch_size, self.seq_length] , self.vocab_size   )

					SCREAMING_SNAKE_CASE__:   int=      None
					if self.use_input_mask:
						SCREAMING_SNAKE_CASE__:   Union[str, Any]=      random_attention_mask([self.batch_size, self.seq_length]   )

					SCREAMING_SNAKE_CASE__:   Optional[int]=      None
					if self.use_token_type_ids:
						SCREAMING_SNAKE_CASE__:   List[str]=      ids_tensor([self.batch_size, self.seq_length] , self.type_vocab_size   )

					SCREAMING_SNAKE_CASE__:   List[str]=      None
					SCREAMING_SNAKE_CASE__:   Tuple=      None
					SCREAMING_SNAKE_CASE__:   Tuple=      None
					if self.use_labels:
						SCREAMING_SNAKE_CASE__:   Union[str, Any]=      ids_tensor([self.batch_size] , self.type_sequence_label_size   )
						SCREAMING_SNAKE_CASE__:   List[Any]=      ids_tensor([self.batch_size, self.seq_length] , self.num_labels   )

					SCREAMING_SNAKE_CASE__:   str=      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=UpperCamelCase__ , )

					return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
				def 						UpperCamelCase_				(  self , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase   )       ->					Tuple:
					SCREAMING_SNAKE_CASE__:   Union[str, Any]=      TFDebertaVaModel(config=UpperCamelCase__   )
					SCREAMING_SNAKE_CASE__:   List[Any]=      {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}

					SCREAMING_SNAKE_CASE__:   str=      [input_ids, input_mask]
					SCREAMING_SNAKE_CASE__:   Optional[int]=      model(UpperCamelCase__   )

					SCREAMING_SNAKE_CASE__:   str=      model(UpperCamelCase__   )

					self.parent.assertEqual(result.last_hidden_state.shape , (self.batch_size, self.seq_length, self.hidden_size)   )
				def 						UpperCamelCase_				(  self , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase   )       ->					int:
					SCREAMING_SNAKE_CASE__:   List[Any]=      TFDebertaVaForMaskedLM(config=UpperCamelCase__   )
					SCREAMING_SNAKE_CASE__:   Tuple=      {
					    'input_ids': input_ids,
					    'attention_mask': input_mask,
					    'token_type_ids': token_type_ids,
					}
					SCREAMING_SNAKE_CASE__:   Optional[Any]=      model(UpperCamelCase__   )
					self.parent.assertEqual(result.logits.shape , (self.batch_size, self.seq_length, self.vocab_size)   )
				def 						UpperCamelCase_				(  self , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase   )       ->					List[Any]:
					SCREAMING_SNAKE_CASE__:   Any=      self.num_labels
					SCREAMING_SNAKE_CASE__:   Optional[Any]=      TFDebertaVaForSequenceClassification(config=UpperCamelCase__   )
					SCREAMING_SNAKE_CASE__:   str=      {
					    'input_ids': input_ids,
					    'attention_mask': input_mask,
					    'token_type_ids': token_type_ids,
					}

					SCREAMING_SNAKE_CASE__:   Any=      model(UpperCamelCase__   )
					self.parent.assertEqual(result.logits.shape , (self.batch_size, self.num_labels)   )
				def 						UpperCamelCase_				(  self , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase   )       ->					Optional[Any]:
					SCREAMING_SNAKE_CASE__:   Union[str, Any]=      self.num_labels
					SCREAMING_SNAKE_CASE__:   Optional[Any]=      TFDebertaVaForTokenClassification(config=UpperCamelCase__   )
					SCREAMING_SNAKE_CASE__:   int=      {
					    'input_ids': input_ids,
					    'attention_mask': input_mask,
					    'token_type_ids': token_type_ids,
					}
					SCREAMING_SNAKE_CASE__:   Optional[Any]=      model(UpperCamelCase__   )
					self.parent.assertEqual(result.logits.shape , (self.batch_size, self.seq_length, self.num_labels)   )
				def 						UpperCamelCase_				(  self , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase   )       ->					Union[str, Any]:
					SCREAMING_SNAKE_CASE__:   List[str]=      TFDebertaVaForQuestionAnswering(config=UpperCamelCase__   )
					SCREAMING_SNAKE_CASE__:   Dict=      {
					    'input_ids': input_ids,
					    'attention_mask': input_mask,
					    'token_type_ids': token_type_ids,
					}

					SCREAMING_SNAKE_CASE__:   List[str]=      model(UpperCamelCase__   )
					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 						UpperCamelCase_				(  self   )       ->					Dict:
					SCREAMING_SNAKE_CASE__:   Dict=      self.prepare_config_and_inputs()
					(
					    SCREAMING_SNAKE_CASE__       
					):   Tuple=      config_and_inputs
					SCREAMING_SNAKE_CASE__:   int=      {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
					return config, inputs_dict






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

				__a  =      False
				__a  =      False
				def 						UpperCamelCase_				(  self   )       ->					Optional[Any]:
					SCREAMING_SNAKE_CASE__:   Dict=      TFDebertaVaModelTester(self   )
					SCREAMING_SNAKE_CASE__:   List[str]=      ConfigTester(self , config_class=UpperCamelCase__ , hidden_size=37   )
				def 						UpperCamelCase_				(  self   )       ->					List[Any]:
					self.config_tester.run_common_tests()
				def 						UpperCamelCase_				(  self   )       ->					Union[str, Any]:
					SCREAMING_SNAKE_CASE__:   Tuple=      self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*UpperCamelCase__   )
				def 						UpperCamelCase_				(  self   )       ->					Union[str, Any]:
					SCREAMING_SNAKE_CASE__:   Union[str, Any]=      self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_masked_lm(*UpperCamelCase__   )
				def 						UpperCamelCase_				(  self   )       ->					Any:
					SCREAMING_SNAKE_CASE__:   str=      self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_question_answering(*UpperCamelCase__   )
				def 						UpperCamelCase_				(  self   )       ->					str:
					SCREAMING_SNAKE_CASE__:   int=      self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_sequence_classification(*UpperCamelCase__   )
				def 						UpperCamelCase_				(  self   )       ->					str:
					SCREAMING_SNAKE_CASE__:   Optional[int]=      self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_token_classification(*UpperCamelCase__   )



				@slow
				def 						UpperCamelCase_				(  self   )       ->					List[Any]:
					SCREAMING_SNAKE_CASE__:   Tuple=      TFDebertaVaModel.from_pretrained('''kamalkraj/deberta-v2-xlarge'''   )
					self.assertIsNotNone(UpperCamelCase__   )






@require_tf
class 		_lowerCamelCase		(   unittest.TestCase    ):
				@unittest.skip(reason='''Model not available yet'''   )
				def 						UpperCamelCase_				(  self   )       ->					Union[str, Any]:
					pass



				@slow
				def 						UpperCamelCase_				(  self   )       ->					Any:
					SCREAMING_SNAKE_CASE__:   int=      TFDebertaVaModel.from_pretrained('''kamalkraj/deberta-v2-xlarge'''   )
					SCREAMING_SNAKE_CASE__:   int=      tf.constant([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]]   )
					SCREAMING_SNAKE_CASE__:   List[Any]=      tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]   )
					SCREAMING_SNAKE_CASE__:   List[str]=      model(UpperCamelCase__ , attention_mask=UpperCamelCase__   )[0]

					SCREAMING_SNAKE_CASE__:   List[str]=      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] , UpperCamelCase__ , atol=1e-4   )


from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


lowercase_     :   List[str] 				=				{
    'configuration_maskformer': ['MASKFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP', 'MaskFormerConfig'],
    'configuration_maskformer_swin': ['MaskFormerSwinConfig'],
}

try:
      if not is_vision_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      lowercase_     :   Optional[Any] 				=				['MaskFormerFeatureExtractor']
      lowercase_     :   Dict 				=				['MaskFormerImageProcessor']


try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      lowercase_     :   str 				=				[
          'MASKFORMER_PRETRAINED_MODEL_ARCHIVE_LIST',
          'MaskFormerForInstanceSegmentation',
          'MaskFormerModel',
          'MaskFormerPreTrainedModel',
      ]
      lowercase_     :   Optional[Any] 				=				[
          'MaskFormerSwinBackbone',
          'MaskFormerSwinModel',
          'MaskFormerSwinPreTrainedModel',
      ]

if TYPE_CHECKING:
      from .configuration_maskformer import MASKFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, MaskFormerConfig
      from .configuration_maskformer_swin import MaskFormerSwinConfig

      try:
            if not is_vision_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .feature_extraction_maskformer import MaskFormerFeatureExtractor
            from .image_processing_maskformer import MaskFormerImageProcessor
      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_maskformer import (
                MASKFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
                MaskFormerForInstanceSegmentation,
                MaskFormerModel,
                MaskFormerPreTrainedModel,
            )
            from .modeling_maskformer_swin import (
                MaskFormerSwinBackbone,
                MaskFormerSwinModel,
                MaskFormerSwinPreTrainedModel,
            )


else:
      import sys

      lowercase_     :   Any 				=				_LazyModule(__name__, globals()['__file__'], _import_structure)

