


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

   '''simple docstring'''




   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						,				):






     """simple docstring"""





     lowerCamelCase :					List[str]    =				parent
     lowerCamelCase :					Union[str, Any]    =				batch_size
     lowerCamelCase :					Any    =				seq_length
     lowerCamelCase :					int    =				is_training
     lowerCamelCase :					Dict    =				use_input_mask
     lowerCamelCase :					Union[str, Any]    =				use_token_type_ids
     lowerCamelCase :					List[str]    =				use_labels
     lowerCamelCase :					Tuple    =				vocab_size
     lowerCamelCase :					Any    =				hidden_size
     lowerCamelCase :					Dict    =				num_hidden_layers
     lowerCamelCase :					Any    =				num_attention_heads
     lowerCamelCase :					List[Any]    =				intermediate_size
     lowerCamelCase :					Union[str, Any]    =				hidden_act
     lowerCamelCase :					Tuple    =				hidden_dropout_prob
     lowerCamelCase :					List[str]    =				attention_probs_dropout_prob
     lowerCamelCase :					int    =				max_position_embeddings
     lowerCamelCase :					List[Any]    =				type_vocab_size
     lowerCamelCase :					Union[str, Any]    =				type_sequence_label_size
     lowerCamelCase :					Union[str, Any]    =				initializer_range
     lowerCamelCase :					str    =				num_labels
     lowerCamelCase :					List[str]    =				num_choices
     lowerCamelCase :					Optional[int]    =				relative_attention
     lowerCamelCase :					Tuple    =				position_biased_input
     lowerCamelCase :					str    =				pos_att_type
     lowerCamelCase :					Tuple    =				scope






   def _snake_case    (		self ):






     """simple docstring"""





     lowerCamelCase :					Any    =				ids_tensor([self.batch_size, self.seq_length]						,				self.vocab_size )

     lowerCamelCase :					List[str]    =				None
     if self.use_input_mask:
       lowerCamelCase :					List[str]    =				random_attention_mask([self.batch_size, self.seq_length] )

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

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

     lowerCamelCase :					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=lowercase_						,				)

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






   def _snake_case    (		self						,				__A						,				__A						,				__A						,				__A						,				__A						,				__A						,				__A ):






     """simple docstring"""





     lowerCamelCase :					Any    =				TFDebertaVaModel(config=lowercase_ )
     lowerCamelCase :					str    =				{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}

     lowerCamelCase :					List[Any]    =				[input_ids, input_mask]
     lowerCamelCase :					Dict    =				model(lowercase_ )

     lowerCamelCase :					Optional[Any]    =				model(lowercase_ )

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






   def _snake_case    (		self						,				__A						,				__A						,				__A						,				__A						,				__A						,				__A						,				__A ):






     """simple docstring"""





     lowerCamelCase :					List[str]    =				TFDebertaVaForMaskedLM(config=lowercase_ )
     lowerCamelCase :					Optional[Any]    =				{
         "input_ids": input_ids,
         "attention_mask": input_mask,
         "token_type_ids": token_type_ids,
     }
     lowerCamelCase :					List[Any]    =				model(lowercase_ )
     self.parent.assertEqual(result.logits.shape						,				(self.batch_size, self.seq_length, self.vocab_size) )






   def _snake_case    (		self						,				__A						,				__A						,				__A						,				__A						,				__A						,				__A						,				__A ):






     """simple docstring"""





     lowerCamelCase :					Union[str, Any]    =				self.num_labels
     lowerCamelCase :					Optional[int]    =				TFDebertaVaForSequenceClassification(config=lowercase_ )
     lowerCamelCase :					List[Any]    =				{
         "input_ids": input_ids,
         "attention_mask": input_mask,
         "token_type_ids": token_type_ids,
     }

     lowerCamelCase :					Dict    =				model(lowercase_ )
     self.parent.assertEqual(result.logits.shape						,				(self.batch_size, self.num_labels) )






   def _snake_case    (		self						,				__A						,				__A						,				__A						,				__A						,				__A						,				__A						,				__A ):






     """simple docstring"""





     lowerCamelCase :					Any    =				self.num_labels
     lowerCamelCase :					Union[str, Any]    =				TFDebertaVaForTokenClassification(config=lowercase_ )
     lowerCamelCase :					Optional[int]    =				{
         "input_ids": input_ids,
         "attention_mask": input_mask,
         "token_type_ids": token_type_ids,
     }
     lowerCamelCase :					List[Any]    =				model(lowercase_ )
     self.parent.assertEqual(result.logits.shape						,				(self.batch_size, self.seq_length, self.num_labels) )






   def _snake_case    (		self						,				__A						,				__A						,				__A						,				__A						,				__A						,				__A						,				__A ):






     """simple docstring"""





     lowerCamelCase :					List[str]    =				TFDebertaVaForQuestionAnswering(config=lowercase_ )
     lowerCamelCase :					Union[str, Any]    =				{
         "input_ids": input_ids,
         "attention_mask": input_mask,
         "token_type_ids": token_type_ids,
     }

     lowerCamelCase :					List[Any]    =				model(lowercase_ )
     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 _snake_case    (		self ):






     """simple docstring"""





     lowerCamelCase :					Dict    =				self.prepare_config_and_inputs()
     (
         (
         lowerCamelCase
     )    ,	(
         lowerCamelCase
     )    ,	(
         lowerCamelCase
     )    ,	(
         lowerCamelCase
     )    ,	(
         lowerCamelCase
     )    ,	(
         lowerCamelCase
     )    ,	(
         lowerCamelCase
     )    ,	
     ) :					int    =				config_and_inputs
     lowerCamelCase :					str    =				{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
     return config, inputs_dict



@require_tf
class 	UpperCAmelCase_					(					_lowerCamelCase		, _lowerCamelCase		, unittest.TestCase    ):

   '''simple docstring'''




   __A :      Optional[int]     		=		(
       (
           TFDebertaVaModel,
           TFDebertaVaForMaskedLM,
           TFDebertaVaForQuestionAnswering,
           TFDebertaVaForSequenceClassification,
           TFDebertaVaForTokenClassification,
       )
       if is_tf_available()
       else ()
   )
   __A :      Any     		=		(
       {
           "feature-extraction": TFDebertaVaModel,
           "fill-mask": TFDebertaVaForMaskedLM,
           "question-answering": TFDebertaVaForQuestionAnswering,
           "text-classification": TFDebertaVaForSequenceClassification,
           "token-classification": TFDebertaVaForTokenClassification,
           "zero-shot": TFDebertaVaForSequenceClassification,
       }
       if is_tf_available()
       else {}
   )

   __A :      int     		=		False
   __A :      Union[str, Any]     		=		False






   def _snake_case    (		self ):






     """simple docstring"""





     lowerCamelCase :					Optional[int]    =				TFDebertaVaModelTester(self )
     lowerCamelCase :					Any    =				ConfigTester(self						,				config_class=lowercase_						,				hidden_size=37 )






   def _snake_case    (		self ):






     """simple docstring"""





     self.config_tester.run_common_tests()






   def _snake_case    (		self ):






     """simple docstring"""





     lowerCamelCase :					int    =				self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_model(*lowercase_ )






   def _snake_case    (		self ):






     """simple docstring"""





     lowerCamelCase :					Any    =				self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_masked_lm(*lowercase_ )






   def _snake_case    (		self ):






     """simple docstring"""





     lowerCamelCase :					int    =				self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_question_answering(*lowercase_ )






   def _snake_case    (		self ):






     """simple docstring"""





     lowerCamelCase :					List[Any]    =				self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_sequence_classification(*lowercase_ )






   def _snake_case    (		self ):






     """simple docstring"""





     lowerCamelCase :					Optional[int]    =				self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_token_classification(*lowercase_ )






   @slow
   def _snake_case    (		self ):






     """simple docstring"""





     lowerCamelCase :					str    =				TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge" )
     self.assertIsNotNone(lowercase_ )



@require_tf
class 	UpperCAmelCase_					(					unittest.TestCase    ):

   '''simple docstring'''




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






     """simple docstring"""





     pass






   @slow
   def _snake_case    (		self ):






     """simple docstring"""





     lowerCamelCase :					Tuple    =				TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge" )
     lowerCamelCase :					int    =				tf.constant([[0, 3_1414, 232, 328, 740, 1140, 1_2695, 69, 4_6078, 1588, 2]] )
     lowerCamelCase :					List[Any]    =				tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]] )
     lowerCamelCase :					Tuple    =				model(lowercase_						,				attention_mask=lowercase_ )[0]

     lowerCamelCase :					int    =				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]						,				lowercase_						,				atol=1e-4 )









'''simple docstring'''

from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


a  :				str									=  logging.get_logger(__name__)

a  :				str									=  {
    'google/bigbird-roberta-base': 'https://huggingface.co/google/bigbird-roberta-base/resolve/main/config.json',
    'google/bigbird-roberta-large': 'https://huggingface.co/google/bigbird-roberta-large/resolve/main/config.json',
    'google/bigbird-base-trivia-itc': 'https://huggingface.co/google/bigbird-base-trivia-itc/resolve/main/config.json',
    # See all BigBird models at https://huggingface.co/models?filter=big_bird
}






class 						a				(   _lowerCamelCase     ):
				snake_case_      =		"big_bird"


				def __init__(		self    :					Union[str, Any]       ,				lowercase_    :					List[Any]=5_0358       ,				lowercase_    :					Tuple=768       ,				lowercase_    :					Dict=12       ,				lowercase_    :					str=12       ,				lowercase_    :					Tuple=3072       ,				lowercase_    :					Any="gelu_new"       ,				lowercase_    :					Optional[Any]=0.1       ,				lowercase_    :					List[Any]=0.1       ,				lowercase_    :					List[Any]=4096       ,				lowercase_    :					List[Any]=2       ,				lowercase_    :					List[str]=0.02       ,				lowercase_    :					Optional[int]=1e-12       ,				lowercase_    :					Tuple=True       ,				lowercase_    :					Tuple=0       ,				lowercase_    :					str=1       ,				lowercase_    :					Union[str, Any]=2       ,				lowercase_    :					Optional[Any]=66       ,				lowercase_    :					Optional[int]="block_sparse"       ,				lowercase_    :					Any=True       ,				lowercase_    :					List[str]=False       ,				lowercase_    :					Any=64       ,				lowercase_    :					Tuple=3       ,				lowercase_    :					Tuple=None       ,				**lowercase_    :					Tuple       ,				):
									super().__init__(
									    pad_token_id=lowercase_       ,				bos_token_id=lowercase_       ,				eos_token_id=lowercase_       ,				sep_token_id=lowercase_       ,				**lowercase_       ,				)

									snake_case_									=				vocab_size
									snake_case_									=				max_position_embeddings
									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_									=				initializer_range
									snake_case_									=				type_vocab_size
									snake_case_									=				layer_norm_eps
									snake_case_									=				use_cache

									snake_case_									=				rescale_embeddings
									snake_case_									=				attention_type
									snake_case_									=				use_bias
									snake_case_									=				block_size
									snake_case_									=				num_random_blocks
									snake_case_									=				classifier_dropout







class 						a				(   _lowerCamelCase     ):


				@property
				def   A_ (		self    :					str					):
									if self.task == "multiple-choice":
														snake_case_									=				{0: '''batch''', 1: '''choice''', 2: '''sequence'''}
									else:
														snake_case_									=				{0: '''batch''', 1: '''sequence'''}
									return OrderedDict(
									    [
									        ('''input_ids''', dynamic_axis),
									        ('''attention_mask''', dynamic_axis),
									    ]					)

