




"""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      lowerCamelCase__      (					unittest.TestCase     ):


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







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


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  List[Any]        =			VersatileDiffusionDualGuidedPipeline.from_pretrained("shi-labs/versatile-diffusion"							)
					# remove text_unet
					pipe.remove_unused_weights()
					pipe.to(SCREAMING_SNAKE_CASE							)
					pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE							)

					snake_case						:  int        =			load_image(
					    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg"							)

					snake_case						:  Optional[int]        =			torch.manual_seed(0							)
					snake_case						:  Optional[Any]        =			pipe(
					    prompt="first prompt"			,	image=SCREAMING_SNAKE_CASE			,	text_to_image_strength=0.75			,	generator=SCREAMING_SNAKE_CASE			,	guidance_scale=7.5			,	num_inference_steps=2			,	output_type="numpy"			,	).images

					with tempfile.TemporaryDirectory() as tmpdirname:
							pipe.save_pretrained(SCREAMING_SNAKE_CASE							)
							snake_case						:  Any        =			VersatileDiffusionDualGuidedPipeline.from_pretrained(SCREAMING_SNAKE_CASE							)

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

					snake_case						:  Any        =			generator.manual_seed(0							)
					snake_case						:  Tuple        =			pipe(
					    prompt="first prompt"			,	image=SCREAMING_SNAKE_CASE			,	text_to_image_strength=0.75			,	generator=SCREAMING_SNAKE_CASE			,	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							):



					"""simple docstring"""







					snake_case						:  List[str]        =			VersatileDiffusionDualGuidedPipeline.from_pretrained("shi-labs/versatile-diffusion"							)
					pipe.remove_unused_weights()
					pipe.to(SCREAMING_SNAKE_CASE							)
					pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE							)

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

					snake_case						:  int        =			image[0, 253:256, 253:256, -1]

					assert image.shape == (1, 512, 512, 3)
					snake_case						:  Optional[Any]        =			np.array([0.07_87, 0.08_49, 0.08_26, 0.08_12, 0.08_07, 0.07_95, 0.08_18, 0.07_98, 0.07_79]							)

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







"""simple docstring"""

def 					UpperCamelCase__       (						lowercase__					:       int				):
		if not isinstance(lowercase__    ,       lowercase__				):
				raise ValueError("double_factorial() only accepts integral values"				)
		if n < 0:
				raise ValueError("double_factorial() not defined for negative values"				)
		return 1 if n <= 1 else n * double_factorial(n - 2				)


if __name__ == "__main__":
							import doctest

							doctest.testmod()

