



import gc
import unittest

import numpy as np
import torch
from torch.backends.cuda import sdp_kernel

from diffusers import (
    CMStochasticIterativeScheduler,
    ConsistencyModelPipeline,
    UNetaDModel,
)
from diffusers.utils import randn_tensor, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_a, require_torch_gpu

from ..pipeline_params import UNCONDITIONAL_IMAGE_GENERATION_BATCH_PARAMS, UNCONDITIONAL_IMAGE_GENERATION_PARAMS
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()





class  __magic_name__   (							A__,  unittest.TestCase						):
		lowercase      :       List[str]          =ConsistencyModelPipeline
		lowercase      :       Dict          =UNCONDITIONAL_IMAGE_GENERATION_PARAMS
		lowercase      :       List[Any]          =UNCONDITIONAL_IMAGE_GENERATION_BATCH_PARAMS

		# Override required_optional_params to remove num_images_per_prompt
		lowercase      :       Dict          =frozenset(
		    [
		        '''num_inference_steps''',
		        '''generator''',
		        '''latents''',
		        '''output_type''',
		        '''return_dict''',
		        '''callback''',
		        '''callback_steps''',
		    ]						)






		@property
		def SCREAMING_SNAKE_CASE_			(						self      :     Optional[Any]      )				->					List[str]:
								'''simple docstring'''







								UpperCAmelCase         =     UNetaDModel.from_pretrained(
								    "diffusers/consistency-models-test"				,		subfolder="test_unet"				,		)
								return unet






		@property
		def SCREAMING_SNAKE_CASE_			(						self      :     Optional[Any]      )				->					List[Any]:
								'''simple docstring'''







								UpperCAmelCase         =     UNetaDModel.from_pretrained(
								    "diffusers/consistency-models-test"				,		subfolder="test_unet_class_cond"				,		)
								return unet






		def SCREAMING_SNAKE_CASE_			(						self      :     int				,		UpperCamelCase__      :     Tuple=False      )				->					List[Any]:
								'''simple docstring'''







								if class_cond:
														UpperCAmelCase         =     self.dummy_cond_unet
								else:
														UpperCAmelCase         =     self.dummy_uncond_unet

								# Default to CM multistep sampler
								UpperCAmelCase         =     CMStochasticIterativeScheduler(
								    num_train_timesteps=40				,		sigma_min=0.0_02				,		sigma_max=80.0				,		)

								UpperCAmelCase         =     {
								    "unet": unet,
								    "scheduler": scheduler,
								}

								return components






		def SCREAMING_SNAKE_CASE_			(						self      :     Union[str, Any]				,		UpperCamelCase__      :     List[str]				,		UpperCamelCase__      :     Dict=0      )				->					Any:
								'''simple docstring'''







								if str(UpperCamelCase__      ).startswith("mps"      ):
														UpperCAmelCase         =     torch.manual_seed(UpperCamelCase__      )
								else:
														UpperCAmelCase         =     torch.Generator(device=UpperCamelCase__      ).manual_seed(UpperCamelCase__      )

								UpperCAmelCase         =     {
								    "batch_size": 1,
								    "num_inference_steps": None,
								    "timesteps": [22, 0],
								    "generator": generator,
								    "output_type": "np",
								}

								return inputs






		def SCREAMING_SNAKE_CASE_			(						self      :     List[str]      )				->					Any:
								'''simple docstring'''







								UpperCAmelCase         =     "cpu"  # ensure determinism for the device-dependent torch.Generator
								UpperCAmelCase         =     self.get_dummy_components()
								UpperCAmelCase         =     ConsistencyModelPipeline(**UpperCamelCase__      )
								UpperCAmelCase         =     pipe.to(UpperCamelCase__      )
								pipe.set_progress_bar_config(disable=UpperCamelCase__      )

								UpperCAmelCase         =     self.get_dummy_inputs(UpperCamelCase__      )
								UpperCAmelCase         =     pipe(**UpperCamelCase__      ).images
								assert image.shape == (1, 32, 32, 3)

								UpperCAmelCase         =     image[0, -3:, -3:, -1]
								UpperCAmelCase         =     np.array([0.35_72, 0.62_73, 0.40_31, 0.39_61, 0.43_21, 0.57_30, 0.52_66, 0.47_80, 0.50_04]      )

								assert np.abs(image_slice.flatten() - expected_slice      ).max() < 1e-3






		def SCREAMING_SNAKE_CASE_			(						self      :     Any      )				->					Optional[int]:
								'''simple docstring'''







								UpperCAmelCase         =     "cpu"  # ensure determinism for the device-dependent torch.Generator
								UpperCAmelCase         =     self.get_dummy_components(class_cond=UpperCamelCase__      )
								UpperCAmelCase         =     ConsistencyModelPipeline(**UpperCamelCase__      )
								UpperCAmelCase         =     pipe.to(UpperCamelCase__      )
								pipe.set_progress_bar_config(disable=UpperCamelCase__      )

								UpperCAmelCase         =     self.get_dummy_inputs(UpperCamelCase__      )
								UpperCAmelCase         =     0
								UpperCAmelCase         =     pipe(**UpperCamelCase__      ).images
								assert image.shape == (1, 32, 32, 3)

								UpperCAmelCase         =     image[0, -3:, -3:, -1]
								UpperCAmelCase         =     np.array([0.35_72, 0.62_73, 0.40_31, 0.39_61, 0.43_21, 0.57_30, 0.52_66, 0.47_80, 0.50_04]      )

								assert np.abs(image_slice.flatten() - expected_slice      ).max() < 1e-3






		def SCREAMING_SNAKE_CASE_			(						self      :     Tuple      )				->					Optional[Any]:
								'''simple docstring'''







								UpperCAmelCase         =     "cpu"  # ensure determinism for the device-dependent torch.Generator
								UpperCAmelCase         =     self.get_dummy_components()
								UpperCAmelCase         =     ConsistencyModelPipeline(**UpperCamelCase__      )
								UpperCAmelCase         =     pipe.to(UpperCamelCase__      )
								pipe.set_progress_bar_config(disable=UpperCamelCase__      )

								UpperCAmelCase         =     self.get_dummy_inputs(UpperCamelCase__      )
								UpperCAmelCase         =     1
								UpperCAmelCase         =     None
								UpperCAmelCase         =     pipe(**UpperCamelCase__      ).images
								assert image.shape == (1, 32, 32, 3)

								UpperCAmelCase         =     image[0, -3:, -3:, -1]
								UpperCAmelCase         =     np.array([0.50_04, 0.50_04, 0.49_94, 0.50_08, 0.49_76, 0.50_18, 0.49_90, 0.49_82, 0.49_87]      )

								assert np.abs(image_slice.flatten() - expected_slice      ).max() < 1e-3







		def SCREAMING_SNAKE_CASE_			(						self      :     Union[str, Any]      )				->					Any:
								'''simple docstring'''







								UpperCAmelCase         =     "cpu"  # ensure determinism for the device-dependent torch.Generator
								UpperCAmelCase         =     self.get_dummy_components(class_cond=UpperCamelCase__      )
								UpperCAmelCase         =     ConsistencyModelPipeline(**UpperCamelCase__      )
								UpperCAmelCase         =     pipe.to(UpperCamelCase__      )
								pipe.set_progress_bar_config(disable=UpperCamelCase__      )

								UpperCAmelCase         =     self.get_dummy_inputs(UpperCamelCase__      )
								UpperCAmelCase         =     1
								UpperCAmelCase         =     None
								UpperCAmelCase         =     0
								UpperCAmelCase         =     pipe(**UpperCamelCase__      ).images
								assert image.shape == (1, 32, 32, 3)

								UpperCAmelCase         =     image[0, -3:, -3:, -1]
								UpperCAmelCase         =     np.array([0.50_04, 0.50_04, 0.49_94, 0.50_08, 0.49_76, 0.50_18, 0.49_90, 0.49_82, 0.49_87]      )

								assert np.abs(image_slice.flatten() - expected_slice      ).max() < 1e-3





@slow
@require_torch_gpu
class  __magic_name__   (							unittest.TestCase						):






		def SCREAMING_SNAKE_CASE_			(						self      :     Any      )				->					Optional[Any]:
								'''simple docstring'''







								super().tearDown()
								gc.collect()
								torch.cuda.empty_cache()






		def SCREAMING_SNAKE_CASE_			(						self      :     int				,		UpperCamelCase__      :     Any=0				,		UpperCamelCase__      :     Union[str, Any]=False				,		UpperCamelCase__      :     List[Any]="cpu"				,		UpperCamelCase__      :     Any=torch.floataa				,		UpperCamelCase__      :     Dict=(1, 3, 64, 64)      )				->					Dict:
								'''simple docstring'''







								UpperCAmelCase         =     torch.manual_seed(UpperCamelCase__      )

								UpperCAmelCase         =     {
								    "num_inference_steps": None,
								    "timesteps": [22, 0],
								    "class_labels": 0,
								    "generator": generator,
								    "output_type": "np",
								}

								if get_fixed_latents:
														UpperCAmelCase         =     self.get_fixed_latents(seed=UpperCamelCase__				,		device=UpperCamelCase__				,		dtype=UpperCamelCase__				,		shape=UpperCamelCase__      )
														UpperCAmelCase         =     latents

								return inputs






		def SCREAMING_SNAKE_CASE_			(						self      :     Optional[int]				,		UpperCamelCase__      :     Optional[int]=0				,		UpperCamelCase__      :     Tuple="cpu"				,		UpperCamelCase__      :     Dict=torch.floataa				,		UpperCamelCase__      :     int=(1, 3, 64, 64)      )				->					Tuple:
								'''simple docstring'''







								if type(UpperCamelCase__      ) == str:
														UpperCAmelCase         =     torch.device(UpperCamelCase__      )
								UpperCAmelCase         =     torch.Generator(device=UpperCamelCase__      ).manual_seed(UpperCamelCase__      )
								UpperCAmelCase         =     randn_tensor(UpperCamelCase__				,		generator=UpperCamelCase__				,		device=UpperCamelCase__				,		dtype=UpperCamelCase__      )
								return latents






		def SCREAMING_SNAKE_CASE_			(						self      :     Union[str, Any]      )				->					Tuple:
								'''simple docstring'''







								UpperCAmelCase         =     UNetaDModel.from_pretrained("diffusers/consistency_models"				,		subfolder="diffusers_cd_imagenet64_l2"      )
								UpperCAmelCase         =     CMStochasticIterativeScheduler(
								    num_train_timesteps=40				,		sigma_min=0.0_02				,		sigma_max=80.0				,		)
								UpperCAmelCase         =     ConsistencyModelPipeline(unet=UpperCamelCase__				,		scheduler=UpperCamelCase__      )
								pipe.to(torch_device=UpperCamelCase__      )
								pipe.set_progress_bar_config(disable=UpperCamelCase__      )

								UpperCAmelCase         =     self.get_inputs()
								UpperCAmelCase         =     pipe(**UpperCamelCase__      ).images
								assert image.shape == (1, 64, 64, 3)

								UpperCAmelCase         =     image[0, -3:, -3:, -1]

								UpperCAmelCase         =     np.array([0.08_88, 0.08_81, 0.06_66, 0.04_79, 0.02_92, 0.01_95, 0.02_01, 0.01_63, 0.02_54]      )

								assert np.abs(image_slice.flatten() - expected_slice      ).max() < 2e-2






		def SCREAMING_SNAKE_CASE_			(						self      :     Tuple      )				->					int:
								'''simple docstring'''







								UpperCAmelCase         =     UNetaDModel.from_pretrained("diffusers/consistency_models"				,		subfolder="diffusers_cd_imagenet64_l2"      )
								UpperCAmelCase         =     CMStochasticIterativeScheduler(
								    num_train_timesteps=40				,		sigma_min=0.0_02				,		sigma_max=80.0				,		)
								UpperCAmelCase         =     ConsistencyModelPipeline(unet=UpperCamelCase__				,		scheduler=UpperCamelCase__      )
								pipe.to(torch_device=UpperCamelCase__      )
								pipe.set_progress_bar_config(disable=UpperCamelCase__      )

								UpperCAmelCase         =     self.get_inputs()
								UpperCAmelCase         =     1
								UpperCAmelCase         =     None
								UpperCAmelCase         =     pipe(**UpperCamelCase__      ).images
								assert image.shape == (1, 64, 64, 3)

								UpperCAmelCase         =     image[0, -3:, -3:, -1]

								UpperCAmelCase         =     np.array([0.03_40, 0.01_52, 0.00_63, 0.02_67, 0.02_21, 0.01_07, 0.04_16, 0.01_86, 0.02_17]      )

								assert np.abs(image_slice.flatten() - expected_slice      ).max() < 2e-2






		@require_torch_a
		def SCREAMING_SNAKE_CASE_			(						self      :     List[str]      )				->					List[Any]:
								'''simple docstring'''







								UpperCAmelCase         =     UNetaDModel.from_pretrained("diffusers/consistency_models"				,		subfolder="diffusers_cd_imagenet64_l2"      )
								UpperCAmelCase         =     CMStochasticIterativeScheduler(
								    num_train_timesteps=40				,		sigma_min=0.0_02				,		sigma_max=80.0				,		)
								UpperCAmelCase         =     ConsistencyModelPipeline(unet=UpperCamelCase__				,		scheduler=UpperCamelCase__      )
								pipe.to(torch_device=UpperCamelCase__				,		torch_dtype=torch.floataa      )
								pipe.set_progress_bar_config(disable=UpperCamelCase__      )

								UpperCAmelCase         =     self.get_inputs(get_fixed_latents=UpperCamelCase__				,		device=UpperCamelCase__      )
								# Ensure usage of flash attention in torch 2.0
								with sdp_kernel(enable_flash=UpperCamelCase__				,		enable_math=UpperCamelCase__				,		enable_mem_efficient=UpperCamelCase__      ):
														UpperCAmelCase         =     pipe(**UpperCamelCase__      ).images
								assert image.shape == (1, 64, 64, 3)

								UpperCAmelCase         =     image[0, -3:, -3:, -1]

								UpperCAmelCase         =     np.array([0.18_75, 0.14_28, 0.12_89, 0.21_51, 0.20_92, 0.14_77, 0.18_77, 0.16_41, 0.13_53]      )

								assert np.abs(image_slice.flatten() - expected_slice      ).max() < 1e-3







		@require_torch_a
		def SCREAMING_SNAKE_CASE_			(						self      :     str      )				->					Optional[int]:
								'''simple docstring'''







								UpperCAmelCase         =     UNetaDModel.from_pretrained("diffusers/consistency_models"				,		subfolder="diffusers_cd_imagenet64_l2"      )
								UpperCAmelCase         =     CMStochasticIterativeScheduler(
								    num_train_timesteps=40				,		sigma_min=0.0_02				,		sigma_max=80.0				,		)
								UpperCAmelCase         =     ConsistencyModelPipeline(unet=UpperCamelCase__				,		scheduler=UpperCamelCase__      )
								pipe.to(torch_device=UpperCamelCase__				,		torch_dtype=torch.floataa      )
								pipe.set_progress_bar_config(disable=UpperCamelCase__      )

								UpperCAmelCase         =     self.get_inputs(get_fixed_latents=UpperCamelCase__				,		device=UpperCamelCase__      )
								UpperCAmelCase         =     1
								UpperCAmelCase         =     None
								# Ensure usage of flash attention in torch 2.0
								with sdp_kernel(enable_flash=UpperCamelCase__				,		enable_math=UpperCamelCase__				,		enable_mem_efficient=UpperCamelCase__      ):
														UpperCAmelCase         =     pipe(**UpperCamelCase__      ).images
								assert image.shape == (1, 64, 64, 3)

								UpperCAmelCase         =     image[0, -3:, -3:, -1]

								UpperCAmelCase         =     np.array([0.16_63, 0.19_48, 0.22_75, 0.16_80, 0.12_04, 0.12_45, 0.18_58, 0.13_38, 0.20_95]      )

								assert np.abs(image_slice.flatten() - expected_slice      ).max() < 1e-3








def    lowerCamelCase_(lowerCamelCase_    ) ->       list[int]:
						UpperCAmelCase         =     len(lowerCamelCase_    )
						for i in range(lowerCamelCase_    ):
												for j in range(i + 1    ,   lowerCamelCase_    ):
																		if numbers[j] < numbers[i]:
																								UpperCAmelCase       ,		UpperCAmelCase         =     numbers[j], numbers[i]
						return numbers


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



