'''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 		SCREAMING_SNAKE_CASE_					(unittest.TestCase      ):



			"""simple docstring"""






			def   lowerCamelCase (							self					):
									# clean up the VRAM after each test
									super().tearDown()
									gc.collect()
									torch.cuda.empty_cache()



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

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

									snake_case :       str				=    torch.manual_seed(0					)
									snake_case :       int				=    pipe(
									    prompt="first prompt"				,			image=snake_case_				,			text_to_image_strength=0.75				,			generator=snake_case_				,			guidance_scale=7.5				,			num_inference_steps=2				,			output_type="numpy"				,			).images

									with tempfile.TemporaryDirectory() as tmpdirname:
															pipe.save_pretrained(snake_case_					)
															snake_case :       Optional[Any]				=    VersatileDiffusionDualGuidedPipeline.from_pretrained(snake_case_					)

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

									snake_case :       List[Any]				=    generator.manual_seed(0					)
									snake_case :       int				=    pipe(
									    prompt="first prompt"				,			image=snake_case_				,			text_to_image_strength=0.75				,			generator=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					):
									snake_case :       Dict				=    VersatileDiffusionDualGuidedPipeline.from_pretrained("shi-labs/versatile-diffusion"					)
									pipe.remove_unused_weights()
									pipe.to(snake_case_					)
									pipe.set_progress_bar_config(disable=snake_case_					)

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

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

									assert image.shape == (1, 512, 512, 3)
									snake_case :       Union[str, Any]				=    np.array([0.0_787, 0.0_849, 0.0_826, 0.0_812, 0.0_807, 0.0_795, 0.0_818, 0.0_798, 0.0_779]					)

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






'''simple docstring'''

from __future__ import annotations


def        UpperCAmelCase__   (				_lowerCAmelCase    :			list[int | float])    ->		int | float:



						"""simple docstring"""

						if len(_lowerCAmelCase) == 0:
												raise ValueError("find_max() arg is an empty sequence")
						snake_case :       Any				=    nums[0]
						for x in nums:
												if x > max_num:
																		snake_case :       int				=    x
						return max_num


if __name__ == "__main__":
						import doctest

						doctest.testmod(verbose=True)





