




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



				def       SCREAMING_SNAKE_CASE       (      self      :		str      )  ->    Union[str, Any]:





								'''simple docstring'''




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



				def       SCREAMING_SNAKE_CASE       (      self      :		str      )  ->    List[Any]:





								'''simple docstring'''




								_lowerCAmelCase    :    Any										=      StableDiffusionKDiffusionPipeline.from_pretrained("""CompVis/stable-diffusion-v1-4"""      )
								_lowerCAmelCase    :    Union[str, Any]										=      sd_pipe.to(_UpperCAmelCase      )
								sd_pipe.set_progress_bar_config(disable=_UpperCAmelCase      )

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

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

								_lowerCAmelCase    :    List[str]										=      output.images

								_lowerCAmelCase    :    List[str]										=      image[0, -3:, -3:, -1]

								assert image.shape == (1, 512, 512, 3)
								_lowerCAmelCase    :    List[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      :		str      )  ->    List[Any]:





								'''simple docstring'''




								_lowerCAmelCase    :    List[Any]										=      StableDiffusionKDiffusionPipeline.from_pretrained("""stabilityai/stable-diffusion-2-1-base"""      )
								_lowerCAmelCase    :    str										=      sd_pipe.to(_UpperCAmelCase      )
								sd_pipe.set_progress_bar_config(disable=_UpperCAmelCase      )

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

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

								_lowerCAmelCase    :    Tuple										=      output.images

								_lowerCAmelCase    :    Any										=      image[0, -3:, -3:, -1]

								assert image.shape == (1, 512, 512, 3)
								_lowerCAmelCase    :    str										=      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      :		List[Any]      )  ->    List[str]:





								'''simple docstring'''




								_lowerCAmelCase    :    List[Any]										=      StableDiffusionKDiffusionPipeline.from_pretrained("""stabilityai/stable-diffusion-2-1-base"""      )
								_lowerCAmelCase    :    List[Any]										=      sd_pipe.to(_UpperCAmelCase      )
								sd_pipe.set_progress_bar_config(disable=_UpperCAmelCase      )

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

								_lowerCAmelCase    :    Union[str, Any]										=      """A painting of a squirrel eating a burger"""
								_lowerCAmelCase    :    List[Any]										=      torch.manual_seed(0      )
								_lowerCAmelCase    :    int										=      sd_pipe(
								    [prompt]		,	generator=_UpperCAmelCase		,	guidance_scale=7.5		,	num_inference_steps=15		,	output_type="""np"""		,	use_karras_sigmas=_UpperCAmelCase		,	)

								_lowerCAmelCase    :    str										=      output.images

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

								assert image.shape == (1, 512, 512, 3)
								_lowerCAmelCase    :    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











def 							_UpperCAmelCase  (UpperCamelCase_ : str      ,    UpperCamelCase_ : bool = False       ):
				'''simple docstring'''

				if not isinstance(UpperCamelCase_      ,    UpperCamelCase_       ):
								_lowerCAmelCase    :    Tuple										=      F"Expected string as input, found {type(UpperCamelCase_       )}"
								raise ValueError(UpperCamelCase_       )
				if not isinstance(UpperCamelCase_      ,    UpperCamelCase_       ):
								_lowerCAmelCase    :    Optional[Any]										=      F"Expected boolean as use_pascal parameter, found {type(UpperCamelCase_       )}"
								raise ValueError(UpperCamelCase_       )

				_lowerCAmelCase    :    Any										=      input_str.split("""_"""       )

				_lowerCAmelCase    :    str										=      0 if use_pascal else 1

				_lowerCAmelCase    :    Any										=      words[start_index:]

				_lowerCAmelCase    :    List[str]										=      [word[0].upper() + word[1:] for word in words_to_capitalize]

				_lowerCAmelCase    :    Any										=      """""" if use_pascal else words[0]

				return "".join([initial_word, *capitalized_words]       )


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

	testmod()

