






import argparse
import json
import os

import fairseq
import torch
from torch import nn

from transformers import (
    SpeechaTextaConfig,
    SpeechaTextaForCausalLM,
    SpeechaTextaTokenizer,
    SpeechEncoderDecoderConfig,
    SpeechEncoderDecoderModel,
    WavaVecaConfig,
    WavaVecaFeatureExtractor,
    WavaVecaModel,
    logging,
)


logging.set_verbosity_info()
snake_case     					=		logging.get_logger(__name__)

snake_case     					=		{
    """post_extract_proj""": """feature_projection.projection""",
    """encoder.pos_conv.0""": """encoder.pos_conv_embed.conv""",
    """self_attn.k_proj""": """encoder.layers.*.attention.k_proj""",
    """self_attn.v_proj""": """encoder.layers.*.attention.v_proj""",
    """self_attn.q_proj""": """encoder.layers.*.attention.q_proj""",
    """self_attn.out_proj""": """encoder.layers.*.attention.out_proj""",
    """self_attn_layer_norm""": """encoder.layers.*.layer_norm""",
    """fc1""": """encoder.layers.*.feed_forward.intermediate_dense""",
    """fc2""": """encoder.layers.*.feed_forward.output_dense""",
    """final_layer_norm""": """encoder.layers.*.final_layer_norm""",
    """encoder.layer_norm""": """encoder.layer_norm""",
    """w2v_model.layer_norm""": """feature_projection.layer_norm""",
    """quantizer.weight_proj""": """quantizer.weight_proj""",
    """quantizer.vars""": """quantizer.codevectors""",
    """project_q""": """project_q""",
    """final_proj""": """project_hid""",
    """w2v_encoder.proj""": """lm_head""",
    """mask_emb""": """masked_spec_embed""",
}
snake_case     					=		[
    """lm_head""",
    """quantizer.weight_proj""",
    """quantizer.codevectors""",
    """project_q""",
    """project_hid""",
]


def 	lowerCamelCase__      (  lowercase    ,  lowercase    ,  lowercase    ,  lowercase    ,  lowercase					):

  """simple docstring"""






  for attribute in key.split("."					):
    SCREAMING_SNAKE_CASE							:   str						    =     getattr(lowercase    ,  lowercase					)

  if weight_type is not None:
    SCREAMING_SNAKE_CASE							:   List[str]						    =     getattr(lowercase    ,  lowercase					).shape
  else:
    SCREAMING_SNAKE_CASE							:   str						    =     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							:   Union[str, Any]						    =     value
  elif weight_type == "weight_g":
    SCREAMING_SNAKE_CASE							:   Any						    =     value
  elif weight_type == "weight_v":
    SCREAMING_SNAKE_CASE							:   List[str]						    =     value
  elif weight_type == "bias":
    SCREAMING_SNAKE_CASE							:   int						    =     value
  else:
    SCREAMING_SNAKE_CASE							:   Optional[int]						    =     value

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


def 	lowerCamelCase__      (  lowercase    ,  lowercase					):

  """simple docstring"""






  SCREAMING_SNAKE_CASE							:   Any						    =     []
  SCREAMING_SNAKE_CASE							:   str						    =     fairseq_model.state_dict()

  SCREAMING_SNAKE_CASE							:   str						    =     hf_model.feature_extractor

  # if encoder has different dim to decoder -> use proj_weight
  SCREAMING_SNAKE_CASE							:   List[str]						    =     None

  for name, value in fairseq_dict.items():
    SCREAMING_SNAKE_CASE							:   List[Any]						    =     False
    if "conv_layers" in name:
      load_conv_layer(
          lowercase    ,  lowercase    ,  lowercase    ,  lowercase    ,  hf_model.config.feat_extract_norm == "group"    ,  )
      SCREAMING_SNAKE_CASE							:   Optional[int]						    =     True
    elif name.split("."					)[0] == "proj":
      SCREAMING_SNAKE_CASE							:   Optional[Any]						    =     fairseq_model.proj
      SCREAMING_SNAKE_CASE							:   str						    =     True
    else:
      for key, mapped_key in MAPPING.items():
        if key in name or key.split("w2v_model."					)[-1] == name.split("."					)[0]:
          SCREAMING_SNAKE_CASE							:   Dict						    =     True
          if "*" in mapped_key:
            SCREAMING_SNAKE_CASE							:   Dict						    =     name.split(lowercase					)[0].split("."					)[-2]
            SCREAMING_SNAKE_CASE							:   Optional[Any]						    =     mapped_key.replace("*"    ,  lowercase					)
          if "weight_g" in name:
            SCREAMING_SNAKE_CASE							:   List[str]						    =     "weight_g"
          elif "weight_v" in name:
            SCREAMING_SNAKE_CASE							:   Optional[Any]						    =     "weight_v"
          elif "bias" in name:
            SCREAMING_SNAKE_CASE							:   Tuple						    =     "bias"
          elif "weight" in name:
            SCREAMING_SNAKE_CASE							:   Union[str, Any]						    =     "weight"
          else:
            SCREAMING_SNAKE_CASE							:   Dict						    =     None
          set_recursively(lowercase    ,  lowercase    ,  lowercase    ,  lowercase    ,  lowercase					)
        continue
    if not is_used:
      unused_weights.append(lowercase					)

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

  return proj_weight


def 	lowerCamelCase__      (  lowercase    ,  lowercase    ,  lowercase    ,  lowercase    ,  lowercase					):

  """simple docstring"""






  SCREAMING_SNAKE_CASE							:   int						    =     full_name.split("conv_layers."					)[-1]
  SCREAMING_SNAKE_CASE							:   Tuple						    =     name.split("."					)
  SCREAMING_SNAKE_CASE							:   int						    =     int(items[0]					)
  SCREAMING_SNAKE_CASE							:   Tuple						    =     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							:   Tuple						    =     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							:   List[str]						    =     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							:   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[int]						    =     value
      logger.info(F'''Feat extract layer norm weight of layer {layer_id} was initialized from {full_name}.'''					)
  else:
    unused_weights.append(lowercase					)


def 	lowerCamelCase__      (  lowercase					):

  """simple docstring"""






  SCREAMING_SNAKE_CASE    ,	SCREAMING_SNAKE_CASE							:   Any						    =     emb.weight.shape
  SCREAMING_SNAKE_CASE							:   Optional[int]						    =     nn.Linear(lowercase    ,  lowercase    ,  bias=lowercase					)
  SCREAMING_SNAKE_CASE							:   str						    =     emb.weight.data
  return lin_layer


def 	lowerCamelCase__      (  lowercase					):

  """simple docstring"""






  with open(lowercase    ,  "r"    ,  encoding="utf-8"					) as f:
    SCREAMING_SNAKE_CASE							:   List[Any]						    =     f.readlines()
    SCREAMING_SNAKE_CASE							:   Union[str, Any]						    =     [line.split(" "					)[0] for line in lines]

  SCREAMING_SNAKE_CASE							:   Optional[int]						    =     len(lowercase					)

  SCREAMING_SNAKE_CASE							:   List[Any]						    =     {
      "<s>": 0,
      "<pad>": 1,
      "</s>": 2,
      "<unk>": 3,
  }

  vocab_dict.update(dict(zip(lowercase    ,  range(4    ,  num_words + 4					)					)					)					)
  return vocab_dict


@torch.no_grad()
def 	lowerCamelCase__      (  lowercase    ,  lowercase    ,  lowercase    ,  lowercase    ,  lowercase    ,  lowercase    ,  lowercase    ,  ):

  """simple docstring"""






  SCREAMING_SNAKE_CASE							:   List[Any]						    =     WavaVecaConfig.from_pretrained(lowercase					)
  SCREAMING_SNAKE_CASE							:   Dict						    =     SpeechaTextaConfig.from_pretrained(
      lowercase    ,  vocab_size=lowercase    ,  decoder_layers=lowercase    ,  do_stable_layer_norm=lowercase					)

  SCREAMING_SNAKE_CASE							:   str						    =     WavaVecaFeatureExtractor(
      feature_size=1    ,  sampling_rate=16000    ,  padding_value=0    ,  do_normalize=lowercase    ,  return_attention_mask=lowercase    ,  )

  SCREAMING_SNAKE_CASE    ,	SCREAMING_SNAKE_CASE    ,	SCREAMING_SNAKE_CASE							:   int						    =     fairseq.checkpoint_utils.load_model_ensemble_and_task(
      [checkpoint_path]    ,  arg_overrides={"data": "/".join(dict_path.split("/"					)[:-1]					)}					)
  SCREAMING_SNAKE_CASE							:   Dict						    =     model[0].eval()

  # set weights for wav2vec2 encoder
  SCREAMING_SNAKE_CASE							:   str						    =     WavaVecaModel(lowercase					)
  SCREAMING_SNAKE_CASE							:   List[str]						    =     recursively_load_weights_wavaveca(model.encoder    ,  lowercase					)

  SCREAMING_SNAKE_CASE							:   Tuple						    =     SpeechaTextaForCausalLM(lowercase					)
  SCREAMING_SNAKE_CASE    ,	SCREAMING_SNAKE_CASE							:   Any						    =     hf_decoder.model.decoder.load_state_dict(model.decoder.state_dict()    ,  strict=lowercase					)

  # set output linear layer
  unexpected_keys.remove("embed_out"					)
  SCREAMING_SNAKE_CASE							:   List[str]						    =     nn.Parameter(model.decoder.embed_out.detach()					)

  # layer norm is init to identity matrix so leaving it is fine
  logger.warning(F'''The following keys are missing when loading the decoder weights: {missing_keys}'''					)
  logger.warning(F'''The following keys are unexpected when loading the decoder weights: {unexpected_keys}'''					)

  SCREAMING_SNAKE_CASE							:   Dict						    =     SpeechEncoderDecoderModel(encoder=lowercase    ,  decoder=lowercase					)
  SCREAMING_SNAKE_CASE							:   Optional[int]						    =     False

  # add projection layer
  SCREAMING_SNAKE_CASE							:   Any						    =     nn.Parameter(projection_layer.weight					)
  SCREAMING_SNAKE_CASE							:   Union[str, Any]						    =     nn.Parameter(projection_layer.bias					)

  SCREAMING_SNAKE_CASE							:   Dict						    =     create_vocab_dict(lowercase					)

  with open(os.path.join(lowercase    ,  "vocab.json"					)    ,  "w"					) as fp:
    json.dump(lowercase    ,  lowercase					)

  SCREAMING_SNAKE_CASE							:   Tuple						    =     SpeechaTextaTokenizer(os.path.join(lowercase    ,  "vocab.json"					)					)
  tokenizer.save_pretrained(lowercase					)

  SCREAMING_SNAKE_CASE							:   Optional[int]						    =     hf_wavavec.config.to_dict()
  SCREAMING_SNAKE_CASE							:   Tuple						    =     tokenizer.pad_token_id
  SCREAMING_SNAKE_CASE							:   Any						    =     tokenizer.bos_token_id
  SCREAMING_SNAKE_CASE							:   str						    =     tokenizer.eos_token_id
  SCREAMING_SNAKE_CASE							:   int						    =     "speech_to_text_2"
  SCREAMING_SNAKE_CASE							:   List[str]						    =     "wav2vec2"

  SCREAMING_SNAKE_CASE							:   Dict						    =     SpeechEncoderDecoderConfig.from_dict(lowercase					)

  hf_wavavec.save_pretrained(lowercase					)
  feature_extractor.save_pretrained(lowercase					)


if __name__ == "__main__":
   snake_case     					=		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(
       """--encoder_config_path""",
       default="""facebook/wav2vec2-large-lv60""",
       type=str,
       help="""Path to hf encoder wav2vec2 checkpoint config""",
   )
   parser.add_argument(
       """--decoder_config_path""",
       default="""facebook/s2t-small-mustc-en-fr-st""",
       type=str,
       help="""Path to hf decoder s2t checkpoint config""",
   )
   parser.add_argument("""--vocab_size""", default=10_224, type=int, help="""Vocab size of decoder""")
   parser.add_argument("""--num_decoder_layers""", default=7, type=int, help="""Number of decoder layers""")

   snake_case     					=		parser.parse_args()
   convert_wavaveca_checkpoint(
       args.checkpoint_path,
       args.pytorch_dump_folder_path,
       args.dict_path,
       encoder_config_path=args.encoder_config_path,
       decoder_config_path=args.decoder_config_path,
       vocab_size=args.vocab_size,
       num_decoder_layers=args.num_decoder_layers,
   )













'''simple docstring'''




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

import torch
from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DiffusionPipeline,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionPipeline,
    UNetaDConditionModel,
)
from diffusers.pipelines.stable_diffusion import StableDiffusionPipelineOutput
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker


__UpperCAmelCase            =       """CompVis/stable-diffusion-v1-1"""
__UpperCAmelCase            =       """CompVis/stable-diffusion-v1-2"""
__UpperCAmelCase            =       """CompVis/stable-diffusion-v1-3"""
__UpperCAmelCase            =       """CompVis/stable-diffusion-v1-4"""




class      UpperCamelCase__					(					lowercase_			):




					"""simple docstring"""


					def __init__(						self				:			List[str]      ,						lowerCamelCase_				:			AutoencoderKL      ,						lowerCamelCase_				:			CLIPTextModel      ,						lowerCamelCase_				:			CLIPTokenizer      ,						lowerCamelCase_				:			UNetaDConditionModel      ,						lowerCamelCase_				:			Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler]      ,						lowerCamelCase_				:			StableDiffusionSafetyChecker      ,						lowerCamelCase_				:			CLIPImageProcessor      ,						lowerCamelCase_				:			bool = True      ,						):

							'''simple docstring'''



							super()._init_()

							SCREAMING_SNAKE_CASE :				Tuple		=			StableDiffusionPipeline.from_pretrained(lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				List[Any]		=			StableDiffusionPipeline.from_pretrained(lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				List[Any]		=			StableDiffusionPipeline.from_pretrained(lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				Optional[int]		=			StableDiffusionPipeline(
							    vae=lowerCamelCase_      ,						text_encoder=lowerCamelCase_      ,						tokenizer=lowerCamelCase_      ,						unet=lowerCamelCase_      ,						scheduler=lowerCamelCase_      ,						safety_checker=lowerCamelCase_      ,						feature_extractor=lowerCamelCase_      ,						requires_safety_checker=lowerCamelCase_      ,						)

							self.register_modules(pipelinea=self.pipea      ,						pipelinea=self.pipea      ,						pipelinea=self.pipea      ,						pipelinea=self.pipea						)


					@property
					def lowerCamelCase_			(						self				:			int						):

							'''simple docstring'''



							return {k: getattr(self      ,						lowerCamelCase_						) for k in self.config.keys() if not k.startswith("""_"""						)}


					def lowerCamelCase_			(						self				:			Any      ,						lowerCamelCase_				:			Optional[Union[str, int]] = "auto"						):

							'''simple docstring'''



							if slice_size == "auto":
									# half the attention head size is usually a good trade-off between
									# speed and memory
									SCREAMING_SNAKE_CASE :				Optional[int]		=			self.unet.config.attention_head_dim // 2
							self.unet.set_attention_slice(lowerCamelCase_						)


					def lowerCamelCase_			(						self				:			Dict						):

							'''simple docstring'''



							self.enable_attention_slicing(lowerCamelCase_						)


					@torch.no_grad()
					def lowerCamelCase_			(						self				:			Optional[Any]      ,						lowerCamelCase_				:			Union[str, List[str]]      ,						lowerCamelCase_				:			int = 5_12      ,						lowerCamelCase_				:			int = 5_12      ,						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      ,						**lowerCamelCase_				:			Union[str, Any]      ,						):

							'''simple docstring'''



							return self.pipea(
							    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_      ,						**lowerCamelCase_      ,						)


					@torch.no_grad()
					def lowerCamelCase_			(						self				:			Optional[int]      ,						lowerCamelCase_				:			Union[str, List[str]]      ,						lowerCamelCase_				:			int = 5_12      ,						lowerCamelCase_				:			int = 5_12      ,						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      ,						**lowerCamelCase_				:			Union[str, Any]      ,						):

							'''simple docstring'''



							return self.pipea(
							    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_      ,						**lowerCamelCase_      ,						)


					@torch.no_grad()
					def lowerCamelCase_			(						self				:			Optional[Any]      ,						lowerCamelCase_				:			Union[str, List[str]]      ,						lowerCamelCase_				:			int = 5_12      ,						lowerCamelCase_				:			int = 5_12      ,						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      ,						**lowerCamelCase_				:			str      ,						):

							'''simple docstring'''



							return self.pipea(
							    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_      ,						**lowerCamelCase_      ,						)


					@torch.no_grad()
					def lowerCamelCase_			(						self				:			Tuple      ,						lowerCamelCase_				:			Union[str, List[str]]      ,						lowerCamelCase_				:			int = 5_12      ,						lowerCamelCase_				:			int = 5_12      ,						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      ,						**lowerCamelCase_				:			Dict      ,						):

							'''simple docstring'''



							return self.pipea(
							    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_      ,						**lowerCamelCase_      ,						)



					@torch.no_grad()
					def lowerCamelCase_			(						self				:			Dict      ,						lowerCamelCase_				:			Union[str, List[str]]      ,						lowerCamelCase_				:			int = 5_12      ,						lowerCamelCase_				:			int = 5_12      ,						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      ,						**lowerCamelCase_				:			Any      ,						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				int		=			"""cuda""" if torch.cuda.is_available() else """cpu"""
							self.to(lowerCamelCase_						)

							# Checks if the height and width are divisible by 8 or not
							if height % 8 != 0 or width % 8 != 0:
									raise ValueError(f'''`height` and `width` must be divisible by 8 but are {height} and {width}.'''						)

							# Get first result from Stable Diffusion Checkpoint v1.1
							SCREAMING_SNAKE_CASE :				List[str]		=			self.textaimg_sda_a(
							    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_      ,						**lowerCamelCase_      ,						)

							# Get first result from Stable Diffusion Checkpoint v1.2
							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			self.textaimg_sda_a(
							    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_      ,						**lowerCamelCase_      ,						)

							# Get first result from Stable Diffusion Checkpoint v1.3
							SCREAMING_SNAKE_CASE :				int		=			self.textaimg_sda_a(
							    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_      ,						**lowerCamelCase_      ,						)

							# Get first result from Stable Diffusion Checkpoint v1.4
							SCREAMING_SNAKE_CASE :				Optional[int]		=			self.textaimg_sda_a(
							    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_      ,						**lowerCamelCase_      ,						)

							# Get all result images into a single list and pass it via StableDiffusionPipelineOutput for final result
							return StableDiffusionPipelineOutput([resa[0], resa[0], resa[0], resa[0]]						)



