




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   :						int				=			False


class    lowerCamelCase    (		unittest.TestCase						):






			'''simple docstring'''





			pass






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






			'''simple docstring'''





			def 							UpperCAmelCase__       ( self			:   List[str]  )						->   List[Any]:
								# clean up the VRAM after each test
								super().tearDown()
								gc.collect()
								torch.cuda.empty_cache()

			def 							UpperCAmelCase__       ( self			:   Optional[int]  )						->   Union[str, Any]:
								__magic_name__							:	Optional[Any]    							=							VersatileDiffusionTextToImagePipeline.from_pretrained('''shi-labs/versatile-diffusion'''  )
								# remove text_unet
								pipe.remove_unused_weights()
								pipe.to(lowerCamelCase_  )
								pipe.set_progress_bar_config(disable=lowerCamelCase_  )

								__magic_name__							:	Tuple    							=							'''A painting of a squirrel eating a burger '''
								__magic_name__							:	int    							=							torch.manual_seed(0  )
								__magic_name__							:	int    							=							pipe(
								    prompt=lowerCamelCase_       ,						generator=lowerCamelCase_       ,						guidance_scale=7.5       ,						num_inference_steps=2       ,						output_type='''numpy'''  ).images

								with tempfile.TemporaryDirectory() as tmpdirname:
													pipe.save_pretrained(lowerCamelCase_  )
													__magic_name__							:	Dict    							=							VersatileDiffusionTextToImagePipeline.from_pretrained(lowerCamelCase_  )
								pipe.to(lowerCamelCase_  )
								pipe.set_progress_bar_config(disable=lowerCamelCase_  )

								__magic_name__							:	Optional[Any]    							=							generator.manual_seed(0  )
								__magic_name__							:	Tuple    							=							pipe(
								    prompt=lowerCamelCase_       ,						generator=lowerCamelCase_       ,						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 							UpperCAmelCase__       ( self			:   Dict  )						->   Optional[int]:
								__magic_name__							:	List[Any]    							=							VersatileDiffusionTextToImagePipeline.from_pretrained(
								    '''shi-labs/versatile-diffusion'''       ,						torch_dtype=torch.floataa  )
								pipe.to(lowerCamelCase_  )
								pipe.set_progress_bar_config(disable=lowerCamelCase_  )

								__magic_name__							:	List[Any]    							=							'''A painting of a squirrel eating a burger '''
								__magic_name__							:	List[Any]    							=							torch.manual_seed(0  )
								__magic_name__							:	Dict    							=							pipe(
								    prompt=lowerCamelCase_       ,						generator=lowerCamelCase_       ,						guidance_scale=7.5       ,						num_inference_steps=50       ,						output_type='''numpy'''  ).images

								__magic_name__							:	Dict    							=							image[0, 253:256, 253:256, -1]

								assert image.shape == (1, 512, 512, 3)
								__magic_name__							:	int    							=							np.array([0.3_3_6_7, 0.3_1_6_9, 0.2_6_5_6, 0.3_8_7_0, 0.4_7_9_0, 0.3_7_9_6, 0.4_0_0_9, 0.4_8_7_8, 0.4_7_7_8]  )

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









import sys
import turtle







def 		lowercase__   (		__A:	tuple[float, float]							,__A:	tuple[float, float]				):





					'''simple docstring'''






					return (pa[0] + pa[0]) / 2, (pa[1] + pa[1]) / 2







def 		lowercase__   (		__A:	tuple[float, float]							,__A:	tuple[float, float]							,__A:	tuple[float, float]							,__A:	int							,):





					'''simple docstring'''






					my_pen.up()
					my_pen.goto(vertexa[0]							,vertexa[1]				)
					my_pen.down()
					my_pen.goto(vertexa[0]							,vertexa[1]				)
					my_pen.goto(vertexa[0]							,vertexa[1]				)
					my_pen.goto(vertexa[0]							,vertexa[1]				)

					if depth == 0:
										return

					triangle(__A							,get_mid(__A							,__A				)							,get_mid(__A							,__A				)							,depth - 1				)
					triangle(__A							,get_mid(__A							,__A				)							,get_mid(__A							,__A				)							,depth - 1				)
					triangle(__A							,get_mid(__A							,__A				)							,get_mid(__A							,__A				)							,depth - 1				)


if __name__ == "__main__":
	if len(sys.argv) != 2:
		raise ValueError(
		    '''Correct format for using this script: '''
		    '''python fractals.py <int:depth_for_fractal>'''
		)
	__lowerCamelCase   :						Any				=			turtle.Turtle()
	my_pen.ht()
	my_pen.speed(5)
	my_pen.pencolor('''red''')

	__lowerCamelCase   :						Optional[Any]				=			[(-1_75, -1_25), (0, 1_75), (1_75, -1_25)]  # vertices of triangle
	triangle(vertices[0], vertices[1], vertices[2], int(sys.argv[1]))



