





'''simple docstring'''







import argparse
import json
from pathlib import Path

import requests
import torch
from huggingface_hub import hf_hub_download
from PIL import Image

from transformers import (
    BertTokenizer,
    ViltConfig,
    ViltForImageAndTextRetrieval,
    ViltForImagesAndTextClassification,
    ViltForMaskedLM,
    ViltForQuestionAnswering,
    ViltImageProcessor,
    ViltProcessor,
)
from transformers.utils import logging


logging.set_verbosity_info()
snake_case_     :       Optional[int]						=  logging.get_logger(__name__)





def        lowerCamelCase_      (  SCREAMING_SNAKE_CASE__      :			Dict,			SCREAMING_SNAKE_CASE__      :			Union[str, Any]=False,			SCREAMING_SNAKE_CASE__      :			Any=False,			SCREAMING_SNAKE_CASE__      :			str=False   ) ->	Optional[int]:
						UpperCAmelCase_			:      Any     						=  []
						for i in range(config.num_hidden_layers   ):
												# encoder layers: output projection, 2 feedforward neural networks and 2 layernorms
												rename_keys.append((F"""transformer.blocks.{i}.norm1.weight""", F"""vilt.encoder.layer.{i}.layernorm_before.weight""")   )
												rename_keys.append((F"""transformer.blocks.{i}.norm1.bias""", F"""vilt.encoder.layer.{i}.layernorm_before.bias""")   )
												rename_keys.append(
												    (F"""transformer.blocks.{i}.attn.proj.weight""", F"""vilt.encoder.layer.{i}.attention.output.dense.weight""")   )
												rename_keys.append(
												    (F"""transformer.blocks.{i}.attn.proj.bias""", F"""vilt.encoder.layer.{i}.attention.output.dense.bias""")   )
												rename_keys.append((F"""transformer.blocks.{i}.norm2.weight""", F"""vilt.encoder.layer.{i}.layernorm_after.weight""")   )
												rename_keys.append((F"""transformer.blocks.{i}.norm2.bias""", F"""vilt.encoder.layer.{i}.layernorm_after.bias""")   )
												rename_keys.append(
												    (F"""transformer.blocks.{i}.mlp.fc1.weight""", F"""vilt.encoder.layer.{i}.intermediate.dense.weight""")   )
												rename_keys.append((F"""transformer.blocks.{i}.mlp.fc1.bias""", F"""vilt.encoder.layer.{i}.intermediate.dense.bias""")   )
												rename_keys.append((F"""transformer.blocks.{i}.mlp.fc2.weight""", F"""vilt.encoder.layer.{i}.output.dense.weight""")   )
												rename_keys.append((F"""transformer.blocks.{i}.mlp.fc2.bias""", F"""vilt.encoder.layer.{i}.output.dense.bias""")   )

						# embeddings
						rename_keys.extend(
						    [
						        # text embeddings
						        ('''text_embeddings.word_embeddings.weight''', '''vilt.embeddings.text_embeddings.word_embeddings.weight'''),
						        (
						            '''text_embeddings.position_embeddings.weight''',
						            '''vilt.embeddings.text_embeddings.position_embeddings.weight''',
						        ),
						        ('''text_embeddings.position_ids''', '''vilt.embeddings.text_embeddings.position_ids'''),
						        (
						            '''text_embeddings.token_type_embeddings.weight''',
						            '''vilt.embeddings.text_embeddings.token_type_embeddings.weight''',
						        ),
						        ('''text_embeddings.LayerNorm.weight''', '''vilt.embeddings.text_embeddings.LayerNorm.weight'''),
						        ('''text_embeddings.LayerNorm.bias''', '''vilt.embeddings.text_embeddings.LayerNorm.bias'''),
						        # patch embeddings
						        ('''transformer.cls_token''', '''vilt.embeddings.cls_token'''),
						        ('''transformer.patch_embed.proj.weight''', '''vilt.embeddings.patch_embeddings.projection.weight'''),
						        ('''transformer.patch_embed.proj.bias''', '''vilt.embeddings.patch_embeddings.projection.bias'''),
						        ('''transformer.pos_embed''', '''vilt.embeddings.position_embeddings'''),
						        # token type embeddings
						        ('''token_type_embeddings.weight''', '''vilt.embeddings.token_type_embeddings.weight'''),
						    ]   )

						# final layernorm + pooler
						rename_keys.extend(
						    [
						        ('''transformer.norm.weight''', '''vilt.layernorm.weight'''),
						        ('''transformer.norm.bias''', '''vilt.layernorm.bias'''),
						        ('''pooler.dense.weight''', '''vilt.pooler.dense.weight'''),
						        ('''pooler.dense.bias''', '''vilt.pooler.dense.bias'''),
						    ]   )

						# classifier head(s)
						if vqa_model:
												# classification head
												rename_keys.extend(
												    [
												        ('''vqa_classifier.0.weight''', '''classifier.0.weight'''),
												        ('''vqa_classifier.0.bias''', '''classifier.0.bias'''),
												        ('''vqa_classifier.1.weight''', '''classifier.1.weight'''),
												        ('''vqa_classifier.1.bias''', '''classifier.1.bias'''),
												        ('''vqa_classifier.3.weight''', '''classifier.3.weight'''),
												        ('''vqa_classifier.3.bias''', '''classifier.3.bias'''),
												    ]   )
						elif nlvr_model:
												# classification head
												rename_keys.extend(
												    [
												        ('''nlvr2_classifier.0.weight''', '''classifier.0.weight'''),
												        ('''nlvr2_classifier.0.bias''', '''classifier.0.bias'''),
												        ('''nlvr2_classifier.1.weight''', '''classifier.1.weight'''),
												        ('''nlvr2_classifier.1.bias''', '''classifier.1.bias'''),
												        ('''nlvr2_classifier.3.weight''', '''classifier.3.weight'''),
												        ('''nlvr2_classifier.3.bias''', '''classifier.3.bias'''),
												    ]   )
						else:
												pass

						return rename_keys





def        lowerCamelCase_      (  SCREAMING_SNAKE_CASE__      :			Tuple,			SCREAMING_SNAKE_CASE__      :			List[Any]   ) ->	List[str]:
						for i in range(config.num_hidden_layers   ):
												UpperCAmelCase_			:      int     						=  '''vilt.'''
												# read in weights + bias of input projection layer (in timm, this is a single matrix + bias)
												UpperCAmelCase_			:      Union[str, Any]     						=  state_dict.pop(F"""transformer.blocks.{i}.attn.qkv.weight"""   )
												UpperCAmelCase_			:      Optional[Any]     						=  state_dict.pop(F"""transformer.blocks.{i}.attn.qkv.bias"""   )
												# next, add query, keys and values (in that order) to the state dict
												UpperCAmelCase_			:      Optional[Any]     						=  in_proj_weight[
												    : config.hidden_size, :
												]
												UpperCAmelCase_			:      List[Any]     						=  in_proj_bias[: config.hidden_size]
												UpperCAmelCase_			:      str     						=  in_proj_weight[
												    config.hidden_size : config.hidden_size * 2, :
												]
												UpperCAmelCase_			:      Dict     						=  in_proj_bias[
												    config.hidden_size : config.hidden_size * 2
												]
												UpperCAmelCase_			:      Tuple     						=  in_proj_weight[
												    -config.hidden_size :, :
												]
												UpperCAmelCase_			:      List[Any]     						=  in_proj_bias[-config.hidden_size :]





def        lowerCamelCase_      (  SCREAMING_SNAKE_CASE__      :			List[Any]   ) ->	int:
						UpperCAmelCase_			:      Union[str, Any]     						=  ['''head.weight''', '''head.bias''']
						for k in ignore_keys:
												state_dict.pop(lowercase__,			lowercase__   )





def        lowerCamelCase_      (  SCREAMING_SNAKE_CASE__      :			Union[str, Any],			SCREAMING_SNAKE_CASE__      :			Union[str, Any],			SCREAMING_SNAKE_CASE__      :			str   ) ->	Union[str, Any]:
						UpperCAmelCase_			:      Dict     						=  dct.pop(lowercase__   )
						UpperCAmelCase_			:      Any     						=  val





@torch.no_grad()
def        lowerCamelCase_      (  SCREAMING_SNAKE_CASE__      :			Any,			SCREAMING_SNAKE_CASE__      :			List[Any]   ) ->	Any:
						UpperCAmelCase_			:      str     						=  ViltConfig(image_size=384,			patch_size=32,			tie_word_embeddings=lowercase__   )
						UpperCAmelCase_			:      Optional[int]     						=  False
						UpperCAmelCase_			:      Optional[Any]     						=  False
						UpperCAmelCase_			:      List[str]     						=  False
						UpperCAmelCase_			:      List[str]     						=  False
						if "vqa" in checkpoint_url:
												UpperCAmelCase_			:      Optional[int]     						=  True
												UpperCAmelCase_			:      Any     						=  3129
												UpperCAmelCase_			:      Dict     						=  '''huggingface/label-files'''
												UpperCAmelCase_			:      Tuple     						=  '''vqa2-id2label.json'''
												UpperCAmelCase_			:      Optional[Any]     						=  json.load(open(hf_hub_download(lowercase__,			lowercase__,			repo_type='''dataset'''   ),			'''r'''   )   )
												UpperCAmelCase_			:      str     						=  {int(lowercase__   ): v for k, v in idalabel.items()}
												UpperCAmelCase_			:      Tuple     						=  idalabel
												UpperCAmelCase_			:      str     						=  {v: k for k, v in idalabel.items()}
												UpperCAmelCase_			:      Tuple     						=  ViltForQuestionAnswering(lowercase__   )
						elif "nlvr" in checkpoint_url:
												UpperCAmelCase_			:      List[Any]     						=  True
												UpperCAmelCase_			:      str     						=  2
												UpperCAmelCase_			:      Optional[Any]     						=  {0: '''False''', 1: '''True'''}
												UpperCAmelCase_			:      int     						=  {v: k for k, v in config.idalabel.items()}
												UpperCAmelCase_			:      str     						=  3
												UpperCAmelCase_			:      Optional[Any]     						=  ViltForImagesAndTextClassification(lowercase__   )
						elif "irtr" in checkpoint_url:
												UpperCAmelCase_			:      Optional[Any]     						=  True
												UpperCAmelCase_			:      Optional[int]     						=  ViltForImageAndTextRetrieval(lowercase__   )
						elif "mlm_itm" in checkpoint_url:
												UpperCAmelCase_			:      Union[str, Any]     						=  True
												UpperCAmelCase_			:      Dict     						=  ViltForMaskedLM(lowercase__   )
						else:
												raise ValueError('''Unknown model type'''   )

						# load state_dict of original model, remove and rename some keys
						UpperCAmelCase_			:      str     						=  torch.hub.load_state_dict_from_url(lowercase__,			map_location='''cpu'''   )['''state_dict''']
						UpperCAmelCase_			:      str     						=  create_rename_keys(lowercase__,			lowercase__,			lowercase__,			lowercase__   )
						for src, dest in rename_keys:
												rename_key(lowercase__,			lowercase__,			lowercase__   )
						read_in_q_k_v(lowercase__,			lowercase__   )
						if mlm_model or irtr_model:
												UpperCAmelCase_			:      int     						=  ['''itm_score.fc.weight''', '''itm_score.fc.bias''']
												for k in ignore_keys:
																		state_dict.pop(lowercase__,			lowercase__   )

    # load state dict into HuggingFace model
						model.eval()
						if mlm_model:
												UpperCAmelCase_						,       UpperCAmelCase_			:      List[Any]     						=  model.load_state_dict(lowercase__,			strict=lowercase__   )
												assert missing_keys == ["mlm_score.decoder.bias"]
						else:
												model.load_state_dict(lowercase__   )

						# Define processor
						UpperCAmelCase_			:      List[str]     						=  ViltImageProcessor(size=384   )
						UpperCAmelCase_			:      List[Any]     						=  BertTokenizer.from_pretrained('''bert-base-uncased'''   )
						UpperCAmelCase_			:      List[str]     						=  ViltProcessor(lowercase__,			lowercase__   )

						# Forward pass on example inputs (image + text)
						if nlvr_model:
												UpperCAmelCase_			:      str     						=  Image.open(requests.get('''https://lil.nlp.cornell.edu/nlvr/exs/ex0_0.jpg''',			stream=lowercase__   ).raw   )
												UpperCAmelCase_			:      Tuple     						=  Image.open(requests.get('''https://lil.nlp.cornell.edu/nlvr/exs/ex0_0.jpg''',			stream=lowercase__   ).raw   )
												UpperCAmelCase_			:      Optional[Any]     						=  (
												    '''The left image contains twice the number of dogs as the right image, and at least two dogs in total are'''
												    ''' standing.'''
												)
												UpperCAmelCase_			:      str     						=  processor(lowercase__,			lowercase__,			return_tensors='''pt'''   )
												UpperCAmelCase_			:      Tuple     						=  processor(lowercase__,			lowercase__,			return_tensors='''pt'''   )
												UpperCAmelCase_			:      List[str]     						=  model(
												    input_ids=encoding_a.input_ids,			pixel_values=encoding_a.pixel_values,			pixel_values_a=encoding_a.pixel_values,			)
						else:
												UpperCAmelCase_			:      int     						=  Image.open(requests.get('''http://images.cocodataset.org/val2017/000000039769.jpg''',			stream=lowercase__   ).raw   )
												if mlm_model:
																		UpperCAmelCase_			:      Union[str, Any]     						=  '''a bunch of [MASK] laying on a [MASK].'''
												else:
																		UpperCAmelCase_			:      Union[str, Any]     						=  '''How many cats are there?'''
												UpperCAmelCase_			:      Union[str, Any]     						=  processor(lowercase__,			lowercase__,			return_tensors='''pt'''   )
												UpperCAmelCase_			:      str     						=  model(**lowercase__   )

						# Verify outputs
						if mlm_model:
												UpperCAmelCase_			:      List[Any]     						=  torch.Size([1, 11, 30522]   )
												UpperCAmelCase_			:      Tuple     						=  torch.tensor([-12.50_61, -12.51_23, -12.51_74]   )
												assert outputs.logits.shape == expected_shape
												assert torch.allclose(outputs.logits[0, 0, :3],			lowercase__,			atol=1E-4   )

												# verify masked token prediction equals "cats"
												UpperCAmelCase_			:      Optional[Any]     						=  outputs.logits[0, 4, :].argmax(-1   ).item()
												assert tokenizer.decode([predicted_id]   ) == "cats"
						elif vqa_model:
												UpperCAmelCase_			:      Dict     						=  torch.Size([1, 3129]   )
												UpperCAmelCase_			:      str     						=  torch.tensor([-15.94_95, -18.14_72, -10.30_41]   )
												assert torch.allclose(outputs.logits[0, :3],			lowercase__,			atol=1E-4   )
												assert outputs.logits.shape == expected_shape
												assert torch.allclose(outputs.logits[0, 0, :3],			lowercase__,			atol=1E-4   )

												# verify vqa prediction equals "2"
												UpperCAmelCase_			:      str     						=  outputs.logits.argmax(-1   ).item()
												assert model.config.idalabel[predicted_idx] == "2"
						elif nlvr_model:
												UpperCAmelCase_			:      str     						=  torch.Size([1, 2]   )
												UpperCAmelCase_			:      int     						=  torch.tensor([-2.87_21, 2.12_91]   )
												assert torch.allclose(outputs.logits[0, :3],			lowercase__,			atol=1E-4   )
												assert outputs.logits.shape == expected_shape

						Path(lowercase__   ).mkdir(exist_ok=lowercase__   )
						print(F"""Saving model and processor to {pytorch_dump_folder_path}"""   )
						model.save_pretrained(lowercase__   )
						processor.save_pretrained(lowercase__   )


if __name__ == "__main__":
					snake_case_     :       Union[str, Any]						=  argparse.ArgumentParser()
					# Required parameters
					parser.add_argument(
					    "--checkpoint_url",
					    default="https://github.com/dandelin/ViLT/releases/download/200k/vilt_200k_mlm_itm.ckpt",
					    type=str,
					    help="URL of the checkpoint you\'d like to convert.",
					)
					parser.add_argument(
					    "--pytorch_dump_folder_path", default=None, type=str, help="Path to the output PyTorch model directory."
					)

					snake_case_     :       List[str]						=  parser.parse_args()
					convert_vilt_checkpoint(args.checkpoint_url, args.pytorch_dump_folder_path)












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


snake_case_     :       Union[str, Any]						=  "CompVis/stable-diffusion-v1-1"
snake_case_     :       Dict						=  "CompVis/stable-diffusion-v1-2"
snake_case_     :       Any						=  "CompVis/stable-diffusion-v1-3"
snake_case_     :       str						=  "CompVis/stable-diffusion-v1-4"


class 					__a      (lowerCamelCase     ):

							def __init__(							self							:     Any       ,     __magic_name__							:     AutoencoderKL       ,     __magic_name__							:     CLIPTextModel       ,     __magic_name__							:     CLIPTokenizer       ,     __magic_name__							:     UNetaDConditionModel       ,     __magic_name__							:     Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler]       ,     __magic_name__							:     StableDiffusionSafetyChecker       ,     __magic_name__							:     CLIPImageProcessor       ,     __magic_name__							:     bool = True       ,     )					->       str:







													"""simple docstring"""
													super()._init_()

													UpperCAmelCase_			:      Any     						=  StableDiffusionPipeline.from_pretrained(__magic_name__   )
													UpperCAmelCase_			:      Dict     						=  StableDiffusionPipeline.from_pretrained(__magic_name__   )
													UpperCAmelCase_			:      List[Any]     						=  StableDiffusionPipeline.from_pretrained(__magic_name__   )
													UpperCAmelCase_			:      Tuple     						=  StableDiffusionPipeline(
													    vae=__magic_name__       ,     text_encoder=__magic_name__       ,     tokenizer=__magic_name__       ,     unet=__magic_name__       ,     scheduler=__magic_name__       ,     safety_checker=__magic_name__       ,     feature_extractor=__magic_name__       ,     requires_safety_checker=__magic_name__       ,     )

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

							@property
							def     UpperCAmelCase__	(							self							:     Tuple   )					->       Dict[str, Any]:







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

							def     UpperCAmelCase__	(							self							:     Dict       ,     __magic_name__							:     Optional[Union[str, int]] = "auto"   )					->       int:







													"""simple docstring"""
													if slice_size == "auto":
																			# half the attention head size is usually a good trade-off between
																			# speed and memory
																			UpperCAmelCase_			:      List[str]     						=  self.unet.config.attention_head_dim // 2
													self.unet.set_attention_slice(__magic_name__   )

							def     UpperCAmelCase__	(							self							:     Tuple   )					->       List[str]:







													"""simple docstring"""
													self.enable_attention_slicing(__magic_name__   )

							@torch.no_grad()
							def     UpperCAmelCase__	(							self							:     List[Any]       ,     __magic_name__							:     Union[str, List[str]]       ,     __magic_name__							:     int = 5_12       ,     __magic_name__							:     int = 5_12       ,     __magic_name__							:     int = 50       ,     __magic_name__							:     float = 7.5       ,     __magic_name__							:     Optional[Union[str, List[str]]] = None       ,     __magic_name__							:     Optional[int] = 1       ,     __magic_name__							:     float = 0.0       ,     __magic_name__							:     Optional[torch.Generator] = None       ,     __magic_name__							:     Optional[torch.FloatTensor] = None       ,     __magic_name__							:     Optional[str] = "pil"       ,     __magic_name__							:     bool = True       ,     __magic_name__							:     Optional[Callable[[int, int, torch.FloatTensor], None]] = None       ,     __magic_name__							:     int = 1       ,     **__magic_name__							:     Tuple       ,     )					->       Optional[int]:







													"""simple docstring"""
													return self.pipea(
													    prompt=__magic_name__       ,     height=__magic_name__       ,     width=__magic_name__       ,     num_inference_steps=__magic_name__       ,     guidance_scale=__magic_name__       ,     negative_prompt=__magic_name__       ,     num_images_per_prompt=__magic_name__       ,     eta=__magic_name__       ,     generator=__magic_name__       ,     latents=__magic_name__       ,     output_type=__magic_name__       ,     return_dict=__magic_name__       ,     callback=__magic_name__       ,     callback_steps=__magic_name__       ,     **__magic_name__       ,     )

							@torch.no_grad()
							def     UpperCAmelCase__	(							self							:     Optional[int]       ,     __magic_name__							:     Union[str, List[str]]       ,     __magic_name__							:     int = 5_12       ,     __magic_name__							:     int = 5_12       ,     __magic_name__							:     int = 50       ,     __magic_name__							:     float = 7.5       ,     __magic_name__							:     Optional[Union[str, List[str]]] = None       ,     __magic_name__							:     Optional[int] = 1       ,     __magic_name__							:     float = 0.0       ,     __magic_name__							:     Optional[torch.Generator] = None       ,     __magic_name__							:     Optional[torch.FloatTensor] = None       ,     __magic_name__							:     Optional[str] = "pil"       ,     __magic_name__							:     bool = True       ,     __magic_name__							:     Optional[Callable[[int, int, torch.FloatTensor], None]] = None       ,     __magic_name__							:     int = 1       ,     **__magic_name__							:     Any       ,     )					->       Any:







													"""simple docstring"""
													return self.pipea(
													    prompt=__magic_name__       ,     height=__magic_name__       ,     width=__magic_name__       ,     num_inference_steps=__magic_name__       ,     guidance_scale=__magic_name__       ,     negative_prompt=__magic_name__       ,     num_images_per_prompt=__magic_name__       ,     eta=__magic_name__       ,     generator=__magic_name__       ,     latents=__magic_name__       ,     output_type=__magic_name__       ,     return_dict=__magic_name__       ,     callback=__magic_name__       ,     callback_steps=__magic_name__       ,     **__magic_name__       ,     )

							@torch.no_grad()
							def     UpperCAmelCase__	(							self							:     List[Any]       ,     __magic_name__							:     Union[str, List[str]]       ,     __magic_name__							:     int = 5_12       ,     __magic_name__							:     int = 5_12       ,     __magic_name__							:     int = 50       ,     __magic_name__							:     float = 7.5       ,     __magic_name__							:     Optional[Union[str, List[str]]] = None       ,     __magic_name__							:     Optional[int] = 1       ,     __magic_name__							:     float = 0.0       ,     __magic_name__							:     Optional[torch.Generator] = None       ,     __magic_name__							:     Optional[torch.FloatTensor] = None       ,     __magic_name__							:     Optional[str] = "pil"       ,     __magic_name__							:     bool = True       ,     __magic_name__							:     Optional[Callable[[int, int, torch.FloatTensor], None]] = None       ,     __magic_name__							:     int = 1       ,     **__magic_name__							:     Dict       ,     )					->       List[str]:







													"""simple docstring"""
													return self.pipea(
													    prompt=__magic_name__       ,     height=__magic_name__       ,     width=__magic_name__       ,     num_inference_steps=__magic_name__       ,     guidance_scale=__magic_name__       ,     negative_prompt=__magic_name__       ,     num_images_per_prompt=__magic_name__       ,     eta=__magic_name__       ,     generator=__magic_name__       ,     latents=__magic_name__       ,     output_type=__magic_name__       ,     return_dict=__magic_name__       ,     callback=__magic_name__       ,     callback_steps=__magic_name__       ,     **__magic_name__       ,     )

							@torch.no_grad()
							def     UpperCAmelCase__	(							self							:     int       ,     __magic_name__							:     Union[str, List[str]]       ,     __magic_name__							:     int = 5_12       ,     __magic_name__							:     int = 5_12       ,     __magic_name__							:     int = 50       ,     __magic_name__							:     float = 7.5       ,     __magic_name__							:     Optional[Union[str, List[str]]] = None       ,     __magic_name__							:     Optional[int] = 1       ,     __magic_name__							:     float = 0.0       ,     __magic_name__							:     Optional[torch.Generator] = None       ,     __magic_name__							:     Optional[torch.FloatTensor] = None       ,     __magic_name__							:     Optional[str] = "pil"       ,     __magic_name__							:     bool = True       ,     __magic_name__							:     Optional[Callable[[int, int, torch.FloatTensor], None]] = None       ,     __magic_name__							:     int = 1       ,     **__magic_name__							:     Optional[int]       ,     )					->       str:







													"""simple docstring"""
													return self.pipea(
													    prompt=__magic_name__       ,     height=__magic_name__       ,     width=__magic_name__       ,     num_inference_steps=__magic_name__       ,     guidance_scale=__magic_name__       ,     negative_prompt=__magic_name__       ,     num_images_per_prompt=__magic_name__       ,     eta=__magic_name__       ,     generator=__magic_name__       ,     latents=__magic_name__       ,     output_type=__magic_name__       ,     return_dict=__magic_name__       ,     callback=__magic_name__       ,     callback_steps=__magic_name__       ,     **__magic_name__       ,     )



							@torch.no_grad()
							def     UpperCAmelCase__	(							self							:     Optional[Any]       ,     __magic_name__							:     Union[str, List[str]]       ,     __magic_name__							:     int = 5_12       ,     __magic_name__							:     int = 5_12       ,     __magic_name__							:     int = 50       ,     __magic_name__							:     float = 7.5       ,     __magic_name__							:     Optional[Union[str, List[str]]] = None       ,     __magic_name__							:     Optional[int] = 1       ,     __magic_name__							:     float = 0.0       ,     __magic_name__							:     Optional[torch.Generator] = None       ,     __magic_name__							:     Optional[torch.FloatTensor] = None       ,     __magic_name__							:     Optional[str] = "pil"       ,     __magic_name__							:     bool = True       ,     __magic_name__							:     Optional[Callable[[int, int, torch.FloatTensor], None]] = None       ,     __magic_name__							:     int = 1       ,     **__magic_name__							:     Optional[int]       ,     )					->       List[Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      int     						=  '''cuda''' if torch.cuda.is_available() else '''cpu'''
													self.to(__magic_name__   )

													# 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
													UpperCAmelCase_			:      Optional[int]     						=  self.textaimg_sda_a(
													    prompt=__magic_name__       ,     height=__magic_name__       ,     width=__magic_name__       ,     num_inference_steps=__magic_name__       ,     guidance_scale=__magic_name__       ,     negative_prompt=__magic_name__       ,     num_images_per_prompt=__magic_name__       ,     eta=__magic_name__       ,     generator=__magic_name__       ,     latents=__magic_name__       ,     output_type=__magic_name__       ,     return_dict=__magic_name__       ,     callback=__magic_name__       ,     callback_steps=__magic_name__       ,     **__magic_name__       ,     )

													# Get first result from Stable Diffusion Checkpoint v1.2
													UpperCAmelCase_			:      int     						=  self.textaimg_sda_a(
													    prompt=__magic_name__       ,     height=__magic_name__       ,     width=__magic_name__       ,     num_inference_steps=__magic_name__       ,     guidance_scale=__magic_name__       ,     negative_prompt=__magic_name__       ,     num_images_per_prompt=__magic_name__       ,     eta=__magic_name__       ,     generator=__magic_name__       ,     latents=__magic_name__       ,     output_type=__magic_name__       ,     return_dict=__magic_name__       ,     callback=__magic_name__       ,     callback_steps=__magic_name__       ,     **__magic_name__       ,     )

													# Get first result from Stable Diffusion Checkpoint v1.3
													UpperCAmelCase_			:      str     						=  self.textaimg_sda_a(
													    prompt=__magic_name__       ,     height=__magic_name__       ,     width=__magic_name__       ,     num_inference_steps=__magic_name__       ,     guidance_scale=__magic_name__       ,     negative_prompt=__magic_name__       ,     num_images_per_prompt=__magic_name__       ,     eta=__magic_name__       ,     generator=__magic_name__       ,     latents=__magic_name__       ,     output_type=__magic_name__       ,     return_dict=__magic_name__       ,     callback=__magic_name__       ,     callback_steps=__magic_name__       ,     **__magic_name__       ,     )

													# Get first result from Stable Diffusion Checkpoint v1.4
													UpperCAmelCase_			:      str     						=  self.textaimg_sda_a(
													    prompt=__magic_name__       ,     height=__magic_name__       ,     width=__magic_name__       ,     num_inference_steps=__magic_name__       ,     guidance_scale=__magic_name__       ,     negative_prompt=__magic_name__       ,     num_images_per_prompt=__magic_name__       ,     eta=__magic_name__       ,     generator=__magic_name__       ,     latents=__magic_name__       ,     output_type=__magic_name__       ,     return_dict=__magic_name__       ,     callback=__magic_name__       ,     callback_steps=__magic_name__       ,     **__magic_name__       ,     )

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





