






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




					@property
					def 						A     (       self       :						Optional[int]     )  ->    Optional[Any]:
								torch.manual_seed(0     )
								UpperCAmelCase_     :   str       =   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 						A     (       self       :						str     )  ->    Optional[int]:
								UpperCAmelCase_     :   int       =   '''cpu'''
								UpperCAmelCase_     :   List[Any]       =   self.dummy_uncond_unet
								UpperCAmelCase_     :   List[Any]       =   DDPMScheduler()

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

								UpperCAmelCase_     :   Dict       =   torch.Generator(device=_A     ).manual_seed(0     )
								UpperCAmelCase_     :   List[Any]       =   ddpm(generator=_A							,				num_inference_steps=2							,				output_type='''numpy'''     ).images

								UpperCAmelCase_     :   List[Any]       =   torch.Generator(device=_A     ).manual_seed(0     )
								UpperCAmelCase_     :   List[Any]       =   ddpm(generator=_A							,				num_inference_steps=2							,				output_type='''numpy'''							,				return_dict=_A     )[0]

								UpperCAmelCase_     :   Union[str, Any]       =   image[0, -3:, -3:, -1]
								UpperCAmelCase_     :   Any       =   image_from_tuple[0, -3:, -3:, -1]

								assert image.shape == (1, 32, 32, 3)
								UpperCAmelCase_     :   Dict       =   np.array(
								    [9.956e-01, 5.785e-01, 4.675e-01, 9.930e-01, 0.0, 1.000, 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 						A     (       self       :						List[Any]     )  ->    Any:
								UpperCAmelCase_     :   Union[str, Any]       =   self.dummy_uncond_unet
								UpperCAmelCase_     :   Tuple       =   DDPMScheduler(prediction_type='''sample'''     )

								UpperCAmelCase_     :   int       =   DDPMPipeline(unet=_A							,				scheduler=_A     )
								ddpm.to(_A     )
								ddpm.set_progress_bar_config(disable=_A     )

								UpperCAmelCase_     :   int       =   torch.manual_seed(0     )
								UpperCAmelCase_     :   int       =   ddpm(generator=_A							,				num_inference_steps=2							,				output_type='''numpy'''     ).images

								UpperCAmelCase_     :   int       =   torch.manual_seed(0     )
								UpperCAmelCase_     :   List[Any]       =   ddpm(generator=_A							,				num_inference_steps=2							,				output_type='''numpy'''     )[0]

								UpperCAmelCase_     :   Dict       =   image[0, -3:, -3:, -1]
								UpperCAmelCase_     :   List[Any]       =   image_eps[0, -3:, -3:, -1]

								assert image.shape == (1, 32, 32, 3)
								UpperCAmelCase_     :   Tuple       =   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 				snake_case__     (			unittest.TestCase):




					def 						A     (       self       :						Optional[int]     )  ->    Dict:
								UpperCAmelCase_     :   int       =   '''google/ddpm-cifar10-32'''

								UpperCAmelCase_     :   int       =   UNetaDModel.from_pretrained(_A     )
								UpperCAmelCase_     :   List[str]       =   DDPMScheduler.from_pretrained(_A     )

								UpperCAmelCase_     :   Optional[Any]       =   DDPMPipeline(unet=_A							,				scheduler=_A     )
								ddpm.to(_A     )
								ddpm.set_progress_bar_config(disable=_A     )

								UpperCAmelCase_     :   str       =   torch.manual_seed(0     )
								UpperCAmelCase_     :   Optional[Any]       =   ddpm(generator=_A							,				output_type='''numpy'''     ).images

								UpperCAmelCase_     :   List[Any]       =   image[0, -3:, -3:, -1]

								assert image.shape == (1, 32, 32, 3)
								UpperCAmelCase_     :   int       =   np.array([0.4_200, 0.3_588, 0.1_939, 0.3_847, 0.3_382, 0.2_647, 0.4_155, 0.3_582, 0.3_385]     )
								assert np.abs(image_slice.flatten() - expected_slice     ).max() < 1e-2










'''simple docstring'''





import unittest

import torch

from diffusers import DDIMScheduler, TextToVideoZeroPipeline
from diffusers.utils import load_pt, require_torch_gpu, slow

from ..test_pipelines_common import assert_mean_pixel_difference


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




					def 						A     (       self       :						Optional[Any]     )  ->    List[str]:
								UpperCAmelCase_     :   Optional[Any]       =   '''runwayml/stable-diffusion-v1-5'''
								UpperCAmelCase_     :   Optional[int]       =   TextToVideoZeroPipeline.from_pretrained(_A							,				torch_dtype=torch.floataa     ).to('''cuda'''     )
								UpperCAmelCase_     :   Tuple       =   DDIMScheduler.from_config(pipe.scheduler.config     )
								UpperCAmelCase_     :   Tuple       =   torch.Generator(device='''cuda'''     ).manual_seed(0     )

								UpperCAmelCase_     :   List[Any]       =   '''A bear is playing a guitar on Times Square'''
								UpperCAmelCase_     :   List[Any]       =   pipe(prompt=_A							,				generator=_A     ).images

								UpperCAmelCase_     :   Any       =   load_pt(
								    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/text-to-video/A bear is playing a guitar on Times Square.pt'''     )

								assert_mean_pixel_difference(_A							,				_A     )


