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 					A							(    UpperCAmelCase_					):


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



         super()._init_()

         UpperCAmelCase__								=  StableDiffusionPipeline.from_pretrained(__UpperCAmelCase		)
         UpperCAmelCase__								=  StableDiffusionPipeline.from_pretrained(__UpperCAmelCase		)
         UpperCAmelCase__								=  StableDiffusionPipeline.from_pretrained(__UpperCAmelCase		)
         UpperCAmelCase__								=  StableDiffusionPipeline(
             vae=__UpperCAmelCase	,  text_encoder=__UpperCAmelCase	,  tokenizer=__UpperCAmelCase	,  unet=__UpperCAmelCase	,  scheduler=__UpperCAmelCase	,  safety_checker=__UpperCAmelCase	,  feature_extractor=__UpperCAmelCase	,  requires_safety_checker=__UpperCAmelCase	,  )

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


   @property
   def       lowercase_				(self					:						int		)						->    Dict[str, Any]:
         """simple docstring"""



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


   def       lowercase_				(self					:						Union[str, Any]	,  __UpperCAmelCase					:						Optional[Union[str, int]] = "auto"		)						->    Optional[int]:
         """simple docstring"""



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


   def       lowercase_				(self					:						int		)						->    Optional[int]:
         """simple docstring"""



         self.enable_attention_slicing(__UpperCAmelCase		)


   @torch.no_grad()
   def       lowercase_				(self					:						Optional[int]	,  __UpperCAmelCase					:						Union[str, List[str]]	,  __UpperCAmelCase					:						int = 5_1_2	,  __UpperCAmelCase					:						int = 5_1_2	,  __UpperCAmelCase					:						int = 5_0	,  __UpperCAmelCase					:						float = 7.5	,  __UpperCAmelCase					:						Optional[Union[str, List[str]]] = None	,  __UpperCAmelCase					:						Optional[int] = 1	,  __UpperCAmelCase					:						float = 0.0	,  __UpperCAmelCase					:						Optional[torch.Generator] = None	,  __UpperCAmelCase					:						Optional[torch.FloatTensor] = None	,  __UpperCAmelCase					:						Optional[str] = "pil"	,  __UpperCAmelCase					:						bool = True	,  __UpperCAmelCase					:						Optional[Callable[[int, int, torch.FloatTensor], None]] = None	,  __UpperCAmelCase					:						int = 1	,  **__UpperCAmelCase					:						Any	,  )						->    Dict:
         """simple docstring"""



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


   @torch.no_grad()
   def       lowercase_				(self					:						List[str]	,  __UpperCAmelCase					:						Union[str, List[str]]	,  __UpperCAmelCase					:						int = 5_1_2	,  __UpperCAmelCase					:						int = 5_1_2	,  __UpperCAmelCase					:						int = 5_0	,  __UpperCAmelCase					:						float = 7.5	,  __UpperCAmelCase					:						Optional[Union[str, List[str]]] = None	,  __UpperCAmelCase					:						Optional[int] = 1	,  __UpperCAmelCase					:						float = 0.0	,  __UpperCAmelCase					:						Optional[torch.Generator] = None	,  __UpperCAmelCase					:						Optional[torch.FloatTensor] = None	,  __UpperCAmelCase					:						Optional[str] = "pil"	,  __UpperCAmelCase					:						bool = True	,  __UpperCAmelCase					:						Optional[Callable[[int, int, torch.FloatTensor], None]] = None	,  __UpperCAmelCase					:						int = 1	,  **__UpperCAmelCase					:						Optional[Any]	,  )						->    Any:
         """simple docstring"""



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


   @torch.no_grad()
   def       lowercase_				(self					:						List[str]	,  __UpperCAmelCase					:						Union[str, List[str]]	,  __UpperCAmelCase					:						int = 5_1_2	,  __UpperCAmelCase					:						int = 5_1_2	,  __UpperCAmelCase					:						int = 5_0	,  __UpperCAmelCase					:						float = 7.5	,  __UpperCAmelCase					:						Optional[Union[str, List[str]]] = None	,  __UpperCAmelCase					:						Optional[int] = 1	,  __UpperCAmelCase					:						float = 0.0	,  __UpperCAmelCase					:						Optional[torch.Generator] = None	,  __UpperCAmelCase					:						Optional[torch.FloatTensor] = None	,  __UpperCAmelCase					:						Optional[str] = "pil"	,  __UpperCAmelCase					:						bool = True	,  __UpperCAmelCase					:						Optional[Callable[[int, int, torch.FloatTensor], None]] = None	,  __UpperCAmelCase					:						int = 1	,  **__UpperCAmelCase					:						Any	,  )						->    Dict:
         """simple docstring"""



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


   @torch.no_grad()
   def       lowercase_				(self					:						Union[str, Any]	,  __UpperCAmelCase					:						Union[str, List[str]]	,  __UpperCAmelCase					:						int = 5_1_2	,  __UpperCAmelCase					:						int = 5_1_2	,  __UpperCAmelCase					:						int = 5_0	,  __UpperCAmelCase					:						float = 7.5	,  __UpperCAmelCase					:						Optional[Union[str, List[str]]] = None	,  __UpperCAmelCase					:						Optional[int] = 1	,  __UpperCAmelCase					:						float = 0.0	,  __UpperCAmelCase					:						Optional[torch.Generator] = None	,  __UpperCAmelCase					:						Optional[torch.FloatTensor] = None	,  __UpperCAmelCase					:						Optional[str] = "pil"	,  __UpperCAmelCase					:						bool = True	,  __UpperCAmelCase					:						Optional[Callable[[int, int, torch.FloatTensor], None]] = None	,  __UpperCAmelCase					:						int = 1	,  **__UpperCAmelCase					:						Union[str, Any]	,  )						->    List[str]:
         """simple docstring"""



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





   @torch.no_grad()
   def       lowercase_				(self					:						int	,  __UpperCAmelCase					:						Union[str, List[str]]	,  __UpperCAmelCase					:						int = 5_1_2	,  __UpperCAmelCase					:						int = 5_1_2	,  __UpperCAmelCase					:						int = 5_0	,  __UpperCAmelCase					:						float = 7.5	,  __UpperCAmelCase					:						Optional[Union[str, List[str]]] = None	,  __UpperCAmelCase					:						Optional[int] = 1	,  __UpperCAmelCase					:						float = 0.0	,  __UpperCAmelCase					:						Optional[torch.Generator] = None	,  __UpperCAmelCase					:						Optional[torch.FloatTensor] = None	,  __UpperCAmelCase					:						Optional[str] = "pil"	,  __UpperCAmelCase					:						bool = True	,  __UpperCAmelCase					:						Optional[Callable[[int, int, torch.FloatTensor], None]] = None	,  __UpperCAmelCase					:						int = 1	,  **__UpperCAmelCase					:						Any	,  )						->    Union[str, Any]:
         """simple docstring"""



         UpperCAmelCase__								=  "cuda" if torch.cuda.is_available() else "cpu"
         self.to(__UpperCAmelCase		)

         # 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__								=  self.textaimg_sda_a(
             prompt=__UpperCAmelCase	,  height=__UpperCAmelCase	,  width=__UpperCAmelCase	,  num_inference_steps=__UpperCAmelCase	,  guidance_scale=__UpperCAmelCase	,  negative_prompt=__UpperCAmelCase	,  num_images_per_prompt=__UpperCAmelCase	,  eta=__UpperCAmelCase	,  generator=__UpperCAmelCase	,  latents=__UpperCAmelCase	,  output_type=__UpperCAmelCase	,  return_dict=__UpperCAmelCase	,  callback=__UpperCAmelCase	,  callback_steps=__UpperCAmelCase	,  **__UpperCAmelCase	,  )

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

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

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

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




from typing import Callable, Optional, Union

from ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCamelCase__    							= logging.get_logger(__name__)

UpperCamelCase__    							= {
    'microsoft/xprophetnet-large-wiki100-cased': (
        'https://huggingface.co/microsoft/xprophetnet-large-wiki100-cased/resolve/main/config.json'
    ),
}





class 					A							(    UpperCAmelCase_					):
   __UpperCAmelCase			:			Optional[int]              =      'xlm-prophetnet'
   __UpperCAmelCase			:			int              =      ['past_key_values']
   __UpperCAmelCase			:			Optional[int]              =      {
       'num_attention_heads': 'num_encoder_attention_heads',
   }


   def __init__(self					:						str	,  __UpperCAmelCase					:						Optional[float] = 0.1	,  __UpperCAmelCase					:						Optional[Union[str, Callable]] = "gelu"	,  __UpperCAmelCase					:						Optional[int] = 3_0_5_2_2	,  __UpperCAmelCase					:						Optional[int] = 1_0_2_4	,  __UpperCAmelCase					:						Optional[int] = 4_0_9_6	,  __UpperCAmelCase					:						Optional[int] = 1_2	,  __UpperCAmelCase					:						Optional[int] = 1_6	,  __UpperCAmelCase					:						Optional[int] = 4_0_9_6	,  __UpperCAmelCase					:						Optional[int] = 1_2	,  __UpperCAmelCase					:						Optional[int] = 1_6	,  __UpperCAmelCase					:						Optional[float] = 0.1	,  __UpperCAmelCase					:						Optional[float] = 0.1	,  __UpperCAmelCase					:						Optional[int] = 5_1_2	,  __UpperCAmelCase					:						Optional[float] = 0.02	,  __UpperCAmelCase					:						Optional[bool] = True	,  __UpperCAmelCase					:						Optional[bool] = True	,  __UpperCAmelCase					:						Optional[int] = 0	,  __UpperCAmelCase					:						Optional[int] = 2	,  __UpperCAmelCase					:						Optional[int] = 3_2	,  __UpperCAmelCase					:						Optional[int] = 1_2_8	,  __UpperCAmelCase					:						Optional[bool] = False	,  __UpperCAmelCase					:						Optional[float] = 0.0	,  __UpperCAmelCase					:						Optional[bool] = True	,  __UpperCAmelCase					:						Optional[int] = 0	,  __UpperCAmelCase					:						Optional[int] = 1	,  __UpperCAmelCase					:						Optional[int] = 2	,  **__UpperCAmelCase					:						Optional[Any]	,  )						->    List[str]:
         """simple docstring"""



         UpperCAmelCase__								=  vocab_size
         UpperCAmelCase__								=  hidden_size
         UpperCAmelCase__								=  encoder_ffn_dim
         UpperCAmelCase__								=  num_encoder_layers
         UpperCAmelCase__								=  num_encoder_attention_heads
         UpperCAmelCase__								=  decoder_ffn_dim
         UpperCAmelCase__								=  num_decoder_layers
         UpperCAmelCase__								=  num_decoder_attention_heads
         UpperCAmelCase__								=  max_position_embeddings
         UpperCAmelCase__								=  init_std  # Normal(0, this parameter)
         UpperCAmelCase__								=  activation_function

         # parameters for xlmprophetnet
         UpperCAmelCase__								=  ngram
         UpperCAmelCase__								=  num_buckets
         UpperCAmelCase__								=  relative_max_distance
         UpperCAmelCase__								=  disable_ngram_loss
         UpperCAmelCase__								=  eps

         # 3 Types of Dropout
         UpperCAmelCase__								=  attention_dropout
         UpperCAmelCase__								=  activation_dropout
         UpperCAmelCase__								=  dropout

         UpperCAmelCase__								=  use_cache

         super().__init__(
             pad_token_id=__UpperCAmelCase	,  bos_token_id=__UpperCAmelCase	,  eos_token_id=__UpperCAmelCase	,  is_encoder_decoder=__UpperCAmelCase	,  add_cross_attention=__UpperCAmelCase	,  decoder_start_token_id=__UpperCAmelCase	,  **__UpperCAmelCase	,  )


   @property
   def       lowercase_				(self					:						int		)						->    int:
         """simple docstring"""



         return self.num_encoder_layers + self.num_decoder_layers





   @num_hidden_layers.setter
   def       lowercase_				(self					:						Any	,  __UpperCAmelCase					:						List[Any]		)						->    Union[str, Any]:
         """simple docstring"""



         raise NotImplementedError(
             "This model does not support the setting of `num_hidden_layers`. Please set `num_encoder_layers` and"
             " `num_decoder_layers`."		)



