






import unittest

import numpy as np
import torch

from diffusers import KarrasVePipeline, KarrasVeScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()


class 					_snake_case						(			unittest.TestCase ):






	@property
	def    lowerCAmelCase_							(		self       )						->    Optional[int]:
					torch.manual_seed(0       )
					snake_case__      :int         =   UNetaDModel(
					    block_out_channels=(32, 64)					,layers_per_block=2					,sample_size=32					,in_channels=3					,out_channels=3					,down_block_types=("DownBlock2D", "AttnDownBlock2D")					,up_block_types=("AttnUpBlock2D", "UpBlock2D")					,)
					return model






	def    lowerCAmelCase_							(		self       )						->    int:
					snake_case__      :List[Any]         =   self.dummy_uncond_unet
					snake_case__      :Optional[Any]         =   KarrasVeScheduler()

					snake_case__      :Any         =   KarrasVePipeline(unet=UpperCamelCase					,scheduler=UpperCamelCase       )
					pipe.to(UpperCamelCase       )
					pipe.set_progress_bar_config(disable=UpperCamelCase       )

					snake_case__      :str         =   torch.manual_seed(0       )
					snake_case__      :Dict         =   pipe(num_inference_steps=2					,generator=UpperCamelCase					,output_type="numpy"       ).images

					snake_case__      :str         =   torch.manual_seed(0       )
					snake_case__      :Union[str, Any]         =   pipe(num_inference_steps=2					,generator=UpperCamelCase					,output_type="numpy"					,return_dict=UpperCamelCase       )[0]

					snake_case__      :List[Any]         =   image[0, -3:, -3:, -1]
					snake_case__      :Dict         =   image_from_tuple[0, -3:, -3:, -1]

					assert image.shape == (1, 32, 32, 3)
					snake_case__      :List[Any]         =   np.array([0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]       )

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




@slow
@require_torch
class 					_snake_case						(			unittest.TestCase ):






	def    lowerCAmelCase_							(		self       )						->    List[Any]:
					snake_case__      :int         =   "google/ncsnpp-celebahq-256"
					snake_case__      :int         =   UNetaDModel.from_pretrained(UpperCamelCase       )
					snake_case__      :Tuple         =   KarrasVeScheduler()

					snake_case__      :str         =   KarrasVePipeline(unet=UpperCamelCase					,scheduler=UpperCamelCase       )
					pipe.to(UpperCamelCase       )
					pipe.set_progress_bar_config(disable=UpperCamelCase       )

					snake_case__      :Optional[Any]         =   torch.manual_seed(0       )
					snake_case__      :Any         =   pipe(num_inference_steps=20					,generator=UpperCamelCase					,output_type="numpy"       ).images

					snake_case__      :str         =   image[0, -3:, -3:, -1]
					assert image.shape == (1, 256, 256, 3)
					snake_case__      :str         =   np.array([0.578, 0.5811, 0.5924, 0.5809, 0.587, 0.5886, 0.5861, 0.5802, 0.586]       )

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







from ...utils import (
    OptionalDependencyNotAvailable,
    is_flax_available,
    is_torch_available,
    is_transformers_available,
)


try:
	if not (is_transformers_available() and is_torch_available()):
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	from ...utils.dummy_torch_and_transformers_objects import *  # noqa F403
else:
	from .multicontrolnet import MultiControlNetModel
	from .pipeline_controlnet import StableDiffusionControlNetPipeline
	from .pipeline_controlnet_imgaimg import StableDiffusionControlNetImgaImgPipeline
	from .pipeline_controlnet_inpaint import StableDiffusionControlNetInpaintPipeline


if is_transformers_available() and is_flax_available():
	from .pipeline_flax_controlnet import FlaxStableDiffusionControlNetPipeline