






'''simple docstring'''







import gc
import random
import tempfile
import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer

from diffusers import AutoencoderKL, DDIMScheduler, LMSDiscreteScheduler, PNDMScheduler, UNetaDConditionModel
from diffusers.pipelines.semantic_stable_diffusion import SemanticStableDiffusionPipeline as StableDiffusionPipeline
from diffusers.utils import floats_tensor, nightly, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu


enable_full_determinism()




class 					__UpperCAmelCase (		unittest.TestCase	):

      '''simple docstring'''





      def 							lowerCamelCase     (					self						):
             # clean up the VRAM after each test
             super().tearDown()
             gc.collect()
             torch.cuda.empty_cache()




      @property
      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__	:   List[str]												=	1
             UpperCAmelCase__	:   List[str]												=	3
             UpperCAmelCase__	:   Tuple												=	(32, 32)

             UpperCAmelCase__	:   Optional[Any]												=	floats_tensor((batch_size, num_channels) + sizes  ,		rng=random.Random(0						)						).to(_SCREAMING_SNAKE_CASE						)
             return image




      @property
      def 							lowerCamelCase     (					self						):
             torch.manual_seed(0						)
             UpperCAmelCase__	:   int												=	UNetaDConditionModel(
                 block_out_channels=(32, 64)  ,		layers_per_block=2  ,		sample_size=32  ,		in_channels=4  ,		out_channels=4  ,		down_block_types=('''DownBlock2D''', '''CrossAttnDownBlock2D''')  ,		up_block_types=('''CrossAttnUpBlock2D''', '''UpBlock2D''')  ,		cross_attention_dim=32  ,		)
             return model




      @property
      def 							lowerCamelCase     (					self						):
             torch.manual_seed(0						)
             UpperCAmelCase__	:   int												=	AutoencoderKL(
                 block_out_channels=[32, 64]  ,		in_channels=3  ,		out_channels=3  ,		down_block_types=['''DownEncoderBlock2D''', '''DownEncoderBlock2D''']  ,		up_block_types=['''UpDecoderBlock2D''', '''UpDecoderBlock2D''']  ,		latent_channels=4  ,		)
             return model




      @property
      def 							lowerCamelCase     (					self						):
             torch.manual_seed(0						)
             UpperCAmelCase__	:   int												=	CLIPTextConfig(
                 bos_token_id=0  ,		eos_token_id=2  ,		hidden_size=32  ,		intermediate_size=37  ,		layer_norm_eps=1E-05  ,		num_attention_heads=4  ,		num_hidden_layers=5  ,		pad_token_id=1  ,		vocab_size=1000  ,		)
             return CLIPTextModel(_SCREAMING_SNAKE_CASE						)




      @property
      def 							lowerCamelCase     (					self						):
             def extract(*_UpperCAmelCase  ,		**_UpperCAmelCase						):




                    class 					__UpperCAmelCase :

                          '''simple docstring'''





                          def __init__(					self						):
                                 UpperCAmelCase__	:   Optional[int]												=	torch.ones([0]						)




                          def 							lowerCamelCase     (					self  ,		_UpperCAmelCase						):
                                 self.pixel_values.to(_SCREAMING_SNAKE_CASE						)
                                 return self


                    return Out()

             return extract




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__	:   List[str]												=	'cpu'  # ensure determinism for the device-dependent torch.Generator
             UpperCAmelCase__	:   Optional[Any]												=	self.dummy_cond_unet
             UpperCAmelCase__	:   List[Any]												=	DDIMScheduler(
                 beta_start=0.0_00_85  ,		beta_end=0.0_12  ,		beta_schedule='''scaled_linear'''  ,		clip_sample=_SCREAMING_SNAKE_CASE  ,		set_alpha_to_one=_SCREAMING_SNAKE_CASE  ,		)

             UpperCAmelCase__	:   int												=	self.dummy_vae
             UpperCAmelCase__	:   Dict												=	self.dummy_text_encoder
             UpperCAmelCase__	:   Optional[Any]												=	CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip'''						)

             # make sure here that pndm scheduler skips prk
             UpperCAmelCase__	:   str												=	StableDiffusionPipeline(
                 unet=_SCREAMING_SNAKE_CASE  ,		scheduler=_SCREAMING_SNAKE_CASE  ,		vae=_SCREAMING_SNAKE_CASE  ,		text_encoder=_SCREAMING_SNAKE_CASE  ,		tokenizer=_SCREAMING_SNAKE_CASE  ,		safety_checker=_SCREAMING_SNAKE_CASE  ,		feature_extractor=self.dummy_extractor  ,		)
             UpperCAmelCase__	:   Dict												=	sd_pipe.to(_SCREAMING_SNAKE_CASE						)
             sd_pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE						)

             UpperCAmelCase__	:   Dict												=	'A painting of a squirrel eating a burger'

             UpperCAmelCase__	:   Tuple												=	torch.Generator(device=_SCREAMING_SNAKE_CASE						).manual_seed(0						)
             UpperCAmelCase__	:   str												=	sd_pipe([prompt]  ,		generator=_SCREAMING_SNAKE_CASE  ,		guidance_scale=6.0  ,		num_inference_steps=2  ,		output_type='''np'''						)
             UpperCAmelCase__	:   Optional[int]												=	output.images

             UpperCAmelCase__	:   Optional[Any]												=	torch.Generator(device=_SCREAMING_SNAKE_CASE						).manual_seed(0						)
             UpperCAmelCase__	:   Tuple												=	sd_pipe(
                 [prompt]  ,		generator=_SCREAMING_SNAKE_CASE  ,		guidance_scale=6.0  ,		num_inference_steps=2  ,		output_type='''np'''  ,		return_dict=_SCREAMING_SNAKE_CASE  ,		)[0]

             UpperCAmelCase__	:   str												=	image[0, -3:, -3:, -1]
             UpperCAmelCase__	:   Dict												=	image_from_tuple[0, -3:, -3:, -1]

             assert image.shape == (1, 64, 64, 3)
             UpperCAmelCase__	:   List[Any]												=	np.array([0.57_53, 0.61_14, 0.50_01, 0.50_34, 0.54_70, 0.47_29, 0.49_71, 0.48_67, 0.48_67]						)

             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 							lowerCamelCase     (					self						):
             UpperCAmelCase__	:   Any												=	'cpu'  # ensure determinism for the device-dependent torch.Generator
             UpperCAmelCase__	:   List[Any]												=	self.dummy_cond_unet
             UpperCAmelCase__	:   str												=	PNDMScheduler(skip_prk_steps=_SCREAMING_SNAKE_CASE						)
             UpperCAmelCase__	:   Tuple												=	self.dummy_vae
             UpperCAmelCase__	:   Optional[Any]												=	self.dummy_text_encoder
             UpperCAmelCase__	:   Tuple												=	CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip'''						)

             # make sure here that pndm scheduler skips prk
             UpperCAmelCase__	:   Dict												=	StableDiffusionPipeline(
                 unet=_SCREAMING_SNAKE_CASE  ,		scheduler=_SCREAMING_SNAKE_CASE  ,		vae=_SCREAMING_SNAKE_CASE  ,		text_encoder=_SCREAMING_SNAKE_CASE  ,		tokenizer=_SCREAMING_SNAKE_CASE  ,		safety_checker=_SCREAMING_SNAKE_CASE  ,		feature_extractor=self.dummy_extractor  ,		)
             UpperCAmelCase__	:   Optional[int]												=	sd_pipe.to(_SCREAMING_SNAKE_CASE						)
             sd_pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE						)

             UpperCAmelCase__	:   int												=	'A painting of a squirrel eating a burger'
             UpperCAmelCase__	:   Dict												=	torch.Generator(device=_SCREAMING_SNAKE_CASE						).manual_seed(0						)
             UpperCAmelCase__	:   Tuple												=	sd_pipe([prompt]  ,		generator=_SCREAMING_SNAKE_CASE  ,		guidance_scale=6.0  ,		num_inference_steps=2  ,		output_type='''np'''						)

             UpperCAmelCase__	:   int												=	output.images

             UpperCAmelCase__	:   List[str]												=	torch.Generator(device=_SCREAMING_SNAKE_CASE						).manual_seed(0						)
             UpperCAmelCase__	:   Tuple												=	sd_pipe(
                 [prompt]  ,		generator=_SCREAMING_SNAKE_CASE  ,		guidance_scale=6.0  ,		num_inference_steps=2  ,		output_type='''np'''  ,		return_dict=_SCREAMING_SNAKE_CASE  ,		)[0]

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

             assert image.shape == (1, 64, 64, 3)
             UpperCAmelCase__	:   str												=	np.array([0.51_22, 0.57_12, 0.48_25, 0.50_53, 0.56_46, 0.47_69, 0.51_79, 0.48_94, 0.49_94]						)

             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 							lowerCamelCase     (					self						):
             UpperCAmelCase__	:   List[Any]												=	StableDiffusionPipeline.from_pretrained(
                 '''hf-internal-testing/tiny-stable-diffusion-lms-pipe'''  ,		safety_checker=_SCREAMING_SNAKE_CASE						)
             assert isinstance(_SCREAMING_SNAKE_CASE  ,		_SCREAMING_SNAKE_CASE						)
             assert isinstance(pipe.scheduler  ,		_SCREAMING_SNAKE_CASE						)
             assert pipe.safety_checker is None

             UpperCAmelCase__	:   Optional[Any]												=	pipe('''example prompt'''  ,		num_inference_steps=2						).images[0]
             assert image is not None

             # check that there's no error when saving a pipeline with one of the models being None
             with tempfile.TemporaryDirectory() as tmpdirname:
                    pipe.save_pretrained(_SCREAMING_SNAKE_CASE						)
                    UpperCAmelCase__	:   Dict												=	StableDiffusionPipeline.from_pretrained(_SCREAMING_SNAKE_CASE						)

             # sanity check that the pipeline still works
             assert pipe.safety_checker is None
             UpperCAmelCase__	:   List[str]												=	pipe('''example prompt'''  ,		num_inference_steps=2						).images[0]
             assert image is not None




      @unittest.skipIf(torch_device != '''cuda'''  ,		'''This test requires a GPU'''						)
      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__	:   Union[str, Any]												=	self.dummy_cond_unet
             UpperCAmelCase__	:   Optional[int]												=	PNDMScheduler(skip_prk_steps=_SCREAMING_SNAKE_CASE						)
             UpperCAmelCase__	:   List[str]												=	self.dummy_vae
             UpperCAmelCase__	:   Tuple												=	self.dummy_text_encoder
             UpperCAmelCase__	:   Dict												=	CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip'''						)

             # put models in fp16
             UpperCAmelCase__	:   Tuple												=	unet.half()
             UpperCAmelCase__	:   Tuple												=	vae.half()
             UpperCAmelCase__	:   Union[str, Any]												=	bert.half()

             # make sure here that pndm scheduler skips prk
             UpperCAmelCase__	:   List[str]												=	StableDiffusionPipeline(
                 unet=_SCREAMING_SNAKE_CASE  ,		scheduler=_SCREAMING_SNAKE_CASE  ,		vae=_SCREAMING_SNAKE_CASE  ,		text_encoder=_SCREAMING_SNAKE_CASE  ,		tokenizer=_SCREAMING_SNAKE_CASE  ,		safety_checker=_SCREAMING_SNAKE_CASE  ,		feature_extractor=self.dummy_extractor  ,		)
             UpperCAmelCase__	:   Any												=	sd_pipe.to(_SCREAMING_SNAKE_CASE						)
             sd_pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE						)

             UpperCAmelCase__	:   Optional[int]												=	'A painting of a squirrel eating a burger'
             UpperCAmelCase__	:   Optional[int]												=	sd_pipe([prompt]  ,		num_inference_steps=2  ,		output_type='''np'''						).images

             assert image.shape == (1, 64, 64, 3)




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

      '''simple docstring'''





      def 							lowerCamelCase     (					self						):
             # clean up the VRAM after each test
             super().tearDown()
             gc.collect()
             torch.cuda.empty_cache()




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__	:   Union[str, Any]												=	'cuda'
             UpperCAmelCase__	:   Optional[int]												=	StableDiffusionPipeline.from_pretrained('''runwayml/stable-diffusion-v1-5'''						)
             UpperCAmelCase__	:   Union[str, Any]												=	pipe.to(_SCREAMING_SNAKE_CASE						)
             pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE						)

             UpperCAmelCase__	:   Any												=	'a photo of a cat'
             UpperCAmelCase__	:   List[str]												=	{
                 'editing_prompt': ['sunglasses'],
                 'reverse_editing_direction': [False],
                 'edit_warmup_steps': 10,
                 'edit_guidance_scale': 6,
                 'edit_threshold': 0.95,
                 'edit_momentum_scale': 0.5,
                 'edit_mom_beta': 0.6,
             }

             UpperCAmelCase__	:   int												=	3
             UpperCAmelCase__	:   Union[str, Any]												=	7

             # no sega enabled
             UpperCAmelCase__	:   List[str]												=	torch.Generator(_SCREAMING_SNAKE_CASE						)
             generator.manual_seed(_SCREAMING_SNAKE_CASE						)
             UpperCAmelCase__	:   int												=	pipe(
                 [prompt]  ,		generator=_SCREAMING_SNAKE_CASE  ,		guidance_scale=_SCREAMING_SNAKE_CASE  ,		num_inference_steps=50  ,		output_type='''np'''  ,		width=512  ,		height=512  ,		)

             UpperCAmelCase__	:   Union[str, Any]												=	output.images
             UpperCAmelCase__	:   Optional[int]												=	image[0, -3:, -3:, -1]
             UpperCAmelCase__	:   List[str]												=	[
                 0.34_67_31_13,
                 0.38_49_27_33,
                 0.37_59_73_52,
                 0.34_08_63_35,
                 0.35_65_07_48,
                 0.35_57_92_05,
                 0.3_38_47_63,
                 0.34_34_02_36,
                 0.3_57_32_71,
             ]

             assert image.shape == (1, 512, 512, 3)

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

             # with sega enabled
             # generator = torch.manual_seed(seed)
             generator.manual_seed(_SCREAMING_SNAKE_CASE						)
             UpperCAmelCase__	:   Optional[Any]												=	pipe(
                 [prompt]  ,		generator=_SCREAMING_SNAKE_CASE  ,		guidance_scale=_SCREAMING_SNAKE_CASE  ,		num_inference_steps=50  ,		output_type='''np'''  ,		width=512  ,		height=512  ,		**_SCREAMING_SNAKE_CASE  ,		)

             UpperCAmelCase__	:   Dict												=	output.images
             UpperCAmelCase__	:   int												=	image[0, -3:, -3:, -1]
             UpperCAmelCase__	:   Optional[Any]												=	[
                 0.41_88_78_26,
                 0.37_72_87_66,
                 0.30_13_82_72,
                 0.41_41_63_35,
                 0.41_66_49_85,
                 0.36_28_33_92,
                 0.36_19_12_46,
                 0.43_36_44_65,
                 0.43_00_17_32,
             ]

             assert image.shape == (1, 512, 512, 3)

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




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__	:   Dict												=	'cuda'
             UpperCAmelCase__	:   str												=	StableDiffusionPipeline.from_pretrained('''runwayml/stable-diffusion-v1-5'''						)
             UpperCAmelCase__	:   Optional[int]												=	pipe.to(_SCREAMING_SNAKE_CASE						)
             pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE						)

             UpperCAmelCase__	:   List[Any]												=	'an image of a crowded boulevard, realistic, 4k'
             UpperCAmelCase__	:   Optional[Any]												=	{
                 'editing_prompt': 'crowd, crowded, people',
                 'reverse_editing_direction': True,
                 'edit_warmup_steps': 10,
                 'edit_guidance_scale': 8.3,
                 'edit_threshold': 0.9,
                 'edit_momentum_scale': 0.5,
                 'edit_mom_beta': 0.6,
             }

             UpperCAmelCase__	:   int												=	9
             UpperCAmelCase__	:   Any												=	7

             # no sega enabled
             UpperCAmelCase__	:   Union[str, Any]												=	torch.Generator(_SCREAMING_SNAKE_CASE						)
             generator.manual_seed(_SCREAMING_SNAKE_CASE						)
             UpperCAmelCase__	:   List[str]												=	pipe(
                 [prompt]  ,		generator=_SCREAMING_SNAKE_CASE  ,		guidance_scale=_SCREAMING_SNAKE_CASE  ,		num_inference_steps=50  ,		output_type='''np'''  ,		width=512  ,		height=512  ,		)

             UpperCAmelCase__	:   List[Any]												=	output.images
             UpperCAmelCase__	:   Optional[int]												=	image[0, -3:, -3:, -1]
             UpperCAmelCase__	:   Any												=	[
                 0.43_49_79_98,
                 0.91_81_40_65,
                 0.7_54_07_39,
                 0.55_58_02_05,
                 0.8_46_72_65,
                 0.5_38_96_91,
                 0.62_57_45_06,
                 0.58_89_77_63,
                 0.50_92_67_57,
             ]

             assert image.shape == (1, 512, 512, 3)

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

             # with sega enabled
             # generator = torch.manual_seed(seed)
             generator.manual_seed(_SCREAMING_SNAKE_CASE						)
             UpperCAmelCase__	:   Dict												=	pipe(
                 [prompt]  ,		generator=_SCREAMING_SNAKE_CASE  ,		guidance_scale=_SCREAMING_SNAKE_CASE  ,		num_inference_steps=50  ,		output_type='''np'''  ,		width=512  ,		height=512  ,		**_SCREAMING_SNAKE_CASE  ,		)

             UpperCAmelCase__	:   Tuple												=	output.images
             UpperCAmelCase__	:   Optional[Any]												=	image[0, -3:, -3:, -1]
             UpperCAmelCase__	:   List[Any]												=	[
                 0.3_08_97_19,
                 0.30_50_01_44,
                 0.29_01_60_42,
                 0.30_63_09_64,
                 0.32_56_87,
                 0.29_41_92_25,
                 0.2_90_80_91,
                 0.28_72_35_98,
                 0.27_69_62_94,
             ]

             assert image.shape == (1, 512, 512, 3)

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




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__	:   Dict												=	'cuda'
             UpperCAmelCase__	:   Any												=	StableDiffusionPipeline.from_pretrained('''runwayml/stable-diffusion-v1-5'''						)
             UpperCAmelCase__	:   Tuple												=	pipe.to(_SCREAMING_SNAKE_CASE						)
             pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE						)

             UpperCAmelCase__	:   int												=	'a castle next to a river'
             UpperCAmelCase__	:   List[str]												=	{
                 'editing_prompt': ['boat on a river, boat', 'monet, impression, sunrise'],
                 'reverse_editing_direction': False,
                 'edit_warmup_steps': [15, 18],
                 'edit_guidance_scale': 6,
                 'edit_threshold': [0.9, 0.8],
                 'edit_momentum_scale': 0.5,
                 'edit_mom_beta': 0.6,
             }

             UpperCAmelCase__	:   List[str]												=	48
             UpperCAmelCase__	:   int												=	7

             # no sega enabled
             UpperCAmelCase__	:   Any												=	torch.Generator(_SCREAMING_SNAKE_CASE						)
             generator.manual_seed(_SCREAMING_SNAKE_CASE						)
             UpperCAmelCase__	:   Optional[Any]												=	pipe(
                 [prompt]  ,		generator=_SCREAMING_SNAKE_CASE  ,		guidance_scale=_SCREAMING_SNAKE_CASE  ,		num_inference_steps=50  ,		output_type='''np'''  ,		width=512  ,		height=512  ,		)

             UpperCAmelCase__	:   List[str]												=	output.images
             UpperCAmelCase__	:   Optional[Any]												=	image[0, -3:, -3:, -1]
             UpperCAmelCase__	:   Union[str, Any]												=	[
                 0.75_16_35_55,
                 0.76_03_71_45,
                 0.6_17_85,
                 0.9_18_96_73,
                 0.8_62_77_01,
                 0.85_18_96_94,
                 0.8_51_28_13,
                 0.87_01_20_76,
                 0.8_31_28_57,
             ]

             assert image.shape == (1, 512, 512, 3)

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

             # with sega enabled
             # generator = torch.manual_seed(seed)
             generator.manual_seed(_SCREAMING_SNAKE_CASE						)
             UpperCAmelCase__	:   Optional[int]												=	pipe(
                 [prompt]  ,		generator=_SCREAMING_SNAKE_CASE  ,		guidance_scale=_SCREAMING_SNAKE_CASE  ,		num_inference_steps=50  ,		output_type='''np'''  ,		width=512  ,		height=512  ,		**_SCREAMING_SNAKE_CASE  ,		)

             UpperCAmelCase__	:   Tuple												=	output.images
             UpperCAmelCase__	:   Optional[Any]												=	image[0, -3:, -3:, -1]
             UpperCAmelCase__	:   Dict												=	[
                 0.73_55_33_65,
                 0.7_53_72_71,
                 0.74_34_19_05,
                 0.66_48_03_56,
                 0.6_47_29_25,
                 0.63_03_94_16,
                 0.64_81_29_05,
                 0.6_74_97_17,
                 0.6_51_71_02,
             ]

             assert image.shape == (1, 512, 512, 3)

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




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__	:   Dict												=	'cuda'
             UpperCAmelCase__	:   Union[str, Any]												=	StableDiffusionPipeline.from_pretrained('''runwayml/stable-diffusion-v1-5'''  ,		torch_dtype=torch.floataa						)
             UpperCAmelCase__	:   Tuple												=	pipe.to(_SCREAMING_SNAKE_CASE						)
             pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE						)

             UpperCAmelCase__	:   Optional[int]												=	'a photo of a cat'
             UpperCAmelCase__	:   Dict												=	{
                 'editing_prompt': ['sunglasses'],
                 'reverse_editing_direction': [False],
                 'edit_warmup_steps': 10,
                 'edit_guidance_scale': 6,
                 'edit_threshold': 0.95,
                 'edit_momentum_scale': 0.5,
                 'edit_mom_beta': 0.6,
             }

             UpperCAmelCase__	:   Tuple												=	3
             UpperCAmelCase__	:   Optional[int]												=	7

             # no sega enabled
             UpperCAmelCase__	:   Dict												=	torch.Generator(_SCREAMING_SNAKE_CASE						)
             generator.manual_seed(_SCREAMING_SNAKE_CASE						)
             UpperCAmelCase__	:   Optional[Any]												=	pipe(
                 [prompt]  ,		generator=_SCREAMING_SNAKE_CASE  ,		guidance_scale=_SCREAMING_SNAKE_CASE  ,		num_inference_steps=50  ,		output_type='''np'''  ,		width=512  ,		height=512  ,		)

             UpperCAmelCase__	:   Optional[Any]												=	output.images
             UpperCAmelCase__	:   Dict												=	image[0, -3:, -3:, -1]
             UpperCAmelCase__	:   Optional[Any]												=	[
                 0.34_88_76_95,
                 0.3_87_69_53,
                 0.3_75,
                 0.34_42_38_28,
                 0.3_58_15_43,
                 0.35_71_77_73,
                 0.3_38_37_89,
                 0.34_57_03_12,
                 0.35_93_75,
             ]

             assert image.shape == (1, 512, 512, 3)

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

             # with sega enabled
             # generator = torch.manual_seed(seed)
             generator.manual_seed(_SCREAMING_SNAKE_CASE						)
             UpperCAmelCase__	:   List[str]												=	pipe(
                 [prompt]  ,		generator=_SCREAMING_SNAKE_CASE  ,		guidance_scale=_SCREAMING_SNAKE_CASE  ,		num_inference_steps=50  ,		output_type='''np'''  ,		width=512  ,		height=512  ,		**_SCREAMING_SNAKE_CASE  ,		)

             UpperCAmelCase__	:   List[str]												=	output.images
             UpperCAmelCase__	:   Union[str, Any]												=	image[0, -3:, -3:, -1]
             UpperCAmelCase__	:   Optional[Any]												=	[
                 0.42_28_51_56,
                 0.36_91_40_62,
                 0.29_07_71_48,
                 0.42_04_10_16,
                 0.41_91_89_45,
                 0.35_49_80_47,
                 0.3_61_81_64,
                 0.4_42_38_28,
                 0.43_11_52_34,
             ]

             assert image.shape == (1, 512, 512, 3)

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

"""simple docstring"""







def        __lowerCAmelCase							(_UpperCamelCase			,    _UpperCamelCase						):
	__lowerCAmelCase     :		Any		     = sorted(_UpperCamelCase			,    key=lambda _UpperCamelCase						: edge[2]						)

	__lowerCAmelCase     :		Union[str, Any]		     = list(range(_UpperCamelCase						)						)

	def find_parent(_UpperCamelCase						):
		if i != parent[i]:
			__lowerCAmelCase     :		int		     = find_parent(parent[i]						)
		return parent[i]

	__lowerCAmelCase     :		Optional[Any]		     = 0
	__lowerCAmelCase     :		List[str]		     = []

	for edge in edges:
		__lowerCAmelCase     :		List[str]		     = find_parent(edge[0]						)
		__lowerCAmelCase     :		Optional[Any]		     = find_parent(edge[1]						)
		if parent_a != parent_b:
			minimum_spanning_tree_cost += edge[2]
			minimum_spanning_tree.append(_UpperCamelCase						)
			__lowerCAmelCase     :		Optional[Any]		     = parent_b

	return minimum_spanning_tree


if __name__ == "__main__":  # pragma: no cover
							lowerCamelCase__   ,		lowerCamelCase__     =						list(map(int, input().strip().split()))
							lowerCamelCase__     =						[]

							for _ in range(num_edges):
														lowerCamelCase__   ,		lowerCamelCase__   ,		lowerCamelCase__     =						(int(x) for x in input().strip().split())
														edges.append((nodea, nodea, cost))

							kruskal(num_nodes, edges)