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


						def 			__A			(			self      :							Optional[Any]		):





												'''simple docstring'''





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


						def 			__A			(			self      :							str		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE				:       Tuple     							=				StableDiffusionKDiffusionPipeline.from_pretrained('''CompVis/stable-diffusion-v1-4'''		)
												SCREAMING_SNAKE_CASE				:       List[Any]     							=				sd_pipe.to(_lowercase		)
												sd_pipe.set_progress_bar_config(disable=_lowercase		)

												sd_pipe.set_scheduler('''sample_euler'''		)

												SCREAMING_SNAKE_CASE				:       Any     							=				'''A painting of a squirrel eating a burger'''
												SCREAMING_SNAKE_CASE				:       Dict     							=				torch.manual_seed(0		)
												SCREAMING_SNAKE_CASE				:       Any     							=				sd_pipe([prompt]       ,						generator=_lowercase       ,						guidance_scale=9.0       ,						num_inference_steps=20       ,						output_type='''np'''		)

												SCREAMING_SNAKE_CASE				:       Dict     							=				output.images

												SCREAMING_SNAKE_CASE				:       Optional[int]     							=				image[0, -3:, -3:, -1]

												assert image.shape == (1, 512, 512, 3)
												SCREAMING_SNAKE_CASE				:       str     							=				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 			__A			(			self      :							Union[str, Any]		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE				:       Optional[Any]     							=				StableDiffusionKDiffusionPipeline.from_pretrained('''stabilityai/stable-diffusion-2-1-base'''		)
												SCREAMING_SNAKE_CASE				:       int     							=				sd_pipe.to(_lowercase		)
												sd_pipe.set_progress_bar_config(disable=_lowercase		)

												sd_pipe.set_scheduler('''sample_euler'''		)

												SCREAMING_SNAKE_CASE				:       str     							=				'''A painting of a squirrel eating a burger'''
												SCREAMING_SNAKE_CASE				:       Any     							=				torch.manual_seed(0		)
												SCREAMING_SNAKE_CASE				:       Any     							=				sd_pipe([prompt]       ,						generator=_lowercase       ,						guidance_scale=9.0       ,						num_inference_steps=20       ,						output_type='''np'''		)

												SCREAMING_SNAKE_CASE				:       Optional[Any]     							=				output.images

												SCREAMING_SNAKE_CASE				:       str     							=				image[0, -3:, -3:, -1]

												assert image.shape == (1, 512, 512, 3)
												SCREAMING_SNAKE_CASE				:       List[str]     							=				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 			__A			(			self      :							Dict		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE				:       List[str]     							=				StableDiffusionKDiffusionPipeline.from_pretrained('''stabilityai/stable-diffusion-2-1-base'''		)
												SCREAMING_SNAKE_CASE				:       Optional[Any]     							=				sd_pipe.to(_lowercase		)
												sd_pipe.set_progress_bar_config(disable=_lowercase		)

												sd_pipe.set_scheduler('''sample_dpmpp_2m'''		)

												SCREAMING_SNAKE_CASE				:       List[Any]     							=				'''A painting of a squirrel eating a burger'''
												SCREAMING_SNAKE_CASE				:       Optional[int]     							=				torch.manual_seed(0		)
												SCREAMING_SNAKE_CASE				:       Dict     							=				sd_pipe(
												    [prompt]       ,						generator=_lowercase       ,						guidance_scale=7.5       ,						num_inference_steps=15       ,						output_type='''np'''       ,						use_karras_sigmas=_lowercase       ,						)

												SCREAMING_SNAKE_CASE				:       Union[str, Any]     							=				output.images

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

												assert image.shape == (1, 512, 512, 3)
												SCREAMING_SNAKE_CASE				:       Dict     							=				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






import random




def    lowerCAmelCase_  (		lowercase:				int	,       lowercase:				float	,       lowercase:				bool = False		)     ->					dict:







 '''simple docstring'''
 _UpperCamelCase:  dict    						=			{i: [] for i in range(lowercase		)}

 # if probability is greater or equal than 1, then generate a complete graph
 if probability >= 1:
  return complete_graph(lowercase		)
 # if probability is lower or equal than 0, then return a graph without edges
 if probability <= 0:
  return graph

 # for each couple of nodes, add an edge from u to v
 # if the number randomly generated is greater than probability probability
 for i in range(lowercase		):
  for j in range(i + 1	,       lowercase		):
   if random.random() < probability:
    graph[i].append(lowercase		)
    if not directed:
     # if the graph is undirected, add an edge in from j to i, either
     graph[j].append(lowercase		)
 return graph




def    lowerCAmelCase_  (		lowercase:				int		)     ->					dict:







 '''simple docstring'''
 return {
     i: [j for j in range(lowercase		) if i != j] for i in range(lowercase		)
 }


if __name__ == "__main__":
  import doctest

  doctest.testmod()