





import gc
import tempfile
import unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionDualGuidedPipeline
from diffusers.utils.testing_utils import load_image, nightly, require_torch_gpu, torch_device


__lowercase													=			False

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






    '''simple docstring'''





    def 	A		(   self						:		List[str]							):

      """simple docstring"""





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





    def 	A		(   self						:		Optional[Any]							):

      """simple docstring"""





      __lowerCAmelCase			=				VersatileDiffusionDualGuidedPipeline.from_pretrained('''shi-labs/versatile-diffusion'''							)
      # remove text_unet
      pipe.remove_unused_weights()
      pipe.to(snake_case							)
      pipe.set_progress_bar_config(disable=snake_case							)

      __lowerCAmelCase			=				load_image(
          '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg'''							)

      __lowerCAmelCase			=				torch.manual_seed(0							)
      __lowerCAmelCase			=				pipe(
          prompt='''first prompt'''			,						image=snake_case			,						text_to_image_strength=0.75			,						generator=snake_case			,						guidance_scale=7.5			,						num_inference_steps=2			,						output_type='''numpy'''			,						).images

      with tempfile.TemporaryDirectory() as tmpdirname:
        pipe.save_pretrained(snake_case							)
        __lowerCAmelCase			=				VersatileDiffusionDualGuidedPipeline.from_pretrained(snake_case							)

      pipe.to(snake_case							)
      pipe.set_progress_bar_config(disable=snake_case							)

      __lowerCAmelCase			=				generator.manual_seed(0							)
      __lowerCAmelCase			=				pipe(
          prompt='''first prompt'''			,						image=snake_case			,						text_to_image_strength=0.75			,						generator=snake_case			,						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						:		Union[str, Any]							):

      """simple docstring"""





      __lowerCAmelCase			=				VersatileDiffusionDualGuidedPipeline.from_pretrained('''shi-labs/versatile-diffusion'''							)
      pipe.remove_unused_weights()
      pipe.to(snake_case							)
      pipe.set_progress_bar_config(disable=snake_case							)

      __lowerCAmelCase			=				'''cyberpunk 2077'''
      __lowerCAmelCase			=				load_image(
          '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg'''							)
      __lowerCAmelCase			=				torch.manual_seed(0							)
      __lowerCAmelCase			=				pipe(
          prompt=snake_case			,						image=snake_case			,						text_to_image_strength=0.75			,						generator=snake_case			,						guidance_scale=7.5			,						num_inference_steps=50			,						output_type='''numpy'''			,						).images

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

      assert image.shape == (1, 512, 512, 3)
      __lowerCAmelCase			=				np.array([0.0787, 0.0849, 0.0826, 0.0812, 0.0807, 0.0795, 0.0818, 0.0798, 0.0779]							)

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











def 					__SCREAMING_SNAKE_CASE  (							__lowercase:		list):



  '''simple docstring'''






  if len(__lowercase) <= 1:
    return data
  else:
    return [
        *quick_sort([e for e in data[1:] if e <= data[0]]),
        data[0],
        *quick_sort([e for e in data[1:] if e > data[0]]),
    ]


if __name__ == "__main__":
      import doctest

      doctest.testmod()
