






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







		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.02       ,A__=False       ,A__=True       ,A__="None"       ,A__=3       ,A__=4       ,A__=None       ,):
						_A	:				str   =      parent
						_A	:				Union[str, Any]   =      batch_size
						_A	:				Any   =      seq_length
						_A	:				Dict   =      is_training
						_A	:				Optional[int]   =      use_input_mask
						_A	:				Optional[Any]   =      use_token_type_ids
						_A	:				Optional[Any]   =      use_labels
						_A	:				Optional[Any]   =      vocab_size
						_A	:				List[Any]   =      hidden_size
						_A	:				List[Any]   =      num_hidden_layers
						_A	:				Optional[int]   =      num_attention_heads
						_A	:				Any   =      intermediate_size
						_A	:				List[str]   =      hidden_act
						_A	:				List[Any]   =      hidden_dropout_prob
						_A	:				Any   =      attention_probs_dropout_prob
						_A	:				int   =      max_position_embeddings
						_A	:				str   =      type_vocab_size
						_A	:				int   =      type_sequence_label_size
						_A	:				Optional[Any]   =      initializer_range
						_A	:				Optional[Any]   =      num_labels
						_A	:				List[str]   =      num_choices
						_A	:				Optional[int]   =      relative_attention
						_A	:				List[str]   =      position_biased_input
						_A	:				List[str]   =      pos_att_type
						_A	:				Optional[Any]   =      scope







		def  A__      (					self		):
						_A	:				str   =      ids_tensor([self.batch_size, self.seq_length]       ,self.vocab_size		)

						_A	:				Optional[int]   =      None
						if self.use_input_mask:
										_A	:				Dict   =      random_attention_mask([self.batch_size, self.seq_length]		)

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

						_A	:				Optional[int]   =      None
						_A	:				Optional[Any]   =      None
						_A	:				Dict   =      None
						if self.use_labels:
										_A	:				Any   =      ids_tensor([self.batch_size]       ,self.type_sequence_label_size		)
										_A	:				Optional[int]   =      ids_tensor([self.batch_size, self.seq_length]       ,self.num_labels		)

						_A	:				Optional[Any]   =      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__		):
						_A	:				Union[str, Any]   =      TFDebertaVaModel(config=A__		)
						_A	:				Any   =      {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}

						_A	:				Optional[int]   =      [input_ids, input_mask]
						_A	:				Any   =      model(A__		)

						_A	:				int   =      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__		):
						_A	:				Optional[int]   =      TFDebertaVaForMaskedLM(config=A__		)
						_A	:				List[Any]   =      {
						    '''input_ids''': input_ids,
						    '''attention_mask''': input_mask,
						    '''token_type_ids''': token_type_ids,
						}
						_A	:				List[str]   =      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__		):
						_A	:				List[Any]   =      self.num_labels
						_A	:				Union[str, Any]   =      TFDebertaVaForSequenceClassification(config=A__		)
						_A	:				Tuple   =      {
						    '''input_ids''': input_ids,
						    '''attention_mask''': input_mask,
						    '''token_type_ids''': token_type_ids,
						}

						_A	:				List[Any]   =      model(A__		)
						self.parent.assertEqual(result.logits.shape       ,(self.batch_size, self.num_labels)		)







		def  A__      (					self       ,A__       ,A__       ,A__       ,A__       ,A__       ,A__       ,A__		):
						_A	:				List[Any]   =      self.num_labels
						_A	:				str   =      TFDebertaVaForTokenClassification(config=A__		)
						_A	:				List[Any]   =      {
						    '''input_ids''': input_ids,
						    '''attention_mask''': input_mask,
						    '''token_type_ids''': token_type_ids,
						}
						_A	:				Tuple   =      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__		):
						_A	:				str   =      TFDebertaVaForQuestionAnswering(config=A__		)
						_A	:				int   =      {
						    '''input_ids''': input_ids,
						    '''attention_mask''': input_mask,
						    '''token_type_ids''': token_type_ids,
						}

						_A	:				Optional[int]   =      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		):
						_A	:				Union[str, Any]   =      self.prepare_config_and_inputs()
						(
						    (
						    _A
						)  ,				(
						    _A
						)  ,				(
						    _A
						)  ,				(
						    _A
						)  ,				(
						    _A
						)  ,				(
						    _A
						)  ,				(
						    _A
						)  ,				
						)	:				Tuple   =      config_and_inputs
						_A	:				Tuple   =      {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
						return config, inputs_dict






@require_tf
class 						UpperCAmelCase__ (							__snake_case     ,				__snake_case     ,				unittest.TestCase							):
		__snake_case      :       Optional[int]     =   (
		    (
		        TFDebertaVaModel,
		        TFDebertaVaForMaskedLM,
		        TFDebertaVaForQuestionAnswering,
		        TFDebertaVaForSequenceClassification,
		        TFDebertaVaForTokenClassification,
		    )
		    if is_tf_available()
		    else ()
		)
		__snake_case      :       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 {}
		)

		__snake_case      :       Dict     =   False
		__snake_case      :       Dict     =   False







		def  A__      (					self		):
						_A	:				Optional[Any]   =      TFDebertaVaModelTester(self		)
						_A	:				Optional[int]   =      ConfigTester(self       ,config_class=A__       ,hidden_size=37		)







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







		def  A__      (					self		):
						_A	:				Optional[int]   =      self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*A__		)







		def  A__      (					self		):
						_A	:				Any   =      self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_masked_lm(*A__		)







		def  A__      (					self		):
						_A	:				List[Any]   =      self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_question_answering(*A__		)







		def  A__      (					self		):
						_A	:				Dict   =      self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_sequence_classification(*A__		)







		def  A__      (					self		):
						_A	:				Union[str, Any]   =      self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_token_classification(*A__		)







		@slow
		def  A__      (					self		):
						_A	:				Any   =      TFDebertaVaModel.from_pretrained('''kamalkraj/deberta-v2-xlarge'''		)
						self.assertIsNotNone(A__		)






@require_tf
class 						UpperCAmelCase__ (							unittest.TestCase							):







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







		@slow
		def  A__      (					self		):
						_A	:				Optional[int]   =      TFDebertaVaModel.from_pretrained('''kamalkraj/deberta-v2-xlarge'''		)
						_A	:				str   =      tf.constant([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]]		)
						_A	:				Dict   =      tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]		)
						_A	:				str   =      model(A__       ,attention_mask=A__		)[0]

						_A	:				str   =      tf.constant(
						    [[[0.23_56, 0.19_48, 0.03_69], [-0.10_63, 0.35_86, -0.51_52], [-0.63_99, -0.02_59, -0.25_25]]]		)
						tf.debugging.assert_near(output[:, 1:4, 1:4]       ,A__       ,atol=1E-4		)











import warnings


warnings.warn(
    'memory_utils has been reorganized to utils.memory. Import `find_executable_batchsize` from the main `__init__`: '
    '`from accelerate import find_executable_batch_size` to avoid this warning.',
    FutureWarning,
)



