






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__   :						str													=   """CompVis/stable-diffusion-v1-1"""
snake_case__   :						Optional[Any]													=   """CompVis/stable-diffusion-v1-2"""
snake_case__   :						List[Any]													=   """CompVis/stable-diffusion-v1-3"""
snake_case__   :						int													=   """CompVis/stable-diffusion-v1-4"""


class     _a							(	UpperCAmelCase__     ):






  """simple docstring"""





  def __init__(  self		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase = True		,		)      ->			List[str]:
     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  _UpperCAmelCase  (  self			)      ->			Dict[str, Any]:
     return {k: getattr(self		,		_UpperCAmelCase			) for k in self.config.keys() if not k.startswith('_'			)}




  def  _UpperCAmelCase  (  self		,		_UpperCAmelCase = "auto"			)      ->			List[str]:
     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  _UpperCAmelCase  (  self			)      ->			int:
     self.enable_attention_slicing(_UpperCAmelCase			)




  @torch.no_grad()
  def  _UpperCAmelCase  (  self		,		_UpperCAmelCase		,		_UpperCAmelCase = 512		,		_UpperCAmelCase = 512		,		_UpperCAmelCase = 50		,		_UpperCAmelCase = 7.5		,		_UpperCAmelCase = None		,		_UpperCAmelCase = 1		,		_UpperCAmelCase = 0.0		,		_UpperCAmelCase = None		,		_UpperCAmelCase = None		,		_UpperCAmelCase = "pil"		,		_UpperCAmelCase = True		,		_UpperCAmelCase = None		,		_UpperCAmelCase = 1		,		**_UpperCAmelCase		,		)      ->			Any:
     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  _UpperCAmelCase  (  self		,		_UpperCAmelCase		,		_UpperCAmelCase = 512		,		_UpperCAmelCase = 512		,		_UpperCAmelCase = 50		,		_UpperCAmelCase = 7.5		,		_UpperCAmelCase = None		,		_UpperCAmelCase = 1		,		_UpperCAmelCase = 0.0		,		_UpperCAmelCase = None		,		_UpperCAmelCase = None		,		_UpperCAmelCase = "pil"		,		_UpperCAmelCase = True		,		_UpperCAmelCase = None		,		_UpperCAmelCase = 1		,		**_UpperCAmelCase		,		)      ->			List[Any]:
     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  _UpperCAmelCase  (  self		,		_UpperCAmelCase		,		_UpperCAmelCase = 512		,		_UpperCAmelCase = 512		,		_UpperCAmelCase = 50		,		_UpperCAmelCase = 7.5		,		_UpperCAmelCase = None		,		_UpperCAmelCase = 1		,		_UpperCAmelCase = 0.0		,		_UpperCAmelCase = None		,		_UpperCAmelCase = None		,		_UpperCAmelCase = "pil"		,		_UpperCAmelCase = True		,		_UpperCAmelCase = None		,		_UpperCAmelCase = 1		,		**_UpperCAmelCase		,		)      ->			Optional[int]:
     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  _UpperCAmelCase  (  self		,		_UpperCAmelCase		,		_UpperCAmelCase = 512		,		_UpperCAmelCase = 512		,		_UpperCAmelCase = 50		,		_UpperCAmelCase = 7.5		,		_UpperCAmelCase = None		,		_UpperCAmelCase = 1		,		_UpperCAmelCase = 0.0		,		_UpperCAmelCase = None		,		_UpperCAmelCase = None		,		_UpperCAmelCase = "pil"		,		_UpperCAmelCase = True		,		_UpperCAmelCase = None		,		_UpperCAmelCase = 1		,		**_UpperCAmelCase		,		)      ->			Tuple:
     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  _UpperCAmelCase  (  self		,		_UpperCAmelCase		,		_UpperCAmelCase = 512		,		_UpperCAmelCase = 512		,		_UpperCAmelCase = 50		,		_UpperCAmelCase = 7.5		,		_UpperCAmelCase = None		,		_UpperCAmelCase = 1		,		_UpperCAmelCase = 0.0		,		_UpperCAmelCase = None		,		_UpperCAmelCase = None		,		_UpperCAmelCase = "pil"		,		_UpperCAmelCase = True		,		_UpperCAmelCase = None		,		_UpperCAmelCase = 1		,		**_UpperCAmelCase		,		)      ->			List[Any]:
     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 ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCAmelCase_           =	logging.get_logger(__name__)

UpperCAmelCase_           =	{
    "RWKV/rwkv-4-169m-pile": "https://huggingface.co/RWKV/rwkv-4-169m-pile/resolve/main/config.json",
    "RWKV/rwkv-4-430m-pile": "https://huggingface.co/RWKV/rwkv-4-430m-pile/resolve/main/config.json",
    "RWKV/rwkv-4-1b5-pile": "https://huggingface.co/RWKV/rwkv-4-1b5-pile/resolve/main/config.json",
    "RWKV/rwkv-4-3b-pile": "https://huggingface.co/RWKV/rwkv-4-3b-pile/resolve/main/config.json",
    "RWKV/rwkv-4-7b-pile": "https://huggingface.co/RWKV/rwkv-4-7b-pile/resolve/main/config.json",
    "RWKV/rwkv-4-14b-pile": "https://huggingface.co/RWKV/rwkv-4-14b-pile/resolve/main/config.json",
    "RWKV/rwkv-raven-1b5": "https://huggingface.co/RWKV/rwkv-raven-1b5/resolve/main/config.json",
    "RWKV/rwkv-raven-3b": "https://huggingface.co/RWKV/rwkv-raven-3b/resolve/main/config.json",
    "RWKV/rwkv-raven-7b": "https://huggingface.co/RWKV/rwkv-raven-7b/resolve/main/config.json",
    "RWKV/rwkv-raven-14b": "https://huggingface.co/RWKV/rwkv-raven-14b/resolve/main/config.json",
}




class 			__UpperCamelCase    (							A__    ):
     __A	:  Tuple							  =   """rwkv"""
     __A	:  Any							  =   {"""max_position_embeddings""": """context_length"""}





     def __init__(     self				,							_UpperCamelCase=50277				,							_UpperCamelCase=1024				,							_UpperCamelCase=4096				,							_UpperCamelCase=32				,							_UpperCamelCase=None				,							_UpperCamelCase=None				,							_UpperCamelCase=1e-5				,							_UpperCamelCase=0				,							_UpperCamelCase=0				,							_UpperCamelCase=6				,							_UpperCamelCase=False				,							_UpperCamelCase=True				,							**_UpperCamelCase				,							):
        _UpperCAmelCase           =   vocab_size
        _UpperCAmelCase           =   context_length
        _UpperCAmelCase           =   hidden_size
        _UpperCAmelCase           =   num_hidden_layers
        _UpperCAmelCase           =   attention_hidden_size if attention_hidden_size is not None else hidden_size
        _UpperCAmelCase           =   intermediate_size if intermediate_size is not None else 4 * hidden_size
        _UpperCAmelCase           =   layer_norm_epsilon
        _UpperCAmelCase           =   rescale_every
        _UpperCAmelCase           =   use_cache

        _UpperCAmelCase           =   bos_token_id
        _UpperCAmelCase           =   eos_token_id

        super().__init__(
            tie_word_embeddings=_UpperCamelCase				,							bos_token_id=_UpperCamelCase				,							eos_token_id=_UpperCamelCase				,							**_UpperCamelCase					)