



import gc
import tempfile
import unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionTextToImagePipeline
from diffusers.utils.testing_utils import nightly, require_torch_gpu, torch_device


lowercase_								=     False
class 				_snake_case			(					unittest.TestCase):
				pass
@nightly
@require_torch_gpu
class 				_snake_case			(					unittest.TestCase):




				def 							A__      (						self					:						Union[str, Any]						):
							# clean up the VRAM after each test
							super().tearDown()
							gc.collect()
							torch.cuda.empty_cache()




				def 							A__      (						self					:						Any						):
							lowercase__					  =				VersatileDiffusionTextToImagePipeline.from_pretrained("shi-labs/versatile-diffusion"						)
							# remove text_unet
							pipe.remove_unused_weights()
							pipe.to(__lowercase						)
							pipe.set_progress_bar_config(disable=__lowercase						)

							lowercase__					  =				"A painting of a squirrel eating a burger "
							lowercase__					  =				torch.manual_seed(0						)
							lowercase__					  =				pipe(
							    prompt=__lowercase,					generator=__lowercase,					guidance_scale=7.5,					num_inference_steps=2,					output_type="numpy"						).images

							with tempfile.TemporaryDirectory() as tmpdirname:
										pipe.save_pretrained(__lowercase						)
										lowercase__					  =				VersatileDiffusionTextToImagePipeline.from_pretrained(__lowercase						)
							pipe.to(__lowercase						)
							pipe.set_progress_bar_config(disable=__lowercase						)

							lowercase__					  =				generator.manual_seed(0						)
							lowercase__					  =				pipe(
							    prompt=__lowercase,					generator=__lowercase,					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 							A__      (						self					:						str						):
							lowercase__					  =				VersatileDiffusionTextToImagePipeline.from_pretrained(
							    "shi-labs/versatile-diffusion",					torch_dtype=torch.floataa						)
							pipe.to(__lowercase						)
							pipe.set_progress_bar_config(disable=__lowercase						)

							lowercase__					  =				"A painting of a squirrel eating a burger "
							lowercase__					  =				torch.manual_seed(0						)
							lowercase__					  =				pipe(
							    prompt=__lowercase,					generator=__lowercase,					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.3367, 0.3169, 0.2656, 0.3870, 0.4790, 0.3796, 0.4009, 0.4878, 0.4778]						)

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









def __lowerCAmelCase (     SCREAMING_SNAKE_CASE_  ):
			if upper_limit < 0:
						raise ValueError("Limit for the Catalan sequence must be ≥ 0"  )

			lowercase__					  =				[0] * (upper_limit + 1)

			# Base case: C(0) = C(1) = 1
			lowercase__					  =				1
			if upper_limit > 0:
						lowercase__					  =				1

			# Recurrence relation: C(i) = sum(C(j).C(i-j-1)), from j = 0 to i
			for i in range(2						,  upper_limit + 1  ):
						for j in range(SCREAMING_SNAKE_CASE_  ):
									catalan_list[i] += catalan_list[j] * catalan_list[i - j - 1]

			return catalan_list


if __name__ == "__main__":
							print("""\n********* Catalan Numbers Using Dynamic Programming ************\n""")
							print("""\n*** Enter -1 at any time to quit ***""")
							print("""\nEnter the upper limit (≥ 0) for the Catalan number sequence: """, end="""""")
							try:
														while True:
																					lowercase_								=     int(input().strip())
																					if N < 0:
																												print("""\n********* Goodbye!! ************""")
																												break
																					else:
																												print(F'The Catalan numbers from 0 through {N} are:')
																												print(catalan_numbers(N))
																												print("""Try another upper limit for the sequence: """, end="""""")
							except (NameError, ValueError):
														print("""\n********* Invalid input, goodbye! ************\n""")

							import doctest

							doctest.testmod()




