





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


a__			:    Tuple			      =		False





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


  def 	__UpperCAmelCase    (       self   ):



       """simple docstring"""





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


  def 	__UpperCAmelCase    (       self   ):



       """simple docstring"""





       A_					      =					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   )

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

       A_					      =					torch.manual_seed(0   )
       A_					      =					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   )
            A_					      =					VersatileDiffusionDualGuidedPipeline.from_pretrained(__snake_case   )

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

       A_					      =					generator.manual_seed(0   )
       A_					      =					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 	__UpperCAmelCase    (       self   ):



       """simple docstring"""





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

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

       A_					      =					image[0, 2_5_3:2_5_6, 2_5_3:2_5_6, -1]

       assert image.shape == (1, 5_1_2, 5_1_2, 3)
       A_					      =					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






from __future__ import annotations

def     UpperCAmelCase_						(						_UpperCAmelCase       :list[int | float]							)  ->							int | float:
     '''simple docstring'''


     if len(_UpperCAmelCase							) == 0:
          raise ValueError('''find_max() arg is an empty sequence'''							)
     A_					      =					nums[0]
     for x in nums:
          if x > max_num:
               A_					      =					x
     return max_num


if __name__ == "__main__":
      import doctest

      doctest.testmod(verbose=True)



