"""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__  		=						"""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				(		lowerCAmelCase_   ):


    def __init__(					self	:  Optional[int]   ,				__lowerCAmelCase	:  AutoencoderKL   ,				__lowerCAmelCase	:  CLIPTextModel   ,				__lowerCAmelCase	:  CLIPTokenizer   ,				__lowerCAmelCase	:  UNetaDConditionModel   ,				__lowerCAmelCase	:  Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler]   ,				__lowerCAmelCase	:  StableDiffusionSafetyChecker   ,				__lowerCAmelCase	:  CLIPImageProcessor   ,				__lowerCAmelCase	:  bool = True   ,				):
      super()._init_()

      _UpperCAmelCase						 =      StableDiffusionPipeline.from_pretrained(__lowerCAmelCase					)
      _UpperCAmelCase						 =      StableDiffusionPipeline.from_pretrained(__lowerCAmelCase					)
      _UpperCAmelCase						 =      StableDiffusionPipeline.from_pretrained(__lowerCAmelCase					)
      _UpperCAmelCase						 =      StableDiffusionPipeline(
          vae=__lowerCAmelCase   ,				text_encoder=__lowerCAmelCase   ,				tokenizer=__lowerCAmelCase   ,				unet=__lowerCAmelCase   ,				scheduler=__lowerCAmelCase   ,				safety_checker=__lowerCAmelCase   ,				feature_extractor=__lowerCAmelCase   ,				requires_safety_checker=__lowerCAmelCase   ,				)

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


    @property
    def      lowerCAmelCase_  (					self	:  Union[str, Any]					):
      return {k: getattr(self   ,				__lowerCAmelCase					) for k in self.config.keys() if not k.startswith("""_"""					)}


    def      lowerCAmelCase_  (					self	:  Dict   ,				__lowerCAmelCase	:  Optional[Union[str, int]] = "auto"					):
      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(__lowerCAmelCase					)


    def      lowerCAmelCase_  (					self	:  Dict					):
      self.enable_attention_slicing(__lowerCAmelCase					)


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


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


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


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


    @torch.no_grad()
    def      lowerCAmelCase_  (					self	:  Dict   ,				__lowerCAmelCase	:  Union[str, List[str]]   ,				__lowerCAmelCase	:  int = 512   ,				__lowerCAmelCase	:  int = 512   ,				__lowerCAmelCase	:  int = 50   ,				__lowerCAmelCase	:  float = 7.5   ,				__lowerCAmelCase	:  Optional[Union[str, List[str]]] = None   ,				__lowerCAmelCase	:  Optional[int] = 1   ,				__lowerCAmelCase	:  float = 0.0   ,				__lowerCAmelCase	:  Optional[torch.Generator] = None   ,				__lowerCAmelCase	:  Optional[torch.FloatTensor] = None   ,				__lowerCAmelCase	:  Optional[str] = "pil"   ,				__lowerCAmelCase	:  bool = True   ,				__lowerCAmelCase	:  Optional[Callable[[int, int, torch.FloatTensor], None]] = None   ,				__lowerCAmelCase	:  int = 1   ,				**__lowerCAmelCase	:  List[Any]   ,				):
      _UpperCAmelCase						 =      """cuda""" if torch.cuda.is_available() else """cpu"""
      self.to(__lowerCAmelCase					)

      # 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=__lowerCAmelCase   ,				height=__lowerCAmelCase   ,				width=__lowerCAmelCase   ,				num_inference_steps=__lowerCAmelCase   ,				guidance_scale=__lowerCAmelCase   ,				negative_prompt=__lowerCAmelCase   ,				num_images_per_prompt=__lowerCAmelCase   ,				eta=__lowerCAmelCase   ,				generator=__lowerCAmelCase   ,				latents=__lowerCAmelCase   ,				output_type=__lowerCAmelCase   ,				return_dict=__lowerCAmelCase   ,				callback=__lowerCAmelCase   ,				callback_steps=__lowerCAmelCase   ,				**__lowerCAmelCase   ,				)

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

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

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

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


import unittest

from knapsack import knapsack as k


class        a				(		unittest.TestCase   ):


    def      lowerCAmelCase_  (					self	:  List[Any]					):
      _UpperCAmelCase						 =      0
      _UpperCAmelCase						 =      [0]
      _UpperCAmelCase						 =      [0]
      _UpperCAmelCase						 =      len(__lowerCAmelCase					)
      self.assertEqual(k.knapsack(__lowerCAmelCase   ,				__lowerCAmelCase   ,				__lowerCAmelCase   ,				__lowerCAmelCase					)   ,				0					)

      _UpperCAmelCase						 =      [60]
      _UpperCAmelCase						 =      [10]
      _UpperCAmelCase						 =      len(__lowerCAmelCase					)
      self.assertEqual(k.knapsack(__lowerCAmelCase   ,				__lowerCAmelCase   ,				__lowerCAmelCase   ,				__lowerCAmelCase					)   ,				0					)


    def      lowerCAmelCase_  (					self	:  Optional[int]					):
      _UpperCAmelCase						 =      3
      _UpperCAmelCase						 =      [1, 2, 3]
      _UpperCAmelCase						 =      [3, 2, 1]
      _UpperCAmelCase						 =      len(__lowerCAmelCase					)
      self.assertEqual(k.knapsack(__lowerCAmelCase   ,				__lowerCAmelCase   ,				__lowerCAmelCase   ,				__lowerCAmelCase					)   ,				5					)


    def      lowerCAmelCase_  (					self	:  Optional[Any]					):
      _UpperCAmelCase						 =      50
      _UpperCAmelCase						 =      [60, 100, 120]
      _UpperCAmelCase						 =      [10, 20, 30]
      _UpperCAmelCase						 =      len(__lowerCAmelCase					)
      self.assertEqual(k.knapsack(__lowerCAmelCase   ,				__lowerCAmelCase   ,				__lowerCAmelCase   ,				__lowerCAmelCase					)   ,				220					)


if __name__ == "__main__":
    unittest.main()
