





'''simple docstring'''


import argparse
import math
import os
from copy import deepcopy

import torch
from audio_diffusion.models import DiffusionAttnUnetaD
from diffusion import sampling
from torch import nn

from diffusers import DanceDiffusionPipeline, IPNDMScheduler, UNetaDModel


_SCREAMING_SNAKE_CASE									=				{
    "gwf-440k": {
        "url": "https://model-server.zqevans2.workers.dev/gwf-440k.ckpt",
        "sample_rate": 4_80_00,
        "sample_size": 6_55_36,
    },
    "jmann-small-190k": {
        "url": "https://model-server.zqevans2.workers.dev/jmann-small-190k.ckpt",
        "sample_rate": 4_80_00,
        "sample_size": 6_55_36,
    },
    "jmann-large-580k": {
        "url": "https://model-server.zqevans2.workers.dev/jmann-large-580k.ckpt",
        "sample_rate": 4_80_00,
        "sample_size": 13_10_72,
    },
    "maestro-uncond-150k": {
        "url": "https://model-server.zqevans2.workers.dev/maestro-uncond-150k.ckpt",
        "sample_rate": 1_60_00,
        "sample_size": 6_55_36,
    },
    "unlocked-uncond-250k": {
        "url": "https://model-server.zqevans2.workers.dev/unlocked-uncond-250k.ckpt",
        "sample_rate": 1_60_00,
        "sample_size": 6_55_36,
    },
    "honk-140k": {
        "url": "https://model-server.zqevans2.workers.dev/honk-140k.ckpt",
        "sample_rate": 1_60_00,
        "sample_size": 6_55_36,
    },
}


def 						__a(SCREAMING_SNAKE_CASE_	:       List[str]		,							SCREAMING_SNAKE_CASE_	:       Any     ):



    '''simple docstring'''





    return torch.atana(SCREAMING_SNAKE_CASE_		,							SCREAMING_SNAKE_CASE_     ) / math.pi * 2


def 						__a(SCREAMING_SNAKE_CASE_	:       int     ):



    '''simple docstring'''





    _lowerCAmelCase						      =   torch.sin(t * math.pi / 2     ) ** 2
    _lowerCAmelCase						      =   (1 - sigma**2) ** 0.5
    return alpha_sigma_to_t(SCREAMING_SNAKE_CASE_		,							SCREAMING_SNAKE_CASE_     )

class  lowerCAmelCase_		(		__magic_name__		):
 pass







class  lowerCAmelCase_		(		nn.Module		):




 def __init__(						self      ,  _lowerCAmelCase		)     ->				Any:
     super().__init__()

     _lowerCAmelCase						      =   DiffusionAttnUnetaD(_lowerCAmelCase      ,  n_attn_layers=4		)
     _lowerCAmelCase						      =   deepcopy(self.diffusion		)
     _lowerCAmelCase						      =   torch.quasirandom.SobolEngine(1      ,  scramble=_lowerCAmelCase		)







def 						__a(SCREAMING_SNAKE_CASE_	:       List[str]     ):



    '''simple docstring'''





    _lowerCAmelCase						      =   MODELS_MAP[model_name]["url"]
    os.system(F'''wget {url} ./'''     )

    return F'''./{model_name}.ckpt'''


_SCREAMING_SNAKE_CASE									=				{
    "1": "resnets.0",
    "2": "attentions.0",
    "3": "resnets.1",
    "4": "attentions.1",
    "5": "resnets.2",
    "6": "attentions.2",
}
_SCREAMING_SNAKE_CASE									=				{
    "8": "resnets.0",
    "9": "attentions.0",
    "10": "resnets.1",
    "11": "attentions.1",
    "12": "resnets.2",
    "13": "attentions.2",
}
_SCREAMING_SNAKE_CASE									=				{
    "1": "resnets.0",
    "2": "attentions.0",
    "3": "resnets.1",
    "4": "attentions.1",
    "5": "resnets.2",
    "6": "attentions.2",
    "8": "resnets.3",
    "9": "attentions.3",
    "10": "resnets.4",
    "11": "attentions.4",
    "12": "resnets.5",
    "13": "attentions.5",
}
_SCREAMING_SNAKE_CASE									=				{
    "0": "resnets.0",
    "1": "resnets.1",
    "2": "resnets.2",
    "4": "resnets.0",
    "5": "resnets.1",
    "6": "resnets.2",
}

_SCREAMING_SNAKE_CASE									=				{
    "skip": "conv_skip",
    "main.0": "conv_1",
    "main.1": "group_norm_1",
    "main.3": "conv_2",
    "main.4": "group_norm_2",
}

_SCREAMING_SNAKE_CASE									=				{
    "norm": "group_norm",
    "qkv_proj": ["query", "key", "value"],
    "out_proj": ["proj_attn"],
}


def 						__a(SCREAMING_SNAKE_CASE_	:       int     ):



    '''simple docstring'''





    if name.startswith("skip"     ):
        return name.replace("skip"		,							RES_CONV_MAP["skip"]     )

    # name has to be of format main.{digit}
    if not name.startswith("main."     ):
        raise ValueError(F'''ResConvBlock error with {name}'''     )

    return name.replace(name[:6]		,							RES_CONV_MAP[name[:6]]     )


def 						__a(SCREAMING_SNAKE_CASE_	:       int     ):



    '''simple docstring'''





    for key, value in ATTN_MAP.items():
        if name.startswith(SCREAMING_SNAKE_CASE_     ) and not isinstance(SCREAMING_SNAKE_CASE_		,							SCREAMING_SNAKE_CASE_     ):
            return name.replace(SCREAMING_SNAKE_CASE_		,							SCREAMING_SNAKE_CASE_     )
        elif name.startswith(SCREAMING_SNAKE_CASE_     ):
            return [name.replace(SCREAMING_SNAKE_CASE_		,							SCREAMING_SNAKE_CASE_     ) for v in value]
    raise ValueError(F'''Attn error with {name}'''     )


def 						__a(SCREAMING_SNAKE_CASE_	:       List[Any]		,							SCREAMING_SNAKE_CASE_	:       str=13     ):



    '''simple docstring'''





    _lowerCAmelCase						      =   input_string

    if string.split("."     )[0] == "timestep_embed":
        return string.replace("timestep_embed"		,							"time_proj"     )

    _lowerCAmelCase						      =   0
    if string.startswith("net.3."     ):
        depth += 1
        _lowerCAmelCase						      =   string[6:]
    elif string.startswith("net."     ):
        _lowerCAmelCase						      =   string[4:]

    while string.startswith("main.7."     ):
        depth += 1
        _lowerCAmelCase						      =   string[7:]

    if string.startswith("main."     ):
        _lowerCAmelCase						      =   string[5:]

    # mid block
    if string[:2].isdigit():
        _lowerCAmelCase						      =   string[:2]
        _lowerCAmelCase						      =   string[2:]
    else:
        _lowerCAmelCase						      =   string[0]
        _lowerCAmelCase						      =   string[1:]

    if depth == max_depth:
        _lowerCAmelCase						      =   MID_NUM_TO_LAYER[layer_num]
        _lowerCAmelCase						      =   "mid_block"
    elif depth > 0 and int(SCREAMING_SNAKE_CASE_     ) < 7:
        _lowerCAmelCase						      =   DOWN_NUM_TO_LAYER[layer_num]
        _lowerCAmelCase						      =   F'''down_blocks.{depth}'''
    elif depth > 0 and int(SCREAMING_SNAKE_CASE_     ) > 7:
        _lowerCAmelCase						      =   UP_NUM_TO_LAYER[layer_num]
        _lowerCAmelCase						      =   F'''up_blocks.{max_depth - depth - 1}'''
    elif depth == 0:
        _lowerCAmelCase						      =   DEPTH_0_TO_LAYER[layer_num]
        _lowerCAmelCase						      =   F'''up_blocks.{max_depth - 1}''' if int(SCREAMING_SNAKE_CASE_     ) > 3 else "down_blocks.0"

    if not string_left.startswith("."     ):
        raise ValueError(F'''Naming error with {input_string} and string_left: {string_left}.'''     )

    _lowerCAmelCase						      =   string_left[1:]

    if "resnets" in new_layer:
        _lowerCAmelCase						      =   convert_resconv_naming(SCREAMING_SNAKE_CASE_     )
    elif "attentions" in new_layer:
        _lowerCAmelCase						      =   convert_attn_naming(SCREAMING_SNAKE_CASE_     )
        _lowerCAmelCase						      =   new_string_left

    if not isinstance(SCREAMING_SNAKE_CASE_		,							SCREAMING_SNAKE_CASE_     ):
        _lowerCAmelCase						      =   prefix + "." + new_layer + "." + string_left
    else:
        _lowerCAmelCase						      =   [prefix + "." + new_layer + "." + s for s in string_left]
    return new_string


def 						__a(SCREAMING_SNAKE_CASE_	:       Optional[Any]     ):



    '''simple docstring'''





    _lowerCAmelCase						      =   {}
    for k, v in state_dict.items():
        if k.endswith("kernel"     ):
            # up- and downsample layers, don't have trainable weights
            continue

        _lowerCAmelCase						      =   rename(SCREAMING_SNAKE_CASE_     )

        # check if we need to transform from Conv => Linear for attention
        if isinstance(SCREAMING_SNAKE_CASE_		,							SCREAMING_SNAKE_CASE_     ):
            _lowerCAmelCase						      =   transform_conv_attns(SCREAMING_SNAKE_CASE_		,							SCREAMING_SNAKE_CASE_		,							SCREAMING_SNAKE_CASE_     )
        else:
            _lowerCAmelCase						      =   v

    return new_state_dict


def 						__a(SCREAMING_SNAKE_CASE_	:       Dict		,							SCREAMING_SNAKE_CASE_	:       List[str]		,							SCREAMING_SNAKE_CASE_	:       Optional[Any]     ):



    '''simple docstring'''





    if len(SCREAMING_SNAKE_CASE_     ) == 1:
        if len(v.shape     ) == 3:
            # weight
            _lowerCAmelCase						      =   v[:, :, 0]
        else:
            # bias
            _lowerCAmelCase						      =   v
    else:
        # qkv matrices
        _lowerCAmelCase						      =   v.shape[0]
        _lowerCAmelCase						      =   trippled_shape // 3
        for i in range(3     ):
            if len(v.shape     ) == 3:
                _lowerCAmelCase						      =   v[i * single_shape : (i + 1) * single_shape, :, 0]
            else:
                _lowerCAmelCase						      =   v[i * single_shape : (i + 1) * single_shape]
    return new_state_dict


def 						__a(SCREAMING_SNAKE_CASE_	:       Optional[Any]     ):



    '''simple docstring'''





    _lowerCAmelCase						      =   torch.device("cuda" if torch.cuda.is_available() else "cpu"     )

    _lowerCAmelCase						      =   args.model_path.split("/"     )[-1].split("."     )[0]
    if not os.path.isfile(args.model_path     ):
        assert (
            model_name == args.model_path
        ), F'''Make sure to provide one of the official model names {MODELS_MAP.keys()}'''
        _lowerCAmelCase						      =   download(SCREAMING_SNAKE_CASE_     )

    _lowerCAmelCase						      =   MODELS_MAP[model_name]["sample_rate"]
    _lowerCAmelCase						      =   MODELS_MAP[model_name]["sample_size"]

    _lowerCAmelCase						      =   Object()
    _lowerCAmelCase						      =   sample_size
    _lowerCAmelCase						      =   sample_rate
    _lowerCAmelCase						      =   0

    _lowerCAmelCase						      =   UNetaDModel(sample_size=SCREAMING_SNAKE_CASE_		,							sample_rate=SCREAMING_SNAKE_CASE_     )
    _lowerCAmelCase						      =   diffusers_model.state_dict()

    _lowerCAmelCase						      =   DiffusionUncond(SCREAMING_SNAKE_CASE_     )
    orig_model.load_state_dict(torch.load(args.model_path		,							map_location=SCREAMING_SNAKE_CASE_     )["state_dict"]     )
    _lowerCAmelCase						      =   orig_model.diffusion_ema.eval()
    _lowerCAmelCase						      =   orig_model.state_dict()
    _lowerCAmelCase						      =   rename_orig_weights(SCREAMING_SNAKE_CASE_     )

    _lowerCAmelCase						      =   set(renamed_state_dict.keys()     ) - set(diffusers_state_dict.keys()     )
    _lowerCAmelCase						      =   set(diffusers_state_dict.keys()     ) - set(renamed_state_dict.keys()     )

    assert len(SCREAMING_SNAKE_CASE_     ) == 0, F'''Problem with {renamed_minus_diffusers}'''
    assert all(k.endswith("kernel"     ) for k in list(SCREAMING_SNAKE_CASE_     )     ), F'''Problem with {diffusers_minus_renamed}'''

    for key, value in renamed_state_dict.items():
        assert (
            diffusers_state_dict[key].squeeze().shape == value.squeeze().shape
        ), F'''Shape for {key} doesn\'t match. Diffusers: {diffusers_state_dict[key].shape} vs. {value.shape}'''
        if key == "time_proj.weight":
            _lowerCAmelCase						      =   value.squeeze()

        _lowerCAmelCase						      =   value

    diffusers_model.load_state_dict(SCREAMING_SNAKE_CASE_     )

    _lowerCAmelCase						      =   100
    _lowerCAmelCase						      =   33

    _lowerCAmelCase						      =   IPNDMScheduler(num_train_timesteps=SCREAMING_SNAKE_CASE_     )

    _lowerCAmelCase						      =   torch.manual_seed(SCREAMING_SNAKE_CASE_     )
    _lowerCAmelCase						      =   torch.randn([1, 2, config.sample_size]		,							generator=SCREAMING_SNAKE_CASE_     ).to(SCREAMING_SNAKE_CASE_     )

    _lowerCAmelCase						      =   torch.linspace(1		,							0		,							steps + 1		,							device=SCREAMING_SNAKE_CASE_     )[:-1]
    _lowerCAmelCase						      =   get_crash_schedule(SCREAMING_SNAKE_CASE_     )

    _lowerCAmelCase						      =   DanceDiffusionPipeline(unet=SCREAMING_SNAKE_CASE_		,							scheduler=SCREAMING_SNAKE_CASE_     )

    _lowerCAmelCase						      =   torch.manual_seed(33     )
    _lowerCAmelCase						      =   pipe(num_inference_steps=SCREAMING_SNAKE_CASE_		,							generator=SCREAMING_SNAKE_CASE_     ).audios

    _lowerCAmelCase						      =   sampling.iplms_sample(SCREAMING_SNAKE_CASE_		,							SCREAMING_SNAKE_CASE_		,							SCREAMING_SNAKE_CASE_		,							{}     )
    _lowerCAmelCase						      =   generated.clamp(-1		,							1     )

    _lowerCAmelCase						      =   (generated - audio).abs().sum()
    _lowerCAmelCase						      =   (generated - audio).abs().max()

    if args.save:
        pipe.save_pretrained(args.checkpoint_path     )

    print("Diff sum"		,							SCREAMING_SNAKE_CASE_     )
    print("Diff max"		,							SCREAMING_SNAKE_CASE_     )

    assert diff_max < 1e-3, F'''Diff max: {diff_max} is too much :-/'''

    print(F'''Conversion for {model_name} successful!'''     )


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

       parser.add_argument("--model_path", default=None, type=str, required=True, help="Path to the model to convert.")
       parser.add_argument(
           "--save", default=True, type=bool, required=False, help="Whether to save the converted model or not."
       )
       parser.add_argument("--checkpoint_path", default=None, type=str, required=True, help="Path to the output model.")
       _SCREAMING_SNAKE_CASE									=				parser.parse_args()

       main(args)









'''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]]						)



