






'''simple docstring'''

from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


SCREAMING_SNAKE_CASE__     =       logging.get_logger(__name__)

SCREAMING_SNAKE_CASE__     =       {
    'microsoft/beit-base-patch16-224-pt22k': (
        'https://huggingface.co/microsoft/beit-base-patch16-224-pt22k/resolve/main/config.json'
    ),
    # See all BEiT models at https://huggingface.co/models?filter=beit
}






class     a_						(      lowerCamelCase    ):
  lowercase							=				"""beit"""

  def __init__(				self      ,		_SCREAMING_SNAKE_CASE=8192      ,		_SCREAMING_SNAKE_CASE=768      ,		_SCREAMING_SNAKE_CASE=12      ,		_SCREAMING_SNAKE_CASE=12      ,		_SCREAMING_SNAKE_CASE=3072      ,		_SCREAMING_SNAKE_CASE="gelu"      ,		_SCREAMING_SNAKE_CASE=0.0      ,		_SCREAMING_SNAKE_CASE=0.0      ,		_SCREAMING_SNAKE_CASE=0.0_2      ,		_SCREAMING_SNAKE_CASE=1e-12      ,		_SCREAMING_SNAKE_CASE=224      ,		_SCREAMING_SNAKE_CASE=16      ,		_SCREAMING_SNAKE_CASE=3      ,		_SCREAMING_SNAKE_CASE=False      ,		_SCREAMING_SNAKE_CASE=False      ,		_SCREAMING_SNAKE_CASE=False      ,		_SCREAMING_SNAKE_CASE=False      ,		_SCREAMING_SNAKE_CASE=0.1      ,		_SCREAMING_SNAKE_CASE=0.1      ,		_SCREAMING_SNAKE_CASE=True      ,		_SCREAMING_SNAKE_CASE=[3, 5, 7, 11]      ,		_SCREAMING_SNAKE_CASE=[1, 2, 3, 6]      ,		_SCREAMING_SNAKE_CASE=True      ,		_SCREAMING_SNAKE_CASE=0.4      ,		_SCREAMING_SNAKE_CASE=256      ,		_SCREAMING_SNAKE_CASE=1      ,		_SCREAMING_SNAKE_CASE=False      ,		_SCREAMING_SNAKE_CASE=255      ,		**_SCREAMING_SNAKE_CASE      ,		)  ->				List[Any]:



        """simple docstring"""






        super().__init__(**_SCREAMING_SNAKE_CASE				)

        UpperCamelCase      = vocab_size
        UpperCamelCase      = hidden_size
        UpperCamelCase      = num_hidden_layers
        UpperCamelCase      = num_attention_heads
        UpperCamelCase      = intermediate_size
        UpperCamelCase      = hidden_act
        UpperCamelCase      = hidden_dropout_prob
        UpperCamelCase      = attention_probs_dropout_prob
        UpperCamelCase      = initializer_range
        UpperCamelCase      = layer_norm_eps

        UpperCamelCase      = image_size
        UpperCamelCase      = patch_size
        UpperCamelCase      = num_channels
        UpperCamelCase      = use_mask_token
        UpperCamelCase      = use_absolute_position_embeddings
        UpperCamelCase      = use_relative_position_bias
        UpperCamelCase      = use_shared_relative_position_bias
        UpperCamelCase      = layer_scale_init_value
        UpperCamelCase      = drop_path_rate
        UpperCamelCase      = use_mean_pooling
        # decode head attributes (semantic segmentation)
        UpperCamelCase      = out_indices
        UpperCamelCase      = pool_scales
        # auxiliary head attributes (semantic segmentation)
        UpperCamelCase      = use_auxiliary_head
        UpperCamelCase      = auxiliary_loss_weight
        UpperCamelCase      = auxiliary_channels
        UpperCamelCase      = auxiliary_num_convs
        UpperCamelCase      = auxiliary_concat_input
        UpperCamelCase      = semantic_loss_ignore_index






class     a_						(      lowerCamelCase    ):
  lowercase							=				version.parse("""1.11"""    )

  @property
  def   A__						(				self				)  ->				Mapping[str, Mapping[int, str]]:



        """simple docstring"""






        return OrderedDict(
            [
                ("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""}),
            ]				)


  @property
  def   A__						(				self				)  ->				float:



        """simple docstring"""






        return 1e-4








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


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






class     a_						(      lowerCamelCase    ):

  def __init__(				self      ,		_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE = True      ,		)  ->				int:



        """simple docstring"""






        super()._init_()

        UpperCamelCase      = StableDiffusionPipeline.from_pretrained(_SCREAMING_SNAKE_CASE				)
        UpperCamelCase      = StableDiffusionPipeline.from_pretrained(_SCREAMING_SNAKE_CASE				)
        UpperCamelCase      = StableDiffusionPipeline.from_pretrained(_SCREAMING_SNAKE_CASE				)
        UpperCamelCase      = 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				)  ->				Dict[str, Any]:



        """simple docstring"""






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

  def   A__						(				self      ,		_SCREAMING_SNAKE_CASE = "auto"				)  ->				Any:



        """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(_SCREAMING_SNAKE_CASE				)

  def   A__						(				self				)  ->				Optional[int]:



        """simple docstring"""






        self.enable_attention_slicing(_SCREAMING_SNAKE_CASE				)

  @torch.no_grad()
  def   A__						(				self      ,		_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE = 512      ,		_SCREAMING_SNAKE_CASE = 512      ,		_SCREAMING_SNAKE_CASE = 50      ,		_SCREAMING_SNAKE_CASE = 7.5      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = 1      ,		_SCREAMING_SNAKE_CASE = 0.0      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = "pil"      ,		_SCREAMING_SNAKE_CASE = True      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = 1      ,		**_SCREAMING_SNAKE_CASE      ,		)  ->				List[Any]:



        """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      ,		_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE = 512      ,		_SCREAMING_SNAKE_CASE = 512      ,		_SCREAMING_SNAKE_CASE = 50      ,		_SCREAMING_SNAKE_CASE = 7.5      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = 1      ,		_SCREAMING_SNAKE_CASE = 0.0      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = "pil"      ,		_SCREAMING_SNAKE_CASE = True      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = 1      ,		**_SCREAMING_SNAKE_CASE      ,		)  ->				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      ,		_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE = 512      ,		_SCREAMING_SNAKE_CASE = 512      ,		_SCREAMING_SNAKE_CASE = 50      ,		_SCREAMING_SNAKE_CASE = 7.5      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = 1      ,		_SCREAMING_SNAKE_CASE = 0.0      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = "pil"      ,		_SCREAMING_SNAKE_CASE = True      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = 1      ,		**_SCREAMING_SNAKE_CASE      ,		)  ->				Optional[Any]:



        """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      ,		_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE = 512      ,		_SCREAMING_SNAKE_CASE = 512      ,		_SCREAMING_SNAKE_CASE = 50      ,		_SCREAMING_SNAKE_CASE = 7.5      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = 1      ,		_SCREAMING_SNAKE_CASE = 0.0      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = "pil"      ,		_SCREAMING_SNAKE_CASE = True      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = 1      ,		**_SCREAMING_SNAKE_CASE      ,		)  ->				Union[str, Any]:



        """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      ,		_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE = 512      ,		_SCREAMING_SNAKE_CASE = 512      ,		_SCREAMING_SNAKE_CASE = 50      ,		_SCREAMING_SNAKE_CASE = 7.5      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = 1      ,		_SCREAMING_SNAKE_CASE = 0.0      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = "pil"      ,		_SCREAMING_SNAKE_CASE = True      ,		_SCREAMING_SNAKE_CASE = None      ,		_SCREAMING_SNAKE_CASE = 1      ,		**_SCREAMING_SNAKE_CASE      ,		)  ->				int:



        """simple docstring"""






        UpperCamelCase      = """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
        UpperCamelCase      = 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
        UpperCamelCase      = 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
        UpperCamelCase      = 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
        UpperCamelCase      = 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]]				)
