




'''simple docstring'''






import argparse
import json

import torch

from diffusers import AutoencoderKL, DDPMPipeline, DDPMScheduler, UNetaDModel, VQModel

def       __lowerCAmelCase (   snake_case__ ,				snake_case__=1						):







			if n_shave_prefix_segments >= 0:
						return ".".join(path.split("."						)[n_shave_prefix_segments:]						)
			else:
						return ".".join(path.split("."						)[:n_shave_prefix_segments]						)

def       __lowerCAmelCase (   snake_case__ ,				snake_case__=0						):
			__UpperCamelCase				:      Optional[Any]									=       []
			for old_item in old_list:
						__UpperCamelCase				:      int									=       old_item
						__UpperCamelCase				:      List[str]									=       new_item.replace("block." ,				"resnets."						)
						__UpperCamelCase				:      List[str]									=       new_item.replace("conv_shorcut" ,				"conv1"						)
						__UpperCamelCase				:      List[Any]									=       new_item.replace("in_shortcut" ,				"conv_shortcut"						)
						__UpperCamelCase				:      Tuple									=       new_item.replace("temb_proj" ,				"time_emb_proj"						)

						__UpperCamelCase				:      Tuple									=       shave_segments(snake_case__ ,				n_shave_prefix_segments=snake_case__						)

						mapping.append({"old": old_item, "new": new_item}						)

			return mapping

def       __lowerCAmelCase (   snake_case__ ,				snake_case__=0 ,				snake_case__=False						):
			__UpperCamelCase				:      Union[str, Any]									=       []
			for old_item in old_list:
						__UpperCamelCase				:      Any									=       old_item

						# In `model.mid`, the layer is called `attn`.
						if not in_mid:
									__UpperCamelCase				:      Union[str, Any]									=       new_item.replace("attn" ,				"attentions"						)
						__UpperCamelCase				:      Optional[int]									=       new_item.replace(".k." ,				".key."						)
						__UpperCamelCase				:      Union[str, Any]									=       new_item.replace(".v." ,				".value."						)
						__UpperCamelCase				:      Optional[int]									=       new_item.replace(".q." ,				".query."						)

						__UpperCamelCase				:      str									=       new_item.replace("proj_out" ,				"proj_attn"						)
						__UpperCamelCase				:      Tuple									=       new_item.replace("norm" ,				"group_norm"						)

						__UpperCamelCase				:      Dict									=       shave_segments(snake_case__ ,				n_shave_prefix_segments=snake_case__						)
						mapping.append({"old": old_item, "new": new_item}						)

			return mapping

def       __lowerCAmelCase (   snake_case__ ,				snake_case__ ,				snake_case__ ,				snake_case__=None ,				snake_case__=None ,				snake_case__=None						):
			assert isinstance(snake_case__ ,				snake_case__						), "Paths should be a list of dicts containing 'old' and 'new' keys."

			if attention_paths_to_split is not None:
						if config is None:
									raise ValueError("Please specify the config if setting \'attention_paths_to_split\' to \'True\'."						)

						for path, path_map in attention_paths_to_split.items():
									__UpperCamelCase				:      Any									=       old_checkpoint[path]
									__UpperCamelCase				:      Dict									=       old_tensor.shape[0] // 3

									__UpperCamelCase				:      Tuple									=       (-1, channels) if len(old_tensor.shape						) == 3 else (-1)

									__UpperCamelCase				:      List[Any]									=       old_tensor.shape[0] // config.get("num_head_channels" ,				1						) // 3

									__UpperCamelCase				:      Optional[int]									=       old_tensor.reshape((num_heads, 3 * channels // num_heads) + old_tensor.shape[1:]						)
									__UpperCamelCase		, __UpperCamelCase		, __UpperCamelCase				:      Optional[int]									=       old_tensor.split(channels // num_heads ,				dim=1						)

									__UpperCamelCase				:      Dict									=       query.reshape(snake_case__						).squeeze()
									__UpperCamelCase				:      List[Any]									=       key.reshape(snake_case__						).squeeze()
									__UpperCamelCase				:      Any									=       value.reshape(snake_case__						).squeeze()

			for path in paths:
						__UpperCamelCase				:      int									=       path["new"]

						if attention_paths_to_split is not None and new_path in attention_paths_to_split:
									continue

						__UpperCamelCase				:      int									=       new_path.replace("down." ,				"down_blocks."						)
						__UpperCamelCase				:      str									=       new_path.replace("up." ,				"up_blocks."						)

						if additional_replacements is not None:
									for replacement in additional_replacements:
												__UpperCamelCase				:      int									=       new_path.replace(replacement["old"] ,				replacement["new"]						)

						if "attentions" in new_path:
									__UpperCamelCase				:      Any									=       old_checkpoint[path["old"]].squeeze()
						else:
									__UpperCamelCase				:      Optional[Any]									=       old_checkpoint[path["old"]]

def       __lowerCAmelCase (   snake_case__ ,				snake_case__						):
			__UpperCamelCase				:      List[str]									=       {}

			__UpperCamelCase				:      Union[str, Any]									=       checkpoint["temb.dense.0.weight"]
			__UpperCamelCase				:      List[str]									=       checkpoint["temb.dense.0.bias"]
			__UpperCamelCase				:      Dict									=       checkpoint["temb.dense.1.weight"]
			__UpperCamelCase				:      Optional[int]									=       checkpoint["temb.dense.1.bias"]

			__UpperCamelCase				:      int									=       checkpoint["norm_out.weight"]
			__UpperCamelCase				:      Optional[Any]									=       checkpoint["norm_out.bias"]

			__UpperCamelCase				:      Optional[int]									=       checkpoint["conv_in.weight"]
			__UpperCamelCase				:      Optional[int]									=       checkpoint["conv_in.bias"]
			__UpperCamelCase				:      str									=       checkpoint["conv_out.weight"]
			__UpperCamelCase				:      int									=       checkpoint["conv_out.bias"]

			__UpperCamelCase				:      str									=       len({".".join(layer.split("."						)[:2]						) for layer in checkpoint if "down" in layer}						)
			__UpperCamelCase				:      Optional[int]									=       {
			    layer_id: [key for key in checkpoint if F"down.{layer_id}" in key] for layer_id in range(snake_case__						)
			}

			__UpperCamelCase				:      List[str]									=       len({".".join(layer.split("."						)[:2]						) for layer in checkpoint if "up" in layer}						)
			__UpperCamelCase				:      Optional[int]									=       {layer_id: [key for key in checkpoint if F"up.{layer_id}" in key] for layer_id in range(snake_case__						)}

			for i in range(snake_case__						):
						__UpperCamelCase				:      Optional[Any]									=       (i - 1) // (config["layers_per_block"] + 1)

						if any("downsample" in layer for layer in down_blocks[i]						):
									__UpperCamelCase				:      int									=       checkpoint[
									    F"down.{i}.downsample.op.weight"
									]
									__UpperCamelCase				:      List[str]									=       checkpoint[F"down.{i}.downsample.op.bias"]
						#            new_checkpoint[f'down_blocks.{i}.downsamplers.0.op.weight'] = checkpoint[f'down.{i}.downsample.conv.weight']
						#            new_checkpoint[f'down_blocks.{i}.downsamplers.0.op.bias'] = checkpoint[f'down.{i}.downsample.conv.bias']

						if any("block" in layer for layer in down_blocks[i]						):
									__UpperCamelCase				:      str									=       len(
									    {".".join(shave_segments(snake_case__ ,				2						).split("."						)[:2]						) for layer in down_blocks[i] if "block" in layer}						)
									__UpperCamelCase				:      Optional[Any]									=       {
									    layer_id: [key for key in down_blocks[i] if F"block.{layer_id}" in key]
									    for layer_id in range(snake_case__						)
									}

									if num_blocks > 0:
												for j in range(config["layers_per_block"]						):
															__UpperCamelCase				:      Optional[int]									=       renew_resnet_paths(blocks[j]						)
															assign_to_checkpoint(snake_case__ ,				snake_case__ ,				snake_case__						)

						if any("attn" in layer for layer in down_blocks[i]						):
									__UpperCamelCase				:      Optional[Any]									=       len(
									    {".".join(shave_segments(snake_case__ ,				2						).split("."						)[:2]						) for layer in down_blocks[i] if "attn" in layer}						)
									__UpperCamelCase				:      Tuple									=       {
									    layer_id: [key for key in down_blocks[i] if F"attn.{layer_id}" in key]
									    for layer_id in range(snake_case__						)
									}

									if num_attn > 0:
												for j in range(config["layers_per_block"]						):
															__UpperCamelCase				:      Tuple									=       renew_attention_paths(attns[j]						)
															assign_to_checkpoint(snake_case__ ,				snake_case__ ,				snake_case__ ,				config=snake_case__						)

			__UpperCamelCase				:      Tuple									=       [key for key in checkpoint if "mid.block_1" in key]
			__UpperCamelCase				:      str									=       [key for key in checkpoint if "mid.block_2" in key]
			__UpperCamelCase				:      str									=       [key for key in checkpoint if "mid.attn_1" in key]

			# Mid new 2
			__UpperCamelCase				:      Union[str, Any]									=       renew_resnet_paths(snake_case__						)
			assign_to_checkpoint(
			    snake_case__ ,				snake_case__ ,				snake_case__ ,				additional_replacements=[{"old": "mid.", "new": "mid_new_2."}, {"old": "block_1", "new": "resnets.0"}] ,				)

			__UpperCamelCase				:      Tuple									=       renew_resnet_paths(snake_case__						)
			assign_to_checkpoint(
			    snake_case__ ,				snake_case__ ,				snake_case__ ,				additional_replacements=[{"old": "mid.", "new": "mid_new_2."}, {"old": "block_2", "new": "resnets.1"}] ,				)

			__UpperCamelCase				:      Optional[int]									=       renew_attention_paths(snake_case__ ,				in_mid=snake_case__						)
			assign_to_checkpoint(
			    snake_case__ ,				snake_case__ ,				snake_case__ ,				additional_replacements=[{"old": "mid.", "new": "mid_new_2."}, {"old": "attn_1", "new": "attentions.0"}] ,				)

			for i in range(snake_case__						):
						__UpperCamelCase				:      str									=       num_up_blocks - 1 - i

						if any("upsample" in layer for layer in up_blocks[i]						):
									__UpperCamelCase				:      Optional[int]									=       checkpoint[
									    F"up.{i}.upsample.conv.weight"
									]
									__UpperCamelCase				:      int									=       checkpoint[F"up.{i}.upsample.conv.bias"]

						if any("block" in layer for layer in up_blocks[i]						):
									__UpperCamelCase				:      Any									=       len(
									    {".".join(shave_segments(snake_case__ ,				2						).split("."						)[:2]						) for layer in up_blocks[i] if "block" in layer}						)
									__UpperCamelCase				:      str									=       {
									    layer_id: [key for key in up_blocks[i] if F"block.{layer_id}" in key] for layer_id in range(snake_case__						)
									}

									if num_blocks > 0:
												for j in range(config["layers_per_block"] + 1						):
															__UpperCamelCase				:      Tuple									=       {"old": F"up_blocks.{i}", "new": F"up_blocks.{block_id}"}
															__UpperCamelCase				:      int									=       renew_resnet_paths(blocks[j]						)
															assign_to_checkpoint(snake_case__ ,				snake_case__ ,				snake_case__ ,				additional_replacements=[replace_indices]						)

						if any("attn" in layer for layer in up_blocks[i]						):
									__UpperCamelCase				:      str									=       len(
									    {".".join(shave_segments(snake_case__ ,				2						).split("."						)[:2]						) for layer in up_blocks[i] if "attn" in layer}						)
									__UpperCamelCase				:      List[Any]									=       {
									    layer_id: [key for key in up_blocks[i] if F"attn.{layer_id}" in key] for layer_id in range(snake_case__						)
									}

									if num_attn > 0:
												for j in range(config["layers_per_block"] + 1						):
															__UpperCamelCase				:      Union[str, Any]									=       {"old": F"up_blocks.{i}", "new": F"up_blocks.{block_id}"}
															__UpperCamelCase				:      Tuple									=       renew_attention_paths(attns[j]						)
															assign_to_checkpoint(snake_case__ ,				snake_case__ ,				snake_case__ ,				additional_replacements=[replace_indices]						)

			__UpperCamelCase				:      List[Any]									=       {k.replace("mid_new_2" ,				"mid_block"						): v for k, v in new_checkpoint.items()}
			return new_checkpoint

def       __lowerCAmelCase (   snake_case__ ,				snake_case__						):
			__UpperCamelCase				:      str									=       {}

			__UpperCamelCase				:      Optional[int]									=       checkpoint["encoder.norm_out.weight"]
			__UpperCamelCase				:      Union[str, Any]									=       checkpoint["encoder.norm_out.bias"]

			__UpperCamelCase				:      List[Any]									=       checkpoint["encoder.conv_in.weight"]
			__UpperCamelCase				:      List[Any]									=       checkpoint["encoder.conv_in.bias"]
			__UpperCamelCase				:      Tuple									=       checkpoint["encoder.conv_out.weight"]
			__UpperCamelCase				:      Union[str, Any]									=       checkpoint["encoder.conv_out.bias"]

			__UpperCamelCase				:      Optional[int]									=       checkpoint["decoder.norm_out.weight"]
			__UpperCamelCase				:      Dict									=       checkpoint["decoder.norm_out.bias"]

			__UpperCamelCase				:      Dict									=       checkpoint["decoder.conv_in.weight"]
			__UpperCamelCase				:      Dict									=       checkpoint["decoder.conv_in.bias"]
			__UpperCamelCase				:      Tuple									=       checkpoint["decoder.conv_out.weight"]
			__UpperCamelCase				:      Dict									=       checkpoint["decoder.conv_out.bias"]

			__UpperCamelCase				:      Optional[int]									=       len({".".join(layer.split("."						)[:3]						) for layer in checkpoint if "down" in layer}						)
			__UpperCamelCase				:      List[str]									=       {
			    layer_id: [key for key in checkpoint if F"down.{layer_id}" in key] for layer_id in range(snake_case__						)
			}

			__UpperCamelCase				:      Any									=       len({".".join(layer.split("."						)[:3]						) for layer in checkpoint if "up" in layer}						)
			__UpperCamelCase				:      str									=       {layer_id: [key for key in checkpoint if F"up.{layer_id}" in key] for layer_id in range(snake_case__						)}

			for i in range(snake_case__						):
						__UpperCamelCase				:      Union[str, Any]									=       (i - 1) // (config["layers_per_block"] + 1)

						if any("downsample" in layer for layer in down_blocks[i]						):
									__UpperCamelCase				:      List[Any]									=       checkpoint[
									    F"encoder.down.{i}.downsample.conv.weight"
									]
									__UpperCamelCase				:      List[str]									=       checkpoint[
									    F"encoder.down.{i}.downsample.conv.bias"
									]

						if any("block" in layer for layer in down_blocks[i]						):
									__UpperCamelCase				:      List[str]									=       len(
									    {".".join(shave_segments(snake_case__ ,				3						).split("."						)[:3]						) for layer in down_blocks[i] if "block" in layer}						)
									__UpperCamelCase				:      Optional[Any]									=       {
									    layer_id: [key for key in down_blocks[i] if F"block.{layer_id}" in key]
									    for layer_id in range(snake_case__						)
									}

									if num_blocks > 0:
												for j in range(config["layers_per_block"]						):
															__UpperCamelCase				:      Optional[int]									=       renew_resnet_paths(blocks[j]						)
															assign_to_checkpoint(snake_case__ ,				snake_case__ ,				snake_case__						)

						if any("attn" in layer for layer in down_blocks[i]						):
									__UpperCamelCase				:      str									=       len(
									    {".".join(shave_segments(snake_case__ ,				3						).split("."						)[:3]						) for layer in down_blocks[i] if "attn" in layer}						)
									__UpperCamelCase				:      str									=       {
									    layer_id: [key for key in down_blocks[i] if F"attn.{layer_id}" in key]
									    for layer_id in range(snake_case__						)
									}

									if num_attn > 0:
												for j in range(config["layers_per_block"]						):
															__UpperCamelCase				:      Optional[Any]									=       renew_attention_paths(attns[j]						)
															assign_to_checkpoint(snake_case__ ,				snake_case__ ,				snake_case__ ,				config=snake_case__						)

			__UpperCamelCase				:      Union[str, Any]									=       [key for key in checkpoint if "mid.block_1" in key]
			__UpperCamelCase				:      Tuple									=       [key for key in checkpoint if "mid.block_2" in key]
			__UpperCamelCase				:      Tuple									=       [key for key in checkpoint if "mid.attn_1" in key]

			# Mid new 2
			__UpperCamelCase				:      Union[str, Any]									=       renew_resnet_paths(snake_case__						)
			assign_to_checkpoint(
			    snake_case__ ,				snake_case__ ,				snake_case__ ,				additional_replacements=[{"old": "mid.", "new": "mid_new_2."}, {"old": "block_1", "new": "resnets.0"}] ,				)

			__UpperCamelCase				:      Any									=       renew_resnet_paths(snake_case__						)
			assign_to_checkpoint(
			    snake_case__ ,				snake_case__ ,				snake_case__ ,				additional_replacements=[{"old": "mid.", "new": "mid_new_2."}, {"old": "block_2", "new": "resnets.1"}] ,				)

			__UpperCamelCase				:      Any									=       renew_attention_paths(snake_case__ ,				in_mid=snake_case__						)
			assign_to_checkpoint(
			    snake_case__ ,				snake_case__ ,				snake_case__ ,				additional_replacements=[{"old": "mid.", "new": "mid_new_2."}, {"old": "attn_1", "new": "attentions.0"}] ,				)

			for i in range(snake_case__						):
						__UpperCamelCase				:      Optional[Any]									=       num_up_blocks - 1 - i

						if any("upsample" in layer for layer in up_blocks[i]						):
									__UpperCamelCase				:      List[str]									=       checkpoint[
									    F"decoder.up.{i}.upsample.conv.weight"
									]
									__UpperCamelCase				:      List[str]									=       checkpoint[
									    F"decoder.up.{i}.upsample.conv.bias"
									]

						if any("block" in layer for layer in up_blocks[i]						):
									__UpperCamelCase				:      Tuple									=       len(
									    {".".join(shave_segments(snake_case__ ,				3						).split("."						)[:3]						) for layer in up_blocks[i] if "block" in layer}						)
									__UpperCamelCase				:      int									=       {
									    layer_id: [key for key in up_blocks[i] if F"block.{layer_id}" in key] for layer_id in range(snake_case__						)
									}

									if num_blocks > 0:
												for j in range(config["layers_per_block"] + 1						):
															__UpperCamelCase				:      Optional[Any]									=       {"old": F"up_blocks.{i}", "new": F"up_blocks.{block_id}"}
															__UpperCamelCase				:      Dict									=       renew_resnet_paths(blocks[j]						)
															assign_to_checkpoint(snake_case__ ,				snake_case__ ,				snake_case__ ,				additional_replacements=[replace_indices]						)

						if any("attn" in layer for layer in up_blocks[i]						):
									__UpperCamelCase				:      str									=       len(
									    {".".join(shave_segments(snake_case__ ,				3						).split("."						)[:3]						) for layer in up_blocks[i] if "attn" in layer}						)
									__UpperCamelCase				:      Any									=       {
									    layer_id: [key for key in up_blocks[i] if F"attn.{layer_id}" in key] for layer_id in range(snake_case__						)
									}

									if num_attn > 0:
												for j in range(config["layers_per_block"] + 1						):
															__UpperCamelCase				:      str									=       {"old": F"up_blocks.{i}", "new": F"up_blocks.{block_id}"}
															__UpperCamelCase				:      Tuple									=       renew_attention_paths(attns[j]						)
															assign_to_checkpoint(snake_case__ ,				snake_case__ ,				snake_case__ ,				additional_replacements=[replace_indices]						)

			__UpperCamelCase				:      Optional[int]									=       {k.replace("mid_new_2" ,				"mid_block"						): v for k, v in new_checkpoint.items()}
			__UpperCamelCase				:      Optional[int]									=       checkpoint["quant_conv.weight"]
			__UpperCamelCase				:      Tuple									=       checkpoint["quant_conv.bias"]
			if "quantize.embedding.weight" in checkpoint:
						__UpperCamelCase				:      str									=       checkpoint["quantize.embedding.weight"]
			__UpperCamelCase				:      Tuple									=       checkpoint["post_quant_conv.weight"]
			__UpperCamelCase				:      Union[str, Any]									=       checkpoint["post_quant_conv.bias"]

			return new_checkpoint


if __name__ == "__main__":
					_lowerCAmelCase				     = argparse.ArgumentParser()

					parser.add_argument(
					    '''--checkpoint_path''', default=None, type=str, required=True, help='''Path to the checkpoint to convert.'''
					)

					parser.add_argument(
					    '''--config_file''',
					    default=None,
					    type=str,
					    required=True,
					    help='''The config json file corresponding to the architecture.''',
					)

					parser.add_argument('''--dump_path''', default=None, type=str, required=True, help='''Path to the output model.''')

					_lowerCAmelCase				     = parser.parse_args()
					_lowerCAmelCase				     = torch.load(args.checkpoint_path)

					with open(args.config_file) as f:
										_lowerCAmelCase				     = json.loads(f.read())

					# unet case
					_lowerCAmelCase				     = {key.split('''.''')[0] for key in checkpoint.keys()}
					if "encoder" in key_prefix_set and "decoder" in key_prefix_set:
										_lowerCAmelCase				     = convert_vq_autoenc_checkpoint(checkpoint, config)
					else:
										_lowerCAmelCase				     = convert_ddpm_checkpoint(checkpoint, config)

					if "ddpm" in config:
										del config["ddpm"]

					if config["_class_name"] == "VQModel":
										_lowerCAmelCase				     = VQModel(**config)
										model.load_state_dict(converted_checkpoint)
										model.save_pretrained(args.dump_path)
					elif config["_class_name"] == "AutoencoderKL":
										_lowerCAmelCase				     = AutoencoderKL(**config)
										model.load_state_dict(converted_checkpoint)
										model.save_pretrained(args.dump_path)
					else:
										_lowerCAmelCase				     = UNetaDModel(**config)
										model.load_state_dict(converted_checkpoint)

										_lowerCAmelCase				     = DDPMScheduler.from_config('''/'''.join(args.checkpoint_path.split('''/''')[:-1]))

										_lowerCAmelCase				     = DDPMPipeline(unet=model, scheduler=scheduler)
										pipe.save_pretrained(args.dump_path)









'''simple docstring'''






from typing import Any, Callable, Dict, List, Optional, Union

import PIL.Image
import torch
from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DiffusionPipeline,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionImgaImgPipeline,
    StableDiffusionInpaintPipelineLegacy,
    StableDiffusionPipeline,
    UNetaDConditionModel,
)
from diffusers.configuration_utils import FrozenDict
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker
from diffusers.utils import deprecate, logging


_lowerCAmelCase				     = logging.get_logger(__name__)  # pylint: disable=invalid-name



class  A		(			SCREAMING_SNAKE_CASE__		):




				'''simple docstring'''





				A				     =    ["safety_checker", "feature_extractor"]
				def __init__(self			,  _UpperCAmelCase			,  _UpperCAmelCase			,  _UpperCAmelCase			,  _UpperCAmelCase			,  _UpperCAmelCase			,  _UpperCAmelCase			,  _UpperCAmelCase			,  _UpperCAmelCase = True			,  )     ->	List[str]:
							super().__init__()
							if hasattr(scheduler.config			,  "steps_offset"      ) and scheduler.config.steps_offset != 1:
										__UpperCamelCase				:      List[str]									=       (
										    f"The configuration file of this scheduler: {scheduler} is outdated. `steps_offset`"
										    f" should be set to 1 instead of {scheduler.config.steps_offset}. Please make sure "
										    "to update the config accordingly as leaving `steps_offset` might led to incorrect results"
										    " in future versions. If you have downloaded this checkpoint from the Hugging Face Hub,"
										    " it would be very nice if you could open a Pull request for the `scheduler/scheduler_config.json`"
										    " file"
										)
										deprecate("steps_offset!=1"			,  "1.0.0"			,  _UpperCAmelCase			,  standard_warn=_UpperCAmelCase      )
										__UpperCamelCase				:      str									=       dict(scheduler.config      )
										__UpperCamelCase				:      Optional[Any]									=       1
										__UpperCamelCase				:      Dict									=       FrozenDict(_UpperCAmelCase      )

							self.register_modules(
							    vae=_UpperCAmelCase			,  text_encoder=_UpperCAmelCase			,  tokenizer=_UpperCAmelCase			,  unet=_UpperCAmelCase			,  scheduler=_UpperCAmelCase			,  safety_checker=_UpperCAmelCase			,  feature_extractor=_UpperCAmelCase			,  )
							self.register_to_config(requires_safety_checker=_UpperCAmelCase      )
				@property
				def 	a_	(self      )     ->	Dict[str, Any]:
							return {k: getattr(self			,  _UpperCAmelCase      ) for k in self.config.keys() if not k.startswith("_"      )}
				def 	a_	(self			,  _UpperCAmelCase = "auto"      )     ->	List[str]:
							if slice_size == "auto":
										# half the attention head size is usually a good trade-off between
										# speed and memory
										__UpperCamelCase				:      Dict									=       self.unet.config.attention_head_dim // 2
							self.unet.set_attention_slice(_UpperCAmelCase      )
				def 	a_	(self      )     ->	Dict:
							self.enable_attention_slicing(_UpperCAmelCase      )
				@torch.no_grad()
				def 	a_	(self			,  _UpperCAmelCase			,  _UpperCAmelCase			,  _UpperCAmelCase			,  _UpperCAmelCase = 0.8			,  _UpperCAmelCase = 5_0			,  _UpperCAmelCase = 7.5			,  _UpperCAmelCase = None			,  _UpperCAmelCase = 1			,  _UpperCAmelCase = 0.0			,  _UpperCAmelCase = None			,  _UpperCAmelCase = "pil"			,  _UpperCAmelCase = True			,  _UpperCAmelCase = None			,  _UpperCAmelCase = 1			,  )     ->	List[str]:
							# For more information on how this function works, please see: https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion#diffusers.StableDiffusionImg2ImgPipeline
							return StableDiffusionInpaintPipelineLegacy(**self.components      )(
							    prompt=_UpperCAmelCase			,  image=_UpperCAmelCase			,  mask_image=_UpperCAmelCase			,  strength=_UpperCAmelCase			,  num_inference_steps=_UpperCAmelCase			,  guidance_scale=_UpperCAmelCase			,  negative_prompt=_UpperCAmelCase			,  num_images_per_prompt=_UpperCAmelCase			,  eta=_UpperCAmelCase			,  generator=_UpperCAmelCase			,  output_type=_UpperCAmelCase			,  return_dict=_UpperCAmelCase			,  callback=_UpperCAmelCase			,  )
				@torch.no_grad()
				def 	a_	(self			,  _UpperCAmelCase			,  _UpperCAmelCase			,  _UpperCAmelCase = 0.8			,  _UpperCAmelCase = 5_0			,  _UpperCAmelCase = 7.5			,  _UpperCAmelCase = None			,  _UpperCAmelCase = 1			,  _UpperCAmelCase = 0.0			,  _UpperCAmelCase = None			,  _UpperCAmelCase = "pil"			,  _UpperCAmelCase = True			,  _UpperCAmelCase = None			,  _UpperCAmelCase = 1			,  **_UpperCAmelCase			,  )     ->	Optional[Any]:
							# For more information on how this function works, please see: https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion#diffusers.StableDiffusionImg2ImgPipeline
							return StableDiffusionImgaImgPipeline(**self.components      )(
							    prompt=_UpperCAmelCase			,  image=_UpperCAmelCase			,  strength=_UpperCAmelCase			,  num_inference_steps=_UpperCAmelCase			,  guidance_scale=_UpperCAmelCase			,  negative_prompt=_UpperCAmelCase			,  num_images_per_prompt=_UpperCAmelCase			,  eta=_UpperCAmelCase			,  generator=_UpperCAmelCase			,  output_type=_UpperCAmelCase			,  return_dict=_UpperCAmelCase			,  callback=_UpperCAmelCase			,  callback_steps=_UpperCAmelCase			,  )





				@torch.no_grad()
				def 	a_	(self			,  _UpperCAmelCase			,  _UpperCAmelCase = 5_1_2			,  _UpperCAmelCase = 5_1_2			,  _UpperCAmelCase = 5_0			,  _UpperCAmelCase = 7.5			,  _UpperCAmelCase = None			,  _UpperCAmelCase = 1			,  _UpperCAmelCase = 0.0			,  _UpperCAmelCase = None			,  _UpperCAmelCase = None			,  _UpperCAmelCase = "pil"			,  _UpperCAmelCase = True			,  _UpperCAmelCase = None			,  _UpperCAmelCase = 1			,  )     ->	Union[str, Any]:
							# For more information on how this function https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion#diffusers.StableDiffusionPipeline
							return StableDiffusionPipeline(**self.components      )(
							    prompt=_UpperCAmelCase			,  height=_UpperCAmelCase			,  width=_UpperCAmelCase			,  num_inference_steps=_UpperCAmelCase			,  guidance_scale=_UpperCAmelCase			,  negative_prompt=_UpperCAmelCase			,  num_images_per_prompt=_UpperCAmelCase			,  eta=_UpperCAmelCase			,  generator=_UpperCAmelCase			,  latents=_UpperCAmelCase			,  output_type=_UpperCAmelCase			,  return_dict=_UpperCAmelCase			,  callback=_UpperCAmelCase			,  callback_steps=_UpperCAmelCase			,  )



