




import inspect
import unittest

from transformers import ViTConfig
from transformers.testing_utils import (
    require_accelerate,
    require_torch,
    require_torch_gpu,
    require_vision,
    slow,
    torch_device,
)
from transformers.utils import cached_property, is_torch_available, is_vision_available

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


if is_torch_available():
			import torch
			from torch import nn

			from transformers import ViTForImageClassification, ViTForMaskedImageModeling, ViTModel
			from transformers.models.vit.modeling_vit import VIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
			from PIL import Image

			from transformers import ViTImageProcessor






class  __magic_name__						:
				'''simple docstring'''







				def __init__(							self:   Dict		,					_lowerCamelCase:   Union[str, Any]		,					_lowerCamelCase:   str=13		,					_lowerCamelCase:   Tuple=30		,					_lowerCamelCase:   str=2		,					_lowerCamelCase:   List[Any]=3		,					_lowerCamelCase:   Union[str, Any]=True		,					_lowerCamelCase:   List[Any]=True		,					_lowerCamelCase:   int=32		,					_lowerCamelCase:   Optional[int]=5		,					_lowerCamelCase:   int=4		,					_lowerCamelCase:   str=37		,					_lowerCamelCase:   Optional[Any]="gelu"		,					_lowerCamelCase:   Tuple=0.1		,					_lowerCamelCase:   Optional[int]=0.1		,					_lowerCamelCase:   Optional[int]=10		,					_lowerCamelCase:   Any=0.02		,					_lowerCamelCase:   Union[str, Any]=None		,					_lowerCamelCase:   Tuple=2		,					):
											SCREAMING_SNAKE_CASE_   	=    parent
											SCREAMING_SNAKE_CASE_   	=    batch_size
											SCREAMING_SNAKE_CASE_   	=    image_size
											SCREAMING_SNAKE_CASE_   	=    patch_size
											SCREAMING_SNAKE_CASE_   	=    num_channels
											SCREAMING_SNAKE_CASE_   	=    is_training
											SCREAMING_SNAKE_CASE_   	=    use_labels
											SCREAMING_SNAKE_CASE_   	=    hidden_size
											SCREAMING_SNAKE_CASE_   	=    num_hidden_layers
											SCREAMING_SNAKE_CASE_   	=    num_attention_heads
											SCREAMING_SNAKE_CASE_   	=    intermediate_size
											SCREAMING_SNAKE_CASE_   	=    hidden_act
											SCREAMING_SNAKE_CASE_   	=    hidden_dropout_prob
											SCREAMING_SNAKE_CASE_   	=    attention_probs_dropout_prob
											SCREAMING_SNAKE_CASE_   	=    type_sequence_label_size
											SCREAMING_SNAKE_CASE_   	=    initializer_range
											SCREAMING_SNAKE_CASE_   	=    scope
											SCREAMING_SNAKE_CASE_   	=    encoder_stride

											# in ViT, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
											SCREAMING_SNAKE_CASE_   	=    (image_size // patch_size) ** 2
											SCREAMING_SNAKE_CASE_   	=    num_patches + 1


				def     _A							(							self:   Tuple		):
											SCREAMING_SNAKE_CASE_   	=    floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)

											SCREAMING_SNAKE_CASE_   	=    None
											if self.use_labels:
																		SCREAMING_SNAKE_CASE_   	=    ids_tensor([self.batch_size]		,					self.type_sequence_label_size		)

											SCREAMING_SNAKE_CASE_   	=    self.get_config()

											return config, pixel_values, labels


				def     _A							(							self:   Tuple		):
											return ViTConfig(
											    image_size=self.image_size		,					patch_size=self.patch_size		,					num_channels=self.num_channels		,					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		,					is_decoder=_lowerCamelCase		,					initializer_range=self.initializer_range		,					encoder_stride=self.encoder_stride		,					)


				def     _A							(							self:   Optional[Any]		,					_lowerCamelCase:   str		,					_lowerCamelCase:   str		,					_lowerCamelCase:   Union[str, Any]		):
											SCREAMING_SNAKE_CASE_   	=    ViTModel(config=_lowerCamelCase		)
											model.to(_lowerCamelCase		)
											model.eval()
											SCREAMING_SNAKE_CASE_   	=    model(_lowerCamelCase		)
											self.parent.assertEqual(result.last_hidden_state.shape		,					(self.batch_size, self.seq_length, self.hidden_size)		)


				def     _A							(							self:   List[str]		,					_lowerCamelCase:   List[str]		,					_lowerCamelCase:   Union[str, Any]		,					_lowerCamelCase:   Optional[Any]		):
											SCREAMING_SNAKE_CASE_   	=    ViTForMaskedImageModeling(config=_lowerCamelCase		)
											model.to(_lowerCamelCase		)
											model.eval()
											SCREAMING_SNAKE_CASE_   	=    model(_lowerCamelCase		)
											self.parent.assertEqual(
											    result.reconstruction.shape		,					(self.batch_size, self.num_channels, self.image_size, self.image_size)		)

											# test greyscale images
											SCREAMING_SNAKE_CASE_   	=    1
											SCREAMING_SNAKE_CASE_   	=    ViTForMaskedImageModeling(_lowerCamelCase		)
											model.to(_lowerCamelCase		)
											model.eval()

											SCREAMING_SNAKE_CASE_   	=    floats_tensor([self.batch_size, 1, self.image_size, self.image_size]		)
											SCREAMING_SNAKE_CASE_   	=    model(_lowerCamelCase		)
											self.parent.assertEqual(result.reconstruction.shape		,					(self.batch_size, 1, self.image_size, self.image_size)		)


				def     _A							(							self:   Tuple		,					_lowerCamelCase:   List[Any]		,					_lowerCamelCase:   int		,					_lowerCamelCase:   Dict		):
											SCREAMING_SNAKE_CASE_   	=    self.type_sequence_label_size
											SCREAMING_SNAKE_CASE_   	=    ViTForImageClassification(_lowerCamelCase		)
											model.to(_lowerCamelCase		)
											model.eval()
											SCREAMING_SNAKE_CASE_   	=    model(_lowerCamelCase		,					labels=_lowerCamelCase		)
											self.parent.assertEqual(result.logits.shape		,					(self.batch_size, self.type_sequence_label_size)		)

											# test greyscale images
											SCREAMING_SNAKE_CASE_   	=    1
											SCREAMING_SNAKE_CASE_   	=    ViTForImageClassification(_lowerCamelCase		)
											model.to(_lowerCamelCase		)
											model.eval()

											SCREAMING_SNAKE_CASE_   	=    floats_tensor([self.batch_size, 1, self.image_size, self.image_size]		)
											SCREAMING_SNAKE_CASE_   	=    model(_lowerCamelCase		)
											self.parent.assertEqual(result.logits.shape		,					(self.batch_size, self.type_sequence_label_size)		)





				def     _A							(							self:   str		):
											SCREAMING_SNAKE_CASE_   	=    self.prepare_config_and_inputs()
											(
											    (
											    SCREAMING_SNAKE_CASE_       
											)	,	(
											    SCREAMING_SNAKE_CASE_       
											)	,	(
											    SCREAMING_SNAKE_CASE_       
											)	,	       
											)   	=    config_and_inputs
											SCREAMING_SNAKE_CASE_   	=    {'''pixel_values''': pixel_values}
											return config, inputs_dict






@require_torch
class  __magic_name__						(  UpperCamelCase__    ,  UpperCamelCase__    ,  unittest.TestCase):
				'''simple docstring'''







				SCREAMING_SNAKE_CASE__					:							int	      =					(
				    (
				        ViTModel,
				        ViTForImageClassification,
				        ViTForMaskedImageModeling,
				    )
				    if is_torch_available()
				    else ()
				)
				SCREAMING_SNAKE_CASE__					:							str	      =					(
				    {"""feature-extraction""": ViTModel, """image-classification""": ViTForImageClassification}
				    if is_torch_available()
				    else {}
				)
				SCREAMING_SNAKE_CASE__					:							Optional[int]	      =					True

				SCREAMING_SNAKE_CASE__					:							Optional[Any]	      =					False
				SCREAMING_SNAKE_CASE__					:							List[Any]	      =					False
				SCREAMING_SNAKE_CASE__					:							str	      =					False


				def     _A							(							self:   Union[str, Any]		):
											SCREAMING_SNAKE_CASE_   	=    ViTModelTester(self		)
											SCREAMING_SNAKE_CASE_   	=    ConfigTester(self		,					config_class=_lowerCamelCase		,					has_text_modality=_lowerCamelCase		,					hidden_size=37		)


				def     _A							(							self:   Optional[Any]		):
											self.config_tester.run_common_tests()


				@unittest.skip(reason='''ViT does not use inputs_embeds'''		)
				def     _A							(							self:   Optional[int]		):
											pass


				def     _A							(							self:   Optional[int]		):
											SCREAMING_SNAKE_CASE_	,	SCREAMING_SNAKE_CASE_   	=    self.model_tester.prepare_config_and_inputs_for_common()

											for model_class in self.all_model_classes:
																		SCREAMING_SNAKE_CASE_   	=    model_class(_lowerCamelCase		)
																		self.assertIsInstance(model.get_input_embeddings()		,					(nn.Module)		)
																		SCREAMING_SNAKE_CASE_   	=    model.get_output_embeddings()
																		self.assertTrue(x is None or isinstance(_lowerCamelCase		,					nn.Linear		)		)


				def     _A							(							self:   List[str]		):
											SCREAMING_SNAKE_CASE_	,	SCREAMING_SNAKE_CASE_   	=    self.model_tester.prepare_config_and_inputs_for_common()

											for model_class in self.all_model_classes:
																		SCREAMING_SNAKE_CASE_   	=    model_class(_lowerCamelCase		)
																		SCREAMING_SNAKE_CASE_   	=    inspect.signature(model.forward		)
																		# signature.parameters is an OrderedDict => so arg_names order is deterministic
																		SCREAMING_SNAKE_CASE_   	=    [*signature.parameters.keys()]

																		SCREAMING_SNAKE_CASE_   	=    ['''pixel_values''']
																		self.assertListEqual(arg_names[:1]		,					_lowerCamelCase		)


				def     _A							(							self:   str		):
											SCREAMING_SNAKE_CASE_   	=    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*_lowerCamelCase		)


				def     _A							(							self:   int		):
											SCREAMING_SNAKE_CASE_   	=    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_masked_image_modeling(*_lowerCamelCase		)


				def     _A							(							self:   Tuple		):
											SCREAMING_SNAKE_CASE_   	=    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_image_classification(*_lowerCamelCase		)





				@slow
				def     _A							(							self:   int		):
											for model_name in VIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																		SCREAMING_SNAKE_CASE_   	=    ViTModel.from_pretrained(_lowerCamelCase		)
																		self.assertIsNotNone(_lowerCamelCase		)






def 			a   ():
							SCREAMING_SNAKE_CASE_   	=    Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''     )
							return image






@require_torch
@require_vision
class  __magic_name__						(  unittest.TestCase):
				'''simple docstring'''







				@cached_property
				def     _A							(							self:   int		):
											return ViTImageProcessor.from_pretrained('''google/vit-base-patch16-224'''		) if is_vision_available() else None


				@slow
				def     _A							(							self:   Optional[Any]		):
											SCREAMING_SNAKE_CASE_   	=    ViTForImageClassification.from_pretrained('''google/vit-base-patch16-224'''		).to(_lowerCamelCase		)

											SCREAMING_SNAKE_CASE_   	=    self.default_image_processor
											SCREAMING_SNAKE_CASE_   	=    prepare_img()
											SCREAMING_SNAKE_CASE_   	=    image_processor(images=_lowerCamelCase		,					return_tensors='''pt'''		).to(_lowerCamelCase		)

											# forward pass
											with torch.no_grad():
																		SCREAMING_SNAKE_CASE_   	=    model(**_lowerCamelCase		)

											# verify the logits
											SCREAMING_SNAKE_CASE_   	=    torch.Size((1, 10_00)		)
											self.assertEqual(outputs.logits.shape		,					_lowerCamelCase		)

											SCREAMING_SNAKE_CASE_   	=    torch.tensor([-0.27_44, 0.82_15, -0.08_36]		).to(_lowerCamelCase		)

											self.assertTrue(torch.allclose(outputs.logits[0, :3]		,					_lowerCamelCase		,					atol=1E-4		)		)


				@slow
				def     _A							(							self:   Union[str, Any]		):
											# ViT models have an `interpolate_pos_encoding` argument in their forward method,
											# allowing to interpolate the pre-trained position embeddings in order to use
											# the model on higher resolutions. The DINO model by Facebook AI leverages this
											# to visualize self-attention on higher resolution images.
											SCREAMING_SNAKE_CASE_   	=    ViTModel.from_pretrained('''facebook/dino-vits8'''		).to(_lowerCamelCase		)

											SCREAMING_SNAKE_CASE_   	=    ViTImageProcessor.from_pretrained('''facebook/dino-vits8'''		,					size=4_80		)
											SCREAMING_SNAKE_CASE_   	=    prepare_img()
											SCREAMING_SNAKE_CASE_   	=    image_processor(images=_lowerCamelCase		,					return_tensors='''pt'''		)
											SCREAMING_SNAKE_CASE_   	=    inputs.pixel_values.to(_lowerCamelCase		)

											# forward pass
											with torch.no_grad():
																		SCREAMING_SNAKE_CASE_   	=    model(_lowerCamelCase		,					interpolate_pos_encoding=_lowerCamelCase		)

											# verify the logits
											SCREAMING_SNAKE_CASE_   	=    torch.Size((1, 36_01, 3_84)		)
											self.assertEqual(outputs.last_hidden_state.shape		,					_lowerCamelCase		)

											SCREAMING_SNAKE_CASE_   	=    torch.tensor(
											    [[4.23_40, 4.39_06, -6.66_92], [4.54_63, 1.89_28, -6.72_57], [4.44_29, 0.84_96, -5.85_85]]		).to(_lowerCamelCase		)

											self.assertTrue(torch.allclose(outputs.last_hidden_state[0, :3, :3]		,					_lowerCamelCase		,					atol=1E-4		)		)





				@slow
				@require_accelerate
				@require_torch_gpu
				def     _A							(							self:   Optional[int]		):
											SCREAMING_SNAKE_CASE_   	=    ViTModel.from_pretrained('''facebook/dino-vits8'''		,					torch_dtype=torch.floataa		,					device_map='''auto'''		)
											SCREAMING_SNAKE_CASE_   	=    self.default_image_processor

											SCREAMING_SNAKE_CASE_   	=    prepare_img()
											SCREAMING_SNAKE_CASE_   	=    image_processor(images=_lowerCamelCase		,					return_tensors='''pt'''		)
											SCREAMING_SNAKE_CASE_   	=    inputs.pixel_values.to(_lowerCamelCase		)

											# forward pass to make sure inference works in fp16
											with torch.no_grad():
																		SCREAMING_SNAKE_CASE_   	=    model(_lowerCamelCase		)








def 			a   (_lowerCAmelCase     ):
							SCREAMING_SNAKE_CASE_	,	SCREAMING_SNAKE_CASE_   	=    [], []
							while len(_lowerCAmelCase     ) > 1:
														SCREAMING_SNAKE_CASE_	,	SCREAMING_SNAKE_CASE_   	=    min(_lowerCAmelCase     ), max(_lowerCAmelCase     )
														start.append(_lowerCAmelCase     )
														end.append(_lowerCAmelCase     )
														collection.remove(_lowerCAmelCase     )
														collection.remove(_lowerCAmelCase     )
							end.reverse()
							return start + collection + end


if __name__ == "__main__":
			__SCREAMING_SNAKE_CASE 						=input("""Enter numbers separated by a comma:\n""").strip()
			__SCREAMING_SNAKE_CASE 						=[int(item) for item in user_input.split(""",""")]
			print(*merge_sort(unsorted), sep=""",""")


