


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					:       Any			    =     False



class A__     ( unittest.TestCase  ):



  """simple docstring"""



  pass




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



  """simple docstring"""



  def    _UpperCamelCase( self			:  Optional[Any]       ):
        # clean up the VRAM after each test
        super().tearDown()
        gc.collect()
        torch.cuda.empty_cache()

  def    _UpperCamelCase( self			:  str       ):
        a__	:  Tuple     =   VersatileDiffusionTextToImagePipeline.from_pretrained("shi-labs/versatile-diffusion"       )
        # remove text_unet
        pipe.remove_unused_weights()
        pipe.to(lowerCamelCase__       )
        pipe.set_progress_bar_config(disable=lowerCamelCase__       )

        a__	:  Tuple     =   "A painting of a squirrel eating a burger "
        a__	:  Any     =   torch.manual_seed(0       )
        a__	:  int     =   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__       )
              a__	:  int     =   VersatileDiffusionTextToImagePipeline.from_pretrained(lowerCamelCase__       )
        pipe.to(lowerCamelCase__       )
        pipe.set_progress_bar_config(disable=lowerCamelCase__       )

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

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

        a__	:  Union[str, Any]     =   image[0, 253:256, 253:256, -1]

        assert image.shape == (1, 512, 512, 3)
        a__	:  List[Any]     =   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








import numpy as np





def 				__lowerCAmelCase(       _SCREAMING_SNAKE_CASE				)							-> np.array:




    """simple docstring"""




    return (2 / (1 + np.exp(-2 * vector				))) - 1


if __name__ == "__main__":
 import doctest

 doctest.testmod()





