"""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        _snake_case   :






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






						def 					lowerCamelCase__   (				self					:	Optional[int]			):
													__lowerCamelCase    :						str						      =   ids_tensor([self.batch_size, self.seq_length]							,    self.vocab_size			)

													__lowerCamelCase    :						int						      =   None
													if self.use_input_mask:
																				__lowerCamelCase    :						List[str]						      =   random_attention_mask([self.batch_size, self.seq_length]			)

													__lowerCamelCase    :						int						      =   None
													if self.use_token_type_ids:
																				__lowerCamelCase    :						List[str]						      =   ids_tensor([self.batch_size, self.seq_length]							,    self.type_vocab_size			)

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

													__lowerCamelCase    :						int						      =   self.get_config()

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






						def 					lowerCamelCase__   (				self					:	Optional[Any]			):
													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=__lowerCamelCase							,    initializer_range=self.initializer_range							,    )






						def 					lowerCamelCase__   (				self					:	Any							,    UpperCAmelCase					:	Tuple							,    UpperCAmelCase					:	str							,    UpperCAmelCase					:	Tuple							,    UpperCAmelCase					:	int							,    UpperCAmelCase					:	List[Any]							,    UpperCAmelCase					:	int							,    UpperCAmelCase					:	int			):
													__lowerCamelCase    :						int						      =   NystromformerModel(config=__lowerCamelCase			)
													model.to(__lowerCamelCase			)
													model.eval()
													__lowerCamelCase    :						List[Any]						      =   model(__lowerCamelCase							,    attention_mask=__lowerCamelCase							,    token_type_ids=__lowerCamelCase			)
													__lowerCamelCase    :						List[Any]						      =   model(__lowerCamelCase							,    token_type_ids=__lowerCamelCase			)
													__lowerCamelCase    :						Dict						      =   model(__lowerCamelCase			)
													self.parent.assertEqual(result.last_hidden_state.shape							,    (self.batch_size, self.seq_length, self.hidden_size)			)






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






						def 					lowerCamelCase__   (				self					:	List[Any]							,    UpperCAmelCase					:	Union[str, Any]							,    UpperCAmelCase					:	int							,    UpperCAmelCase					:	str							,    UpperCAmelCase					:	Dict							,    UpperCAmelCase					:	Optional[int]							,    UpperCAmelCase					:	Optional[Any]							,    UpperCAmelCase					:	Tuple			):
													__lowerCamelCase    :						Dict						      =   self.num_labels
													__lowerCamelCase    :						int						      =   NystromformerForTokenClassification(config=__lowerCamelCase			)
													model.to(__lowerCamelCase			)
													model.eval()
													__lowerCamelCase    :						Optional[int]						      =   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 					lowerCamelCase__   (				self					:	List[Any]							,    UpperCAmelCase					:	int							,    UpperCAmelCase					:	Any							,    UpperCAmelCase					:	Optional[Any]							,    UpperCAmelCase					:	List[str]							,    UpperCAmelCase					:	Tuple							,    UpperCAmelCase					:	Dict							,    UpperCAmelCase					:	List[Any]			):
													__lowerCamelCase    :						List[Any]						      =   self.num_choices
													__lowerCamelCase    :						Optional[Any]						      =   NystromformerForMultipleChoice(config=__lowerCamelCase			)
													model.to(__lowerCamelCase			)
													model.eval()
													__lowerCamelCase    :						Optional[int]						      =   input_ids.unsqueeze(1			).expand(-1							,    self.num_choices							,    -1			).contiguous()
													__lowerCamelCase    :						Optional[Any]						      =   token_type_ids.unsqueeze(1			).expand(-1							,    self.num_choices							,    -1			).contiguous()
													__lowerCamelCase    :						List[str]						      =   input_mask.unsqueeze(1			).expand(-1							,    self.num_choices							,    -1			).contiguous()
													__lowerCamelCase    :						Optional[int]						      =   model(
													    __lowerCamelCase							,    attention_mask=__lowerCamelCase							,    token_type_ids=__lowerCamelCase							,    labels=__lowerCamelCase							,    )
													self.parent.assertEqual(result.logits.shape							,    (self.batch_size, self.num_choices)			)







						def 					lowerCamelCase__   (				self					:	Union[str, Any]			):
													__lowerCamelCase    :						Union[str, Any]						      =   self.prepare_config_and_inputs()
													(
													    (
													    __lowerCamelCase		
													)      ,     (
													    __lowerCamelCase		
													)      ,     (
													    __lowerCamelCase		
													)      ,     (
													    __lowerCamelCase		
													)      ,     (
													    __lowerCamelCase		
													)      ,     (
													    __lowerCamelCase		
													)      ,     (
													    __lowerCamelCase		
													)      ,     		
													)    :						int						      =   config_and_inputs
													__lowerCamelCase    :						Union[str, Any]						      =   {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
													return config, inputs_dict

@require_torch
class        _snake_case   (    _UpperCamelCase ,       _UpperCamelCase ,       unittest.TestCase						):
						snake_case__	     =	(
						    (
						        NystromformerModel,
						        NystromformerForMaskedLM,
						        NystromformerForMultipleChoice,
						        NystromformerForQuestionAnswering,
						        NystromformerForSequenceClassification,
						        NystromformerForTokenClassification,
						    )
						    if is_torch_available()
						    else ()
						)
						snake_case__	     =	(
						    {
						        """feature-extraction""": NystromformerModel,
						        """fill-mask""": NystromformerForMaskedLM,
						        """question-answering""": NystromformerForQuestionAnswering,
						        """text-classification""": NystromformerForSequenceClassification,
						        """token-classification""": NystromformerForTokenClassification,
						        """zero-shot""": NystromformerForSequenceClassification,
						    }
						    if is_torch_available()
						    else {}
						)
						snake_case__	     =	False
						snake_case__	     =	False






						def 					lowerCamelCase__   (				self					:	int			):
													__lowerCamelCase    :						str						      =   NystromformerModelTester(self			)
													__lowerCamelCase    :						str						      =   ConfigTester(self							,    config_class=__lowerCamelCase							,    hidden_size=37			)






						def 					lowerCamelCase__   (				self					:	List[str]			):
													self.config_tester.run_common_tests()






						def 					lowerCamelCase__   (				self					:	Tuple			):
													__lowerCamelCase    :						int						      =   self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_model(*__lowerCamelCase			)






						def 					lowerCamelCase__   (				self					:	List[Any]			):
													__lowerCamelCase    :						str						      =   self.model_tester.prepare_config_and_inputs()
													for type in ["absolute", "relative_key", "relative_key_query"]:
																				__lowerCamelCase    :						int						      =   type
																				self.model_tester.create_and_check_model(*__lowerCamelCase			)






						def 					lowerCamelCase__   (				self					:	Dict			):
													__lowerCamelCase    :						str						      =   self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_masked_lm(*__lowerCamelCase			)






						def 					lowerCamelCase__   (				self					:	Any			):
													__lowerCamelCase    :						Optional[int]						      =   self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_multiple_choice(*__lowerCamelCase			)






						def 					lowerCamelCase__   (				self					:	Union[str, Any]			):
													__lowerCamelCase    :						Union[str, Any]						      =   self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_question_answering(*__lowerCamelCase			)






						def 					lowerCamelCase__   (				self					:	Optional[int]			):
													__lowerCamelCase    :						List[str]						      =   self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_sequence_classification(*__lowerCamelCase			)






						def 					lowerCamelCase__   (				self					:	Tuple			):
													__lowerCamelCase    :						int						      =   self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_token_classification(*__lowerCamelCase			)







						@slow
						def 					lowerCamelCase__   (				self					:	str			):
													for model_name in NYSTROMFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																				__lowerCamelCase    :						int						      =   NystromformerModel.from_pretrained(__lowerCamelCase			)
																				self.assertIsNotNone(__lowerCamelCase			)

@require_torch
class        _snake_case   (    unittest.TestCase						):






						@slow
						def 					lowerCamelCase__   (				self					:	Optional[int]			):
													__lowerCamelCase    :						int						      =   NystromformerModel.from_pretrained("uw-madison/nystromformer-512"			)
													__lowerCamelCase    :						List[str]						      =   torch.tensor([[0, 1, 2, 3, 4, 5]]			)

													with torch.no_grad():
																				__lowerCamelCase    :						List[Any]						      =   model(__lowerCamelCase			)[0]

													__lowerCamelCase    :						int						      =   torch.Size((1, 6, 768)			)
													self.assertEqual(output.shape							,    __lowerCamelCase			)

													__lowerCamelCase    :						Optional[int]						      =   torch.tensor(
													    [[[-0.4_5_3_2, -0.0_9_3_6, 0.5_1_3_7], [-0.2_6_7_6, 0.0_6_2_8, 0.6_1_8_6], [-0.3_6_2_9, -0.1_7_2_6, 0.4_7_1_6]]]			)

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







						@slow
						def 					lowerCamelCase__   (				self					:	Tuple			):
													__lowerCamelCase    :						Union[str, Any]						      =   "the [MASK] of Belgium is Brussels"

													__lowerCamelCase    :						List[str]						      =   AutoTokenizer.from_pretrained("uw-madison/nystromformer-512"			)
													__lowerCamelCase    :						List[Any]						      =   NystromformerForMaskedLM.from_pretrained("uw-madison/nystromformer-512"			)

													__lowerCamelCase    :						int						      =   tokenizer(__lowerCamelCase							,    return_tensors="pt"			)

													with torch.no_grad():
																				__lowerCamelCase    :						Dict						      =   model(encoding.input_ids			).logits

													__lowerCamelCase    :						Union[str, Any]						      =   token_logits[:, 2, :].argmax(-1			)[0]

													self.assertEqual(tokenizer.decode(__lowerCamelCase			)							,    "capital"			)





from __future__ import annotations




def 			__magic_name__				( A		:					list   ):






			'''simple docstring'''







			if len(A   ) == 0:
						return []
			a    ,		a    =			min(A   ), max(A   )
			a    =			int(max_value - min_value   ) + 1
			a    =			[[] for _ in range(A   )]

			for i in my_list:
						buckets[int(i - min_value   )].append(A   )

			return [v for bucket in buckets for v in sorted(A   )]


if __name__ == "__main__":
		from doctest import testmod

		testmod()
		assert bucket_sort([4, 5, 3, 2, 1]) == [1, 2, 3, 4, 5]
		assert bucket_sort([0, 1, -10, 15, 2, -2]) == [-10, -2, 0, 1, 2, 15]






