





import unittest

from knapsack import greedy_knapsack as kp


class   A      (unittest.TestCase							):
			'''simple docstring'''




			def        a_	(      self       :   Optional[Any]       )     ->     Union[str, Any]:







					"""simple docstring"""






					A__  				=       [10, 20, 30, 40, 50, 60]
					A__  				=       [2, 4, 6, 8, 10, 12]
					A__  				=       1_00
					self.assertEqual(kp.calc_profit(__lowerCAmelCase							,     __lowerCAmelCase							,     __lowerCAmelCase       )							,     2_10       )






			def        a_	(      self       :   Tuple       )     ->     Optional[Any]:







					"""simple docstring"""






					self.assertRaisesRegex(__lowerCAmelCase							,     """max_weight must greater than zero."""       )






			def        a_	(      self       :   str       )     ->     List[str]:







					"""simple docstring"""






					self.assertRaisesRegex(__lowerCAmelCase							,     """Weight can not be negative."""       )






			def        a_	(      self       :   Dict       )     ->     Tuple:







					"""simple docstring"""






					self.assertRaisesRegex(__lowerCAmelCase							,     """Profit can not be negative."""       )






			def        a_	(      self       :   Optional[Any]       )     ->     Union[str, Any]:







					"""simple docstring"""






					self.assertRaisesRegex(__lowerCAmelCase							,     """max_weight must greater than zero."""       )







			def        a_	(      self       :   List[Any]       )     ->     str:







					"""simple docstring"""






					self.assertRaisesRegex(
					    __lowerCAmelCase							,     """The length of profit and weight must be same."""       )


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










import unittest

from transformers import EsmConfig, is_torch_available
from transformers.testing_utils import TestCasePlus, require_torch, slow, torch_device

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


if is_torch_available():
					import torch

					from transformers import EsmForMaskedLM, EsmForSequenceClassification, EsmForTokenClassification, EsmModel
					from transformers.models.esm.modeling_esm import (
					    ESM_PRETRAINED_MODEL_ARCHIVE_LIST,
					    EsmEmbeddings,
					    create_position_ids_from_input_ids,
					)


class   A      :
			'''simple docstring'''




			def __init__(      self       :   Union[str, Any]							,     __lowerCAmelCase       :   int							,     __lowerCAmelCase       :   Tuple=13							,     __lowerCAmelCase       :   Optional[Any]=7							,     __lowerCAmelCase       :   List[str]=False							,     __lowerCAmelCase       :   Optional[Any]=True							,     __lowerCAmelCase       :   Tuple=False							,     __lowerCAmelCase       :   Any=True							,     __lowerCAmelCase       :   Union[str, Any]=33							,     __lowerCAmelCase       :   List[str]=32							,     __lowerCAmelCase       :   Optional[Any]=5							,     __lowerCAmelCase       :   Dict=4							,     __lowerCAmelCase       :   List[Any]=37							,     __lowerCAmelCase       :   str="gelu"							,     __lowerCAmelCase       :   Any=0.1							,     __lowerCAmelCase       :   str=0.1							,     __lowerCAmelCase       :   List[Any]=5_12							,     __lowerCAmelCase       :   Dict=16							,     __lowerCAmelCase       :   Any=2							,     __lowerCAmelCase       :   List[str]=0.0_2							,     __lowerCAmelCase       :   Dict=3							,     __lowerCAmelCase       :   Optional[int]=4							,     __lowerCAmelCase       :   Tuple=None							,     )     ->     int:







					"""simple docstring"""






					A__  				=       parent
					A__  				=       batch_size
					A__  				=       seq_length
					A__  				=       is_training
					A__  				=       use_input_mask
					A__  				=       use_token_type_ids
					A__  				=       use_labels
					A__  				=       vocab_size
					A__  				=       hidden_size
					A__  				=       num_hidden_layers
					A__  				=       num_attention_heads
					A__  				=       intermediate_size
					A__  				=       hidden_act
					A__  				=       hidden_dropout_prob
					A__  				=       attention_probs_dropout_prob
					A__  				=       max_position_embeddings
					A__  				=       type_vocab_size
					A__  				=       type_sequence_label_size
					A__  				=       initializer_range
					A__  				=       num_labels
					A__  				=       num_choices
					A__  				=       scope






			def        a_	(      self       :   List[Any]       )     ->     Tuple:







					"""simple docstring"""






					A__  				=       ids_tensor([self.batch_size, self.seq_length]							,     self.vocab_size       )

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

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

					A__  				=       self.get_config()

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






			def        a_	(      self       :   Optional[int]       )     ->     str:







					"""simple docstring"""






					return EsmConfig(
					    vocab_size=self.vocab_size							,     hidden_size=self.hidden_size							,     pad_token_id=1							,     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							,     )






			def        a_	(      self       :   str							,     __lowerCAmelCase       :   List[Any]							,     __lowerCAmelCase       :   int							,     __lowerCAmelCase       :   int							,     __lowerCAmelCase       :   int							,     __lowerCAmelCase       :   Any							,     __lowerCAmelCase       :   Optional[int]       )     ->     str:







					"""simple docstring"""






					A__  				=       EsmModel(config=__lowerCAmelCase       )
					model.to(__lowerCAmelCase       )
					model.eval()
					A__  				=       model(__lowerCAmelCase							,     attention_mask=__lowerCAmelCase       )
					A__  				=       model(__lowerCAmelCase       )
					A__  				=       model(__lowerCAmelCase       )

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






			def        a_	(      self       :   List[Any]							,     __lowerCAmelCase       :   List[str]							,     __lowerCAmelCase       :   List[str]							,     __lowerCAmelCase       :   Tuple							,     __lowerCAmelCase       :   Optional[int]							,     __lowerCAmelCase       :   Union[str, Any]							,     __lowerCAmelCase       :   Any       )     ->     str:







					"""simple docstring"""






					A__  				=       EsmForMaskedLM(config=__lowerCAmelCase       )
					model.to(__lowerCAmelCase       )
					model.eval()
					A__  				=       model(__lowerCAmelCase							,     attention_mask=__lowerCAmelCase							,     labels=__lowerCAmelCase       )
					self.parent.assertEqual(result.logits.shape							,     (self.batch_size, self.seq_length, self.vocab_size)       )






			def        a_	(      self       :   Optional[int]							,     __lowerCAmelCase       :   List[Any]							,     __lowerCAmelCase       :   int							,     __lowerCAmelCase       :   Optional[Any]							,     __lowerCAmelCase       :   str							,     __lowerCAmelCase       :   str							,     __lowerCAmelCase       :   List[str]       )     ->     Any:







					"""simple docstring"""






					A__  				=       self.num_labels
					A__  				=       EsmForTokenClassification(config=__lowerCAmelCase       )
					model.to(__lowerCAmelCase       )
					model.eval()
					A__  				=       model(__lowerCAmelCase							,     attention_mask=__lowerCAmelCase							,     labels=__lowerCAmelCase       )
					self.parent.assertEqual(result.logits.shape							,     (self.batch_size, self.seq_length, self.num_labels)       )







			def        a_	(      self       :   Any       )     ->     Dict:







					"""simple docstring"""






					A__  				=       self.prepare_config_and_inputs()
					(
					    (
					    A__
					)				,      (
					    A__
					)				,      (
					    A__
					)				,      (
					    A__
					)				,      (
					    A__
					)				,      (
					    A__
					)				,      
					)  				=       config_and_inputs
					A__  				=       {"""input_ids""": input_ids, """attention_mask""": input_mask}
					return config, inputs_dict


@require_torch
class   A      (SCREAMING_SNAKE_CASE       ,					SCREAMING_SNAKE_CASE       ,					unittest.TestCase   ):
			'''simple docstring'''




			__lowerCamelCase     :	List[str]          =   False

			__lowerCamelCase     :	Union[str, Any]          =   (
			    (
			        EsmForMaskedLM,
			        EsmModel,
			        EsmForSequenceClassification,
			        EsmForTokenClassification,
			    )
			    if is_torch_available()
			    else ()
			)
			__lowerCamelCase     :	List[Any]          =   ()
			__lowerCamelCase     :	Optional[int]          =   (
			    {
			        '''feature-extraction''': EsmModel,
			        '''fill-mask''': EsmForMaskedLM,
			        '''text-classification''': EsmForSequenceClassification,
			        '''token-classification''': EsmForTokenClassification,
			        '''zero-shot''': EsmForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)
			__lowerCamelCase     :	Any          =   True






			def        a_	(      self       :   Tuple       )     ->     Optional[int]:







					"""simple docstring"""






					A__  				=       EsmModelTester(self       )
					A__  				=       ConfigTester(self							,     config_class=__lowerCAmelCase							,     hidden_size=37       )






			def        a_	(      self       :   Any       )     ->     str:







					"""simple docstring"""






					self.config_tester.run_common_tests()






			def        a_	(      self       :   List[str]       )     ->     Optional[int]:







					"""simple docstring"""






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






			def        a_	(      self       :   Optional[int]       )     ->     str:







					"""simple docstring"""






					A__  				=       self.model_tester.prepare_config_and_inputs()
					for type in ["absolute", "relative_key", "relative_key_query"]:
							A__  				=       type
							self.model_tester.create_and_check_model(*__lowerCAmelCase       )






			def        a_	(      self       :   Optional[Any]       )     ->     Optional[Any]:







					"""simple docstring"""






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






			def        a_	(      self       :   Union[str, Any]       )     ->     Union[str, Any]:







					"""simple docstring"""






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






			@slow
			def        a_	(      self       :   Optional[int]       )     ->     int:







					"""simple docstring"""






					for model_name in ESM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							A__  				=       EsmModel.from_pretrained(__lowerCAmelCase       )
							self.assertIsNotNone(__lowerCAmelCase       )






			def        a_	(      self       :   List[str]       )     ->     Union[str, Any]:







					"""simple docstring"""






					A__  				=       self.model_tester.prepare_config_and_inputs()[0]
					A__  				=       EsmEmbeddings(config=__lowerCAmelCase       )

					A__  				=       torch.as_tensor([[12, 31, 13, model.padding_idx]]       )
					A__  				=       torch.as_tensor(
					    [
					        [
					            0 + model.padding_idx + 1,
					            1 + model.padding_idx + 1,
					            2 + model.padding_idx + 1,
					            model.padding_idx,
					        ]
					    ]       )
					A__  				=       create_position_ids_from_input_ids(__lowerCAmelCase							,     model.padding_idx       )
					self.assertEqual(position_ids.shape							,     expected_positions.shape       )
					self.assertTrue(torch.all(torch.eq(__lowerCAmelCase							,     __lowerCAmelCase       )       )       )






			def        a_	(      self       :   List[Any]       )     ->     str:







					"""simple docstring"""






					A__  				=       self.model_tester.prepare_config_and_inputs()[0]
					A__  				=       EsmEmbeddings(config=__lowerCAmelCase       )

					A__  				=       torch.empty(2							,     4							,     30       )
					A__  				=       [
					    0 + embeddings.padding_idx + 1,
					    1 + embeddings.padding_idx + 1,
					    2 + embeddings.padding_idx + 1,
					    3 + embeddings.padding_idx + 1,
					]
					A__  				=       torch.as_tensor([expected_single_positions, expected_single_positions]       )
					A__  				=       embeddings.create_position_ids_from_inputs_embeds(__lowerCAmelCase       )
					self.assertEqual(position_ids.shape							,     expected_positions.shape       )
					self.assertTrue(torch.all(torch.eq(__lowerCAmelCase							,     __lowerCAmelCase       )       )       )






			@unittest.skip("""Esm does not support embedding resizing"""       )
			def        a_	(      self       :   Dict       )     ->     Tuple:







					"""simple docstring"""






					pass






			@unittest.skip("""Esm does not support embedding resizing"""       )
			def        a_	(      self       :   List[str]       )     ->     Optional[int]:







					"""simple docstring"""






					pass







			@unittest.skip("""Will be fixed soon by reducing the size of the model used for common tests."""       )
			def        a_	(      self       :   List[Any]       )     ->     Dict:







					"""simple docstring"""






					pass


@require_torch
class   A      (SCREAMING_SNAKE_CASE   ):
			'''simple docstring'''




			@slow
			def        a_	(      self       :   int       )     ->     Optional[int]:







					"""simple docstring"""






					with torch.no_grad():
							A__  				=       EsmForMaskedLM.from_pretrained("""facebook/esm2_t6_8M_UR50D"""       )
							model.eval()
							A__  				=       torch.tensor([[0, 1, 2, 3, 4, 5]]       )
							A__  				=       model(__lowerCAmelCase       )[0]

							A__  				=       33

							A__  				=       torch.Size((1, 6, vocab_size)       )
							self.assertEqual(output.shape							,     __lowerCAmelCase       )

							A__  				=       torch.tensor(
							    [[[8.9_2_1_5, -1_0.5_8_9_8, -6.4_6_7_1], [-6.3_9_6_7, -1_3.9_1_1_4, -1.1_2_1_2], [-7.7_8_1_2, -1_3.9_5_1_6, -3.7_4_0_6]]]       )
							self.assertTrue(torch.allclose(output[:, :3, :3]							,     __lowerCAmelCase							,     atol=1e-4       )       )







			@slow
			def        a_	(      self       :   List[str]       )     ->     Tuple:







					"""simple docstring"""






					with torch.no_grad():
							A__  				=       EsmModel.from_pretrained("""facebook/esm2_t6_8M_UR50D"""       )
							model.eval()

							A__  				=       torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]       )
							A__  				=       model(__lowerCAmelCase       )[0]
							# compare the actual values for a slice.
							A__  				=       torch.tensor(
							    [[[0.1_4_4_4, 0.5_4_1_3, 0.3_2_4_8], [0.3_0_3_4, 0.0_0_5_3, 0.3_1_0_8], [0.3_2_2_8, -0.2_4_9_9, 0.3_4_1_5]]]       )
							self.assertTrue(torch.allclose(output[:, :3, :3]							,     __lowerCAmelCase							,     atol=1e-4       )       )



