





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


lowercase				:	Any      						=  False





class 			A__   (							unittest.TestCase     ):




   """simple docstring"""



   pass





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




   """simple docstring"""



   def 							__lowercase		( self)      ->						List[str]:







          '''simple docstring'''

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

   def 							__lowercase		( self)      ->						int:







          '''simple docstring'''

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

          a__						:     str			=    generator.manual_seed(0)
          a__						:     Union[str, Any]			=    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 							__lowercase		( self)      ->						str:







          '''simple docstring'''

          a__						:     Optional[int]			=    VersatileDiffusionTextToImagePipeline.from_pretrained(
              'shi-labs/versatile-diffusion' ,  torch_dtype=torch.floataa)
          pipe.to(lowercase)
          pipe.set_progress_bar_config(disable=lowercase)

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

          a__						:     int			=    image[0, 253:256, 253:256, -1]

          assert image.shape == (1, 512, 512, 3)
          a__						:     Any			=    np.array([0.33_67, 0.31_69, 0.26_56, 0.38_70, 0.47_90, 0.37_96, 0.40_09, 0.48_78, 0.47_78])

          assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2









def A_     (		A__    )  ->		int:

       if not isinstance(A__		,				A__    ):
              raise TypeError('only integers accepted as input'    )
       else:
              a__						:     List[Any]			=    str(abs(A__    )    )
              a__						:     Optional[int]			=    [list(A__    ) for char in range(len(A__    )    )]
              for index in range(len(A__    )    ):
                     num_transpositions[index].pop(A__    )
              return max(
                  int(''.join(list(A__    )    )    ) for transposition in num_transpositions    )


if __name__ == "__main__":
    __import__("""doctest""").testmod()


