


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


__magic_name__			=     'CompVis/stable-diffusion-v1-1'
__magic_name__			=     'CompVis/stable-diffusion-v1-2'
__magic_name__			=     'CompVis/stable-diffusion-v1-3'
__magic_name__			=     'CompVis/stable-diffusion-v1-4'



class 	__lowerCAmelCase		(							lowerCAmelCase__    ):


  '''simple docstring'''







  def __init__(							self :       Optional[int]	,_a :       Optional[Any]	,_a :       int	,_a :       List[Any]	,_a :       List[Any]	,_a :       Tuple	,_a :       Any	,_a :       Optional[Any]	,_a :       int = True	,):

        '''simple docstring'''




        super()._init_()

        A_						:  Union[str, Any]          =				StableDiffusionPipeline.from_pretrained(_SCREAMING_SNAKE_CASE )
        A_						:  str          =				StableDiffusionPipeline.from_pretrained(_SCREAMING_SNAKE_CASE )
        A_						:  str          =				StableDiffusionPipeline.from_pretrained(_SCREAMING_SNAKE_CASE )
        A_						:  str          =				StableDiffusionPipeline(
            vae=_SCREAMING_SNAKE_CASE	,text_encoder=_SCREAMING_SNAKE_CASE	,tokenizer=_SCREAMING_SNAKE_CASE	,unet=_SCREAMING_SNAKE_CASE	,scheduler=_SCREAMING_SNAKE_CASE	,safety_checker=_SCREAMING_SNAKE_CASE	,feature_extractor=_SCREAMING_SNAKE_CASE	,requires_safety_checker=_SCREAMING_SNAKE_CASE	,)

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






  @property
  def        _a							(							self :       Optional[int] ):

        '''simple docstring'''




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






  def        _a							(							self :       int	,_a :       Dict = "auto" ):

        '''simple docstring'''




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






  def        _a							(							self :       Any ):

        '''simple docstring'''




        self.enable_attention_slicing(_SCREAMING_SNAKE_CASE )






  @torch.no_grad()
  def        _a							(							self :       int	,_a :       Union[str, Any]	,_a :       Any = 512	,_a :       List[Any] = 512	,_a :       int = 50	,_a :       Any = 7.5	,_a :       Any = None	,_a :       Optional[Any] = 1	,_a :       List[Any] = 0.0	,_a :       Union[str, Any] = None	,_a :       Tuple = None	,_a :       int = "pil"	,_a :       Optional[Any] = True	,_a :       Optional[int] = None	,_a :       Any = 1	,**_a :       int	,):

        '''simple docstring'''




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






  @torch.no_grad()
  def        _a							(							self :       int	,_a :       Dict	,_a :       Optional[int] = 512	,_a :       str = 512	,_a :       Optional[int] = 50	,_a :       Optional[int] = 7.5	,_a :       Any = None	,_a :       Tuple = 1	,_a :       Tuple = 0.0	,_a :       Union[str, Any] = None	,_a :       Union[str, Any] = None	,_a :       Union[str, Any] = "pil"	,_a :       Optional[Any] = True	,_a :       Optional[Any] = None	,_a :       int = 1	,**_a :       int	,):

        '''simple docstring'''




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






  @torch.no_grad()
  def        _a							(							self :       int	,_a :       Optional[int]	,_a :       List[Any] = 512	,_a :       Dict = 512	,_a :       str = 50	,_a :       Optional[Any] = 7.5	,_a :       Optional[int] = None	,_a :       List[Any] = 1	,_a :       Optional[Any] = 0.0	,_a :       int = None	,_a :       List[str] = None	,_a :       int = "pil"	,_a :       List[Any] = True	,_a :       List[str] = None	,_a :       List[str] = 1	,**_a :       List[str]	,):

        '''simple docstring'''




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






  @torch.no_grad()
  def        _a							(							self :       List[str]	,_a :       str	,_a :       Union[str, Any] = 512	,_a :       Optional[Any] = 512	,_a :       List[Any] = 50	,_a :       Optional[int] = 7.5	,_a :       Optional[int] = None	,_a :       Dict = 1	,_a :       int = 0.0	,_a :       int = None	,_a :       Optional[Any] = None	,_a :       Optional[Any] = "pil"	,_a :       Optional[int] = True	,_a :       Optional[int] = None	,_a :       Optional[Any] = 1	,**_a :       Optional[int]	,):

        '''simple docstring'''




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






  @torch.no_grad()
  def        _a							(							self :       List[str]	,_a :       Optional[int]	,_a :       Dict = 512	,_a :       Tuple = 512	,_a :       Any = 50	,_a :       int = 7.5	,_a :       Optional[Any] = None	,_a :       Optional[int] = 1	,_a :       str = 0.0	,_a :       Optional[Any] = None	,_a :       Optional[Any] = None	,_a :       List[str] = "pil"	,_a :       int = True	,_a :       List[Any] = None	,_a :       Any = 1	,**_a :       Optional[Any]	,):

        '''simple docstring'''




        A_						:  List[Any]          =				"""cuda""" if torch.cuda.is_available() else """cpu"""
        self.to(_SCREAMING_SNAKE_CASE )

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

        # Get first result from Stable Diffusion Checkpoint v1.2
        A_						:  Optional[Any]          =				self.textaimg_sda_a(
            prompt=_SCREAMING_SNAKE_CASE	,height=_SCREAMING_SNAKE_CASE	,width=_SCREAMING_SNAKE_CASE	,num_inference_steps=_SCREAMING_SNAKE_CASE	,guidance_scale=_SCREAMING_SNAKE_CASE	,negative_prompt=_SCREAMING_SNAKE_CASE	,num_images_per_prompt=_SCREAMING_SNAKE_CASE	,eta=_SCREAMING_SNAKE_CASE	,generator=_SCREAMING_SNAKE_CASE	,latents=_SCREAMING_SNAKE_CASE	,output_type=_SCREAMING_SNAKE_CASE	,return_dict=_SCREAMING_SNAKE_CASE	,callback=_SCREAMING_SNAKE_CASE	,callback_steps=_SCREAMING_SNAKE_CASE	,**_SCREAMING_SNAKE_CASE	,)

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

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

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




'''simple docstring'''


from ... import PretrainedConfig


__magic_name__			=      {
    'sijunhe/nezha-cn-base': 'https://huggingface.co/sijunhe/nezha-cn-base/resolve/main/config.json',
}



class 	__lowerCAmelCase		(							__SCREAMING_SNAKE_CASE    ):


  '''simple docstring'''







  a_  					=							NEZHA_PRETRAINED_CONFIG_ARCHIVE_MAP
  a_  					=							"""nezha"""






  def __init__(							self :       int	,_a :       Union[str, Any]=21128	,_a :       int=768	,_a :       Any=12	,_a :       List[str]=12	,_a :       str=3072	,_a :       int="gelu"	,_a :       int=0.1	,_a :       str=0.1	,_a :       Tuple=512	,_a :       List[Any]=64	,_a :       Dict=2	,_a :       List[Any]=0.02	,_a :       Optional[Any]=1e-12	,_a :       List[Any]=0.1	,_a :       Union[str, Any]=0	,_a :       Any=2	,_a :       Union[str, Any]=3	,_a :       int=True	,**_a :       int	,):

        '''simple docstring'''




        super().__init__(pad_token_id=_a	,bos_token_id=_a	,eos_token_id=_a	,**_a )

        A_						:  Tuple          =				vocab_size
        A_						:  int          =				hidden_size
        A_						:  Any          =				num_hidden_layers
        A_						:  List[Any]          =				num_attention_heads
        A_						:  Tuple          =				hidden_act
        A_						:  List[Any]          =				intermediate_size
        A_						:  List[str]          =				hidden_dropout_prob
        A_						:  Tuple          =				attention_probs_dropout_prob
        A_						:  Dict          =				max_position_embeddings
        A_						:  Optional[Any]          =				max_relative_position
        A_						:  List[Any]          =				type_vocab_size
        A_						:  int          =				initializer_range
        A_						:  Tuple          =				layer_norm_eps
        A_						:  Dict          =				classifier_dropout
        A_						:  int          =				use_cache
