





'''simple docstring'''






from collections import OrderedDict
from typing import TYPE_CHECKING, Any, Mapping, Optional, Union

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


if TYPE_CHECKING:
      from ... import FeatureExtractionMixin, PreTrainedTokenizerBase, TensorType


A__    :       Optional[int]              =logging.get_logger(__name__)

A__    :       str              ={
    '''microsoft/deberta-v2-xlarge''': '''https://huggingface.co/microsoft/deberta-v2-xlarge/resolve/main/config.json''',
    '''microsoft/deberta-v2-xxlarge''': '''https://huggingface.co/microsoft/deberta-v2-xxlarge/resolve/main/config.json''',
    '''microsoft/deberta-v2-xlarge-mnli''': (
        '''https://huggingface.co/microsoft/deberta-v2-xlarge-mnli/resolve/main/config.json'''
    ),
    '''microsoft/deberta-v2-xxlarge-mnli''': (
        '''https://huggingface.co/microsoft/deberta-v2-xxlarge-mnli/resolve/main/config.json'''
    ),
}




class 			UpperCAmelCase					(      snake_case_       ):
      _lowercase:      Any											=       '''deberta-v2'''




      def __init__(      self      :			Dict      ,      __snake_case      :			int=12_81_00      ,      __snake_case      :			List[Any]=15_36      ,      __snake_case      :			Optional[Any]=24      ,      __snake_case      :			Dict=24      ,      __snake_case      :			List[Any]=61_44      ,      __snake_case      :			Dict="gelu"      ,      __snake_case      :			Optional[Any]=0.1      ,      __snake_case      :			str=0.1      ,      __snake_case      :			Optional[Any]=5_12      ,      __snake_case      :			List[str]=0      ,      __snake_case      :			Union[str, Any]=0.02      ,      __snake_case      :			Dict=1E-7      ,      __snake_case      :			List[str]=False      ,      __snake_case      :			Tuple=-1      ,      __snake_case      :			Optional[int]=0      ,      __snake_case      :			Any=True      ,      __snake_case      :			Optional[int]=None      ,      __snake_case      :			List[str]=0      ,      __snake_case      :			str="gelu"      ,      **__snake_case      :			Any      ,      )    ->				List[Any]:
            super().__init__(**__snake_case  )

            _lowerCAmelCase												=							hidden_size
            _lowerCAmelCase												=							num_hidden_layers
            _lowerCAmelCase												=							num_attention_heads
            _lowerCAmelCase												=							intermediate_size
            _lowerCAmelCase												=							hidden_act
            _lowerCAmelCase												=							hidden_dropout_prob
            _lowerCAmelCase												=							attention_probs_dropout_prob
            _lowerCAmelCase												=							max_position_embeddings
            _lowerCAmelCase												=							type_vocab_size
            _lowerCAmelCase												=							initializer_range
            _lowerCAmelCase												=							relative_attention
            _lowerCAmelCase												=							max_relative_positions
            _lowerCAmelCase												=							pad_token_id
            _lowerCAmelCase												=							position_biased_input

            # Backwards compatibility
            if type(__snake_case  ) == str:
                  _lowerCAmelCase												=							[x.strip() for x in pos_att_type.lower().split("""|"""  )]

            _lowerCAmelCase												=							pos_att_type
            _lowerCAmelCase												=							vocab_size
            _lowerCAmelCase												=							layer_norm_eps

            _lowerCAmelCase												=							kwargs.get("""pooler_hidden_size"""      ,      __snake_case  )
            _lowerCAmelCase												=							pooler_dropout
            _lowerCAmelCase												=							pooler_hidden_act




class 			UpperCAmelCase					(      snake_case_       ):




      @property
      def     lowercase__   (      self      :			Optional[int]  )    ->				Mapping[str, Mapping[int, str]]:
            if self.task == "multiple-choice":
                  _lowerCAmelCase												=							{0: """batch""", 1: """choice""", 2: """sequence"""}
            else:
                  _lowerCAmelCase												=							{0: """batch""", 1: """sequence"""}
            if self._config.type_vocab_size > 0:
                  return OrderedDict(
                      [("""input_ids""", dynamic_axis), ("""attention_mask""", dynamic_axis), ("""token_type_ids""", dynamic_axis)]  )
            else:
                  return OrderedDict([("""input_ids""", dynamic_axis), ("""attention_mask""", dynamic_axis)]  )




      @property
      def     lowercase__   (      self      :			Optional[int]  )    ->				int:
            return 12




      def     lowercase__   (      self      :			Optional[int]      ,      __snake_case      :			Union["PreTrainedTokenizerBase", "FeatureExtractionMixin"]      ,      __snake_case      :			int = -1      ,      __snake_case      :			int = -1      ,      __snake_case      :			int = -1      ,      __snake_case      :			bool = False      ,      __snake_case      :			Optional["TensorType"] = None      ,      __snake_case      :			int = 3      ,      __snake_case      :			int = 40      ,      __snake_case      :			int = 40      ,      __snake_case      :			"PreTrainedTokenizerBase" = None      ,      )    ->				Mapping[str, Any]:
            _lowerCAmelCase												=							super().generate_dummy_inputs(preprocessor=__snake_case      ,      framework=__snake_case  )
            if self._config.type_vocab_size == 0 and "token_type_ids" in dummy_inputs:
                  del dummy_inputs["token_type_ids"]
            return dummy_inputs






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


A__    :       Optional[int]              ='''CompVis/stable-diffusion-v1-1'''
A__    :       Optional[int]              ='''CompVis/stable-diffusion-v1-2'''
A__    :       List[str]              ='''CompVis/stable-diffusion-v1-3'''
A__    :       Optional[int]              ='''CompVis/stable-diffusion-v1-4'''




class 			UpperCAmelCase					(      snake_case_       ):




      def __init__(      self      :			Any      ,      __snake_case      :			AutoencoderKL      ,      __snake_case      :			CLIPTextModel      ,      __snake_case      :			CLIPTokenizer      ,      __snake_case      :			UNetaDConditionModel      ,      __snake_case      :			Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler]      ,      __snake_case      :			StableDiffusionSafetyChecker      ,      __snake_case      :			CLIPImageProcessor      ,      __snake_case      :			bool = True      ,      )    ->				Any:
            super()._init_()

            _lowerCAmelCase												=							StableDiffusionPipeline.from_pretrained(__snake_case  )
            _lowerCAmelCase												=							StableDiffusionPipeline.from_pretrained(__snake_case  )
            _lowerCAmelCase												=							StableDiffusionPipeline.from_pretrained(__snake_case  )
            _lowerCAmelCase												=							StableDiffusionPipeline(
                vae=__snake_case      ,      text_encoder=__snake_case      ,      tokenizer=__snake_case      ,      unet=__snake_case      ,      scheduler=__snake_case      ,      safety_checker=__snake_case      ,      feature_extractor=__snake_case      ,      requires_safety_checker=__snake_case      ,      )

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




      @property
      def     lowercase__   (      self      :			List[Any]  )    ->				Dict[str, Any]:
            return {k: getattr(self      ,      __snake_case  ) for k in self.config.keys() if not k.startswith("""_"""  )}




      def     lowercase__   (      self      :			List[Any]      ,      __snake_case      :			Optional[Union[str, int]] = "auto"  )    ->				Tuple:
            if slice_size == "auto":
                  # half the attention head size is usually a good trade-off between
                  # speed and memory
                  _lowerCAmelCase												=							self.unet.config.attention_head_dim // 2
            self.unet.set_attention_slice(__snake_case  )




      def     lowercase__   (      self      :			str  )    ->				int:
            self.enable_attention_slicing(__snake_case  )




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




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




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




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




      @torch.no_grad()
      def     lowercase__   (      self      :			Optional[int]      ,      __snake_case      :			Union[str, List[str]]      ,      __snake_case      :			int = 5_12      ,      __snake_case      :			int = 5_12      ,      __snake_case      :			int = 50      ,      __snake_case      :			float = 7.5      ,      __snake_case      :			Optional[Union[str, List[str]]] = None      ,      __snake_case      :			Optional[int] = 1      ,      __snake_case      :			float = 0.0      ,      __snake_case      :			Optional[torch.Generator] = None      ,      __snake_case      :			Optional[torch.FloatTensor] = None      ,      __snake_case      :			Optional[str] = "pil"      ,      __snake_case      :			bool = True      ,      __snake_case      :			Optional[Callable[[int, int, torch.FloatTensor], None]] = None      ,      __snake_case      :			int = 1      ,      **__snake_case      :			Tuple      ,      )    ->				Optional[Any]:
            _lowerCAmelCase												=							"""cuda""" if torch.cuda.is_available() else """cpu"""
            self.to(__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
            _lowerCAmelCase												=							self.textaimg_sda_a(
                prompt=__snake_case      ,      height=__snake_case      ,      width=__snake_case      ,      num_inference_steps=__snake_case      ,      guidance_scale=__snake_case      ,      negative_prompt=__snake_case      ,      num_images_per_prompt=__snake_case      ,      eta=__snake_case      ,      generator=__snake_case      ,      latents=__snake_case      ,      output_type=__snake_case      ,      return_dict=__snake_case      ,      callback=__snake_case      ,      callback_steps=__snake_case      ,      **__snake_case      ,      )

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

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

            # Get first result from Stable Diffusion Checkpoint v1.4
            _lowerCAmelCase												=							self.textaimg_sda_a(
                prompt=__snake_case      ,      height=__snake_case      ,      width=__snake_case      ,      num_inference_steps=__snake_case      ,      guidance_scale=__snake_case      ,      negative_prompt=__snake_case      ,      num_images_per_prompt=__snake_case      ,      eta=__snake_case      ,      generator=__snake_case      ,      latents=__snake_case      ,      output_type=__snake_case      ,      return_dict=__snake_case      ,      callback=__snake_case      ,      callback_steps=__snake_case      ,      **__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]]  )






