



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_							:      str      =  False






class      UpperCamelCase    (						unittest.TestCase     ):
	pass






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



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



	def 			__A							(       self		):
							A__							=       VersatileDiffusionTextToImagePipeline.from_pretrained("shi-labs/versatile-diffusion"		)
							# remove text_unet
							pipe.remove_unused_weights()
							pipe.to(_a		)
							pipe.set_progress_bar_config(disable=_a		)

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

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

							A__							=       generator.manual_seed(0		)
							A__							=       pipe(
							    prompt=_a			,	generator=_a			,	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 			__A							(       self		):
							A__							=       VersatileDiffusionTextToImagePipeline.from_pretrained(
							    "shi-labs/versatile-diffusion"			,	torch_dtype=torch.floataa		)
							pipe.to(_a		)
							pipe.set_progress_bar_config(disable=_a		)

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

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

							assert image.shape == (1, 512, 512, 3)
							A__							=       np.array([0.3_367, 0.3_169, 0.2_656, 0.3_870, 0.4_790, 0.3_796, 0.4_009, 0.4_878, 0.4_778]		)

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










def  UpperCamelCase						(       _A			:				int			,							_A			:				int    )->       int:





						"""simple docstring"""





						return int((input_a, input_a).count(0    ) == 0    )
def  UpperCamelCase						(       )->       None:





						"""simple docstring"""





						assert and_gate(0			,							0    ) == 0
						assert and_gate(0			,							1    ) == 0
						assert and_gate(1			,							0    ) == 0
						assert and_gate(1			,							1    ) == 1


if __name__ == "__main__":
						test_and_gate()
						print(and_gate(1, 0))
						print(and_gate(0, 0))
						print(and_gate(0, 1))
						print(and_gate(1, 1))





