



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







       '''simple docstring'''


       pass



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







       '''simple docstring'''


       def 					lowercase__    (							self      :  Any   )			->						Tuple:


             '''simple docstring'''




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



       def 					lowercase__    (							self      :  List[Any]   )			->						Dict:


             '''simple docstring'''




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

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

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

             UpperCAmelCase_      			=							generator.manual_seed(0   )
             UpperCAmelCase_      			=							pipe(
                 prompt=_UpperCAmelCase		,    generator=_UpperCAmelCase		,    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 					lowercase__    (							self      :  Tuple   )			->						List[Any]:


             '''simple docstring'''




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

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

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

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









"""simple docstring"""





from ..utils import DummyObject, requires_backends
class 				lowercase__       (   metaclass=SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       UpperCamelCase						=					['''flax''']



       def __init__(							self      :  Tuple		,    *_UpperCAmelCase      :  str		,    **_UpperCAmelCase      :  Any   )			->						List[str]:


             '''simple docstring'''




             requires_backends(self		,    ["flax"]   )



       @classmethod
       def 					lowercase__    (							cls      :  List[Any]		,    *_UpperCAmelCase      :  Dict		,    **_UpperCAmelCase      :  Tuple   )			->						List[Any]:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )







       @classmethod
       def 					lowercase__    (							cls      :  List[Any]		,    *_UpperCAmelCase      :  List[Any]		,    **_UpperCAmelCase      :  str   )			->						int:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )



class 				lowercase__       (   metaclass=SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       UpperCamelCase						=					['''flax''']



       def __init__(							self      :  Union[str, Any]		,    *_UpperCAmelCase      :  Any		,    **_UpperCAmelCase      :  Tuple   )			->						str:


             '''simple docstring'''




             requires_backends(self		,    ["flax"]   )



       @classmethod
       def 					lowercase__    (							cls      :  str		,    *_UpperCAmelCase      :  Optional[int]		,    **_UpperCAmelCase      :  int   )			->						Any:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )







       @classmethod
       def 					lowercase__    (							cls      :  List[str]		,    *_UpperCAmelCase      :  Optional[Any]		,    **_UpperCAmelCase      :  Optional[int]   )			->						Dict:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )



class 				lowercase__       (   metaclass=SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       UpperCamelCase						=					['''flax''']



       def __init__(							self      :  Union[str, Any]		,    *_UpperCAmelCase      :  Dict		,    **_UpperCAmelCase      :  Dict   )			->						str:


             '''simple docstring'''




             requires_backends(self		,    ["flax"]   )



       @classmethod
       def 					lowercase__    (							cls      :  Optional[int]		,    *_UpperCAmelCase      :  int		,    **_UpperCAmelCase      :  List[Any]   )			->						List[str]:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )







       @classmethod
       def 					lowercase__    (							cls      :  Dict		,    *_UpperCAmelCase      :  Dict		,    **_UpperCAmelCase      :  Union[str, Any]   )			->						int:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )



class 				lowercase__       (   metaclass=SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       UpperCamelCase						=					['''flax''']



       def __init__(							self      :  Any		,    *_UpperCAmelCase      :  str		,    **_UpperCAmelCase      :  Tuple   )			->						Optional[int]:


             '''simple docstring'''




             requires_backends(self		,    ["flax"]   )



       @classmethod
       def 					lowercase__    (							cls      :  str		,    *_UpperCAmelCase      :  Optional[Any]		,    **_UpperCAmelCase      :  List[str]   )			->						str:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )







       @classmethod
       def 					lowercase__    (							cls      :  int		,    *_UpperCAmelCase      :  Any		,    **_UpperCAmelCase      :  int   )			->						Dict:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )



class 				lowercase__       (   metaclass=SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       UpperCamelCase						=					['''flax''']



       def __init__(							self      :  str		,    *_UpperCAmelCase      :  int		,    **_UpperCAmelCase      :  Dict   )			->						Tuple:


             '''simple docstring'''




             requires_backends(self		,    ["flax"]   )



       @classmethod
       def 					lowercase__    (							cls      :  Optional[Any]		,    *_UpperCAmelCase      :  List[str]		,    **_UpperCAmelCase      :  List[Any]   )			->						List[Any]:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )







       @classmethod
       def 					lowercase__    (							cls      :  List[Any]		,    *_UpperCAmelCase      :  int		,    **_UpperCAmelCase      :  int   )			->						Optional[Any]:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )



class 				lowercase__       (   metaclass=SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       UpperCamelCase						=					['''flax''']



       def __init__(							self      :  Dict		,    *_UpperCAmelCase      :  Any		,    **_UpperCAmelCase      :  Optional[Any]   )			->						int:


             '''simple docstring'''




             requires_backends(self		,    ["flax"]   )



       @classmethod
       def 					lowercase__    (							cls      :  List[Any]		,    *_UpperCAmelCase      :  str		,    **_UpperCAmelCase      :  List[str]   )			->						Any:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )







       @classmethod
       def 					lowercase__    (							cls      :  List[str]		,    *_UpperCAmelCase      :  str		,    **_UpperCAmelCase      :  Optional[Any]   )			->						Tuple:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )



class 				lowercase__       (   metaclass=SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       UpperCamelCase						=					['''flax''']



       def __init__(							self      :  Union[str, Any]		,    *_UpperCAmelCase      :  Optional[int]		,    **_UpperCAmelCase      :  Tuple   )			->						str:


             '''simple docstring'''




             requires_backends(self		,    ["flax"]   )



       @classmethod
       def 					lowercase__    (							cls      :  str		,    *_UpperCAmelCase      :  Union[str, Any]		,    **_UpperCAmelCase      :  Union[str, Any]   )			->						List[str]:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )







       @classmethod
       def 					lowercase__    (							cls      :  List[Any]		,    *_UpperCAmelCase      :  Optional[int]		,    **_UpperCAmelCase      :  Optional[Any]   )			->						str:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )



class 				lowercase__       (   metaclass=SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       UpperCamelCase						=					['''flax''']



       def __init__(							self      :  Optional[Any]		,    *_UpperCAmelCase      :  str		,    **_UpperCAmelCase      :  int   )			->						Union[str, Any]:


             '''simple docstring'''




             requires_backends(self		,    ["flax"]   )



       @classmethod
       def 					lowercase__    (							cls      :  Union[str, Any]		,    *_UpperCAmelCase      :  Optional[Any]		,    **_UpperCAmelCase      :  List[Any]   )			->						str:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )







       @classmethod
       def 					lowercase__    (							cls      :  List[Any]		,    *_UpperCAmelCase      :  Dict		,    **_UpperCAmelCase      :  str   )			->						List[str]:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )



class 				lowercase__       (   metaclass=SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       UpperCamelCase						=					['''flax''']



       def __init__(							self      :  List[str]		,    *_UpperCAmelCase      :  Optional[int]		,    **_UpperCAmelCase      :  Optional[int]   )			->						Tuple:


             '''simple docstring'''




             requires_backends(self		,    ["flax"]   )



       @classmethod
       def 					lowercase__    (							cls      :  Union[str, Any]		,    *_UpperCAmelCase      :  Optional[int]		,    **_UpperCAmelCase      :  str   )			->						Union[str, Any]:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )







       @classmethod
       def 					lowercase__    (							cls      :  Optional[int]		,    *_UpperCAmelCase      :  Any		,    **_UpperCAmelCase      :  List[str]   )			->						Optional[int]:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )



class 				lowercase__       (   metaclass=SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       UpperCamelCase						=					['''flax''']



       def __init__(							self      :  Optional[Any]		,    *_UpperCAmelCase      :  Union[str, Any]		,    **_UpperCAmelCase      :  Optional[Any]   )			->						Tuple:


             '''simple docstring'''




             requires_backends(self		,    ["flax"]   )



       @classmethod
       def 					lowercase__    (							cls      :  Optional[int]		,    *_UpperCAmelCase      :  Union[str, Any]		,    **_UpperCAmelCase      :  Dict   )			->						Any:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )







       @classmethod
       def 					lowercase__    (							cls      :  List[str]		,    *_UpperCAmelCase      :  List[str]		,    **_UpperCAmelCase      :  Optional[Any]   )			->						List[str]:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )



class 				lowercase__       (   metaclass=SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       UpperCamelCase						=					['''flax''']



       def __init__(							self      :  Tuple		,    *_UpperCAmelCase      :  List[str]		,    **_UpperCAmelCase      :  Optional[int]   )			->						Tuple:


             '''simple docstring'''




             requires_backends(self		,    ["flax"]   )



       @classmethod
       def 					lowercase__    (							cls      :  Any		,    *_UpperCAmelCase      :  Tuple		,    **_UpperCAmelCase      :  Optional[int]   )			->						Any:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )







       @classmethod
       def 					lowercase__    (							cls      :  List[Any]		,    *_UpperCAmelCase      :  int		,    **_UpperCAmelCase      :  int   )			->						int:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )



class 				lowercase__       (   metaclass=SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       UpperCamelCase						=					['''flax''']



       def __init__(							self      :  Tuple		,    *_UpperCAmelCase      :  int		,    **_UpperCAmelCase      :  Any   )			->						List[Any]:


             '''simple docstring'''




             requires_backends(self		,    ["flax"]   )



       @classmethod
       def 					lowercase__    (							cls      :  str		,    *_UpperCAmelCase      :  int		,    **_UpperCAmelCase      :  str   )			->						Any:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )







       @classmethod
       def 					lowercase__    (							cls      :  int		,    *_UpperCAmelCase      :  Dict		,    **_UpperCAmelCase      :  List[Any]   )			->						Dict:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )



class 				lowercase__       (   metaclass=SCREAMING_SNAKE_CASE				):







       '''simple docstring'''


       UpperCamelCase						=					['''flax''']



       def __init__(							self      :  int		,    *_UpperCAmelCase      :  Any		,    **_UpperCAmelCase      :  int   )			->						Union[str, Any]:


             '''simple docstring'''




             requires_backends(self		,    ["flax"]   )



       @classmethod
       def 					lowercase__    (							cls      :  Optional[int]		,    *_UpperCAmelCase      :  Dict		,    **_UpperCAmelCase      :  Dict   )			->						Dict:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )







       @classmethod
       def 					lowercase__    (							cls      :  str		,    *_UpperCAmelCase      :  Dict		,    **_UpperCAmelCase      :  Any   )			->						List[str]:


             '''simple docstring'''




             requires_backends(cls		,    ["flax"]   )




