


"""simple docstring"""






import unittest

import numpy as np
import torch

from diffusers import DDPMPipeline, DDPMScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu, slow, torch_device


enable_full_determinism()






class     A(     unittest.TestCase		):

		"""simple docstring"""





		@property
		def      _UpperCamelCase(   self      )			->  List[str]:

					"""simple docstring"""



					torch.manual_seed(0      )
					_UpperCamelCase				:Union[str, Any]				    =  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      _UpperCamelCase(   self      )			->  Any:

					"""simple docstring"""



					_UpperCamelCase				:List[Any]				    =  '''cpu'''
					_UpperCamelCase				:List[str]				    =  self.dummy_uncond_unet
					_UpperCamelCase				:Union[str, Any]				    =  DDPMScheduler()

					_UpperCamelCase				:List[Any]				    =  DDPMPipeline(unet=SCREAMING_SNAKE_CASE__				,							scheduler=SCREAMING_SNAKE_CASE__      )
					ddpm.to(SCREAMING_SNAKE_CASE__      )
					ddpm.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE__      )

					_UpperCamelCase				:int				    =  torch.Generator(device=SCREAMING_SNAKE_CASE__      ).manual_seed(0      )
					_UpperCamelCase				:Optional[int]				    =  ddpm(generator=SCREAMING_SNAKE_CASE__				,							num_inference_steps=2				,							output_type='''numpy'''      ).images

					_UpperCamelCase				:Optional[int]				    =  torch.Generator(device=SCREAMING_SNAKE_CASE__      ).manual_seed(0      )
					_UpperCamelCase				:List[Any]				    =  ddpm(generator=SCREAMING_SNAKE_CASE__				,							num_inference_steps=2				,							output_type='''numpy'''				,							return_dict=SCREAMING_SNAKE_CASE__      )[0]

					_UpperCamelCase				:Optional[int]				    =  image[0, -3:, -3:, -1]
					_UpperCamelCase				:List[str]				    =  image_from_tuple[0, -3:, -3:, -1]

					assert image.shape == (1, 32, 32, 3)
					_UpperCamelCase				:Union[str, Any]				    =  np.array(
					    [9.956E-01, 5.785E-01, 4.675E-01, 9.930E-01, 0.0, 1.0_0_0, 1.199E-03, 2.648E-04, 5.101E-04]      )

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





		def      _UpperCamelCase(   self      )			->  List[str]:

					"""simple docstring"""



					_UpperCamelCase				:str				    =  self.dummy_uncond_unet
					_UpperCamelCase				:str				    =  DDPMScheduler(prediction_type='''sample'''      )

					_UpperCamelCase				:str				    =  DDPMPipeline(unet=SCREAMING_SNAKE_CASE__				,							scheduler=SCREAMING_SNAKE_CASE__      )
					ddpm.to(SCREAMING_SNAKE_CASE__      )
					ddpm.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE__      )

					_UpperCamelCase				:List[Any]				    =  torch.manual_seed(0      )
					_UpperCamelCase				:Union[str, Any]				    =  ddpm(generator=SCREAMING_SNAKE_CASE__				,							num_inference_steps=2				,							output_type='''numpy'''      ).images

					_UpperCamelCase				:int				    =  torch.manual_seed(0      )
					_UpperCamelCase				:Tuple				    =  ddpm(generator=SCREAMING_SNAKE_CASE__				,							num_inference_steps=2				,							output_type='''numpy'''      )[0]

					_UpperCamelCase				:Tuple				    =  image[0, -3:, -3:, -1]
					_UpperCamelCase				:int				    =  image_eps[0, -3:, -3:, -1]

					assert image.shape == (1, 32, 32, 3)
					_UpperCamelCase				:str				    =  1E-2 if torch_device != '''mps''' else 3E-2
					assert np.abs(image_slice.flatten() - image_eps_slice.flatten()      ).max() < tolerance






@slow
@require_torch_gpu
class     A(     unittest.TestCase		):

		"""simple docstring"""





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

					"""simple docstring"""



					_UpperCamelCase				:int				    =  '''google/ddpm-cifar10-32'''

					_UpperCamelCase				:str				    =  UNetaDModel.from_pretrained(SCREAMING_SNAKE_CASE__      )
					_UpperCamelCase				:int				    =  DDPMScheduler.from_pretrained(SCREAMING_SNAKE_CASE__      )

					_UpperCamelCase				:Any				    =  DDPMPipeline(unet=SCREAMING_SNAKE_CASE__				,							scheduler=SCREAMING_SNAKE_CASE__      )
					ddpm.to(SCREAMING_SNAKE_CASE__      )
					ddpm.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE__      )

					_UpperCamelCase				:int				    =  torch.manual_seed(0      )
					_UpperCamelCase				:Any				    =  ddpm(generator=SCREAMING_SNAKE_CASE__				,							output_type='''numpy'''      ).images

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

					assert image.shape == (1, 32, 32, 3)
					_UpperCamelCase				:Optional[int]				    =  np.array([0.4_2_0_0, 0.3_5_8_8, 0.1_9_3_9, 0.3_8_4_7, 0.3_3_8_2, 0.2_6_4_7, 0.4_1_5_5, 0.3_5_8_2, 0.3_3_8_5]      )
					assert np.abs(image_slice.flatten() - expected_slice      ).max() < 1E-2





"""simple docstring"""






from dataclasses import dataclass
from typing import List, Optional, Union

import numpy as np
import PIL

from ...utils import BaseOutput, is_invisible_watermark_available, is_torch_available, is_transformers_available






@dataclass
class     A(     lowerCamelCase__		):

		"""simple docstring"""





		A         =       42


if is_transformers_available() and is_torch_available() and is_invisible_watermark_available():
					from .pipeline_stable_diffusion_xl import StableDiffusionXLPipeline
					from .pipeline_stable_diffusion_xl_imgaimg import StableDiffusionXLImgaImgPipeline

