"""simple docstring"""




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


_a				:		List[str]	   =       False
class 						__A							(			unittest.TestCase		):
					pass







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






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






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

							_lowerCAmelCase						:	List[str]        =					"""A painting of a squirrel eating a burger """
							_lowerCAmelCase						:	Optional[Any]        =					torch.manual_seed(0  )
							_lowerCAmelCase						:	Optional[Any]        =					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__  )
									_lowerCAmelCase						:	str        =					VersatileDiffusionTextToImagePipeline.from_pretrained(a__  )
							pipe.to(a__  )
							pipe.set_progress_bar_config(disable=a__  )

							_lowerCAmelCase						:	Optional[int]        =					generator.manual_seed(0  )
							_lowerCAmelCase						:	int        =					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  ):
							_lowerCAmelCase						:	Tuple        =					VersatileDiffusionTextToImagePipeline.from_pretrained(
							    """shi-labs/versatile-diffusion"""    ,					torch_dtype=torch.floataa  )
							pipe.to(a__  )
							pipe.set_progress_bar_config(disable=a__  )

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

							_lowerCAmelCase						:	Any        =					image[0, 253:256, 253:256, -1]

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





"""simple docstring"""




from ..utils import DummyObject, requires_backends
class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Optional[Any]		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      List[Any]		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      int		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      str		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Optional[int]		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      List[Any]		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      str		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Union[str, Any]		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Optional[int]		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      List[str]		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Any		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      str		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Tuple		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      str		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Tuple		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      str		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Tuple		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      str		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Dict		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Dict		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Union[str, Any]		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Tuple		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      List[Any]		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Optional[int]		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Optional[Any]		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Optional[Any]		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      List[Any]		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      int		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      Dict		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      List[str]		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )







class 						__A							(			metaclass=SCREAMING_SNAKE_CASE_		):
     _UpperCamelCase							:      int		 =		["sentencepiece"]






     def __init__(		self    ,					*a__    ,					**a__  ):
       requires_backends(self    ,					["""sentencepiece"""]  )




