




from typing import Optional, Tuple, Union

import flax
import flax.linen as nn
import jax
import jax.numpy as jnp
from flax.core.frozen_dict import FrozenDict

from ..configuration_utils import ConfigMixin, flax_register_to_config
from ..utils import BaseOutput
from .embeddings_flax import FlaxTimestepEmbedding, FlaxTimesteps
from .modeling_flax_utils import FlaxModelMixin
from .unet_ad_blocks_flax import (
    FlaxCrossAttnDownBlockaD,
    FlaxDownBlockaD,
    FlaxUNetMidBlockaDCrossAttn,
)







@flax.struct.dataclass
class a (     __SCREAMING_SNAKE_CASE  ):
						"""simple docstring"""

						UpperCamelCase_	:       Optional[Any]       	=		42
						UpperCamelCase_	:       Tuple       	=		42







class a (     nn.Module  ):
						"""simple docstring"""

						UpperCamelCase_	:       Tuple       	=		42
						UpperCamelCase_	:       int       	=		(16, 32, 96, 2_56)
						UpperCamelCase_	:       str       	=		jnp.floataa






						def     UpperCAmelCase_      ( self :     str				)    ->						Any:
													"""simple docstring"""


													__lowercase      =    nn.Conv(
													    self.block_out_channels[0]				,							kernel_size=(3, 3)				,							padding=((1, 1), (1, 1))				,							dtype=self.dtype				,							)

													__lowercase      =    []
													for i in range(len(self.block_out_channels				) - 1				):
																				__lowercase      =    self.block_out_channels[i]
																				__lowercase      =    self.block_out_channels[i + 1]
																				__lowercase      =    nn.Conv(
																				    _SCREAMING_SNAKE_CASE				,							kernel_size=(3, 3)				,							padding=((1, 1), (1, 1))				,							dtype=self.dtype				,							)
																				blocks.append(_SCREAMING_SNAKE_CASE				)
																				__lowercase      =    nn.Conv(
																				    _SCREAMING_SNAKE_CASE				,							kernel_size=(3, 3)				,							strides=(2, 2)				,							padding=((1, 1), (1, 1))				,							dtype=self.dtype				,							)
																				blocks.append(_SCREAMING_SNAKE_CASE				)
													__lowercase      =    blocks

													__lowercase      =    nn.Conv(
													    self.conditioning_embedding_channels				,							kernel_size=(3, 3)				,							padding=((1, 1), (1, 1))				,							kernel_init=nn.initializers.zeros_init()				,							bias_init=nn.initializers.zeros_init()				,							dtype=self.dtype				,							)






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


													__lowercase      =    self.conv_in(_SCREAMING_SNAKE_CASE				)
													__lowercase      =    nn.silu(_SCREAMING_SNAKE_CASE				)

													for block in self.blocks:
																				__lowercase      =    block(_SCREAMING_SNAKE_CASE				)
																				__lowercase      =    nn.silu(_SCREAMING_SNAKE_CASE				)

													__lowercase      =    self.conv_out(_SCREAMING_SNAKE_CASE				)

													return embedding







@flax_register_to_config
class a (     nn.Module       ,						__SCREAMING_SNAKE_CASE       ,						__SCREAMING_SNAKE_CASE  ):
						"""simple docstring"""

						UpperCamelCase_	:       Union[str, Any]       	=		32
						UpperCamelCase_	:       List[str]       	=		4
						UpperCamelCase_	:       Optional[int]       	=		(
						    'CrossAttnDownBlock2D',
						    'CrossAttnDownBlock2D',
						    'CrossAttnDownBlock2D',
						    'DownBlock2D',
						)
						UpperCamelCase_	:       Optional[Any]       	=		False
						UpperCamelCase_	:       str       	=		(3_20, 6_40, 12_80, 12_80)
						UpperCamelCase_	:       List[Any]       	=		2
						UpperCamelCase_	:       List[Any]       	=		8
						UpperCamelCase_	:       List[Any]       	=		None
						UpperCamelCase_	:       List[Any]       	=		12_80
						UpperCamelCase_	:       Optional[Any]       	=		0.0
						UpperCamelCase_	:       Tuple       	=		False
						UpperCamelCase_	:       Any       	=		jnp.floataa
						UpperCamelCase_	:       List[Any]       	=		True
						UpperCamelCase_	:       List[Any]       	=		0
						UpperCamelCase_	:       Any       	=		'rgb'
						UpperCamelCase_	:       List[Any]       	=		(16, 32, 96, 2_56)






						def     UpperCAmelCase_      ( self :     str				,							lowerCamelCase__ :     str				)    ->						FrozenDict:
													"""simple docstring"""


													__lowercase      =    (1, self.in_channels, self.sample_size, self.sample_size)
													__lowercase      =    jnp.zeros(_SCREAMING_SNAKE_CASE				,							dtype=jnp.floataa				)
													__lowercase      =    jnp.ones((1,)				,							dtype=jnp.intaa				)
													__lowercase      =    jnp.zeros((1, 1, self.cross_attention_dim)				,							dtype=jnp.floataa				)
													__lowercase      =    (1, 3, self.sample_size * 8, self.sample_size * 8)
													__lowercase      =    jnp.zeros(_SCREAMING_SNAKE_CASE				,							dtype=jnp.floataa				)

													__lowercase     ,     __lowercase      =    jax.random.split(_SCREAMING_SNAKE_CASE				)
													__lowercase      =    {'''params''': params_rng, '''dropout''': dropout_rng}

													return self.init(_SCREAMING_SNAKE_CASE				,							_SCREAMING_SNAKE_CASE				,							_SCREAMING_SNAKE_CASE				,							_SCREAMING_SNAKE_CASE				,							_SCREAMING_SNAKE_CASE				)["params"]






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


													__lowercase      =    self.block_out_channels
													__lowercase      =    block_out_channels[0] * 4

													# If `num_attention_heads` is not defined (which is the case for most models)
													# it will default to `attention_head_dim`. This looks weird upon first reading it and it is.
													# The reason for this behavior is to correct for incorrectly named variables that were introduced
													# when this library was created. The incorrect naming was only discovered much later in https://github.com/huggingface/diffusers/issues/2011#issuecomment-1547958131
													# Changing `attention_head_dim` to `num_attention_heads` for 40,000+ configurations is too backwards breaking
													# which is why we correct for the naming here.
													__lowercase      =    self.num_attention_heads or self.attention_head_dim

													# input
													__lowercase      =    nn.Conv(
													    block_out_channels[0]				,							kernel_size=(3, 3)				,							strides=(1, 1)				,							padding=((1, 1), (1, 1))				,							dtype=self.dtype				,							)

													# time
													__lowercase      =    FlaxTimesteps(
													    block_out_channels[0]				,							flip_sin_to_cos=self.flip_sin_to_cos				,							freq_shift=self.config.freq_shift				)
													__lowercase      =    FlaxTimestepEmbedding(_SCREAMING_SNAKE_CASE				,							dtype=self.dtype				)

													__lowercase      =    FlaxControlNetConditioningEmbedding(
													    conditioning_embedding_channels=block_out_channels[0]				,							block_out_channels=self.conditioning_embedding_out_channels				,							)

													__lowercase      =    self.only_cross_attention
													if isinstance(_SCREAMING_SNAKE_CASE				,							_SCREAMING_SNAKE_CASE				):
																				__lowercase      =    (only_cross_attention,) * len(self.down_block_types				)

													if isinstance(_SCREAMING_SNAKE_CASE				,							_SCREAMING_SNAKE_CASE				):
																				__lowercase      =    (num_attention_heads,) * len(self.down_block_types				)

													# down
													__lowercase      =    []
													__lowercase      =    []

													__lowercase      =    block_out_channels[0]

													__lowercase      =    nn.Conv(
													    _SCREAMING_SNAKE_CASE				,							kernel_size=(1, 1)				,							padding='''VALID'''				,							kernel_init=nn.initializers.zeros_init()				,							bias_init=nn.initializers.zeros_init()				,							dtype=self.dtype				,							)
													controlnet_down_blocks.append(_SCREAMING_SNAKE_CASE				)

													for i, down_block_type in enumerate(self.down_block_types				):
																				__lowercase      =    output_channel
																				__lowercase      =    block_out_channels[i]
																				__lowercase      =    i == len(_SCREAMING_SNAKE_CASE				) - 1

																				if down_block_type == "CrossAttnDownBlock2D":
																											__lowercase      =    FlaxCrossAttnDownBlockaD(
																											    in_channels=_SCREAMING_SNAKE_CASE				,							out_channels=_SCREAMING_SNAKE_CASE				,							dropout=self.dropout				,							num_layers=self.layers_per_block				,							num_attention_heads=num_attention_heads[i]				,							add_downsample=not is_final_block				,							use_linear_projection=self.use_linear_projection				,							only_cross_attention=only_cross_attention[i]				,							dtype=self.dtype				,							)
																				else:
																											__lowercase      =    FlaxDownBlockaD(
																											    in_channels=_SCREAMING_SNAKE_CASE				,							out_channels=_SCREAMING_SNAKE_CASE				,							dropout=self.dropout				,							num_layers=self.layers_per_block				,							add_downsample=not is_final_block				,							dtype=self.dtype				,							)

																				down_blocks.append(_SCREAMING_SNAKE_CASE				)

																				for _ in range(self.layers_per_block				):
																											__lowercase      =    nn.Conv(
																											    _SCREAMING_SNAKE_CASE				,							kernel_size=(1, 1)				,							padding='''VALID'''				,							kernel_init=nn.initializers.zeros_init()				,							bias_init=nn.initializers.zeros_init()				,							dtype=self.dtype				,							)
																											controlnet_down_blocks.append(_SCREAMING_SNAKE_CASE				)

																				if not is_final_block:
																											__lowercase      =    nn.Conv(
																											    _SCREAMING_SNAKE_CASE				,							kernel_size=(1, 1)				,							padding='''VALID'''				,							kernel_init=nn.initializers.zeros_init()				,							bias_init=nn.initializers.zeros_init()				,							dtype=self.dtype				,							)
																											controlnet_down_blocks.append(_SCREAMING_SNAKE_CASE				)

													__lowercase      =    down_blocks
													__lowercase      =    controlnet_down_blocks

													# mid
													__lowercase      =    block_out_channels[-1]
													__lowercase      =    FlaxUNetMidBlockaDCrossAttn(
													    in_channels=_SCREAMING_SNAKE_CASE				,							dropout=self.dropout				,							num_attention_heads=num_attention_heads[-1]				,							use_linear_projection=self.use_linear_projection				,							dtype=self.dtype				,							)

													__lowercase      =    nn.Conv(
													    _SCREAMING_SNAKE_CASE				,							kernel_size=(1, 1)				,							padding='''VALID'''				,							kernel_init=nn.initializers.zeros_init()				,							bias_init=nn.initializers.zeros_init()				,							dtype=self.dtype				,							)






						def __call__( self :     Union[str, Any]				,							lowerCamelCase__ :     Any				,							lowerCamelCase__ :     Union[str, Any]				,							lowerCamelCase__ :     Any				,							lowerCamelCase__ :     Dict				,							lowerCamelCase__ :     Optional[Any] = 1.0				,							lowerCamelCase__ :     Any = True				,							lowerCamelCase__ :     Union[str, Any] = False				,							)    ->						Union[FlaxControlNetOutput, Tuple]:
													"""simple docstring"""


													__lowercase      =    self.controlnet_conditioning_channel_order
													if channel_order == "bgr":
																				__lowercase      =    jnp.flip(_SCREAMING_SNAKE_CASE				,							axis=1				)

													# 1. time
													if not isinstance(_SCREAMING_SNAKE_CASE				,							jnp.ndarray				):
																				__lowercase      =    jnp.array([timesteps]				,							dtype=jnp.intaa				)
													elif isinstance(_SCREAMING_SNAKE_CASE				,							jnp.ndarray				) and len(timesteps.shape				) == 0:
																				__lowercase      =    timesteps.astype(dtype=jnp.floataa				)
																				__lowercase      =    jnp.expand_dims(_SCREAMING_SNAKE_CASE				,							0				)

													__lowercase      =    self.time_proj(_SCREAMING_SNAKE_CASE				)
													__lowercase      =    self.time_embedding(_SCREAMING_SNAKE_CASE				)

													# 2. pre-process
													__lowercase      =    jnp.transpose(_SCREAMING_SNAKE_CASE				,							(0, 2, 3, 1)				)
													__lowercase      =    self.conv_in(_SCREAMING_SNAKE_CASE				)

													__lowercase      =    jnp.transpose(_SCREAMING_SNAKE_CASE				,							(0, 2, 3, 1)				)
													__lowercase      =    self.controlnet_cond_embedding(_SCREAMING_SNAKE_CASE				)
													sample += controlnet_cond

													# 3. down
													__lowercase      =    (sample,)
													for down_block in self.down_blocks:
																				if isinstance(_SCREAMING_SNAKE_CASE				,							_SCREAMING_SNAKE_CASE				):
																											__lowercase     ,     __lowercase      =    down_block(_SCREAMING_SNAKE_CASE				,							_SCREAMING_SNAKE_CASE				,							_SCREAMING_SNAKE_CASE				,							deterministic=not train				)
																				else:
																											__lowercase     ,     __lowercase      =    down_block(_SCREAMING_SNAKE_CASE				,							_SCREAMING_SNAKE_CASE				,							deterministic=not train				)
																				down_block_res_samples += res_samples

													# 4. mid
													__lowercase      =    self.mid_block(_SCREAMING_SNAKE_CASE				,							_SCREAMING_SNAKE_CASE				,							_SCREAMING_SNAKE_CASE				,							deterministic=not train				)

													# 5. contronet blocks
													__lowercase      =    ()
													for down_block_res_sample, controlnet_block in zip(_SCREAMING_SNAKE_CASE				,							self.controlnet_down_blocks				):
																				__lowercase      =    controlnet_block(_SCREAMING_SNAKE_CASE				)
																				controlnet_down_block_res_samples += (down_block_res_sample,)

													__lowercase      =    controlnet_down_block_res_samples

													__lowercase      =    self.controlnet_mid_block(_SCREAMING_SNAKE_CASE				)

													# 6. scaling
													__lowercase      =    [sample * conditioning_scale for sample in down_block_res_samples]
													mid_block_res_sample *= conditioning_scale

													if not return_dict:
																				return (down_block_res_samples, mid_block_res_sample)

													return FlaxControlNetOutput(
													    down_block_res_samples=_SCREAMING_SNAKE_CASE				,							mid_block_res_sample=_SCREAMING_SNAKE_CASE				)












import gc
import random
import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer

from diffusers import AutoencoderKL, CycleDiffusionPipeline, DDIMScheduler, UNetaDConditionModel
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, skip_mps

from ..pipeline_params import (
    IMAGE_TO_IMAGE_IMAGE_PARAMS,
    TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS,
    TEXT_GUIDED_IMAGE_VARIATION_PARAMS,
)
from ..test_pipelines_common import PipelineLatentTesterMixin, PipelineTesterMixin


enable_full_determinism()







class a (     __SCREAMING_SNAKE_CASE       ,						__SCREAMING_SNAKE_CASE       ,						unittest.TestCase  ):
						"""simple docstring"""

						UpperCamelCase_	:       Any       	=		CycleDiffusionPipeline
						UpperCamelCase_	:       List[str]       	=		TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {
						    'negative_prompt',
						    'height',
						    'width',
						    'negative_prompt_embeds',
						}
						UpperCamelCase_	:       int       	=		PipelineTesterMixin.required_optional_params - {'latents'}
						UpperCamelCase_	:       Dict       	=		TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS.union({'source_prompt'}  )
						UpperCamelCase_	:       Dict       	=		IMAGE_TO_IMAGE_IMAGE_PARAMS
						UpperCamelCase_	:       Optional[Any]       	=		IMAGE_TO_IMAGE_IMAGE_PARAMS






						def     UpperCAmelCase_      ( self :     int				)    ->						Dict:
													"""simple docstring"""


													torch.manual_seed(0				)
													__lowercase      =    UNetaDConditionModel(
													    block_out_channels=(32, 64)				,							layers_per_block=2				,							sample_size=32				,							in_channels=4				,							out_channels=4				,							down_block_types=('''DownBlock2D''', '''CrossAttnDownBlock2D''')				,							up_block_types=('''CrossAttnUpBlock2D''', '''UpBlock2D''')				,							cross_attention_dim=32				,							)
													__lowercase      =    DDIMScheduler(
													    beta_start=0.0_0_0_8_5				,							beta_end=0.0_1_2				,							beta_schedule='''scaled_linear'''				,							num_train_timesteps=1_000				,							clip_sample=lowerCamelCase__				,							set_alpha_to_one=lowerCamelCase__				,							)
													torch.manual_seed(0				)
													__lowercase      =    AutoencoderKL(
													    block_out_channels=[32, 64]				,							in_channels=3				,							out_channels=3				,							down_block_types=['''DownEncoderBlock2D''', '''DownEncoderBlock2D''']				,							up_block_types=['''UpDecoderBlock2D''', '''UpDecoderBlock2D''']				,							latent_channels=4				,							)
													torch.manual_seed(0				)
													__lowercase      =    CLIPTextConfig(
													    bos_token_id=0				,							eos_token_id=2				,							hidden_size=32				,							intermediate_size=37				,							layer_norm_eps=1e-0_5				,							num_attention_heads=4				,							num_hidden_layers=5				,							pad_token_id=1				,							vocab_size=1_000				,							)
													__lowercase      =    CLIPTextModel(lowerCamelCase__				)
													__lowercase      =    CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip'''				)

													__lowercase      =    {
													    '''unet''': unet,
													    '''scheduler''': scheduler,
													    '''vae''': vae,
													    '''text_encoder''': text_encoder,
													    '''tokenizer''': tokenizer,
													    '''safety_checker''': None,
													    '''feature_extractor''': None,
													}
													return components






						def     UpperCAmelCase_      ( self :     Any				,							lowerCamelCase__ :     int				,							lowerCamelCase__ :     List[str]=0				)    ->						Any:
													"""simple docstring"""


													__lowercase      =    floats_tensor((1, 3, 32, 32)				,							rng=random.Random(lowerCamelCase__				)				).to(lowerCamelCase__				)
													__lowercase      =    image / 2 + 0.5
													if str(lowerCamelCase__				).startswith('''mps'''				):
																				__lowercase      =    torch.manual_seed(lowerCamelCase__				)
													else:
																				__lowercase      =    torch.Generator(device=lowerCamelCase__				).manual_seed(lowerCamelCase__				)
													__lowercase      =    {
													    '''prompt''': '''An astronaut riding an elephant''',
													    '''source_prompt''': '''An astronaut riding a horse''',
													    '''image''': image,
													    '''generator''': generator,
													    '''num_inference_steps''': 2,
													    '''eta''': 0.1,
													    '''strength''': 0.8,
													    '''guidance_scale''': 3,
													    '''source_guidance_scale''': 1,
													    '''output_type''': '''numpy''',
													}
													return inputs






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


													__lowercase      =    '''cpu'''  # ensure determinism for the device-dependent torch.Generator

													__lowercase      =    self.get_dummy_components()
													__lowercase      =    CycleDiffusionPipeline(**lowerCamelCase__				)
													__lowercase      =    pipe.to(lowerCamelCase__				)
													pipe.set_progress_bar_config(disable=lowerCamelCase__				)

													__lowercase      =    self.get_dummy_inputs(lowerCamelCase__				)
													__lowercase      =    pipe(**lowerCamelCase__				)
													__lowercase      =    output.images

													__lowercase      =    images[0, -3:, -3:, -1]

													assert images.shape == (1, 32, 32, 3)
													__lowercase      =    np.array([0.4_4_5_9, 0.4_9_4_3, 0.4_5_4_4, 0.6_6_4_3, 0.5_4_7_4, 0.4_3_2_7, 0.5_7_0_1, 0.5_9_5_9, 0.5_1_7_9]				)

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






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


													__lowercase      =    self.get_dummy_components()
													for name, module in components.items():
																				if hasattr(lowerCamelCase__				,							'''half'''				):
																											__lowercase      =    module.half()
													__lowercase      =    CycleDiffusionPipeline(**lowerCamelCase__				)
													__lowercase      =    pipe.to(lowerCamelCase__				)
													pipe.set_progress_bar_config(disable=lowerCamelCase__				)

													__lowercase      =    self.get_dummy_inputs(lowerCamelCase__				)
													__lowercase      =    pipe(**lowerCamelCase__				)
													__lowercase      =    output.images

													__lowercase      =    images[0, -3:, -3:, -1]

													assert images.shape == (1, 32, 32, 3)
													__lowercase      =    np.array([0.3_5_0_6, 0.4_5_4_3, 0.4_4_6, 0.4_5_7_5, 0.5_1_9_5, 0.4_1_5_5, 0.5_2_7_3, 0.5_1_8, 0.4_1_1_6]				)

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






						@skip_mps
						def     UpperCAmelCase_      ( self :     str				)    ->						int:
													"""simple docstring"""


													return super().test_save_load_local()






						@unittest.skip('''non-deterministic pipeline'''				)
						def     UpperCAmelCase_      ( self :     int				)    ->						Union[str, Any]:
													"""simple docstring"""


													return super().test_inference_batch_single_identical()






						@skip_mps
						def     UpperCAmelCase_      ( self :     int				)    ->						Optional[int]:
													"""simple docstring"""


													return super().test_dict_tuple_outputs_equivalent()






						@skip_mps
						def     UpperCAmelCase_      ( self :     List[Any]				)    ->						List[str]:
													"""simple docstring"""


													return super().test_save_load_optional_components()






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


													return super().test_attention_slicing_forward_pass()







@slow
@require_torch_gpu
class a (     unittest.TestCase  ):
						"""simple docstring"""

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


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






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


													__lowercase      =    load_image(
													    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'''
													    '''/cycle-diffusion/black_colored_car.png'''				)
													__lowercase      =    load_numpy(
													    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/cycle-diffusion/blue_colored_car_fp16.npy'''				)
													__lowercase      =    init_image.resize((512, 512)				)

													__lowercase      =    '''CompVis/stable-diffusion-v1-4'''
													__lowercase      =    DDIMScheduler.from_pretrained(lowerCamelCase__				,							subfolder='''scheduler'''				)
													__lowercase      =    CycleDiffusionPipeline.from_pretrained(
													    lowerCamelCase__				,							scheduler=lowerCamelCase__				,							safety_checker=lowerCamelCase__				,							torch_dtype=torch.floataa				,							revision='''fp16'''				)

													pipe.to(lowerCamelCase__				)
													pipe.set_progress_bar_config(disable=lowerCamelCase__				)
													pipe.enable_attention_slicing()

													__lowercase      =    '''A black colored car'''
													__lowercase      =    '''A blue colored car'''

													__lowercase      =    torch.manual_seed(0				)
													__lowercase      =    pipe(
													    prompt=lowerCamelCase__				,							source_prompt=lowerCamelCase__				,							image=lowerCamelCase__				,							num_inference_steps=100				,							eta=0.1				,							strength=0.8_5				,							guidance_scale=3				,							source_guidance_scale=1				,							generator=lowerCamelCase__				,							output_type='''np'''				,							)
													__lowercase      =    output.images

													# the values aren't exactly equal, but the images look the same visually
													assert np.abs(image - expected_image				).max() < 5e-1






						def     UpperCAmelCase_      ( self :     Tuple				)    ->						List[str]:
													"""simple docstring"""


													__lowercase      =    load_image(
													    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'''
													    '''/cycle-diffusion/black_colored_car.png'''				)
													__lowercase      =    load_numpy(
													    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/cycle-diffusion/blue_colored_car.npy'''				)
													__lowercase      =    init_image.resize((512, 512)				)

													__lowercase      =    '''CompVis/stable-diffusion-v1-4'''
													__lowercase      =    DDIMScheduler.from_pretrained(lowerCamelCase__				,							subfolder='''scheduler'''				)
													__lowercase      =    CycleDiffusionPipeline.from_pretrained(lowerCamelCase__				,							scheduler=lowerCamelCase__				,							safety_checker=lowerCamelCase__				)

													pipe.to(lowerCamelCase__				)
													pipe.set_progress_bar_config(disable=lowerCamelCase__				)
													pipe.enable_attention_slicing()

													__lowercase      =    '''A black colored car'''
													__lowercase      =    '''A blue colored car'''

													__lowercase      =    torch.manual_seed(0				)
													__lowercase      =    pipe(
													    prompt=lowerCamelCase__				,							source_prompt=lowerCamelCase__				,							image=lowerCamelCase__				,							num_inference_steps=100				,							eta=0.1				,							strength=0.8_5				,							guidance_scale=3				,							source_guidance_scale=1				,							generator=lowerCamelCase__				,							output_type='''np'''				,							)
													__lowercase      =    output.images

													assert np.abs(image - expected_image				).max() < 2e-2






