
'''simple docstring'''


import unittest

from transformers import AutoTokenizer, NystromformerConfig, is_torch_available
from transformers.testing_utils import 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 (
					    NystromformerForMaskedLM,
					    NystromformerForMultipleChoice,
					    NystromformerForQuestionAnswering,
					    NystromformerForSequenceClassification,
					    NystromformerForTokenClassification,
					    NystromformerModel,
					)
					from transformers.models.nystromformer.modeling_nystromformer import NYSTROMFORMER_PRETRAINED_MODEL_ARCHIVE_LIST

class 	__lowercase				:

			def __init__(self			,   A			,   A=1_3			,   A=7			,   A=True			,   A=True			,   A=True			,   A=True			,   A=9_9			,   A=3_2			,   A=5			,   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=3			,   A=4			,   A=None			,   ):
								lowerCamelCase_					:      Any     =		parent
								lowerCamelCase_					:      Dict     =		batch_size
								lowerCamelCase_					:      Any     =		seq_length
								lowerCamelCase_					:      List[str]     =		is_training
								lowerCamelCase_					:      Union[str, Any]     =		use_input_mask
								lowerCamelCase_					:      Tuple     =		use_token_type_ids
								lowerCamelCase_					:      List[str]     =		use_labels
								lowerCamelCase_					:      List[str]     =		vocab_size
								lowerCamelCase_					:      Dict     =		hidden_size
								lowerCamelCase_					:      str     =		num_hidden_layers
								lowerCamelCase_					:      List[str]     =		num_attention_heads
								lowerCamelCase_					:      int     =		intermediate_size
								lowerCamelCase_					:      Union[str, Any]     =		hidden_act
								lowerCamelCase_					:      List[Any]     =		hidden_dropout_prob
								lowerCamelCase_					:      Tuple     =		attention_probs_dropout_prob
								lowerCamelCase_					:      Any     =		max_position_embeddings
								lowerCamelCase_					:      List[Any]     =		type_vocab_size
								lowerCamelCase_					:      str     =		type_sequence_label_size
								lowerCamelCase_					:      Tuple     =		initializer_range
								lowerCamelCase_					:      List[Any]     =		num_labels
								lowerCamelCase_					:      Dict     =		num_choices
								lowerCamelCase_					:      str     =		scope

			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      Optional[Any]     =		ids_tensor([self.batch_size, self.seq_length]			,   self.vocab_size      )

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

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

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

								lowerCamelCase_					:      Dict     =		self.get_config()

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

			def        UpperCAmelCase__ (self      ):
								return NystromformerConfig(
								    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			,   is_decoder=A			,   initializer_range=self.initializer_range			,   )

			def        UpperCAmelCase__ (self			,   A			,   A			,   A			,   A			,   A			,   A			,   A      ):
								lowerCamelCase_					:      Any     =		NystromformerModel(config=A      )
								model.to(A      )
								model.eval()
								lowerCamelCase_					:      Union[str, Any]     =		model(A			,   attention_mask=A			,   token_type_ids=A      )
								lowerCamelCase_					:      Union[str, Any]     =		model(A			,   token_type_ids=A      )
								lowerCamelCase_					:      Any     =		model(A      )
								self.parent.assertEqual(result.last_hidden_state.shape			,   (self.batch_size, self.seq_length, self.hidden_size)      )

			def        UpperCAmelCase__ (self			,   A			,   A			,   A			,   A			,   A			,   A			,   A      ):
								lowerCamelCase_					:      int     =		NystromformerForMaskedLM(config=A      )
								model.to(A      )
								model.eval()
								lowerCamelCase_					:      Union[str, Any]     =		model(A			,   attention_mask=A			,   token_type_ids=A			,   labels=A      )
								self.parent.assertEqual(result.logits.shape			,   (self.batch_size, self.seq_length, self.vocab_size)      )

			def        UpperCAmelCase__ (self			,   A			,   A			,   A			,   A			,   A			,   A			,   A      ):
								lowerCamelCase_					:      Dict     =		NystromformerForQuestionAnswering(config=A      )
								model.to(A      )
								model.eval()
								lowerCamelCase_					:      Tuple     =		model(
								    A			,   attention_mask=A			,   token_type_ids=A			,   start_positions=A			,   end_positions=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        UpperCAmelCase__ (self			,   A			,   A			,   A			,   A			,   A			,   A			,   A      ):
								lowerCamelCase_					:      Union[str, Any]     =		self.num_labels
								lowerCamelCase_					:      Optional[int]     =		NystromformerForSequenceClassification(A      )
								model.to(A      )
								model.eval()
								lowerCamelCase_					:      Dict     =		model(A			,   attention_mask=A			,   token_type_ids=A			,   labels=A      )
								self.parent.assertEqual(result.logits.shape			,   (self.batch_size, self.num_labels)      )

			def        UpperCAmelCase__ (self			,   A			,   A			,   A			,   A			,   A			,   A			,   A      ):
								lowerCamelCase_					:      Any     =		self.num_labels
								lowerCamelCase_					:      Dict     =		NystromformerForTokenClassification(config=A      )
								model.to(A      )
								model.eval()
								lowerCamelCase_					:      Optional[Any]     =		model(A			,   attention_mask=A			,   token_type_ids=A			,   labels=A      )
								self.parent.assertEqual(result.logits.shape			,   (self.batch_size, self.seq_length, self.num_labels)      )

			def        UpperCAmelCase__ (self			,   A			,   A			,   A			,   A			,   A			,   A			,   A      ):
								lowerCamelCase_					:      Tuple     =		self.num_choices
								lowerCamelCase_					:      Tuple     =		NystromformerForMultipleChoice(config=A      )
								model.to(A      )
								model.eval()
								lowerCamelCase_					:      Tuple     =		input_ids.unsqueeze(1      ).expand(-1			,   self.num_choices			,   -1      ).contiguous()
								lowerCamelCase_					:      List[str]     =		token_type_ids.unsqueeze(1      ).expand(-1			,   self.num_choices			,   -1      ).contiguous()
								lowerCamelCase_					:      Optional[Any]     =		input_mask.unsqueeze(1      ).expand(-1			,   self.num_choices			,   -1      ).contiguous()
								lowerCamelCase_					:      Optional[int]     =		model(
								    A			,   attention_mask=A			,   token_type_ids=A			,   labels=A			,   )
								self.parent.assertEqual(result.logits.shape			,   (self.batch_size, self.num_choices)      )






			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      Optional[Any]     =		self.prepare_config_and_inputs()
								(
								    (
								    lowerCamelCase_
								),      (
								    lowerCamelCase_
								),      (
								    lowerCamelCase_
								),      (
								    lowerCamelCase_
								),      (
								    lowerCamelCase_
								),      (
								    lowerCamelCase_
								),      (
								    lowerCamelCase_
								),      
								)					:      int     =		config_and_inputs
								lowerCamelCase_					:      Any     =		{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
								return config, inputs_dict

@require_torch
class 	__lowercase				(  _lowercase      ,     _lowercase      ,     unittest.TestCase    ):
			lowerCamelCase			:		Optional[int]	      =			(
			    (
			        NystromformerModel,
			        NystromformerForMaskedLM,
			        NystromformerForMultipleChoice,
			        NystromformerForQuestionAnswering,
			        NystromformerForSequenceClassification,
			        NystromformerForTokenClassification,
			    )
			    if is_torch_available()
			    else ()
			)
			lowerCamelCase			:		Optional[int]	      =			(
			    {
			        "feature-extraction": NystromformerModel,
			        "fill-mask": NystromformerForMaskedLM,
			        "question-answering": NystromformerForQuestionAnswering,
			        "text-classification": NystromformerForSequenceClassification,
			        "token-classification": NystromformerForTokenClassification,
			        "zero-shot": NystromformerForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)
			lowerCamelCase			:		int	      =			False
			lowerCamelCase			:		Any	      =			False

			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      Optional[Any]     =		NystromformerModelTester(self      )
								lowerCamelCase_					:      List[str]     =		ConfigTester(self			,   config_class=A			,   hidden_size=3_7      )

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

			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      Dict     =		self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*A      )

			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      Optional[int]     =		self.model_tester.prepare_config_and_inputs()
								for type in ["absolute", "relative_key", "relative_key_query"]:
													lowerCamelCase_					:      List[Any]     =		type
													self.model_tester.create_and_check_model(*A      )

			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      Optional[Any]     =		self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_masked_lm(*A      )

			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      List[str]     =		self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_multiple_choice(*A      )

			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      int     =		self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_question_answering(*A      )

			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      str     =		self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_sequence_classification(*A      )

			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      Any     =		self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_token_classification(*A      )






			@slow
			def        UpperCAmelCase__ (self      ):
								for model_name in NYSTROMFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													lowerCamelCase_					:      Dict     =		NystromformerModel.from_pretrained(A      )
													self.assertIsNotNone(A      )

@require_torch
class 	__lowercase				(  unittest.TestCase    ):

			@slow
			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      str     =		NystromformerModel.from_pretrained('''uw-madison/nystromformer-512'''      )
								lowerCamelCase_					:      Any     =		torch.tensor([[0, 1, 2, 3, 4, 5]]      )

								with torch.no_grad():
													lowerCamelCase_					:      Optional[int]     =		model(A      )[0]

								lowerCamelCase_					:      Dict     =		torch.Size((1, 6, 7_6_8)      )
								self.assertEqual(output.shape			,   A      )

								lowerCamelCase_					:      Any     =		torch.tensor(
								    [[[-0.45_32, -0.09_36, 0.51_37], [-0.26_76, 0.06_28, 0.61_86], [-0.36_29, -0.17_26, 0.47_16]]]      )

								self.assertTrue(torch.allclose(output[:, :3, :3]			,   A			,   atol=1E-4      )      )






			@slow
			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      str     =		'''the [MASK] of Belgium is Brussels'''

								lowerCamelCase_					:      Tuple     =		AutoTokenizer.from_pretrained('''uw-madison/nystromformer-512'''      )
								lowerCamelCase_					:      Tuple     =		NystromformerForMaskedLM.from_pretrained('''uw-madison/nystromformer-512'''      )

								lowerCamelCase_					:      List[Any]     =		tokenizer(A			,   return_tensors='''pt'''      )

								with torch.no_grad():
													lowerCamelCase_					:      Optional[Any]     =		model(encoding.input_ids      ).logits

								lowerCamelCase_					:      Tuple     =		token_logits[:, 2, :].argmax(-1      )[0]

								self.assertEqual(tokenizer.decode(A      )			,   '''capital'''      )




'''simple docstring'''


import os
from math import logaa




def lowercase_	(   _lowercase = "base_exp.txt"				)     ->							int:
					'''simple docstring'''

					lowerCamelCase_					:      float     =		0
					lowerCamelCase_					:      Dict     =		0
					for i, line in enumerate(open(os.path.join(os.path.dirname(_lowercase				)			,       _lowercase				)				)				):
										lowerCamelCase_,      lowerCamelCase_					:      Dict     =		list(map(_lowercase			,       line.split(''','''				)				)				)
										if x * logaa(_lowercase				) > largest:
															lowerCamelCase_					:      List[str]     =		x * logaa(_lowercase				)
															lowerCamelCase_					:      Union[str, Any]     =		i + 1
					return result


if __name__ == "__main__":
					print(solution())


