






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


__UpperCamelCase      :      Tuple     						=						False


class        __UpperCamelCase    (     unittest.TestCase   ):
	pass


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







	def  _a   (  self      :							Optional[int]			)		-> Tuple:
		"""simple docstring"""







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







	def  _a   (  self      :							Union[str, Any]			)		-> str:
		"""simple docstring"""







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

		__lowercase             =  """A painting of a squirrel eating a burger """
		__lowercase             =  torch.manual_seed(0			)
		__lowercase             =  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			)
			__lowercase             =  VersatileDiffusionTextToImagePipeline.from_pretrained(_lowerCAmelCase			)
		pipe.to(_lowerCAmelCase			)
		pipe.set_progress_bar_config(disable=_lowerCAmelCase			)

		__lowercase             =  generator.manual_seed(0			)
		__lowercase             =  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  _a   (  self      :							Optional[int]			)		-> Tuple:
		"""simple docstring"""







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

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

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

		assert image.shape == (1, 512, 512, 3)
		__lowercase             =  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 				snake_case  (     lowerCamelCase					):




	'''simple docstring'''







	if not isinstance(lowerCamelCase				,  lowerCamelCase					):
		raise ValueError("""check_bouncy() accepts only integer arguments"""					)
	__lowercase             =  str(lowerCamelCase					)
	__lowercase             =  """""".join(sorted(lowerCamelCase					)					)
	return sorted_str_n != str_n and sorted_str_n[::-1] != str_n





def 				snake_case  (     lowerCamelCase = 99					):




	'''simple docstring'''







	if not 0 < percent < 100:
		raise ValueError("""solution() only accepts values from 0 to 100"""					)
	__lowercase             =  0
	__lowercase             =  1

	while True:
		if check_bouncy(lowerCamelCase					):
			bouncy_num += 1
		if (bouncy_num / num) * 100 >= percent:
			return num
		num += 1


if __name__ == "__main__":
						from doctest import testmod

						testmod()
						print(F'''{solution(99)}''')

