




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







						'''simple docstring'''





						def 			snake_case__		(		self				:	Optional[int]		):






							"""simple docstring"""






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






						def 			snake_case__		(		self				:	Union[str, Any]		):






							"""simple docstring"""






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

							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=__lowercase			,      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, 5_12, 5_12, 3)
							snake_case_						       =	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 			snake_case__		(		self				:	Union[str, Any]		):






							"""simple docstring"""






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

							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=__lowercase			,      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, 5_12, 5_12, 3)
							snake_case_						       =	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 			snake_case__		(		self				:	int		):






							"""simple docstring"""






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

							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=__lowercase			,      guidance_scale=7.5			,      num_inference_steps=15			,      output_type="np"			,      use_karras_sigmas=__lowercase			,      )

							snake_case_						       =	output.images

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

							assert image.shape == (1, 5_12, 5_12, 3)
							snake_case_						       =	np.array(
							    [0.1138_1689, 0.1211_2921, 0.138_9457, 0.1254_9606, 0.124_4964, 0.1083_1517, 0.1156_2866, 0.1086_7816, 0.1049_9048]		)

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






from typing import TYPE_CHECKING

from ...file_utils import _LazyModule, is_tokenizers_available, is_torch_available, is_vision_available
from ...utils import OptionalDependencyNotAvailable


lowercase__							:	Union[str, Any]											=		{"configuration_dpt": ["DPT_PRETRAINED_CONFIG_ARCHIVE_MAP", "DPTConfig"]}

try:
		if not is_vision_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		lowercase__							:	Tuple											=		["DPTFeatureExtractor"]
		lowercase__							:	Optional[Any]											=		["DPTImageProcessor"]

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		lowercase__							:	Dict											=		[
		    "DPT_PRETRAINED_MODEL_ARCHIVE_LIST",
		    "DPTForDepthEstimation",
		    "DPTForSemanticSegmentation",
		    "DPTModel",
		    "DPTPreTrainedModel",
		]


if TYPE_CHECKING:
		from .configuration_dpt import DPT_PRETRAINED_CONFIG_ARCHIVE_MAP, DPTConfig

		try:
				if not is_vision_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .feature_extraction_dpt import DPTFeatureExtractor
				from .image_processing_dpt import DPTImageProcessor

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_dpt import (
				    DPT_PRETRAINED_MODEL_ARCHIVE_LIST,
				    DPTForDepthEstimation,
				    DPTForSemanticSegmentation,
				    DPTModel,
				    DPTPreTrainedModel,
				)


else:
		import sys

		lowercase__							:	List[Any]											=		_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)
