




'''simple docstring'''


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







							@property
							def      __lowerCAmelCase    (						self :						Any      )    ->							Optional[int]:


														"""simple docstring"""


														torch.manual_seed(0      )
														_a			  =       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 :						Tuple      )    ->							List[Any]:


														"""simple docstring"""


														_a			  =       self.dummy_uncond_unet
														_a			  =       KarrasVeScheduler()

														_a			  =       KarrasVePipeline(unet=lowerCAmelCase_							,    scheduler=lowerCAmelCase_      )
														pipe.to(lowerCAmelCase_      )
														pipe.set_progress_bar_config(disable=lowerCAmelCase_      )

														_a			  =       torch.manual_seed(0      )
														_a			  =       pipe(num_inference_steps=2							,    generator=lowerCAmelCase_							,    output_type='''numpy'''      ).images

														_a			  =       torch.manual_seed(0      )
														_a			  =       pipe(num_inference_steps=2							,    generator=lowerCAmelCase_							,    output_type='''numpy'''							,    return_dict=lowerCAmelCase_      )[0]

														_a			  =       image[0, -3:, -3:, -1]
														_a			  =       image_from_tuple[0, -3:, -3:, -1]

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







							def      __lowerCAmelCase    (						self :						Any      )    ->							Tuple:


														"""simple docstring"""


														_a			  =       '''google/ncsnpp-celebahq-256'''
														_a			  =       UNetaDModel.from_pretrained(lowerCAmelCase_      )
														_a			  =       KarrasVeScheduler()

														_a			  =       KarrasVePipeline(unet=lowerCAmelCase_							,    scheduler=lowerCAmelCase_      )
														pipe.to(lowerCAmelCase_      )
														pipe.set_progress_bar_config(disable=lowerCAmelCase_      )

														_a			  =       torch.manual_seed(0      )
														_a			  =       pipe(num_inference_steps=20							,    generator=lowerCAmelCase_							,    output_type='''numpy'''      ).images

														_a			  =       image[0, -3:, -3:, -1]
														assert image.shape == (1, 2_56, 2_56, 3)
														_a			  =       np.array([0.5_7_8, 0.5_8_1_1, 0.5_9_2_4, 0.5_8_0_9, 0.5_8_7, 0.5_8_8_6, 0.5_8_6_1, 0.5_8_0_2, 0.5_8_6]      )

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







'''simple docstring'''


import os
import sys
from contextlib import contextmanager


# Windows only
if os.name == "nt":
				import ctypes
				import msvcrt  # noqa

				class     A					(	ctypes.Structure					):
											# _fields is a specific attr expected by ctypes
											lowercase_           =       [('size', ctypes.c_int), ('visible', ctypes.c_byte)]
def 	snake_case_					():





							'''simple docstring'''


							if os.name == "nt":
														_a			  =       CursorInfo()
														_a			  =       ctypes.windll.kernelaa.GetStdHandle(-11   )
														ctypes.windll.kernelaa.GetConsoleCursorInfo(UpperCamelCase				,		ctypes.byref(UpperCamelCase   )   )
														_a			  =       False
														ctypes.windll.kernelaa.SetConsoleCursorInfo(UpperCamelCase				,		ctypes.byref(UpperCamelCase   )   )
							elif os.name == "posix":
														sys.stdout.write('''\033[?25l'''   )
														sys.stdout.flush()
def 	snake_case_					():





							'''simple docstring'''


							if os.name == "nt":
														_a			  =       CursorInfo()
														_a			  =       ctypes.windll.kernelaa.GetStdHandle(-11   )
														ctypes.windll.kernelaa.GetConsoleCursorInfo(UpperCamelCase				,		ctypes.byref(UpperCamelCase   )   )
														_a			  =       True
														ctypes.windll.kernelaa.SetConsoleCursorInfo(UpperCamelCase				,		ctypes.byref(UpperCamelCase   )   )
							elif os.name == "posix":
														sys.stdout.write('''\033[?25h'''   )
														sys.stdout.flush()

@contextmanager
def 	snake_case_					():





							'''simple docstring'''


							try:
														hide_cursor()
														yield
							finally:
														show_cursor()

