

import torch

from diffusers import DPMSolverSDEScheduler
from diffusers.utils import torch_device
from diffusers.utils.testing_utils import require_torchsde

from .test_schedulers import SchedulerCommonTest







@require_torchsde
class        a__       (   UpperCAmelCase       ):







  """simple docstring"""




  UpperCAmelCase__      : Union[str, Any]			       =(DPMSolverSDEScheduler,)
  UpperCAmelCase__      : Dict			       =1_0


  def  _lowercase      (			self    : Any				,				**UpperCAmelCase__    : int		)					->Any:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      Optional[Any]       =   {
            """num_train_timesteps""": 1_1_0_0,
            """beta_start""": 0.00_01,
            """beta_end""": 0.02,
            """beta_schedule""": """linear""",
            """noise_sampler_seed""": 0,
        }

        config.update(**UpperCAmelCase__		)
        return config


  def  _lowercase      (			self    : Dict		)					->Union[str, Any]:
        """simple docstring"""







        for timesteps in [1_0, 5_0, 1_0_0, 1_0_0_0]:
              self.check_over_configs(num_train_timesteps=UpperCAmelCase__		)


  def  _lowercase      (			self    : Tuple		)					->Dict:
        """simple docstring"""







        for beta_start, beta_end in zip([0.0_00_01, 0.00_01, 0.0_01]				,				[0.00_02, 0.0_02, 0.02]		):
              self.check_over_configs(beta_start=UpperCAmelCase__				,				beta_end=UpperCAmelCase__		)


  def  _lowercase      (			self    : Union[str, Any]		)					->Tuple:
        """simple docstring"""







        for schedule in ["linear", "scaled_linear"]:
              self.check_over_configs(beta_schedule=UpperCAmelCase__		)


  def  _lowercase      (			self    : Any		)					->Dict:
        """simple docstring"""







        for prediction_type in ["epsilon", "v_prediction"]:
              self.check_over_configs(prediction_type=UpperCAmelCase__		)


  def  _lowercase      (			self    : Tuple		)					->int:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      Any       =   self.scheduler_classes[0]
        SCREAMING_SNAKE_CASE :      int       =   self.get_scheduler_config()
        SCREAMING_SNAKE_CASE :      int       =   scheduler_class(**UpperCAmelCase__		)

        scheduler.set_timesteps(self.num_inference_steps		)

        SCREAMING_SNAKE_CASE :      List[Any]       =   self.dummy_model()
        SCREAMING_SNAKE_CASE :      Any       =   self.dummy_sample_deter * scheduler.init_noise_sigma
        SCREAMING_SNAKE_CASE :      Union[str, Any]       =   sample.to(UpperCAmelCase__		)

        for i, t in enumerate(scheduler.timesteps		):
              SCREAMING_SNAKE_CASE :      Any       =   scheduler.scale_model_input(UpperCAmelCase__				,				UpperCAmelCase__		)

              SCREAMING_SNAKE_CASE :      Optional[Any]       =   model(UpperCAmelCase__				,				UpperCAmelCase__		)

              SCREAMING_SNAKE_CASE :      Tuple       =   scheduler.step(UpperCAmelCase__				,				UpperCAmelCase__				,				UpperCAmelCase__		)
              SCREAMING_SNAKE_CASE :      Optional[int]       =   output.prev_sample

        SCREAMING_SNAKE_CASE :      str       =   torch.sum(torch.abs(UpperCAmelCase__		)		)
        SCREAMING_SNAKE_CASE :      Tuple       =   torch.mean(torch.abs(UpperCAmelCase__		)		)

        if torch_device in ["mps"]:
              assert abs(result_sum.item() - 1_67.47_82_10_44_92_18_75		) < 1e-2
              assert abs(result_mean.item() - 0.21_78_70_59_64_56_52_77		) < 1e-3
        elif torch_device in ["cuda"]:
              assert abs(result_sum.item() - 1_71.59_35_21_11_81_64_06		) < 1e-2
              assert abs(result_mean.item() - 0.2_23_42_90_68_92_29_96_52		) < 1e-3
        else:
              assert abs(result_sum.item() - 1_62.52_38_34_22_85_15_62		) < 1e-2
              assert abs(result_mean.item() - 0.2_11_61_95_70_85_13_26		) < 1e-3


  def  _lowercase      (			self    : List[Any]		)					->List[Any]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      Tuple       =   self.scheduler_classes[0]
        SCREAMING_SNAKE_CASE :      List[str]       =   self.get_scheduler_config(prediction_type="""v_prediction"""		)
        SCREAMING_SNAKE_CASE :      List[Any]       =   scheduler_class(**UpperCAmelCase__		)

        scheduler.set_timesteps(self.num_inference_steps		)

        SCREAMING_SNAKE_CASE :      int       =   self.dummy_model()
        SCREAMING_SNAKE_CASE :      str       =   self.dummy_sample_deter * scheduler.init_noise_sigma
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   sample.to(UpperCAmelCase__		)

        for i, t in enumerate(scheduler.timesteps		):
              SCREAMING_SNAKE_CASE :      Tuple       =   scheduler.scale_model_input(UpperCAmelCase__				,				UpperCAmelCase__		)

              SCREAMING_SNAKE_CASE :      List[str]       =   model(UpperCAmelCase__				,				UpperCAmelCase__		)

              SCREAMING_SNAKE_CASE :      int       =   scheduler.step(UpperCAmelCase__				,				UpperCAmelCase__				,				UpperCAmelCase__		)
              SCREAMING_SNAKE_CASE :      Optional[int]       =   output.prev_sample

        SCREAMING_SNAKE_CASE :      Optional[Any]       =   torch.sum(torch.abs(UpperCAmelCase__		)		)
        SCREAMING_SNAKE_CASE :      Any       =   torch.mean(torch.abs(UpperCAmelCase__		)		)

        if torch_device in ["mps"]:
              assert abs(result_sum.item() - 1_24.77_14_92_00_43_94_53		) < 1e-2
              assert abs(result_mean.item() - 0.1_62_26_28_90_14_81_62_84		) < 1e-3
        elif torch_device in ["cuda"]:
              assert abs(result_sum.item() - 1_28.1_66_33_60_59_57_03		) < 1e-2
              assert abs(result_mean.item() - 0.1_66_88_32_60_01_16_72_97		) < 1e-3
        else:
              assert abs(result_sum.item() - 1_19.8_48_75_48_82_81_25		) < 1e-2
              assert abs(result_mean.item() - 0.15_60_53_06_62_53_66_21		) < 1e-3


  def  _lowercase      (			self    : Optional[Any]		)					->Tuple:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      Dict       =   self.scheduler_classes[0]
        SCREAMING_SNAKE_CASE :      Tuple       =   self.get_scheduler_config()
        SCREAMING_SNAKE_CASE :      Any       =   scheduler_class(**UpperCAmelCase__		)

        scheduler.set_timesteps(self.num_inference_steps				,				device=UpperCAmelCase__		)

        SCREAMING_SNAKE_CASE :      str       =   self.dummy_model()
        SCREAMING_SNAKE_CASE :      Union[str, Any]       =   self.dummy_sample_deter.to(UpperCAmelCase__		) * scheduler.init_noise_sigma

        for t in scheduler.timesteps:
              SCREAMING_SNAKE_CASE :      Tuple       =   scheduler.scale_model_input(UpperCAmelCase__				,				UpperCAmelCase__		)

              SCREAMING_SNAKE_CASE :      str       =   model(UpperCAmelCase__				,				UpperCAmelCase__		)

              SCREAMING_SNAKE_CASE :      Any       =   scheduler.step(UpperCAmelCase__				,				UpperCAmelCase__				,				UpperCAmelCase__		)
              SCREAMING_SNAKE_CASE :      Union[str, Any]       =   output.prev_sample

        SCREAMING_SNAKE_CASE :      str       =   torch.sum(torch.abs(UpperCAmelCase__		)		)
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   torch.mean(torch.abs(UpperCAmelCase__		)		)

        if torch_device in ["mps"]:
              assert abs(result_sum.item() - 1_67.46_95_73_97_46_09_38		) < 1e-2
              assert abs(result_mean.item() - 0.2_18_05_93_46_07_98_26_35		) < 1e-3
        elif torch_device in ["cuda"]:
              assert abs(result_sum.item() - 1_71.59_35_36_37_69_53_12		) < 1e-2
              assert abs(result_mean.item() - 0.2_23_42_90_83_82_41_57_71		) < 1e-3
        else:
              assert abs(result_sum.item() - 1_62.52_38_34_22_85_15_62		) < 1e-2
              assert abs(result_mean.item() - 0.2_11_61_95_70_85_13_26		) < 1e-3




  def  _lowercase      (			self    : List[Any]		)					->Dict:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      List[str]       =   self.scheduler_classes[0]
        SCREAMING_SNAKE_CASE :      Any       =   self.get_scheduler_config()
        SCREAMING_SNAKE_CASE :      Tuple       =   scheduler_class(**UpperCAmelCase__				,				use_karras_sigmas=UpperCAmelCase__		)

        scheduler.set_timesteps(self.num_inference_steps				,				device=UpperCAmelCase__		)

        SCREAMING_SNAKE_CASE :      str       =   self.dummy_model()
        SCREAMING_SNAKE_CASE :      List[str]       =   self.dummy_sample_deter.to(UpperCAmelCase__		) * scheduler.init_noise_sigma
        SCREAMING_SNAKE_CASE :      Dict       =   sample.to(UpperCAmelCase__		)

        for t in scheduler.timesteps:
              SCREAMING_SNAKE_CASE :      List[Any]       =   scheduler.scale_model_input(UpperCAmelCase__				,				UpperCAmelCase__		)

              SCREAMING_SNAKE_CASE :      List[Any]       =   model(UpperCAmelCase__				,				UpperCAmelCase__		)

              SCREAMING_SNAKE_CASE :      List[Any]       =   scheduler.step(UpperCAmelCase__				,				UpperCAmelCase__				,				UpperCAmelCase__		)
              SCREAMING_SNAKE_CASE :      Union[str, Any]       =   output.prev_sample

        SCREAMING_SNAKE_CASE :      Union[str, Any]       =   torch.sum(torch.abs(UpperCAmelCase__		)		)
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   torch.mean(torch.abs(UpperCAmelCase__		)		)

        if torch_device in ["mps"]:
              assert abs(result_sum.item() - 1_76.66_97_41_35_74_21_88		) < 1e-2
              assert abs(result_mean.item() - 0.2_30_03_87_27_30_98_18_11		) < 1e-2
        elif torch_device in ["cuda"]:
              assert abs(result_sum.item() - 1_77.63_65_35_64_45_31_25		) < 1e-2
              assert abs(result_mean.item() - 0.2_30_03_87_27_30_98_18_11		) < 1e-2
        else:
              assert abs(result_sum.item() - 1_70.3_13_52_23_38_86_72		) < 1e-2
              assert abs(result_mean.item() - 0.2_30_03_87_27_30_98_18_11		) < 1e-2







import gc
import random
import unittest

import numpy as np
import torch
from transformers import XLMRobertaTokenizer

from diffusers import (
    AltDiffusionImgaImgPipeline,
    AutoencoderKL,
    PNDMScheduler,
    UNetaDConditionModel,
)
from diffusers.image_processor import VaeImageProcessor
from diffusers.pipelines.alt_diffusion.modeling_roberta_series import (
    RobertaSeriesConfig,
    RobertaSeriesModelWithTransformation,
)
from diffusers.utils import floats_tensor, load_image, load_numpy, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu


enable_full_determinism()







class        a__       (   unittest.TestCase       ):







  """simple docstring"""




  def  _lowercase      (			self    : Union[str, Any]		)					->List[Any]:
        """simple docstring"""







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


  @property
  def  _lowercase      (			self    : str		)					->Tuple:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      Optional[int]       =   1
        SCREAMING_SNAKE_CASE :      Dict       =   3
        SCREAMING_SNAKE_CASE :      List[Any]       =   (3_2, 3_2)

        SCREAMING_SNAKE_CASE :      Any       =   floats_tensor((batch_size, num_channels) + sizes				,				rng=random.Random(0		)		).to(UpperCAmelCase__		)
        return image


  @property
  def  _lowercase      (			self    : Tuple		)					->List[Any]:
        """simple docstring"""







        torch.manual_seed(0		)
        SCREAMING_SNAKE_CASE :      str       =   UNetaDConditionModel(
            block_out_channels=(3_2, 6_4)				,				layers_per_block=2				,				sample_size=3_2				,				in_channels=4				,				out_channels=4				,				down_block_types=("""DownBlock2D""", """CrossAttnDownBlock2D""")				,				up_block_types=("""CrossAttnUpBlock2D""", """UpBlock2D""")				,				cross_attention_dim=3_2				,				)
        return model


  @property
  def  _lowercase      (			self    : str		)					->int:
        """simple docstring"""







        torch.manual_seed(0		)
        SCREAMING_SNAKE_CASE :      Tuple       =   AutoencoderKL(
            block_out_channels=[3_2, 6_4]				,				in_channels=3				,				out_channels=3				,				down_block_types=["""DownEncoderBlock2D""", """DownEncoderBlock2D"""]				,				up_block_types=["""UpDecoderBlock2D""", """UpDecoderBlock2D"""]				,				latent_channels=4				,				)
        return model


  @property
  def  _lowercase      (			self    : Tuple		)					->Union[str, Any]:
        """simple docstring"""







        torch.manual_seed(0		)
        SCREAMING_SNAKE_CASE :      str       =   RobertaSeriesConfig(
            hidden_size=3_2				,				project_dim=3_2				,				intermediate_size=3_7				,				layer_norm_eps=1e-05				,				num_attention_heads=4				,				num_hidden_layers=5				,				pad_token_id=1				,				vocab_size=5_0_0_6				,				)
        return RobertaSeriesModelWithTransformation(UpperCAmelCase__		)


  @property
  def  _lowercase      (			self    : Union[str, Any]		)					->List[str]:
        """simple docstring"""







        def extract(*UpperCAmelCase__    : List[Any]				,				**UpperCAmelCase__    : Tuple		):







              class        a__       :







                """simple docstring"""




                def __init__(			self    : Tuple		)					->Dict:
                      """simple docstring"""







                      SCREAMING_SNAKE_CASE :      Union[str, Any]       =   torch.ones([0]		)




                def  _lowercase      (			self    : Optional[int]				,				UpperCAmelCase__    : Dict		)					->Optional[Any]:
                      """simple docstring"""







                      self.pixel_values.to(UpperCAmelCase__		)
                      return self


              return Out()

        return extract


  def  _lowercase      (			self    : List[str]		)					->Optional[int]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      Optional[int]       =   """cpu"""  # ensure determinism for the device-dependent torch.Generator
        SCREAMING_SNAKE_CASE :      Optional[int]       =   self.dummy_cond_unet
        SCREAMING_SNAKE_CASE :      str       =   PNDMScheduler(skip_prk_steps=UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      List[Any]       =   self.dummy_vae
        SCREAMING_SNAKE_CASE :      str       =   self.dummy_text_encoder
        SCREAMING_SNAKE_CASE :      Union[str, Any]       =   XLMRobertaTokenizer.from_pretrained("""hf-internal-testing/tiny-xlm-roberta"""		)
        SCREAMING_SNAKE_CASE :      List[Any]       =   7_7

        SCREAMING_SNAKE_CASE :      str       =   self.dummy_image.to(UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      Union[str, Any]       =   init_image / 2 + 0.5

        # make sure here that pndm scheduler skips prk
        SCREAMING_SNAKE_CASE :      List[str]       =   AltDiffusionImgaImgPipeline(
            unet=UpperCAmelCase__				,				scheduler=UpperCAmelCase__				,				vae=UpperCAmelCase__				,				text_encoder=UpperCAmelCase__				,				tokenizer=UpperCAmelCase__				,				safety_checker=UpperCAmelCase__				,				feature_extractor=self.dummy_extractor				,				)
        SCREAMING_SNAKE_CASE :      Union[str, Any]       =   VaeImageProcessor(vae_scale_factor=alt_pipe.vae_scale_factor				,				do_normalize=UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      Tuple       =   alt_pipe.to(UpperCAmelCase__		)
        alt_pipe.set_progress_bar_config(disable=UpperCAmelCase__		)

        SCREAMING_SNAKE_CASE :      str       =   """A painting of a squirrel eating a burger"""
        SCREAMING_SNAKE_CASE :      Tuple       =   torch.Generator(device=UpperCAmelCase__		).manual_seed(0		)
        SCREAMING_SNAKE_CASE :      List[Any]       =   alt_pipe(
            [prompt]				,				generator=UpperCAmelCase__				,				guidance_scale=6.0				,				num_inference_steps=2				,				output_type="""np"""				,				image=UpperCAmelCase__				,				)

        SCREAMING_SNAKE_CASE :      List[str]       =   output.images

        SCREAMING_SNAKE_CASE :      List[Any]       =   torch.Generator(device=UpperCAmelCase__		).manual_seed(0		)
        SCREAMING_SNAKE_CASE :      Any       =   alt_pipe(
            [prompt]				,				generator=UpperCAmelCase__				,				guidance_scale=6.0				,				num_inference_steps=2				,				output_type="""np"""				,				image=UpperCAmelCase__				,				return_dict=UpperCAmelCase__				,				)[0]

        SCREAMING_SNAKE_CASE :      Optional[Any]       =   image[0, -3:, -3:, -1]
        SCREAMING_SNAKE_CASE :      int       =   image_from_tuple[0, -3:, -3:, -1]

        assert image.shape == (1, 3_2, 3_2, 3)
        SCREAMING_SNAKE_CASE :      str       =   np.array([0.44_27, 0.37_31, 0.42_49, 0.49_41, 0.45_46, 0.41_48, 0.41_93, 0.46_66, 0.44_99]		)

        assert np.abs(image_slice.flatten() - expected_slice		).max() < 5e-3
        assert np.abs(image_from_tuple_slice.flatten() - expected_slice		).max() < 5e-3


  @unittest.skipIf(torch_device != """cuda"""				,				"""This test requires a GPU"""		)
  def  _lowercase      (			self    : Optional[int]		)					->List[str]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      Union[str, Any]       =   self.dummy_cond_unet
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   PNDMScheduler(skip_prk_steps=UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      List[str]       =   self.dummy_vae
        SCREAMING_SNAKE_CASE :      int       =   self.dummy_text_encoder
        SCREAMING_SNAKE_CASE :      List[Any]       =   XLMRobertaTokenizer.from_pretrained("""hf-internal-testing/tiny-xlm-roberta"""		)
        SCREAMING_SNAKE_CASE :      Tuple       =   7_7

        SCREAMING_SNAKE_CASE :      Optional[int]       =   self.dummy_image.to(UpperCAmelCase__		)

        # put models in fp16
        SCREAMING_SNAKE_CASE :      List[Any]       =   unet.half()
        SCREAMING_SNAKE_CASE :      Tuple       =   vae.half()
        SCREAMING_SNAKE_CASE :      str       =   bert.half()

        # make sure here that pndm scheduler skips prk
        SCREAMING_SNAKE_CASE :      str       =   AltDiffusionImgaImgPipeline(
            unet=UpperCAmelCase__				,				scheduler=UpperCAmelCase__				,				vae=UpperCAmelCase__				,				text_encoder=UpperCAmelCase__				,				tokenizer=UpperCAmelCase__				,				safety_checker=UpperCAmelCase__				,				feature_extractor=self.dummy_extractor				,				)
        SCREAMING_SNAKE_CASE :      Optional[int]       =   VaeImageProcessor(vae_scale_factor=alt_pipe.vae_scale_factor				,				do_normalize=UpperCAmelCase__		)
        SCREAMING_SNAKE_CASE :      str       =   alt_pipe.to(UpperCAmelCase__		)
        alt_pipe.set_progress_bar_config(disable=UpperCAmelCase__		)

        SCREAMING_SNAKE_CASE :      int       =   """A painting of a squirrel eating a burger"""
        SCREAMING_SNAKE_CASE :      List[str]       =   torch.manual_seed(0		)
        SCREAMING_SNAKE_CASE :      Any       =   alt_pipe(
            [prompt]				,				generator=UpperCAmelCase__				,				num_inference_steps=2				,				output_type="""np"""				,				image=UpperCAmelCase__				,				).images

        assert image.shape == (1, 3_2, 3_2, 3)




  @unittest.skipIf(torch_device != """cuda"""				,				"""This test requires a GPU"""		)
  def  _lowercase      (			self    : Dict		)					->Any:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      Dict       =   load_image(
            """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"""
            """/img2img/sketch-mountains-input.jpg"""		)
        # resize to resolution that is divisible by 8 but not 16 or 32
        SCREAMING_SNAKE_CASE :      Union[str, Any]       =   init_image.resize((7_6_0, 5_0_4)		)

        SCREAMING_SNAKE_CASE :      int       =   """BAAI/AltDiffusion"""
        SCREAMING_SNAKE_CASE :      List[str]       =   AltDiffusionImgaImgPipeline.from_pretrained(
            UpperCAmelCase__				,				safety_checker=UpperCAmelCase__				,				)
        pipe.to(UpperCAmelCase__		)
        pipe.set_progress_bar_config(disable=UpperCAmelCase__		)
        pipe.enable_attention_slicing()

        SCREAMING_SNAKE_CASE :      int       =   """A fantasy landscape, trending on artstation"""

        SCREAMING_SNAKE_CASE :      Optional[Any]       =   torch.manual_seed(0		)
        SCREAMING_SNAKE_CASE :      Union[str, Any]       =   pipe(
            prompt=UpperCAmelCase__				,				image=UpperCAmelCase__				,				strength=0.75				,				guidance_scale=7.5				,				generator=UpperCAmelCase__				,				output_type="""np"""				,				)
        SCREAMING_SNAKE_CASE :      Tuple       =   output.images[0]

        SCREAMING_SNAKE_CASE :      Tuple       =   image[2_5_5:2_5_8, 3_8_3:3_8_6, -1]

        assert image.shape == (5_0_4, 7_6_0, 3)
        SCREAMING_SNAKE_CASE :      List[str]       =   np.array([0.93_58, 0.93_97, 0.95_99, 0.99_01, 1.00_00, 1.00_00, 0.98_82, 1.00_00, 1.00_00]		)

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







@slow
@require_torch_gpu
class        a__       (   unittest.TestCase       ):







  """simple docstring"""




  def  _lowercase      (			self    : Any		)					->List[str]:
        """simple docstring"""







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




  def  _lowercase      (			self    : Optional[Any]		)					->Optional[Any]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE :      Any       =   load_image(
            """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"""
            """/img2img/sketch-mountains-input.jpg"""		)
        SCREAMING_SNAKE_CASE :      str       =   init_image.resize((7_6_8, 5_1_2)		)
        SCREAMING_SNAKE_CASE :      int       =   load_numpy(
            """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/img2img/fantasy_landscape_alt.npy"""		)

        SCREAMING_SNAKE_CASE :      Tuple       =   """BAAI/AltDiffusion"""
        SCREAMING_SNAKE_CASE :      str       =   AltDiffusionImgaImgPipeline.from_pretrained(
            UpperCAmelCase__				,				safety_checker=UpperCAmelCase__				,				)
        pipe.to(UpperCAmelCase__		)
        pipe.set_progress_bar_config(disable=UpperCAmelCase__		)
        pipe.enable_attention_slicing()

        SCREAMING_SNAKE_CASE :      Dict       =   """A fantasy landscape, trending on artstation"""

        SCREAMING_SNAKE_CASE :      Optional[int]       =   torch.manual_seed(0		)
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   pipe(
            prompt=UpperCAmelCase__				,				image=UpperCAmelCase__				,				strength=0.75				,				guidance_scale=7.5				,				generator=UpperCAmelCase__				,				output_type="""np"""				,				)
        SCREAMING_SNAKE_CASE :      Optional[Any]       =   output.images[0]

        assert image.shape == (5_1_2, 7_6_8, 3)
        # img2img is flaky across GPUs even in fp32, so using MAE here
        assert np.abs(expected_image - image		).max() < 1e-2




