


"""simple docstring"""
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      __A     (unittest.TestCase):





							'''simple docstring'''

							def 		lowerCAmelCase       (				self							:      Tuple       )					->Dict:



														"""simple docstring"""



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



							def 		lowerCAmelCase       (				self							:      List[Any]       )					->Dict:



														"""simple docstring"""



														snake_case_           =		StableDiffusionKDiffusionPipeline.from_pretrained("""CompVis/stable-diffusion-v1-4"""       )
														snake_case_           =		sd_pipe.to(__a       )
														sd_pipe.set_progress_bar_config(disable=__a       )

														sd_pipe.set_scheduler("""sample_euler"""       )

														snake_case_           =		'A painting of a squirrel eating a burger'
														snake_case_           =		torch.manual_seed(0       )
														snake_case_           =		sd_pipe([prompt]		,       generator=__a		,       guidance_scale=9.0		,       num_inference_steps=20		,       output_type="""np"""       )

														snake_case_           =		output.images

														snake_case_           =		image[0, -3:, -3:, -1]

														assert image.shape == (1, 512, 512, 3)
														snake_case_           =		np.array([0.0_447, 0.0_492, 0.0_468, 0.0_408, 0.0_383, 0.0_408, 0.0_354, 0.0_380, 0.0_339]       )

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



							def 		lowerCAmelCase       (				self							:      Optional[int]       )					->List[Any]:



														"""simple docstring"""



														snake_case_           =		StableDiffusionKDiffusionPipeline.from_pretrained("""stabilityai/stable-diffusion-2-1-base"""       )
														snake_case_           =		sd_pipe.to(__a       )
														sd_pipe.set_progress_bar_config(disable=__a       )

														sd_pipe.set_scheduler("""sample_euler"""       )

														snake_case_           =		'A painting of a squirrel eating a burger'
														snake_case_           =		torch.manual_seed(0       )
														snake_case_           =		sd_pipe([prompt]		,       generator=__a		,       guidance_scale=9.0		,       num_inference_steps=20		,       output_type="""np"""       )

														snake_case_           =		output.images

														snake_case_           =		image[0, -3:, -3:, -1]

														assert image.shape == (1, 512, 512, 3)
														snake_case_           =		np.array([0.1_237, 0.1_320, 0.1_438, 0.1_359, 0.1_390, 0.1_132, 0.1_277, 0.1_175, 0.1_112]       )

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



							def 		lowerCAmelCase       (				self							:      int       )					->List[Any]:



														"""simple docstring"""



														snake_case_           =		StableDiffusionKDiffusionPipeline.from_pretrained("""stabilityai/stable-diffusion-2-1-base"""       )
														snake_case_           =		sd_pipe.to(__a       )
														sd_pipe.set_progress_bar_config(disable=__a       )

														sd_pipe.set_scheduler("""sample_dpmpp_2m"""       )

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

														snake_case_           =		output.images

														snake_case_           =		image[0, -3:, -3:, -1]

														assert image.shape == (1, 512, 512, 3)
														snake_case_           =		np.array(
														    [0.11_381_689, 0.12_112_921, 0.1_389_457, 0.12_549_606, 0.1_244_964, 0.10_831_517, 0.11_562_866, 0.10_867_816, 0.10_499_048]       )

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







"""simple docstring"""
__SCREAMING_SNAKE_CASE							:    str		=    'Input must be a string of 8 numbers plus letter'
__SCREAMING_SNAKE_CASE							:    Dict		=    'TRWAGMYFPDXBNJZSQVHLCKE'







def 						_a				(      _SCREAMING_SNAKE_CASE				)    ->				bool:

							if not isinstance(_SCREAMING_SNAKE_CASE				, _SCREAMING_SNAKE_CASE				):
														snake_case_           =		f"""Expected string as input, found {type(_SCREAMING_SNAKE_CASE				).__name__}"""
														raise TypeError(_SCREAMING_SNAKE_CASE				)

							snake_case_           =		spanish_id.replace("""-"""				, """"""				).upper()
							if len(_SCREAMING_SNAKE_CASE				) != 9:
														raise ValueError(_SCREAMING_SNAKE_CASE				)

							try:
														snake_case_           =		int(spanish_id_clean[0:8]				)
														snake_case_           =		spanish_id_clean[8]
							except ValueError as ex:
														raise ValueError(_SCREAMING_SNAKE_CASE				) from ex

							if letter.isdigit():
														raise ValueError(_SCREAMING_SNAKE_CASE				)

							return letter == LOOKUP_LETTERS[number % 23]


if __name__ == "__main__":
				import doctest

				doctest.testmod()



