
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		:   Tuple         =    False



@nightly
@require_torch_gpu
class       a_   ( unittest.TestCase						):






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






			def       UpperCamelCase_							(			self     ):
									_lowercase									=				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									=				load_image(
									    """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg"""     )

									_lowercase									=				torch.manual_seed(0     )
									_lowercase									=				pipe(
									    prompt="""first prompt"""							, image=__UpperCamelCase							, text_to_image_strength=0.75							, generator=__UpperCamelCase							, guidance_scale=7.5							, num_inference_steps=2							, output_type="""numpy"""							, ).images

									with tempfile.TemporaryDirectory() as tmpdirname:
															pipe.save_pretrained(__UpperCamelCase     )
															_lowercase									=				VersatileDiffusionDualGuidedPipeline.from_pretrained(__UpperCamelCase     )

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

									_lowercase									=				generator.manual_seed(0     )
									_lowercase									=				pipe(
									    prompt="""first prompt"""							, image=__UpperCamelCase							, text_to_image_strength=0.75							, 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       UpperCamelCase_							(			self     ):
									_lowercase									=				VersatileDiffusionDualGuidedPipeline.from_pretrained("""shi-labs/versatile-diffusion"""     )
									pipe.remove_unused_weights()
									pipe.to(__UpperCamelCase     )
									pipe.set_progress_bar_config(disable=__UpperCamelCase     )

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

									_lowercase									=				image[0, 253:256, 253:256, -1]

									assert image.shape == (1, 512, 512, 3)
									_lowercase									=				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

def   UpperCamelCase__     (    SCREAMING_SNAKE_CASE_  :  int					)     ->    int:
						return n * (2 * n - 1)




def   UpperCamelCase__     (    SCREAMING_SNAKE_CASE_  :  int					)     ->    bool:
						_lowercase									=				(1 + 24 * n) ** 0.5
						return ((1 + root) / 6) % 1 == 0




def   UpperCamelCase__     (    SCREAMING_SNAKE_CASE_  :  int = 1_44					)     ->    int:
						_lowercase									=				start
						_lowercase									=				hexagonal_num(SCREAMING_SNAKE_CASE_					)
						while not is_pentagonal(SCREAMING_SNAKE_CASE_					):
												n += 1
												_lowercase									=				hexagonal_num(SCREAMING_SNAKE_CASE_					)
						return num


if __name__ == "__main__":
		print(F'{solution()} = ')