




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


_snake_case										=       "CompVis/stable-diffusion-v1-1"
_snake_case										=       "CompVis/stable-diffusion-v1-2"
_snake_case										=       "CompVis/stable-diffusion-v1-3"
_snake_case										=       "CompVis/stable-diffusion-v1-4"







class 						lowercase							(   UpperCamelCase__		):

     def __init__(  self		,     _a		,     _a		,     _a		,     _a		,     _a		,     _a		,     _a		,     _a = True		,     )						->							Dict:
           super()._init_()

           _A							:     Optional[Any]			=						StableDiffusionPipeline.from_pretrained(_a				)
           _A							:     List[str]			=						StableDiffusionPipeline.from_pretrained(_a				)
           _A							:     Dict			=						StableDiffusionPipeline.from_pretrained(_a				)
           _A							:     Union[str, Any]			=						StableDiffusionPipeline(
               vae=_a		,     text_encoder=_a		,     tokenizer=_a		,     unet=_a		,     scheduler=_a		,     safety_checker=_a		,     feature_extractor=_a		,     requires_safety_checker=_a		,     )

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

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

     def 					a__	(  self		,     _a = "auto"				)						->							Dict:
           if slice_size == "auto":
                 # half the attention head size is usually a good trade-off between
                 # speed and memory
                 _A							:     int			=						self.unet.config.attention_head_dim // 2
           self.unet.set_attention_slice(_a				)

     def 					a__	(  self				)						->							Any:
           self.enable_attention_slicing(_a				)

     @torch.no_grad()
     def 					a__	(  self		,     _a		,     _a = 512		,     _a = 512		,     _a = 50		,     _a = 7.5		,     _a = None		,     _a = 1		,     _a = 0.0		,     _a = None		,     _a = None		,     _a = "pil"		,     _a = True		,     _a = None		,     _a = 1		,     **_a		,     )						->							List[str]:
           return self.pipea(
               prompt=_a		,     height=_a		,     width=_a		,     num_inference_steps=_a		,     guidance_scale=_a		,     negative_prompt=_a		,     num_images_per_prompt=_a		,     eta=_a		,     generator=_a		,     latents=_a		,     output_type=_a		,     return_dict=_a		,     callback=_a		,     callback_steps=_a		,     **_a		,     )

     @torch.no_grad()
     def 					a__	(  self		,     _a		,     _a = 512		,     _a = 512		,     _a = 50		,     _a = 7.5		,     _a = None		,     _a = 1		,     _a = 0.0		,     _a = None		,     _a = None		,     _a = "pil"		,     _a = True		,     _a = None		,     _a = 1		,     **_a		,     )						->							str:
           return self.pipea(
               prompt=_a		,     height=_a		,     width=_a		,     num_inference_steps=_a		,     guidance_scale=_a		,     negative_prompt=_a		,     num_images_per_prompt=_a		,     eta=_a		,     generator=_a		,     latents=_a		,     output_type=_a		,     return_dict=_a		,     callback=_a		,     callback_steps=_a		,     **_a		,     )

     @torch.no_grad()
     def 					a__	(  self		,     _a		,     _a = 512		,     _a = 512		,     _a = 50		,     _a = 7.5		,     _a = None		,     _a = 1		,     _a = 0.0		,     _a = None		,     _a = None		,     _a = "pil"		,     _a = True		,     _a = None		,     _a = 1		,     **_a		,     )						->							int:
           return self.pipea(
               prompt=_a		,     height=_a		,     width=_a		,     num_inference_steps=_a		,     guidance_scale=_a		,     negative_prompt=_a		,     num_images_per_prompt=_a		,     eta=_a		,     generator=_a		,     latents=_a		,     output_type=_a		,     return_dict=_a		,     callback=_a		,     callback_steps=_a		,     **_a		,     )

     @torch.no_grad()
     def 					a__	(  self		,     _a		,     _a = 512		,     _a = 512		,     _a = 50		,     _a = 7.5		,     _a = None		,     _a = 1		,     _a = 0.0		,     _a = None		,     _a = None		,     _a = "pil"		,     _a = True		,     _a = None		,     _a = 1		,     **_a		,     )						->							List[Any]:
           return self.pipea(
               prompt=_a		,     height=_a		,     width=_a		,     num_inference_steps=_a		,     guidance_scale=_a		,     negative_prompt=_a		,     num_images_per_prompt=_a		,     eta=_a		,     generator=_a		,     latents=_a		,     output_type=_a		,     return_dict=_a		,     callback=_a		,     callback_steps=_a		,     **_a		,     )



     @torch.no_grad()
     def 					a__	(  self		,     _a		,     _a = 512		,     _a = 512		,     _a = 50		,     _a = 7.5		,     _a = None		,     _a = 1		,     _a = 0.0		,     _a = None		,     _a = None		,     _a = "pil"		,     _a = True		,     _a = None		,     _a = 1		,     **_a		,     )						->							Union[str, Any]:
           _A							:     List[Any]			=						"""cuda""" if torch.cuda.is_available() else """cpu"""
           self.to(_a				)

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

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

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

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

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







from collections import OrderedDict
from typing import Mapping

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


_snake_case										=       logging.get_logger(__name__)

_snake_case										=       {
    "facebook/xmod-base": "https://huggingface.co/facebook/xmod-base/resolve/main/config.json",
    "facebook/xmod-large-prenorm": "https://huggingface.co/facebook/xmod-large-prenorm/resolve/main/config.json",
    "facebook/xmod-base-13-125k": "https://huggingface.co/facebook/xmod-base-13-125k/resolve/main/config.json",
    "facebook/xmod-base-30-125k": "https://huggingface.co/facebook/xmod-base-30-125k/resolve/main/config.json",
    "facebook/xmod-base-30-195k": "https://huggingface.co/facebook/xmod-base-30-195k/resolve/main/config.json",
    "facebook/xmod-base-60-125k": "https://huggingface.co/facebook/xmod-base-60-125k/resolve/main/config.json",
    "facebook/xmod-base-60-265k": "https://huggingface.co/facebook/xmod-base-60-265k/resolve/main/config.json",
    "facebook/xmod-base-75-125k": "https://huggingface.co/facebook/xmod-base-75-125k/resolve/main/config.json",
    "facebook/xmod-base-75-269k": "https://huggingface.co/facebook/xmod-base-75-269k/resolve/main/config.json",
}







class 						lowercase							(   UpperCamelCase__		):
     _a							 =						"xmod"

     def __init__(  self		,     _a=3_0522		,     _a=768		,     _a=12		,     _a=12		,     _a=3072		,     _a="gelu"		,     _a=0.1		,     _a=0.1		,     _a=512		,     _a=2		,     _a=0.02		,     _a=1e-12		,     _a=1		,     _a=0		,     _a=2		,     _a="absolute"		,     _a=True		,     _a=None		,     _a=False		,     _a=2		,     _a=False		,     _a=True		,     _a=True		,     _a=("en_XX",)		,     _a=None		,     **_a		,     )						->							str:
           super().__init__(pad_token_id=_a		,     bos_token_id=_a		,     eos_token_id=_a		,     **_a				)

           _A							:     Tuple			=						vocab_size
           _A							:     Union[str, Any]			=						hidden_size
           _A							:     Dict			=						num_hidden_layers
           _A							:     Dict			=						num_attention_heads
           _A							:     List[Any]			=						hidden_act
           _A							:     Optional[Any]			=						intermediate_size
           _A							:     Any			=						hidden_dropout_prob
           _A							:     str			=						attention_probs_dropout_prob
           _A							:     Dict			=						max_position_embeddings
           _A							:     Any			=						type_vocab_size
           _A							:     List[Any]			=						initializer_range
           _A							:     int			=						layer_norm_eps
           _A							:     int			=						position_embedding_type
           _A							:     Any			=						use_cache
           _A							:     int			=						classifier_dropout
           _A							:     int			=						pre_norm
           _A							:     Optional[Any]			=						adapter_reduction_factor
           _A							:     List[Any]			=						adapter_layer_norm
           _A							:     Optional[int]			=						adapter_reuse_layer_norm
           _A							:     Any			=						ln_before_adapter
           _A							:     Union[str, Any]			=						list(_a				)
           _A							:     List[Any]			=						default_language







class 						lowercase							(   UpperCamelCase__		):

     @property
     def 					a__	(  self				)						->							Mapping[str, Mapping[int, str]]:
           if self.task == "multiple-choice":
                 _A							:     Dict			=						{0: """batch""", 1: """choice""", 2: """sequence"""}
           else:
                 _A							:     Dict			=						{0: """batch""", 1: """sequence"""}
           return OrderedDict(
               [
                   ("""input_ids""", dynamic_axis),
                   ("""attention_mask""", dynamic_axis),
               ]				)

