


import argparse
import json
import os

import fairseq
import torch
from fairseq.data import Dictionary

# Register SEW's fairseq modules
from sew_asapp import tasks  # noqa: F401

from transformers import (
    SEWDConfig,
    SEWDForCTC,
    SEWDModel,
    WavaVecaCTCTokenizer,
    WavaVecaFeatureExtractor,
    WavaVecaProcessor,
    logging,
)


logging.set_verbosity_info()
__lowerCAmelCase     :			str      =logging.get_logger(__name__)

__lowerCAmelCase     :			int      ={
    'post_extract_proj': 'feature_projection',
    'encoder.pos_conv.0': 'encoder.pos_conv_embed.conv',
    'attention.self.query_proj': 'encoder.encoder.layer.*.attention.self.query_proj',
    'attention.self.key_proj': 'encoder.encoder.layer.*.attention.self.key_proj',
    'attention.self.value_proj': 'encoder.encoder.layer.*.attention.self.value_proj',
    'attention.output.dense': 'encoder.encoder.layer.*.attention.output.dense',
    'attention.output.LayerNorm': 'encoder.encoder.layer.*.attention.output.LayerNorm',
    'intermediate.dense': 'encoder.encoder.layer.*.intermediate.dense',
    'output.dense': 'encoder.encoder.layer.*.output.dense',
    'output.LayerNorm': 'encoder.encoder.layer.*.output.LayerNorm',
    'encoder.encoder.rel_embeddings': 'encoder.encoder.rel_embeddings',
    'encoder.encoder.LayerNorm': 'encoder.encoder.LayerNorm',
    'encoder.upsample.0': 'encoder.upsample.projection',
    'encoder.layer_norm': 'encoder.layer_norm',
    'w2v_model.layer_norm': 'layer_norm',
    'w2v_encoder.proj': 'lm_head',
    'mask_emb': 'masked_spec_embed',
}


def 	_UpperCamelCase							(				lowercase__   ,	lowercase__   ,	lowercase__   ,	lowercase__   ,	lowercase__				):
						for attribute in key.split('''.'''				):
												__SCREAMING_SNAKE_CASE						:					int		      =		getattr(lowercase__   ,	lowercase__				)

						if weight_type is not None:
												__SCREAMING_SNAKE_CASE						:					Any		      =		getattr(lowercase__   ,	lowercase__				).shape
						else:
												__SCREAMING_SNAKE_CASE						:					Any		      =		hf_pointer.shape

						assert hf_shape == value.shape, (
						    F'''Shape of hf {key + '.' + weight_type if weight_type is not None else ''} is {hf_shape}, but should be'''
						    F''' {value.shape} for {full_name}'''
						)

						if weight_type == "weight":
												__SCREAMING_SNAKE_CASE						:					Optional[Any]		      =		value
						elif weight_type == "weight_g":
												__SCREAMING_SNAKE_CASE						:					Any		      =		value
						elif weight_type == "weight_v":
												__SCREAMING_SNAKE_CASE						:					List[Any]		      =		value
						elif weight_type == "bias":
												__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		value
						else:
												__SCREAMING_SNAKE_CASE						:					List[str]		      =		value

						logger.info(F'''{key + '.' + weight_type if weight_type is not None else ''} was initialized from {full_name}.'''				)


def 	_UpperCamelCase							(				lowercase__   ,	lowercase__   ,	lowercase__				):
						__SCREAMING_SNAKE_CASE						:					Tuple		      =		[]
						__SCREAMING_SNAKE_CASE						:					List[Any]		      =		fairseq_model.state_dict()

						__SCREAMING_SNAKE_CASE						:					Optional[Any]		      =		hf_model.sew_d.feature_extractor if is_finetuned else hf_model.feature_extractor

						for name, value in fairseq_dict.items():
												__SCREAMING_SNAKE_CASE						:					int		      =		False
												if "conv_layers" in name:
																		load_conv_layer(
																		    lowercase__   ,	lowercase__   ,	lowercase__   ,	lowercase__   ,	hf_model.config.feat_extract_norm == '''group'''   ,	)
																		__SCREAMING_SNAKE_CASE						:					Tuple		      =		True
												else:
																		for key, mapped_key in MAPPING.items():
																								__SCREAMING_SNAKE_CASE						:					Tuple		      =		'''sew_d.''' + mapped_key if (is_finetuned and mapped_key != '''lm_head''') else mapped_key

																								if key in name or key.split('''w2v_model.'''				)[-1] == name.split('''.'''				)[0]:
																														__SCREAMING_SNAKE_CASE						:					List[Any]		      =		True
																														if "*" in mapped_key:
																																				__SCREAMING_SNAKE_CASE						:					Dict		      =		name.split(lowercase__				)[0].split('''.'''				)[-2]
																																				if not layer_index.isnumeric():
																																										continue
																																				__SCREAMING_SNAKE_CASE						:					Optional[int]		      =		mapped_key.replace('''*'''   ,	lowercase__				)
																														if "weight_g" in name:
																																				__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		'''weight_g'''
																														elif "weight_v" in name:
																																				__SCREAMING_SNAKE_CASE						:					Optional[Any]		      =		'''weight_v'''
																														elif "weight" in name:
																																				__SCREAMING_SNAKE_CASE						:					str		      =		'''weight'''
																														elif "bias" in name:
																																				__SCREAMING_SNAKE_CASE						:					List[Any]		      =		'''bias'''
																														else:
																																				__SCREAMING_SNAKE_CASE						:					str		      =		None
																														set_recursively(lowercase__   ,	lowercase__   ,	lowercase__   ,	lowercase__   ,	lowercase__				)
																								continue
												if not is_used:
																		unused_weights.append(lowercase__				)

						logger.warning(F'''Unused weights: {unused_weights}'''				)


def 	_UpperCamelCase							(				lowercase__   ,	lowercase__   ,	lowercase__   ,	lowercase__   ,	lowercase__				):
						__SCREAMING_SNAKE_CASE						:					int		      =		full_name.split('''conv_layers.'''				)[-1]
						__SCREAMING_SNAKE_CASE						:					List[Any]		      =		name.split('''.'''				)
						__SCREAMING_SNAKE_CASE						:					Optional[Any]		      =		int(items[0]				)
						__SCREAMING_SNAKE_CASE						:					List[Any]		      =		int(items[1]				)

						if type_id == 0:
												if "bias" in name:
																		assert value.shape == feature_extractor.conv_layers[layer_id].conv.bias.data.shape, (
																		    F'''{full_name} has size {value.shape}, but'''
																		    F''' {feature_extractor.conv_layers[layer_id].conv.bias.data.shape} was found.'''
																		)
																		__SCREAMING_SNAKE_CASE						:					str		      =		value
																		logger.info(F'''Feat extract conv layer {layer_id} was initialized from {full_name}.'''				)
												elif "weight" in name:
																		assert value.shape == feature_extractor.conv_layers[layer_id].conv.weight.data.shape, (
																		    F'''{full_name} has size {value.shape}, but'''
																		    F''' {feature_extractor.conv_layers[layer_id].conv.weight.data.shape} was found.'''
																		)
																		__SCREAMING_SNAKE_CASE						:					Dict		      =		value
																		logger.info(F'''Feat extract conv layer {layer_id} was initialized from {full_name}.'''				)
						elif (type_id == 2 and not use_group_norm) or (type_id == 2 and layer_id == 0 and use_group_norm):
												if "bias" in name:
																		assert value.shape == feature_extractor.conv_layers[layer_id].layer_norm.bias.data.shape, (
																		    F'''{full_name} has size {value.shape}, but {feature_extractor[layer_id].layer_norm.bias.data.shape} was'''
																		    " found."
																		)
																		__SCREAMING_SNAKE_CASE						:					Optional[int]		      =		value
																		logger.info(F'''Feat extract layer norm weight of layer {layer_id} was initialized from {full_name}.'''				)
												elif "weight" in name:
																		assert value.shape == feature_extractor.conv_layers[layer_id].layer_norm.weight.data.shape, (
																		    F'''{full_name} has size {value.shape}, but'''
																		    F''' {feature_extractor[layer_id].layer_norm.weight.data.shape} was found.'''
																		)
																		__SCREAMING_SNAKE_CASE						:					Optional[Any]		      =		value
																		logger.info(F'''Feat extract layer norm weight of layer {layer_id} was initialized from {full_name}.'''				)
						else:
												unused_weights.append(lowercase__				)


def 	_UpperCamelCase							(				lowercase__   ,	lowercase__				):
						__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		SEWDConfig()
						if is_finetuned:
												__SCREAMING_SNAKE_CASE						:					Tuple		      =		model.wav_encoder.wav_model.cfg
						else:
												__SCREAMING_SNAKE_CASE						:					List[str]		      =		model.cfg

						__SCREAMING_SNAKE_CASE						:					List[str]		      =		fs_config.conv_bias
						__SCREAMING_SNAKE_CASE						:					str		      =		eval(fs_config.conv_feature_layers				)
						__SCREAMING_SNAKE_CASE						:					List[str]		      =		[x[0] for x in conv_layers]
						__SCREAMING_SNAKE_CASE						:					Tuple		      =		[x[1] for x in conv_layers]
						__SCREAMING_SNAKE_CASE						:					List[Any]		      =		[x[2] for x in conv_layers]
						__SCREAMING_SNAKE_CASE						:					Optional[int]		      =		'''gelu'''
						__SCREAMING_SNAKE_CASE						:					int		      =		'''layer''' if fs_config.extractor_mode == '''layer_norm''' else '''group'''
						__SCREAMING_SNAKE_CASE						:					str		      =		0.0
						__SCREAMING_SNAKE_CASE						:					str		      =		fs_config.activation_fn.name
						__SCREAMING_SNAKE_CASE						:					List[str]		      =		fs_config.encoder_embed_dim
						__SCREAMING_SNAKE_CASE						:					Optional[Any]		      =		0.02
						__SCREAMING_SNAKE_CASE						:					int		      =		fs_config.encoder_ffn_embed_dim
						__SCREAMING_SNAKE_CASE						:					Optional[Any]		      =		1e-5
						__SCREAMING_SNAKE_CASE						:					Any		      =		fs_config.encoder_layerdrop
						__SCREAMING_SNAKE_CASE						:					Dict		      =		fs_config.encoder_attention_heads
						__SCREAMING_SNAKE_CASE						:					Dict		      =		fs_config.conv_pos_groups
						__SCREAMING_SNAKE_CASE						:					Any		      =		fs_config.conv_pos
						__SCREAMING_SNAKE_CASE						:					Tuple		      =		len(lowercase__				)
						__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		fs_config.encoder_layers
						__SCREAMING_SNAKE_CASE						:					Tuple		      =		fs_config.squeeze_factor
						# DeBERTa-specific parameters:
						__SCREAMING_SNAKE_CASE						:					Tuple		      =		fs_config.max_position_embeddings
						__SCREAMING_SNAKE_CASE						:					Any		      =		fs_config.position_buckets
						__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		fs_config.share_att_key
						__SCREAMING_SNAKE_CASE						:					Tuple		      =		fs_config.relative_attention
						__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		fs_config.position_biased_input
						__SCREAMING_SNAKE_CASE						:					List[str]		      =		tuple(fs_config.pos_att_type.split('''|'''				)				)
						__SCREAMING_SNAKE_CASE						:					str		      =		fs_config.norm_rel_ebd

						# take care of any params that are overridden by the Wav2VecCtc model
						if is_finetuned:
												__SCREAMING_SNAKE_CASE						:					Tuple		      =		model.cfg
												__SCREAMING_SNAKE_CASE						:					Optional[Any]		      =		fs_config.final_dropout
												__SCREAMING_SNAKE_CASE						:					Optional[int]		      =		fs_config.layerdrop
						__SCREAMING_SNAKE_CASE						:					int		      =		fs_config.activation_dropout
						__SCREAMING_SNAKE_CASE						:					Optional[int]		      =		fs_config.mask_prob > 0 or fs_config.mask_channel_prob > 0
						__SCREAMING_SNAKE_CASE						:					str		      =		fs_config.attention_dropout
						__SCREAMING_SNAKE_CASE						:					int		      =		fs_config.dropout_input
						__SCREAMING_SNAKE_CASE						:					List[str]		      =		fs_config.dropout
						__SCREAMING_SNAKE_CASE						:					Dict		      =		fs_config.mask_channel_length
						__SCREAMING_SNAKE_CASE						:					Dict		      =		fs_config.mask_channel_prob
						__SCREAMING_SNAKE_CASE						:					Optional[Any]		      =		fs_config.mask_length
						__SCREAMING_SNAKE_CASE						:					Any		      =		fs_config.mask_prob

						__SCREAMING_SNAKE_CASE						:					str		      =		'''Wav2Vec2FeatureExtractor'''
						__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		'''Wav2Vec2CTCTokenizer'''

						return config


@torch.no_grad()
def 	_UpperCamelCase							(				lowercase__   ,	lowercase__   ,	lowercase__=None   ,	lowercase__=None   ,	lowercase__=True				):

						if is_finetuned:
												__SCREAMING_SNAKE_CASE      ,      __SCREAMING_SNAKE_CASE      ,      __SCREAMING_SNAKE_CASE						:					Dict		      =		fairseq.checkpoint_utils.load_model_ensemble_and_task(
												    [checkpoint_path]   ,	arg_overrides={'''data''': '''/'''.join(dict_path.split('''/'''				)[:-1]				)}				)
						else:
												__SCREAMING_SNAKE_CASE      ,      __SCREAMING_SNAKE_CASE      ,      __SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		fairseq.checkpoint_utils.load_model_ensemble_and_task([checkpoint_path]				)

						if config_path is not None:
												__SCREAMING_SNAKE_CASE						:					str		      =		SEWDConfig.from_pretrained(lowercase__				)
						else:
												__SCREAMING_SNAKE_CASE						:					Any		      =		convert_config(model[0]   ,	lowercase__				)
						__SCREAMING_SNAKE_CASE						:					Optional[Any]		      =		model[0].eval()

						__SCREAMING_SNAKE_CASE						:					List[str]		      =		True if config.feat_extract_norm == '''layer''' else False
						__SCREAMING_SNAKE_CASE						:					int		      =		WavaVecaFeatureExtractor(
						    feature_size=1   ,	sampling_rate=16000   ,	padding_value=0   ,	do_normalize=lowercase__   ,	return_attention_mask=lowercase__   ,	)

						if is_finetuned:
												if dict_path:
																		__SCREAMING_SNAKE_CASE						:					Tuple		      =		Dictionary.load(lowercase__				)

																		# important change bos & pad token id since CTC symbol is <pad> and
																		# not <s> as in fairseq
																		__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		target_dict.pad_index
																		__SCREAMING_SNAKE_CASE						:					int		      =		target_dict.bos_index
																		__SCREAMING_SNAKE_CASE						:					Optional[int]		      =		target_dict.pad_index
																		__SCREAMING_SNAKE_CASE						:					Tuple		      =		target_dict.bos_index
																		__SCREAMING_SNAKE_CASE						:					Tuple		      =		target_dict.eos_index
																		__SCREAMING_SNAKE_CASE						:					str		      =		len(target_dict.symbols				)
																		__SCREAMING_SNAKE_CASE						:					List[str]		      =		os.path.join(lowercase__   ,	'''vocab.json'''				)
																		if not os.path.isdir(lowercase__				):
																								logger.error('''--pytorch_dump_folder_path ({}) should be a directory'''.format(lowercase__				)				)
																								return
																		os.makedirs(lowercase__   ,	exist_ok=lowercase__				)
																		with open(lowercase__   ,	'''w'''   ,	encoding='''utf-8'''				) as vocab_handle:
																								json.dump(target_dict.indices   ,	lowercase__				)
																		__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		WavaVecaCTCTokenizer(
																		    lowercase__   ,	unk_token=target_dict.unk_word   ,	pad_token=target_dict.pad_word   ,	bos_token=target_dict.bos_word   ,	eos_token=target_dict.eos_word   ,	word_delimiter_token='''|'''   ,	do_lower_case=lowercase__   ,	)
																		__SCREAMING_SNAKE_CASE						:					Tuple		      =		WavaVecaProcessor(feature_extractor=lowercase__   ,	tokenizer=lowercase__				)
																		processor.save_pretrained(lowercase__				)

												__SCREAMING_SNAKE_CASE						:					Dict		      =		SEWDForCTC(lowercase__				)
						else:
												__SCREAMING_SNAKE_CASE						:					Dict		      =		SEWDModel(lowercase__				)
												feature_extractor.save_pretrained(lowercase__				)

						recursively_load_weights(lowercase__   ,	lowercase__   ,	lowercase__				)

						hf_model.save_pretrained(lowercase__				)


if __name__ == "__main__":
						__lowerCAmelCase     :			Optional[Any]      =argparse.ArgumentParser()
						parser.add_argument('--pytorch_dump_folder_path', default=None, type=str, help='Path to the output PyTorch model.')
						parser.add_argument('--checkpoint_path', default=None, type=str, help='Path to fairseq checkpoint')
						parser.add_argument('--dict_path', default=None, type=str, help='Path to dict of fine-tuned model')
						parser.add_argument('--config_path', default=None, type=str, help='Path to hf config.json of model to convert')
						parser.add_argument(
						    '--is_finetuned', action='store_true', help='Whether the model to convert is a fine-tuned model or not'
						)
						__lowerCAmelCase     :			List[Any]      =parser.parse_args()
						convert_sew_checkpoint(
						    args.checkpoint_path, args.pytorch_dump_folder_path, args.config_path, args.dict_path, args.is_finetuned
						)




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     :			Tuple      =logging.get_logger(__name__)  # pylint: disable=invalid-name
class 	_lowercase				(      A__	):






				'''simple docstring'''



				SCREAMING_SNAKE_CASE__    :      Union[str, Any]      =		['''safety_checker''', '''feature_extractor''']


				def __init__(	self      :int      ,      lowerCAmelCase__      :AutoencoderKL      ,      lowerCAmelCase__      :CLIPTextModel      ,      lowerCAmelCase__      :CLIPTokenizer      ,      lowerCAmelCase__      :UNetaDConditionModel      ,      lowerCAmelCase__      :Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler]      ,      lowerCAmelCase__      :StableDiffusionSafetyChecker      ,      lowerCAmelCase__      :CLIPImageProcessor      ,      lowerCAmelCase__      :bool = True      ,      )		->      List[Any]:
										super().__init__()
										if hasattr(scheduler.config      ,      '''steps_offset'''     ) and scheduler.config.steps_offset != 1:
																__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		(
																    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'''      ,      lowerCAmelCase__      ,      standard_warn=lowerCAmelCase__     )
																__SCREAMING_SNAKE_CASE						:					Dict		      =		dict(scheduler.config     )
																__SCREAMING_SNAKE_CASE						:					Tuple		      =		1
																__SCREAMING_SNAKE_CASE						:					Dict		      =		FrozenDict(lowerCAmelCase__     )

										self.register_modules(
										    vae=lowerCAmelCase__      ,      text_encoder=lowerCAmelCase__      ,      tokenizer=lowerCAmelCase__      ,      unet=lowerCAmelCase__      ,      scheduler=lowerCAmelCase__      ,      safety_checker=lowerCAmelCase__      ,      feature_extractor=lowerCAmelCase__      ,      )
										self.register_to_config(requires_safety_checker=lowerCAmelCase__     )


				@property
				def 		__magic_name__(	self      :Union[str, Any]     )		->      Dict[str, Any]:
										return {k: getattr(self      ,      lowerCAmelCase__     ) for k in self.config.keys() if not k.startswith('''_'''     )}


				def 		__magic_name__(	self      :str      ,      lowerCAmelCase__      :Optional[Union[str, int]] = "auto"     )		->      str:
										if slice_size == "auto":
																# half the attention head size is usually a good trade-off between
																# speed and memory
																__SCREAMING_SNAKE_CASE						:					Union[str, Any]		      =		self.unet.config.attention_head_dim // 2
										self.unet.set_attention_slice(lowerCAmelCase__     )


				def 		__magic_name__(	self      :Optional[int]     )		->      Union[str, Any]:
										self.enable_attention_slicing(lowerCAmelCase__     )


				@torch.no_grad()
				def 		__magic_name__(	self      :str      ,      lowerCAmelCase__      :Union[str, List[str]]      ,      lowerCAmelCase__      :Union[torch.FloatTensor, PIL.Image.Image]      ,      lowerCAmelCase__      :Union[torch.FloatTensor, PIL.Image.Image]      ,      lowerCAmelCase__      :float = 0.8      ,      lowerCAmelCase__      :Optional[int] = 50      ,      lowerCAmelCase__      :Optional[float] = 7.5      ,      lowerCAmelCase__      :Optional[Union[str, List[str]]] = None      ,      lowerCAmelCase__      :Optional[int] = 1      ,      lowerCAmelCase__      :Optional[float] = 0.0      ,      lowerCAmelCase__      :Optional[torch.Generator] = None      ,      lowerCAmelCase__      :Optional[str] = "pil"      ,      lowerCAmelCase__      :bool = True      ,      lowerCAmelCase__      :Optional[Callable[[int, int, torch.FloatTensor], None]] = None      ,      lowerCAmelCase__      :int = 1      ,      )		->      Any:
										# 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=lowerCAmelCase__      ,      image=lowerCAmelCase__      ,      mask_image=lowerCAmelCase__      ,      strength=lowerCAmelCase__      ,      num_inference_steps=lowerCAmelCase__      ,      guidance_scale=lowerCAmelCase__      ,      negative_prompt=lowerCAmelCase__      ,      num_images_per_prompt=lowerCAmelCase__      ,      eta=lowerCAmelCase__      ,      generator=lowerCAmelCase__      ,      output_type=lowerCAmelCase__      ,      return_dict=lowerCAmelCase__      ,      callback=lowerCAmelCase__      ,      )


				@torch.no_grad()
				def 		__magic_name__(	self      :Dict      ,      lowerCAmelCase__      :Union[str, List[str]]      ,      lowerCAmelCase__      :Union[torch.FloatTensor, PIL.Image.Image]      ,      lowerCAmelCase__      :float = 0.8      ,      lowerCAmelCase__      :Optional[int] = 50      ,      lowerCAmelCase__      :Optional[float] = 7.5      ,      lowerCAmelCase__      :Optional[Union[str, List[str]]] = None      ,      lowerCAmelCase__      :Optional[int] = 1      ,      lowerCAmelCase__      :Optional[float] = 0.0      ,      lowerCAmelCase__      :Optional[torch.Generator] = None      ,      lowerCAmelCase__      :Optional[str] = "pil"      ,      lowerCAmelCase__      :bool = True      ,      lowerCAmelCase__      :Optional[Callable[[int, int, torch.FloatTensor], None]] = None      ,      lowerCAmelCase__      :int = 1      ,      **lowerCAmelCase__      :Optional[Any]      ,      )		->      Dict:
										# 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=lowerCAmelCase__      ,      image=lowerCAmelCase__      ,      strength=lowerCAmelCase__      ,      num_inference_steps=lowerCAmelCase__      ,      guidance_scale=lowerCAmelCase__      ,      negative_prompt=lowerCAmelCase__      ,      num_images_per_prompt=lowerCAmelCase__      ,      eta=lowerCAmelCase__      ,      generator=lowerCAmelCase__      ,      output_type=lowerCAmelCase__      ,      return_dict=lowerCAmelCase__      ,      callback=lowerCAmelCase__      ,      callback_steps=lowerCAmelCase__      ,      )



				@torch.no_grad()
				def 		__magic_name__(	self      :Tuple      ,      lowerCAmelCase__      :Union[str, List[str]]      ,      lowerCAmelCase__      :int = 512      ,      lowerCAmelCase__      :int = 512      ,      lowerCAmelCase__      :int = 50      ,      lowerCAmelCase__      :float = 7.5      ,      lowerCAmelCase__      :Optional[Union[str, List[str]]] = None      ,      lowerCAmelCase__      :Optional[int] = 1      ,      lowerCAmelCase__      :float = 0.0      ,      lowerCAmelCase__      :Optional[torch.Generator] = None      ,      lowerCAmelCase__      :Optional[torch.FloatTensor] = None      ,      lowerCAmelCase__      :Optional[str] = "pil"      ,      lowerCAmelCase__      :bool = True      ,      lowerCAmelCase__      :Optional[Callable[[int, int, torch.FloatTensor], None]] = None      ,      lowerCAmelCase__      :int = 1      ,      )		->      Optional[int]:
										# For more information on how this function https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion#diffusers.StableDiffusionPipeline
										return StableDiffusionPipeline(**self.components     )(
										    prompt=lowerCAmelCase__      ,      height=lowerCAmelCase__      ,      width=lowerCAmelCase__      ,      num_inference_steps=lowerCAmelCase__      ,      guidance_scale=lowerCAmelCase__      ,      negative_prompt=lowerCAmelCase__      ,      num_images_per_prompt=lowerCAmelCase__      ,      eta=lowerCAmelCase__      ,      generator=lowerCAmelCase__      ,      latents=lowerCAmelCase__      ,      output_type=lowerCAmelCase__      ,      return_dict=lowerCAmelCase__      ,      callback=lowerCAmelCase__      ,      callback_steps=lowerCAmelCase__      ,      )
