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






					def 	_snake_case    (   self		):


											"""simple docstring"""





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






					def 	_snake_case    (   self		):


											"""simple docstring"""





											lowercase_	:     str													=       StableDiffusionKDiffusionPipeline.from_pretrained('''CompVis/stable-diffusion-v1-4'''		)
											lowercase_	:     int													=       sd_pipe.to(__SCREAMING_SNAKE_CASE		)
											sd_pipe.set_progress_bar_config(disable=__SCREAMING_SNAKE_CASE		)

											sd_pipe.set_scheduler('''sample_euler'''		)

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

											lowercase_	:     str													=       output.images

											lowercase_	:     str													=       image[0, -3:, -3:, -1]

											assert image.shape == (1, 5_12, 5_12, 3)
											lowercase_	:     str													=       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 	_snake_case    (   self		):


											"""simple docstring"""





											lowercase_	:     Any													=       StableDiffusionKDiffusionPipeline.from_pretrained('''stabilityai/stable-diffusion-2-1-base'''		)
											lowercase_	:     Optional[int]													=       sd_pipe.to(__SCREAMING_SNAKE_CASE		)
											sd_pipe.set_progress_bar_config(disable=__SCREAMING_SNAKE_CASE		)

											sd_pipe.set_scheduler('''sample_euler'''		)

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

											lowercase_	:     Any													=       output.images

											lowercase_	:     List[Any]													=       image[0, -3:, -3:, -1]

											assert image.shape == (1, 5_12, 5_12, 3)
											lowercase_	:     str													=       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 	_snake_case    (   self		):


											"""simple docstring"""





											lowercase_	:     str													=       StableDiffusionKDiffusionPipeline.from_pretrained('''stabilityai/stable-diffusion-2-1-base'''		)
											lowercase_	:     Optional[Any]													=       sd_pipe.to(__SCREAMING_SNAKE_CASE		)
											sd_pipe.set_progress_bar_config(disable=__SCREAMING_SNAKE_CASE		)

											sd_pipe.set_scheduler('''sample_dpmpp_2m'''		)

											lowercase_	:     List[Any]													=       '''A painting of a squirrel eating a burger'''
											lowercase_	:     int													=       torch.manual_seed(0		)
											lowercase_	:     Dict													=       sd_pipe(
											    [prompt]				,							generator=__SCREAMING_SNAKE_CASE				,							guidance_scale=7.5				,							num_inference_steps=15				,							output_type='''np'''				,							use_karras_sigmas=__SCREAMING_SNAKE_CASE				,							)

											lowercase_	:     Union[str, Any]													=       output.images

											lowercase_	:     List[Any]													=       image[0, -3:, -3:, -1]

											assert image.shape == (1, 5_12, 5_12, 3)
											lowercase_	:     Optional[int]													=       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'''







def 					snake_case_		(				__SCREAMING_SNAKE_CASE					: int							):



						"""simple docstring"""





						lowercase_	:     Optional[int]													=       int(__SCREAMING_SNAKE_CASE							)
						if decimal in (0, 1):  # Exit cases for the recursion
												return str(__SCREAMING_SNAKE_CASE							)
						lowercase_						, lowercase_	:     List[str]													=       divmod(__SCREAMING_SNAKE_CASE      ,      2							)
						return binary_recursive(__SCREAMING_SNAKE_CASE							) + str(__SCREAMING_SNAKE_CASE							)
def 					snake_case_		(				__SCREAMING_SNAKE_CASE					: str							):



						"""simple docstring"""





						lowercase_	:     str													=       str(__SCREAMING_SNAKE_CASE							).strip()
						if not number:
												raise ValueError('''No input value was provided'''							)
						lowercase_	:     Optional[int]													=       '''-''' if number.startswith('''-'''							) else ''''''
						lowercase_	:     Union[str, Any]													=       number.lstrip('''-'''							)
						if not number.isnumeric():
												raise ValueError('''Input value is not an integer'''							)
						return F'''{negative}0b{binary_recursive(int(__SCREAMING_SNAKE_CASE							)							)}'''


if __name__ == "__main__":
							from doctest import testmod

							testmod()



