




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		,      _A		,      _A=1_3		,      _A=7		,      _A=True		,      _A=True		,      _A=True		,      _A=True		,      _A=9_9		,      _A=3_2		,      _A=2		,      _A=4		,      _A=3_7		,      _A="gelu"		,      _A=0.1		,      _A=0.1		,      _A=5_1_2		,      _A=1_6		,      _A=2		,      _A=0.02		,      _A=False		,      _A=True		,      _A="None"		,      _A=3		,      _A=4		,      _A=None		,      ):




											"""simple docstring"""



											__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     __SCREAMING_SNAKE_CASE(       self      ):




											"""simple docstring"""



											__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=_A		,      )

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






						def     __SCREAMING_SNAKE_CASE(       self		,      _A		,      _A		,      _A		,      _A		,      _A		,      _A		,      _A      ):




											"""simple docstring"""



											__lowerCAmelCase           =	TFDebertaVaModel(config=_A      )
											__lowerCAmelCase           =	{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}

											__lowerCAmelCase           =	[input_ids, input_mask]
											__lowerCAmelCase           =	model(_A      )

											__lowerCAmelCase           =	model(_A      )

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






						def     __SCREAMING_SNAKE_CASE(       self		,      _A		,      _A		,      _A		,      _A		,      _A		,      _A		,      _A      ):




											"""simple docstring"""



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






						def     __SCREAMING_SNAKE_CASE(       self		,      _A		,      _A		,      _A		,      _A		,      _A		,      _A		,      _A      ):




											"""simple docstring"""



											__lowerCAmelCase           =	self.num_labels
											__lowerCAmelCase           =	TFDebertaVaForSequenceClassification(config=_A      )
											__lowerCAmelCase           =	{
											    "input_ids": input_ids,
											    "attention_mask": input_mask,
											    "token_type_ids": token_type_ids,
											}

											__lowerCAmelCase           =	model(_A      )
											self.parent.assertEqual(result.logits.shape		,      (self.batch_size, self.num_labels)      )






						def     __SCREAMING_SNAKE_CASE(       self		,      _A		,      _A		,      _A		,      _A		,      _A		,      _A		,      _A      ):




											"""simple docstring"""



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






						def     __SCREAMING_SNAKE_CASE(       self		,      _A		,      _A		,      _A		,      _A		,      _A		,      _A		,      _A      ):




											"""simple docstring"""



											__lowerCAmelCase           =	TFDebertaVaForQuestionAnswering(config=_A      )
											__lowerCAmelCase           =	{
											    "input_ids": input_ids,
											    "attention_mask": input_mask,
											    "token_type_ids": token_type_ids,
											}

											__lowerCAmelCase           =	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     __SCREAMING_SNAKE_CASE(       self      ):




											"""simple docstring"""



											__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				):
						_a							:   List[Any] =   (
						    (
						        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							:   Any =   False






						def     __SCREAMING_SNAKE_CASE(       self      ):




											"""simple docstring"""



											__lowerCAmelCase           =	TFDebertaVaModelTester(self      )
											__lowerCAmelCase           =	ConfigTester(self		,      config_class=_A		,      hidden_size=3_7      )






						def     __SCREAMING_SNAKE_CASE(       self      ):




											"""simple docstring"""



											self.config_tester.run_common_tests()






						def     __SCREAMING_SNAKE_CASE(       self      ):




											"""simple docstring"""



											__lowerCAmelCase           =	self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*_A      )






						def     __SCREAMING_SNAKE_CASE(       self      ):




											"""simple docstring"""



											__lowerCAmelCase           =	self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_masked_lm(*_A      )






						def     __SCREAMING_SNAKE_CASE(       self      ):




											"""simple docstring"""



											__lowerCAmelCase           =	self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_question_answering(*_A      )






						def     __SCREAMING_SNAKE_CASE(       self      ):




											"""simple docstring"""



											__lowerCAmelCase           =	self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_sequence_classification(*_A      )






						def     __SCREAMING_SNAKE_CASE(       self      ):




											"""simple docstring"""



											__lowerCAmelCase           =	self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_token_classification(*_A      )






						@slow
						def     __SCREAMING_SNAKE_CASE(       self      ):




											"""simple docstring"""



											__lowerCAmelCase           =	TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge"      )
											self.assertIsNotNone(_A      )






@require_tf
class       a__   ( unittest.TestCase				):






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




											"""simple docstring"""



											pass






						@slow
						def     __SCREAMING_SNAKE_CASE(       self      ):




											"""simple docstring"""



											__lowerCAmelCase           =	TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge"      )
											__lowerCAmelCase           =	tf.constant([[0, 3_1_4_1_4, 2_3_2, 3_2_8, 7_4_0, 1_1_4_0, 1_2_6_9_5, 6_9, 4_6_0_7_8, 1_5_8_8, 2]]      )
											__lowerCAmelCase           =	tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]      )
											__lowerCAmelCase           =	model(_A		,      attention_mask=_A      )[0]

											__lowerCAmelCase           =	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 math







def      _a				(						SCREAMING_SNAKE_CASE_							:    int					):

					if 1 < number < 4:
										# 2 and 3 are primes
										return True
					elif number < 2 or number % 2 == 0 or number % 3 == 0:
										# Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
										return False

					# All primes number are in format of 6k +/- 1
					for i in range(5				,				int(math.sqrt(SCREAMING_SNAKE_CASE_					) + 1					)				,				6					):
										if number % i == 0 or number % (i + 2) == 0:
															return False
					return True







def      _a				(						SCREAMING_SNAKE_CASE_							:    float = 0.1					):
					__lowerCAmelCase           =	3
					__lowerCAmelCase           =	3

					while primes / (2 * j - 1) >= ratio:
										for i in range(j * j + j + 1				,				(j + 2) * (j + 2)				,				j + 1					):
															primes += is_prime(SCREAMING_SNAKE_CASE_					)
										j += 2
					return j


if __name__ == "__main__":
					import doctest

					doctest.testmod()




