






"""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 	a		:






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






    def   UpperCamelCase			(			self	:				List[str]   )	->						int:
      lowerCamelCase_       	=		ids_tensor([self.batch_size, self.seq_length]			,		self.vocab_size   )

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

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

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

      lowerCamelCase_       	=		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=__SCREAMING_SNAKE_CASE			,		)

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






    def   UpperCamelCase			(			self	:				Union[str, Any]			,		__SCREAMING_SNAKE_CASE	:				Dict			,		__SCREAMING_SNAKE_CASE	:				Dict			,		__SCREAMING_SNAKE_CASE	:				List[str]			,		__SCREAMING_SNAKE_CASE	:				Optional[Any]			,		__SCREAMING_SNAKE_CASE	:				Tuple			,		__SCREAMING_SNAKE_CASE	:				Union[str, Any]			,		__SCREAMING_SNAKE_CASE	:				int   )	->						Optional[Any]:
      lowerCamelCase_       	=		TFDebertaVaModel(config=__SCREAMING_SNAKE_CASE   )
      lowerCamelCase_       	=		{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}

      lowerCamelCase_       	=		[input_ids, input_mask]
      lowerCamelCase_       	=		model(__SCREAMING_SNAKE_CASE   )

      lowerCamelCase_       	=		model(__SCREAMING_SNAKE_CASE   )

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






    def   UpperCamelCase			(			self	:				Dict			,		__SCREAMING_SNAKE_CASE	:				List[str]			,		__SCREAMING_SNAKE_CASE	:				List[Any]			,		__SCREAMING_SNAKE_CASE	:				Optional[int]			,		__SCREAMING_SNAKE_CASE	:				Optional[Any]			,		__SCREAMING_SNAKE_CASE	:				Tuple			,		__SCREAMING_SNAKE_CASE	:				Optional[Any]			,		__SCREAMING_SNAKE_CASE	:				List[str]   )	->						str:
      lowerCamelCase_       	=		TFDebertaVaForMaskedLM(config=__SCREAMING_SNAKE_CASE   )
      lowerCamelCase_       	=		{
          'input_ids': input_ids,
          'attention_mask': input_mask,
          'token_type_ids': token_type_ids,
      }
      lowerCamelCase_       	=		model(__SCREAMING_SNAKE_CASE   )
      self.parent.assertEqual(result.logits.shape			,		(self.batch_size, self.seq_length, self.vocab_size)   )






    def   UpperCamelCase			(			self	:				Dict			,		__SCREAMING_SNAKE_CASE	:				str			,		__SCREAMING_SNAKE_CASE	:				Dict			,		__SCREAMING_SNAKE_CASE	:				List[str]			,		__SCREAMING_SNAKE_CASE	:				List[Any]			,		__SCREAMING_SNAKE_CASE	:				List[Any]			,		__SCREAMING_SNAKE_CASE	:				Union[str, Any]			,		__SCREAMING_SNAKE_CASE	:				str   )	->						Optional[int]:
      lowerCamelCase_       	=		self.num_labels
      lowerCamelCase_       	=		TFDebertaVaForSequenceClassification(config=__SCREAMING_SNAKE_CASE   )
      lowerCamelCase_       	=		{
          'input_ids': input_ids,
          'attention_mask': input_mask,
          'token_type_ids': token_type_ids,
      }

      lowerCamelCase_       	=		model(__SCREAMING_SNAKE_CASE   )
      self.parent.assertEqual(result.logits.shape			,		(self.batch_size, self.num_labels)   )






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






    def   UpperCamelCase			(			self	:				Any			,		__SCREAMING_SNAKE_CASE	:				str			,		__SCREAMING_SNAKE_CASE	:				List[str]			,		__SCREAMING_SNAKE_CASE	:				Tuple			,		__SCREAMING_SNAKE_CASE	:				List[str]			,		__SCREAMING_SNAKE_CASE	:				Union[str, Any]			,		__SCREAMING_SNAKE_CASE	:				Union[str, Any]			,		__SCREAMING_SNAKE_CASE	:				Optional[int]   )	->						int:
      lowerCamelCase_       	=		TFDebertaVaForQuestionAnswering(config=__SCREAMING_SNAKE_CASE   )
      lowerCamelCase_       	=		{
          'input_ids': input_ids,
          'attention_mask': input_mask,
          'token_type_ids': token_type_ids,
      }

      lowerCamelCase_       	=		model(__SCREAMING_SNAKE_CASE   )
      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	:				List[Any]   )	->						Dict:
      lowerCamelCase_       	=		self.prepare_config_and_inputs()
      (
          (
          lowerCamelCase_
      )	,      (
          lowerCamelCase_
      )	,      (
          lowerCamelCase_
      )	,      (
          lowerCamelCase_
      )	,      (
          lowerCamelCase_
      )	,      (
          lowerCamelCase_
      )	,      (
          lowerCamelCase_
      )	,      
      )       	=		config_and_inputs
      lowerCamelCase_       	=		{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
      return config, inputs_dict






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

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






    def   UpperCamelCase			(			self	:				List[Any]   )	->						Dict:
      lowerCamelCase_       	=		TFDebertaVaModelTester(self   )
      lowerCamelCase_       	=		ConfigTester(self			,		config_class=__SCREAMING_SNAKE_CASE			,		hidden_size=37   )






    def   UpperCamelCase			(			self	:				Tuple   )	->						Dict:
      self.config_tester.run_common_tests()






    def   UpperCamelCase			(			self	:				Optional[Any]   )	->						Tuple:
      lowerCamelCase_       	=		self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*__SCREAMING_SNAKE_CASE   )






    def   UpperCamelCase			(			self	:				List[str]   )	->						str:
      lowerCamelCase_       	=		self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_masked_lm(*__SCREAMING_SNAKE_CASE   )






    def   UpperCamelCase			(			self	:				Optional[int]   )	->						Union[str, Any]:
      lowerCamelCase_       	=		self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_question_answering(*__SCREAMING_SNAKE_CASE   )






    def   UpperCamelCase			(			self	:				Tuple   )	->						List[Any]:
      lowerCamelCase_       	=		self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_sequence_classification(*__SCREAMING_SNAKE_CASE   )






    def   UpperCamelCase			(			self	:				Union[str, Any]   )	->						Tuple:
      lowerCamelCase_       	=		self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_token_classification(*__SCREAMING_SNAKE_CASE   )






    @slow
    def   UpperCamelCase			(			self	:				Any   )	->						Optional[Any]:
      lowerCamelCase_       	=		TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge'   )
      self.assertIsNotNone(__SCREAMING_SNAKE_CASE   )






@require_tf
class 	a		(   unittest.TestCase						):






    @unittest.skip(reason='Model not available yet'   )
    def   UpperCamelCase			(			self	:				Any   )	->						Optional[Any]:
      pass






    @slow
    def   UpperCamelCase			(			self	:				str   )	->						Tuple:
      lowerCamelCase_       	=		TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge'   )
      lowerCamelCase_       	=		tf.constant([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]]   )
      lowerCamelCase_       	=		tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]   )
      lowerCamelCase_       	=		model(__SCREAMING_SNAKE_CASE			,		attention_mask=__SCREAMING_SNAKE_CASE   )[0]

      lowerCamelCase_       	=		tf.constant(
          [[[0.2_356, 0.1_948, 0.0_369], [-0.1_063, 0.3_586, -0.5_152], [-0.6_399, -0.0_259, -0.2_525]]]   )
      tf.debugging.assert_near(output[:, 1:4, 1:4]			,		__SCREAMING_SNAKE_CASE			,		atol=1e-4   )












"""simple docstring"""





def 	lowerCamelCase__			(				_lowerCamelCase			:						str					) ->							bool:
  lowerCamelCase_       	=		0
  for ch in input_str:
    lowerCamelCase_       	=		ord(_lowerCamelCase					)
    lowerCamelCase_       	=		pow(2						,							_lowerCamelCase					)

    # If we already turned on bit for current character's unicode
    if bitmap >> ch_unicode & 1 == 1:
      return False
    bitmap |= ch_bit_index_on
  return True


if __name__ == "__main__":
  import doctest

  doctest.testmod()




