



"""simple docstring"""





import gc
import tempfile
import unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionTextToImagePipeline
from diffusers.utils.testing_utils import nightly, require_torch_gpu, torch_device


lowerCamelCase  			=		False
class  lowercase__  (       unittest.TestCase ):







       '''simple docstring'''


       pass



@nightly
@require_torch_gpu
class  lowercase__  (       unittest.TestCase ):







       '''simple docstring'''


       def 	lowercase__							(				self     :    Dict       )					->		Tuple:


             '''simple docstring'''




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



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


             '''simple docstring'''




             UpperCAmelCase_     					=				VersatileDiffusionTextToImagePipeline.from_pretrained("shi-labs/versatile-diffusion"       )
             # remove text_unet
             pipe.remove_unused_weights()
             pipe.to(_UpperCAmelCase       )
             pipe.set_progress_bar_config(disable=_UpperCAmelCase       )

             UpperCAmelCase_     					=				"A painting of a squirrel eating a burger "
             UpperCAmelCase_     					=				torch.manual_seed(0       )
             UpperCAmelCase_     					=				pipe(
                 prompt=_UpperCAmelCase						,							generator=_UpperCAmelCase						,							guidance_scale=7.5						,							num_inference_steps=2						,							output_type="numpy"       ).images

             with tempfile.TemporaryDirectory() as tmpdirname:
                   pipe.save_pretrained(_UpperCAmelCase       )
                   UpperCAmelCase_     					=				VersatileDiffusionTextToImagePipeline.from_pretrained(_UpperCAmelCase       )
             pipe.to(_UpperCAmelCase       )
             pipe.set_progress_bar_config(disable=_UpperCAmelCase       )

             UpperCAmelCase_     					=				generator.manual_seed(0       )
             UpperCAmelCase_     					=				pipe(
                 prompt=_UpperCAmelCase						,							generator=_UpperCAmelCase						,							guidance_scale=7.5						,							num_inference_steps=2						,							output_type="numpy"       ).images

             assert np.abs(image - new_image       ).sum() < 1e-5, "Models don't have the same forward pass"







       def 	lowercase__							(				self     :    Dict       )					->		Optional[int]:


             '''simple docstring'''




             UpperCAmelCase_     					=				VersatileDiffusionTextToImagePipeline.from_pretrained(
                 "shi-labs/versatile-diffusion"						,							torch_dtype=torch.floataa       )
             pipe.to(_UpperCAmelCase       )
             pipe.set_progress_bar_config(disable=_UpperCAmelCase       )

             UpperCAmelCase_     					=				"A painting of a squirrel eating a burger "
             UpperCAmelCase_     					=				torch.manual_seed(0       )
             UpperCAmelCase_     					=				pipe(
                 prompt=_UpperCAmelCase						,							generator=_UpperCAmelCase						,							guidance_scale=7.5						,							num_inference_steps=50						,							output_type="numpy"       ).images

             UpperCAmelCase_     					=				image[0, 253:256, 253:256, -1]

             assert image.shape == (1, 512, 512, 3)
             UpperCAmelCase_     					=				np.array([0.3367, 0.3169, 0.2656, 0.3870, 0.4790, 0.3796, 0.4009, 0.4878, 0.4778]       )

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





"""simple docstring"""


import random





def      lowerCamelCase_					(   __lowerCAmelCase  ,       __lowerCAmelCase  ,       __lowerCAmelCase = False							)				->   dict:




						'''simple docstring'''



						lowerCamelCase__   ={i: [] for i in range(__lowerCAmelCase							)}

						# if probability is greater or equal than 1, then generate a complete graph
						if probability >= 1:
												return complete_graph(__lowerCAmelCase							)
						# 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(__lowerCAmelCase							):
												for j in range(i + 1  ,       __lowerCAmelCase							):
																		if random.random() < probability:
																								graph[i].append(__lowerCAmelCase							)
																								if not directed:
																														# if the graph is undirected, add an edge in from j to i, either
																														graph[j].append(__lowerCAmelCase							)
						return graph





def      lowerCamelCase_					(   __lowerCAmelCase							)				->   dict:




						'''simple docstring'''



						return {
						    i: [j for j in range(__lowerCAmelCase							) if i != j] for i in range(__lowerCAmelCase							)
						}


if __name__ == "__main__":
	import doctest

	doctest.testmod()


