




"""simple docstring"""




import gc
import tempfile
import unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionDualGuidedPipeline
from diffusers.utils.testing_utils import load_image, nightly, require_torch_gpu, torch_device


a_            =   False

@nightly
@require_torch_gpu
class        UpperCAmelCase_  (	unittest.TestCase						):
		def 					_lowerCamelCase    (		self   )		->   Dict:
					# clean up the VRAM after each test
					super().tearDown()
					gc.collect()
					torch.cuda.empty_cache()
		def 					_lowerCamelCase    (		self   )		->   Optional[int]:
					__lowercase	:       Union[str, Any]				=   VersatileDiffusionDualGuidedPipeline.from_pretrained('''shi-labs/versatile-diffusion'''   )
					# remove text_unet
					pipe.remove_unused_weights()
					pipe.to(UpperCamelCase_   )
					pipe.set_progress_bar_config(disable=UpperCamelCase_   )

					__lowercase	:       Optional[Any]				=   load_image(
					    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg'''   )

					__lowercase	:       str				=   torch.manual_seed(0   )
					__lowercase	:       Optional[Any]				=   pipe(
					    prompt='''first prompt'''							,		image=UpperCamelCase_							,		text_to_image_strength=0.7_5							,		generator=UpperCamelCase_							,		guidance_scale=7.5							,		num_inference_steps=2							,		output_type='''numpy'''							,		).images

					with tempfile.TemporaryDirectory() as tmpdirname:
								pipe.save_pretrained(UpperCamelCase_   )
								__lowercase	:       Dict				=   VersatileDiffusionDualGuidedPipeline.from_pretrained(UpperCamelCase_   )

					pipe.to(UpperCamelCase_   )
					pipe.set_progress_bar_config(disable=UpperCamelCase_   )

					__lowercase	:       List[Any]				=   generator.manual_seed(0   )
					__lowercase	:       Optional[Any]				=   pipe(
					    prompt='''first prompt'''							,		image=UpperCamelCase_							,		text_to_image_strength=0.7_5							,		generator=UpperCamelCase_							,		guidance_scale=7.5							,		num_inference_steps=2							,		output_type='''numpy'''							,		).images

					assert np.abs(image - new_image   ).sum() < 1E-5, "Models don't have the same forward pass"
		def 					_lowerCamelCase    (		self   )		->   Tuple:
					__lowercase	:       List[Any]				=   VersatileDiffusionDualGuidedPipeline.from_pretrained('''shi-labs/versatile-diffusion'''   )
					pipe.remove_unused_weights()
					pipe.to(UpperCamelCase_   )
					pipe.set_progress_bar_config(disable=UpperCamelCase_   )

					__lowercase	:       Dict				=   '''cyberpunk 2077'''
					__lowercase	:       Dict				=   load_image(
					    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg'''   )
					__lowercase	:       Optional[Any]				=   torch.manual_seed(0   )
					__lowercase	:       Optional[int]				=   pipe(
					    prompt=UpperCamelCase_							,		image=UpperCamelCase_							,		text_to_image_strength=0.7_5							,		generator=UpperCamelCase_							,		guidance_scale=7.5							,		num_inference_steps=50							,		output_type='''numpy'''							,		).images

					__lowercase	:       Union[str, Any]				=   image[0, 2_53:2_56, 2_53:2_56, -1]

					assert image.shape == (1, 5_12, 5_12, 3)
					__lowercase	:       Optional[int]				=   np.array([0.0_7_8_7, 0.0_8_4_9, 0.0_8_2_6, 0.0_8_1_2, 0.0_8_0_7, 0.0_7_9_5, 0.0_8_1_8, 0.0_7_9_8, 0.0_7_7_9]   )

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









"""simple docstring"""




def       __UpperCAmelCase      (				__UpperCamelCase					):
			if len(__UpperCamelCase					) <= 1:
						return data
			else:
						return [
						    *quick_sort([e for e in data[1:] if e <= data[0]]					),
						    data[0],
						    *quick_sort([e for e in data[1:] if e > data[0]]					),
						]


if __name__ == "__main__":
			import doctest

			doctest.testmod()



