


"""simple docstring"""







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 						_A  (  _a  ):







    """simple docstring"""




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






    def 	__snake_case							(					self				:    int):
      a						:		List[Any]      							=			ids_tensor([self.batch_size, self.seq_length]				, self.vocab_size)

      a						:		Union[str, Any]      							=			None
      if self.use_input_mask:
        a						:		Optional[int]      							=			ids_tensor([self.batch_size, self.seq_length]				, vocab_size=2)

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

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

      a						:		Tuple      							=			self.get_config()

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






    def 	__snake_case							(					self				:    Tuple):
      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 	__snake_case							(					self				:    Tuple):
      a						:		Any      							=			self.get_config()
      a						:		int      							=			300
      return config






    def 	__snake_case							(					self				:    Dict				, __UpperCAmelCase				:    List[str]):
      self.parent.assertListEqual(list(result.loss.size())				, [])






    def 	__snake_case							(					self				:    Any				, __UpperCAmelCase				:    str				, __UpperCAmelCase				:    Tuple				, __UpperCAmelCase				:    Optional[int]				, __UpperCAmelCase				:    str				, __UpperCAmelCase				:    Dict				, __UpperCAmelCase				:    str				, __UpperCAmelCase				:    Optional[int]):
      a						:		Dict      							=			DebertaModel(config=__UpperCAmelCase)
      model.to(__UpperCAmelCase)
      model.eval()
      a						:		Optional[int]      							=			model(__UpperCAmelCase				, attention_mask=__UpperCAmelCase				, token_type_ids=__UpperCAmelCase)[0]
      a						:		Any      							=			model(__UpperCAmelCase				, token_type_ids=__UpperCAmelCase)[0]
      a						:		Any      							=			model(__UpperCAmelCase)[0]

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






    def 	__snake_case							(					self				:    Optional[Any]				, __UpperCAmelCase				:    Union[str, Any]				, __UpperCAmelCase				:    List[Any]				, __UpperCAmelCase				:    Union[str, Any]				, __UpperCAmelCase				:    int				, __UpperCAmelCase				:    Any				, __UpperCAmelCase				:    Any				, __UpperCAmelCase				:    int):
      a						:		Any      							=			DebertaForMaskedLM(config=__UpperCAmelCase)
      model.to(__UpperCAmelCase)
      model.eval()
      a						:		Union[str, Any]      							=			model(__UpperCAmelCase				, attention_mask=__UpperCAmelCase				, token_type_ids=__UpperCAmelCase				, labels=__UpperCAmelCase)

      self.parent.assertEqual(result.logits.shape				, (self.batch_size, self.seq_length, self.vocab_size))






    def 	__snake_case							(					self				:    List[Any]				, __UpperCAmelCase				:    List[str]				, __UpperCAmelCase				:    Optional[int]				, __UpperCAmelCase				:    Optional[int]				, __UpperCAmelCase				:    int				, __UpperCAmelCase				:    Any				, __UpperCAmelCase				:    Optional[Any]				, __UpperCAmelCase				:    Union[str, Any]):
      a						:		List[str]      							=			self.num_labels
      a						:		Union[str, Any]      							=			DebertaForSequenceClassification(__UpperCAmelCase)
      model.to(__UpperCAmelCase)
      model.eval()
      a						:		Tuple      							=			model(__UpperCAmelCase				, attention_mask=__UpperCAmelCase				, token_type_ids=__UpperCAmelCase				, labels=__UpperCAmelCase)
      self.parent.assertListEqual(list(result.logits.size())				, [self.batch_size, self.num_labels])
      self.check_loss_output(__UpperCAmelCase)






    def 	__snake_case							(					self				:    Dict				, __UpperCAmelCase				:    int				, __UpperCAmelCase				:    Dict				, __UpperCAmelCase				:    Optional[Any]				, __UpperCAmelCase				:    List[str]				, __UpperCAmelCase				:    Optional[int]				, __UpperCAmelCase				:    Any				, __UpperCAmelCase				:    str):
      a						:		Optional[Any]      							=			self.num_labels
      a						:		Tuple      							=			DebertaForTokenClassification(config=__UpperCAmelCase)
      model.to(__UpperCAmelCase)
      model.eval()
      a						:		Union[str, Any]      							=			model(__UpperCAmelCase				, attention_mask=__UpperCAmelCase				, token_type_ids=__UpperCAmelCase				, labels=__UpperCAmelCase)
      self.parent.assertEqual(result.logits.shape				, (self.batch_size, self.seq_length, self.num_labels))






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






@require_torch
class 						_A  (  _a    ,_a    ,unittest.TestCase  ):







    """simple docstring"""




    UpperCAmelCase       :							List[str]	=       (
        (
            DebertaModel,
            DebertaForMaskedLM,
            DebertaForSequenceClassification,
            DebertaForTokenClassification,
            DebertaForQuestionAnswering,
        )
        if is_torch_available()
        else ()
    )
    UpperCAmelCase       :							Optional[int]	=       (
        {
            """feature-extraction""": DebertaModel,
            """fill-mask""": DebertaForMaskedLM,
            """question-answering""": DebertaForQuestionAnswering,
            """text-classification""": DebertaForSequenceClassification,
            """token-classification""": DebertaForTokenClassification,
            """zero-shot""": DebertaForSequenceClassification,
        }
        if is_torch_available()
        else {}
    )

    UpperCAmelCase       :							List[Any]	=       True
    UpperCAmelCase       :							str	=       False
    UpperCAmelCase       :							Optional[Any]	=       False
    UpperCAmelCase       :							int	=       False
    UpperCAmelCase       :							str	=       False






    def 	__snake_case							(					self				:    List[str]):
      a						:		int      							=			DebertaModelTester(self)
      a						:		Optional[int]      							=			ConfigTester(self				, config_class=__UpperCAmelCase				, hidden_size=37)






    def 	__snake_case							(					self				:    Tuple):
      self.config_tester.run_common_tests()






    def 	__snake_case							(					self				:    List[Any]):
      a						:		Optional[int]      							=			self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_deberta_model(*__UpperCAmelCase)






    def 	__snake_case							(					self				:    Union[str, Any]):
      a						:		str      							=			self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_deberta_for_sequence_classification(*__UpperCAmelCase)






    def 	__snake_case							(					self				:    List[Any]):
      a						:		Union[str, Any]      							=			self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_deberta_for_masked_lm(*__UpperCAmelCase)






    def 	__snake_case							(					self				:    int):
      a						:		int      							=			self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_deberta_for_question_answering(*__UpperCAmelCase)






    def 	__snake_case							(					self				:    str):
      a						:		List[Any]      							=			self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_deberta_for_token_classification(*__UpperCAmelCase)






    @slow
    def 	__snake_case							(					self				:    str):
      for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
        a						:		str      							=			DebertaModel.from_pretrained(__UpperCAmelCase)
        self.assertIsNotNone(__UpperCAmelCase)






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







    """simple docstring"""




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






    @slow
    def 	__snake_case							(					self				:    int):
      a						:		Dict      							=			DebertaModel.from_pretrained("microsoft/deberta-base")

      a						:		Optional[Any]      							=			torch.tensor([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]])
      a						:		Any      							=			torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
      with torch.no_grad():
        a						:		int      							=			model(__UpperCAmelCase				, attention_mask=__UpperCAmelCase)[0]
      # compare the actual values for a slice.
      a						:		Optional[int]      							=			torch.tensor(
          [[[-0.5_986, -0.8_055, -0.8_462], [1.4_484, -0.9_348, -0.8_059], [0.3_123, 0.0_032, -1.4_131]]])
      self.assertTrue(torch.allclose(output[:, 1:4, 1:4]				, __UpperCAmelCase				, atol=1e-4)				, f'''{output[:, 1:4, 1:4]}''')










"""simple docstring"""







import unittest

from knapsack import knapsack as k






class 						_A  (  unittest.TestCase  ):







    """simple docstring"""




    def 	__snake_case							(					self				:    List[Any]):
      a						:		str      							=			0
      a						:		Optional[int]      							=			[0]
      a						:		Union[str, Any]      							=			[0]
      a						:		Any      							=			len(__UpperCAmelCase)
      self.assertEqual(k.knapsack(__UpperCAmelCase				, __UpperCAmelCase				, __UpperCAmelCase				, __UpperCAmelCase)				, 0)

      a						:		List[str]      							=			[60]
      a						:		str      							=			[10]
      a						:		Optional[int]      							=			len(__UpperCAmelCase)
      self.assertEqual(k.knapsack(__UpperCAmelCase				, __UpperCAmelCase				, __UpperCAmelCase				, __UpperCAmelCase)				, 0)






    def 	__snake_case							(					self				:    Optional[int]):
      a						:		Any      							=			3
      a						:		str      							=			[1, 2, 3]
      a						:		Tuple      							=			[3, 2, 1]
      a						:		Any      							=			len(__UpperCAmelCase)
      self.assertEqual(k.knapsack(__UpperCAmelCase				, __UpperCAmelCase				, __UpperCAmelCase				, __UpperCAmelCase)				, 5)






    def 	__snake_case							(					self				:    Tuple):
      a						:		int      							=			50
      a						:		List[Any]      							=			[60, 100, 120]
      a						:		Optional[int]      							=			[10, 20, 30]
      a						:		str      							=			len(__UpperCAmelCase)
      self.assertEqual(k.knapsack(__UpperCAmelCase				, __UpperCAmelCase				, __UpperCAmelCase				, __UpperCAmelCase)				, 220)


if __name__ == "__main__":
 unittest.main()






