



import gc
import unittest

import numpy as np
import torch

from diffusers import StableDiffusionKDiffusionPipeline
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu


enable_full_determinism()

@slow
@require_torch_gpu
class 	lowerCamelCase_    ( unittest.TestCase						):






						'''simple docstring'''







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







						def 			SCREAMING_SNAKE_CASE__		(	self      :			Optional[Any] )      ->				Optional[int]:
									A							:					int              =						StableDiffusionKDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4" )
									A							:					Union[str, Any]              =						sd_pipe.to(__lowerCamelCase )
									sd_pipe.set_progress_bar_config(disable=__lowerCamelCase )

									sd_pipe.set_scheduler("sample_euler" )

									A							:					Dict              =						"A painting of a squirrel eating a burger"
									A							:					str              =						torch.manual_seed(0 )
									A							:					int              =						sd_pipe([prompt]	,	generator=__lowerCamelCase	,	guidance_scale=9.0	,	num_inference_steps=20	,	output_type="np" )

									A							:					Any              =						output.images

									A							:					Optional[Any]              =						image[0, -3:, -3:, -1]

									assert image.shape == (1, 5_12, 5_12, 3)
									A							:					Any              =						np.array([0.0447, 0.0492, 0.0468, 0.0408, 0.0383, 0.0408, 0.0354, 0.0380, 0.0339] )

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







						def 			SCREAMING_SNAKE_CASE__		(	self      :			Tuple )      ->				Union[str, Any]:
									A							:					Tuple              =						StableDiffusionKDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1-base" )
									A							:					Any              =						sd_pipe.to(__lowerCamelCase )
									sd_pipe.set_progress_bar_config(disable=__lowerCamelCase )

									sd_pipe.set_scheduler("sample_euler" )

									A							:					Dict              =						"A painting of a squirrel eating a burger"
									A							:					Any              =						torch.manual_seed(0 )
									A							:					Optional[int]              =						sd_pipe([prompt]	,	generator=__lowerCamelCase	,	guidance_scale=9.0	,	num_inference_steps=20	,	output_type="np" )

									A							:					List[Any]              =						output.images

									A							:					int              =						image[0, -3:, -3:, -1]

									assert image.shape == (1, 5_12, 5_12, 3)
									A							:					Optional[int]              =						np.array([0.1237, 0.1320, 0.1438, 0.1359, 0.1390, 0.1132, 0.1277, 0.1175, 0.1112] )

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







						def 			SCREAMING_SNAKE_CASE__		(	self      :			Tuple )      ->				Optional[int]:
									A							:					int              =						StableDiffusionKDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1-base" )
									A							:					List[str]              =						sd_pipe.to(__lowerCamelCase )
									sd_pipe.set_progress_bar_config(disable=__lowerCamelCase )

									sd_pipe.set_scheduler("sample_dpmpp_2m" )

									A							:					str              =						"A painting of a squirrel eating a burger"
									A							:					str              =						torch.manual_seed(0 )
									A							:					Dict              =						sd_pipe(
									    [prompt]	,	generator=__lowerCamelCase	,	guidance_scale=7.5	,	num_inference_steps=15	,	output_type="np"	,	use_karras_sigmas=__lowerCamelCase	,	)

									A							:					str              =						output.images

									A							:					int              =						image[0, -3:, -3:, -1]

									assert image.shape == (1, 5_12, 5_12, 3)
									A							:					str              =						np.array(
									    [0.11381689, 0.12112921, 0.1389457, 0.12549606, 0.1244964, 0.10831517, 0.11562866, 0.10867816, 0.10499048] )

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




import os


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/check_doctest_list.py
__SCREAMING_SNAKE_CASE           =  """."""


if __name__ == "__main__":
							__SCREAMING_SNAKE_CASE           =  os.path.join(REPO_PATH, """utils/documentation_tests.txt""")
							__SCREAMING_SNAKE_CASE           =  []
							__SCREAMING_SNAKE_CASE           =  []
							with open(doctest_file_path) as fp:
														for line in fp:
																					__SCREAMING_SNAKE_CASE           =  line.strip()
																					__SCREAMING_SNAKE_CASE           =  os.path.join(REPO_PATH, line)
																					if not (os.path.isfile(path) or os.path.isdir(path)):
																												non_existent_paths.append(line)
																					all_paths.append(path)
							if len(non_existent_paths) > 0:
														__SCREAMING_SNAKE_CASE           =  """\n""".join(non_existent_paths)
														raise ValueError(F"""`utils/documentation_tests.txt` contains non-existent paths:\n{non_existent_paths}""")
							if all_paths != sorted(all_paths):
														raise ValueError("""Files in `utils/documentation_tests.txt` are not in alphabetical order.""")