






import unittest

from transformers import DebertaConfig, is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
      import torch

      from transformers import (
          DebertaForMaskedLM,
          DebertaForQuestionAnswering,
          DebertaForSequenceClassification,
          DebertaForTokenClassification,
          DebertaModel,
      )
      from transformers.models.deberta.modeling_deberta import DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST







class 				UpperCAmelCase_  (		__lowerCamelCase		):




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




     def   __UpperCAmelCase  (				self		):
          UpperCAmelCase__      :  List[str]				      =			ids_tensor([self.batch_size, self.seq_length]	,						self.vocab_size		)

          UpperCAmelCase__      :  Tuple				      =			None
          if self.use_input_mask:
               UpperCAmelCase__      :  Dict				      =			ids_tensor([self.batch_size, self.seq_length]	,						vocab_size=2		)

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

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

          UpperCAmelCase__      :  Optional[int]				      =			self.get_config()

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




     def   __UpperCAmelCase  (				self		):
          return DebertaConfig(
              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	,						initializer_range=self.initializer_range	,						relative_attention=self.relative_attention	,						position_biased_input=self.position_biased_input	,						pos_att_type=self.pos_att_type	,						)




     def   __UpperCAmelCase  (				self		):
          UpperCAmelCase__      :  Dict				      =			self.get_config()
          UpperCAmelCase__      :  Tuple				      =			300
          return config




     def   __UpperCAmelCase  (				self	,						_lowerCAmelCase		):
          self.parent.assertListEqual(list(result.loss.size()		)	,						[]		)




     def   __UpperCAmelCase  (				self	,						_lowerCAmelCase	,						_lowerCAmelCase	,						_lowerCAmelCase	,						_lowerCAmelCase	,						_lowerCAmelCase	,						_lowerCAmelCase	,						_lowerCAmelCase		):
          UpperCAmelCase__      :  str				      =			DebertaModel(config=_lowerCAmelCase		)
          model.to(_lowerCAmelCase		)
          model.eval()
          UpperCAmelCase__      :  int				      =			model(_lowerCAmelCase	,						attention_mask=_lowerCAmelCase	,						token_type_ids=_lowerCAmelCase		)[0]
          UpperCAmelCase__      :  int				      =			model(_lowerCAmelCase	,						token_type_ids=_lowerCAmelCase		)[0]
          UpperCAmelCase__      :  List[str]				      =			model(_lowerCAmelCase		)[0]

          self.parent.assertListEqual(list(sequence_output.size()		)	,						[self.batch_size, self.seq_length, self.hidden_size]		)




     def   __UpperCAmelCase  (				self	,						_lowerCAmelCase	,						_lowerCAmelCase	,						_lowerCAmelCase	,						_lowerCAmelCase	,						_lowerCAmelCase	,						_lowerCAmelCase	,						_lowerCAmelCase		):
          UpperCAmelCase__      :  str				      =			DebertaForMaskedLM(config=_lowerCAmelCase		)
          model.to(_lowerCAmelCase		)
          model.eval()
          UpperCAmelCase__      :  List[Any]				      =			model(_lowerCAmelCase	,						attention_mask=_lowerCAmelCase	,						token_type_ids=_lowerCAmelCase	,						labels=_lowerCAmelCase		)

          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		):
          UpperCAmelCase__      :  Tuple				      =			self.num_labels
          UpperCAmelCase__      :  List[str]				      =			DebertaForSequenceClassification(_lowerCAmelCase		)
          model.to(_lowerCAmelCase		)
          model.eval()
          UpperCAmelCase__      :  Tuple				      =			model(_lowerCAmelCase	,						attention_mask=_lowerCAmelCase	,						token_type_ids=_lowerCAmelCase	,						labels=_lowerCAmelCase		)
          self.parent.assertListEqual(list(result.logits.size()		)	,						[self.batch_size, self.num_labels]		)
          self.check_loss_output(_lowerCAmelCase		)




     def   __UpperCAmelCase  (				self	,						_lowerCAmelCase	,						_lowerCAmelCase	,						_lowerCAmelCase	,						_lowerCAmelCase	,						_lowerCAmelCase	,						_lowerCAmelCase	,						_lowerCAmelCase		):
          UpperCAmelCase__      :  Union[str, Any]				      =			self.num_labels
          UpperCAmelCase__      :  str				      =			DebertaForTokenClassification(config=_lowerCAmelCase		)
          model.to(_lowerCAmelCase		)
          model.eval()
          UpperCAmelCase__      :  List[Any]				      =			model(_lowerCAmelCase	,						attention_mask=_lowerCAmelCase	,						token_type_ids=_lowerCAmelCase	,						labels=_lowerCAmelCase		)
          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		):
          UpperCAmelCase__      :  Optional[Any]				      =			DebertaForQuestionAnswering(config=_lowerCAmelCase		)
          model.to(_lowerCAmelCase		)
          model.eval()
          UpperCAmelCase__      :  int				      =			model(
              _lowerCAmelCase	,						attention_mask=_lowerCAmelCase	,						token_type_ids=_lowerCAmelCase	,						start_positions=_lowerCAmelCase	,						end_positions=_lowerCAmelCase	,						)
          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		):
          UpperCAmelCase__      :  Union[str, Any]				      =			self.prepare_config_and_inputs()
          (
              (
              UpperCAmelCase__
          )      ,		(
              UpperCAmelCase__
          )      ,		(
              UpperCAmelCase__
          )      ,		(
              UpperCAmelCase__
          )      ,		(
              UpperCAmelCase__
          )      ,		(
              UpperCAmelCase__
          )      ,		(
              UpperCAmelCase__
          )      ,		
          )      :  str				      =			config_and_inputs
          UpperCAmelCase__      :  Dict				      =			{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
          return config, inputs_dict







@require_torch
class 				UpperCAmelCase_  (		__lowerCamelCase							,      __lowerCamelCase							,      unittest.TestCase		):
     __lowerCamelCase      				=  (
         (
             DebertaModel,
             DebertaForMaskedLM,
             DebertaForSequenceClassification,
             DebertaForTokenClassification,
             DebertaForQuestionAnswering,
         )
         if is_torch_available()
         else ()
     )
     __lowerCamelCase      				=  (
         {
             'feature-extraction': DebertaModel,
             'fill-mask': DebertaForMaskedLM,
             'question-answering': DebertaForQuestionAnswering,
             'text-classification': DebertaForSequenceClassification,
             'token-classification': DebertaForTokenClassification,
             'zero-shot': DebertaForSequenceClassification,
         }
         if is_torch_available()
         else {}
     )

     __lowerCamelCase      				=  True
     __lowerCamelCase      				=  False
     __lowerCamelCase      				=  False
     __lowerCamelCase      				=  False
     __lowerCamelCase      				=  False




     def   __UpperCAmelCase  (				self		):
          UpperCAmelCase__      :  Optional[int]				      =			DebertaModelTester(self		)
          UpperCAmelCase__      :  Dict				      =			ConfigTester(self	,						config_class=_lowerCAmelCase	,						hidden_size=37		)




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




     def   __UpperCAmelCase  (				self		):
          UpperCAmelCase__      :  Optional[int]				      =			self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_deberta_model(*_lowerCAmelCase		)




     def   __UpperCAmelCase  (				self		):
          UpperCAmelCase__      :  Optional[int]				      =			self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_deberta_for_sequence_classification(*_lowerCAmelCase		)




     def   __UpperCAmelCase  (				self		):
          UpperCAmelCase__      :  int				      =			self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_deberta_for_masked_lm(*_lowerCAmelCase		)




     def   __UpperCAmelCase  (				self		):
          UpperCAmelCase__      :  str				      =			self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_deberta_for_question_answering(*_lowerCAmelCase		)




     def   __UpperCAmelCase  (				self		):
          UpperCAmelCase__      :  Tuple				      =			self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_deberta_for_token_classification(*_lowerCAmelCase		)




     @slow
     def   __UpperCAmelCase  (				self		):
          for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               UpperCAmelCase__      :  int				      =			DebertaModel.from_pretrained(_lowerCAmelCase		)
               self.assertIsNotNone(_lowerCAmelCase		)







@require_torch
@require_sentencepiece
@require_tokenizers
class 				UpperCAmelCase_  (		unittest.TestCase		):




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




     @slow
     def   __UpperCAmelCase  (				self		):
          UpperCAmelCase__      :  Tuple				      =			DebertaModel.from_pretrained("""microsoft/deberta-base"""		)

          UpperCAmelCase__      :  Union[str, Any]				      =			torch.tensor([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]]		)
          UpperCAmelCase__      :  Union[str, Any]				      =			torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]		)
          with torch.no_grad():
               UpperCAmelCase__      :  List[str]				      =			model(_lowerCAmelCase	,						attention_mask=_lowerCAmelCase		)[0]
          # compare the actual values for a slice.
          UpperCAmelCase__      :  Dict				      =			torch.tensor(
              [[[-0.5_9_8_6, -0.8_0_5_5, -0.8_4_6_2], [1.4_4_8_4, -0.9_3_4_8, -0.8_0_5_9], [0.3_1_2_3, 0.0_0_3_2, -1.4_1_3_1]]]		)
          self.assertTrue(torch.allclose(output[:, 1:4, 1:4]	,						_lowerCAmelCase	,						atol=1e-4		)	,						f"{output[:, 1:4, 1:4]}"		)










'''simple docstring'''





from __future__ import annotations

from functools import lru_cache
from math import ceil

UpperCAmelCase__  			=				1_0_0

UpperCAmelCase__  			=				set(range(3, NUM_PRIMES, 2))
primes.add(2)
UpperCAmelCase__  			=				42

for prime in range(3, ceil(NUM_PRIMES**0.5), 2):
					if prime not in primes:
										continue
					primes.difference_update(set(range(prime * prime, NUM_PRIMES, prime)))






@lru_cache(maxsize=100 )
def 						UpperCAmelCase__(				_SCREAMING_SNAKE_CASE					: int ):






			"""simple docstring"""




			if number_to_partition < 0:
						return set()
			elif number_to_partition == 0:
						return {1}

			__A=	set()
			__A=	42
			__A=	42

			for prime in primes:
						if prime > number_to_partition:
									continue
						for sub in partition(number_to_partition - prime ):
									ret.add(sub * prime )

			return ret






def 						UpperCAmelCase__(				_SCREAMING_SNAKE_CASE					: int = 5000 ):






			"""simple docstring"""




			for number_to_partition in range(1,_SCREAMING_SNAKE_CASE ):
						if len(partition(_SCREAMING_SNAKE_CASE ) ) > number_unique_partitions:
									return number_to_partition
			return None


if __name__ == "__main__":
					print(F"""{solution() = }""")



