






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




class 							lowerCAmelCase__       (    UpperCAmelCase__				):






      '''simple docstring'''

      def __init__(		self  :						Optional[Any]		,			lowercase_  :						AutoencoderKL		,			lowercase_  :						CLIPTextModel		,			lowercase_  :						CLIPTokenizer		,			lowercase_  :						UNetaDConditionModel		,			lowercase_  :						Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler]		,			lowercase_  :						StableDiffusionSafetyChecker		,			lowercase_  :						CLIPImageProcessor		,			lowercase_  :						bool = True		,			):




          '''simple docstring'''


          super()._init_()

          SCREAMING_SNAKE_CASE_   :						Tuple							=	StableDiffusionPipeline.from_pretrained(lowercase_)
          SCREAMING_SNAKE_CASE_   :						Optional[Any]							=	StableDiffusionPipeline.from_pretrained(lowercase_)
          SCREAMING_SNAKE_CASE_   :						List[Any]							=	StableDiffusionPipeline.from_pretrained(lowercase_)
          SCREAMING_SNAKE_CASE_   :						Optional[int]							=	StableDiffusionPipeline(
              vae=lowercase_		,			text_encoder=lowercase_		,			tokenizer=lowercase_		,			unet=lowercase_		,			scheduler=lowercase_		,			safety_checker=lowercase_		,			feature_extractor=lowercase_		,			requires_safety_checker=lowercase_		,			)

          self.register_modules(pipelinea=self.pipea		,			pipelinea=self.pipea		,			pipelinea=self.pipea		,			pipelinea=self.pipea)
      @property
      def _SCREAMING_SNAKE_CASE				(		self  :						List[str]):




          '''simple docstring'''


          return {k: getattr(self		,			lowercase_) for k in self.config.keys() if not k.startswith('''_''')}
      def _SCREAMING_SNAKE_CASE				(		self  :						str		,			lowercase_  :						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_   :						List[Any]							=	self.unet.config.attention_head_dim // 2
          self.unet.set_attention_slice(lowercase_)
      def _SCREAMING_SNAKE_CASE				(		self  :						int):




          '''simple docstring'''


          self.enable_attention_slicing(lowercase_)
      @torch.no_grad()
      def _SCREAMING_SNAKE_CASE				(		self  :						str		,			lowercase_  :						Union[str, List[str]]		,			lowercase_  :						int = 512		,			lowercase_  :						int = 512		,			lowercase_  :						int = 50		,			lowercase_  :						float = 7.5		,			lowercase_  :						Optional[Union[str, List[str]]] = None		,			lowercase_  :						Optional[int] = 1		,			lowercase_  :						float = 0.0		,			lowercase_  :						Optional[torch.Generator] = None		,			lowercase_  :						Optional[torch.FloatTensor] = None		,			lowercase_  :						Optional[str] = "pil"		,			lowercase_  :						bool = True		,			lowercase_  :						Optional[Callable[[int, int, torch.FloatTensor], None]] = None		,			lowercase_  :						int = 1		,			**lowercase_  :						List[Any]		,			):




          '''simple docstring'''


          return self.pipea(
              prompt=lowercase_		,			height=lowercase_		,			width=lowercase_		,			num_inference_steps=lowercase_		,			guidance_scale=lowercase_		,			negative_prompt=lowercase_		,			num_images_per_prompt=lowercase_		,			eta=lowercase_		,			generator=lowercase_		,			latents=lowercase_		,			output_type=lowercase_		,			return_dict=lowercase_		,			callback=lowercase_		,			callback_steps=lowercase_		,			**lowercase_		,			)
      @torch.no_grad()
      def _SCREAMING_SNAKE_CASE				(		self  :						Tuple		,			lowercase_  :						Union[str, List[str]]		,			lowercase_  :						int = 512		,			lowercase_  :						int = 512		,			lowercase_  :						int = 50		,			lowercase_  :						float = 7.5		,			lowercase_  :						Optional[Union[str, List[str]]] = None		,			lowercase_  :						Optional[int] = 1		,			lowercase_  :						float = 0.0		,			lowercase_  :						Optional[torch.Generator] = None		,			lowercase_  :						Optional[torch.FloatTensor] = None		,			lowercase_  :						Optional[str] = "pil"		,			lowercase_  :						bool = True		,			lowercase_  :						Optional[Callable[[int, int, torch.FloatTensor], None]] = None		,			lowercase_  :						int = 1		,			**lowercase_  :						Optional[int]		,			):




          '''simple docstring'''


          return self.pipea(
              prompt=lowercase_		,			height=lowercase_		,			width=lowercase_		,			num_inference_steps=lowercase_		,			guidance_scale=lowercase_		,			negative_prompt=lowercase_		,			num_images_per_prompt=lowercase_		,			eta=lowercase_		,			generator=lowercase_		,			latents=lowercase_		,			output_type=lowercase_		,			return_dict=lowercase_		,			callback=lowercase_		,			callback_steps=lowercase_		,			**lowercase_		,			)
      @torch.no_grad()
      def _SCREAMING_SNAKE_CASE				(		self  :						List[str]		,			lowercase_  :						Union[str, List[str]]		,			lowercase_  :						int = 512		,			lowercase_  :						int = 512		,			lowercase_  :						int = 50		,			lowercase_  :						float = 7.5		,			lowercase_  :						Optional[Union[str, List[str]]] = None		,			lowercase_  :						Optional[int] = 1		,			lowercase_  :						float = 0.0		,			lowercase_  :						Optional[torch.Generator] = None		,			lowercase_  :						Optional[torch.FloatTensor] = None		,			lowercase_  :						Optional[str] = "pil"		,			lowercase_  :						bool = True		,			lowercase_  :						Optional[Callable[[int, int, torch.FloatTensor], None]] = None		,			lowercase_  :						int = 1		,			**lowercase_  :						Optional[Any]		,			):




          '''simple docstring'''


          return self.pipea(
              prompt=lowercase_		,			height=lowercase_		,			width=lowercase_		,			num_inference_steps=lowercase_		,			guidance_scale=lowercase_		,			negative_prompt=lowercase_		,			num_images_per_prompt=lowercase_		,			eta=lowercase_		,			generator=lowercase_		,			latents=lowercase_		,			output_type=lowercase_		,			return_dict=lowercase_		,			callback=lowercase_		,			callback_steps=lowercase_		,			**lowercase_		,			)
      @torch.no_grad()
      def _SCREAMING_SNAKE_CASE				(		self  :						Any		,			lowercase_  :						Union[str, List[str]]		,			lowercase_  :						int = 512		,			lowercase_  :						int = 512		,			lowercase_  :						int = 50		,			lowercase_  :						float = 7.5		,			lowercase_  :						Optional[Union[str, List[str]]] = None		,			lowercase_  :						Optional[int] = 1		,			lowercase_  :						float = 0.0		,			lowercase_  :						Optional[torch.Generator] = None		,			lowercase_  :						Optional[torch.FloatTensor] = None		,			lowercase_  :						Optional[str] = "pil"		,			lowercase_  :						bool = True		,			lowercase_  :						Optional[Callable[[int, int, torch.FloatTensor], None]] = None		,			lowercase_  :						int = 1		,			**lowercase_  :						Optional[Any]		,			):




          '''simple docstring'''


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



      @torch.no_grad()
      def _SCREAMING_SNAKE_CASE				(		self  :						Optional[Any]		,			lowercase_  :						Union[str, List[str]]		,			lowercase_  :						int = 512		,			lowercase_  :						int = 512		,			lowercase_  :						int = 50		,			lowercase_  :						float = 7.5		,			lowercase_  :						Optional[Union[str, List[str]]] = None		,			lowercase_  :						Optional[int] = 1		,			lowercase_  :						float = 0.0		,			lowercase_  :						Optional[torch.Generator] = None		,			lowercase_  :						Optional[torch.FloatTensor] = None		,			lowercase_  :						Optional[str] = "pil"		,			lowercase_  :						bool = True		,			lowercase_  :						Optional[Callable[[int, int, torch.FloatTensor], None]] = None		,			lowercase_  :						int = 1		,			**lowercase_  :						int		,			):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_   :						List[str]							=	'''cuda''' if torch.cuda.is_available() else '''cpu'''
          self.to(lowercase_)

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

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

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

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

          # 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"""






def       _A    (__a = 1_00							)				-> int:
    """simple docstring"""






    SCREAMING_SNAKE_CASE_   :						int							=	(n * (n + 1) // 2) ** 2
    SCREAMING_SNAKE_CASE_   :						Optional[Any]							=	n * (n + 1) * (2 * n + 1) // 6
    return sum_cubes - sum_squares


if __name__ == "__main__":
  print(f'''{solution() = }''')


