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

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

			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      Dict     =		StableDiffusionKDiffusionPipeline.from_pretrained('''CompVis/stable-diffusion-v1-4'''      )
								lowerCamelCase_					:      Dict     =		sd_pipe.to(A      )
								sd_pipe.set_progress_bar_config(disable=A      )

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

								lowerCamelCase_					:      Tuple     =		'''A painting of a squirrel eating a burger'''
								lowerCamelCase_					:      Tuple     =		torch.manual_seed(0      )
								lowerCamelCase_					:      Tuple     =		sd_pipe([prompt]			,   generator=A			,   guidance_scale=9.0			,   num_inference_steps=2_0			,   output_type='''np'''      )

								lowerCamelCase_					:      Dict     =		output.images

								lowerCamelCase_					:      Dict     =		image[0, -3:, -3:, -1]

								assert image.shape == (1, 5_1_2, 5_1_2, 3)
								lowerCamelCase_					:      Tuple     =		np.array([0.04_47, 0.04_92, 0.04_68, 0.04_08, 0.03_83, 0.04_08, 0.03_54, 0.03_80, 0.03_39]      )

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

			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      Tuple     =		StableDiffusionKDiffusionPipeline.from_pretrained('''stabilityai/stable-diffusion-2-1-base'''      )
								lowerCamelCase_					:      Optional[Any]     =		sd_pipe.to(A      )
								sd_pipe.set_progress_bar_config(disable=A      )

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

								lowerCamelCase_					:      Optional[int]     =		'''A painting of a squirrel eating a burger'''
								lowerCamelCase_					:      List[str]     =		torch.manual_seed(0      )
								lowerCamelCase_					:      str     =		sd_pipe([prompt]			,   generator=A			,   guidance_scale=9.0			,   num_inference_steps=2_0			,   output_type='''np'''      )

								lowerCamelCase_					:      Optional[Any]     =		output.images

								lowerCamelCase_					:      Tuple     =		image[0, -3:, -3:, -1]

								assert image.shape == (1, 5_1_2, 5_1_2, 3)
								lowerCamelCase_					:      Optional[Any]     =		np.array([0.12_37, 0.13_20, 0.14_38, 0.13_59, 0.13_90, 0.11_32, 0.12_77, 0.11_75, 0.11_12]      )

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






			def        UpperCAmelCase__ (self      ):
								lowerCamelCase_					:      Optional[int]     =		StableDiffusionKDiffusionPipeline.from_pretrained('''stabilityai/stable-diffusion-2-1-base'''      )
								lowerCamelCase_					:      int     =		sd_pipe.to(A      )
								sd_pipe.set_progress_bar_config(disable=A      )

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

								lowerCamelCase_					:      Union[str, Any]     =		'''A painting of a squirrel eating a burger'''
								lowerCamelCase_					:      Optional[Any]     =		torch.manual_seed(0      )
								lowerCamelCase_					:      Union[str, Any]     =		sd_pipe(
								    [prompt]			,   generator=A			,   guidance_scale=7.5			,   num_inference_steps=1_5			,   output_type='''np'''			,   use_karras_sigmas=A			,   )

								lowerCamelCase_					:      Optional[int]     =		output.images

								lowerCamelCase_					:      Tuple     =		image[0, -3:, -3:, -1]

								assert image.shape == (1, 5_1_2, 5_1_2, 3)
								lowerCamelCase_					:      Any     =		np.array(
								    [0.11_38_16_89, 0.12_11_29_21, 0.1_38_94_57, 0.12_54_96_06, 0.1_24_49_64, 0.10_83_15_17, 0.11_56_28_66, 0.10_86_78_16, 0.10_49_90_48]      )

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




'''simple docstring'''


def lowercase_	(   _lowercase			,       _lowercase				)     ->							Dict:
					'''simple docstring'''

					lowerCamelCase_					:      List[Any]     =		0
					while b > 0:
										if b & 1:
															res += a

										a += a
										b >>= 1

					return res




def lowercase_	(   _lowercase			,       _lowercase			,       _lowercase				)     ->							Optional[Any]:
					'''simple docstring'''

					lowerCamelCase_					:      str     =		0
					while b > 0:
										if b & 1:
															lowerCamelCase_					:      Optional[int]     =		((res % c) + (a % c)) % c

										a += a
										b >>= 1

					return res


