



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






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





							def 						UpperCamelCase_					(   self		:		Optional[Any]	):

											'''simple docstring'''
											# clean up the VRAM after each test
											super().tearDown()
											gc.collect()
											torch.cuda.empty_cache()





							def 						UpperCamelCase_					(   self		:		List[Any]	):

											'''simple docstring'''
											__a       =		VersatileDiffusionTextToImagePipeline.from_pretrained("""shi-labs/versatile-diffusion"""	)
											# remove text_unet
											pipe.remove_unused_weights()
											pipe.to(__lowercase	)
											pipe.set_progress_bar_config(disable=__lowercase	)

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

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

											__a       =		generator.manual_seed(0	)
											__a       =		pipe(
											    prompt=__lowercase      ,				generator=__lowercase      ,				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		:		List[str]	):

											'''simple docstring'''
											__a       =		VersatileDiffusionTextToImagePipeline.from_pretrained(
											    """shi-labs/versatile-diffusion"""      ,				torch_dtype=torch.floataa	)
											pipe.to(__lowercase	)
											pipe.set_progress_bar_config(disable=__lowercase	)

											__a       =		"""A painting of a squirrel eating a burger """
											__a       =		torch.manual_seed(0	)
											__a       =		pipe(
											    prompt=__lowercase      ,				generator=__lowercase      ,				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.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





def   lowerCAmelCase__						(							_SCREAMING_SNAKE_CASE       :			int = 3				,     _SCREAMING_SNAKE_CASE       :			int = 7				,     _SCREAMING_SNAKE_CASE       :			int = 100_0000    ):
				"""simple docstring"""







				__a       =		0
				__a       =		1

				for current_denominator in range(1				,     limit + 1    ):
								__a       =		current_denominator * numerator // denominator
								if current_denominator % denominator == 0:
												current_numerator -= 1
								if current_numerator * max_denominator > current_denominator * max_numerator:
												__a       =		current_numerator
												__a       =		current_denominator
				return max_numerator


if __name__ == "__main__":
						print(solution(numerator=3, denominator=7, limit=100_0000))
