



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__  :  Dict								=					'''CompVis/stable-diffusion-v1-1'''
A__  :  int								=					'''CompVis/stable-diffusion-v1-2'''
A__  :  List[Any]								=					'''CompVis/stable-diffusion-v1-3'''
A__  :  List[Any]								=					'''CompVis/stable-diffusion-v1-4'''



class 				__snake_case						(     UpperCamelCase_						):




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

									lowerCAmelCase_			:     Dict									= StableDiffusionPipeline.from_pretrained(A_)
									lowerCAmelCase_			:     Union[str, Any]									= StableDiffusionPipeline.from_pretrained(A_)
									lowerCAmelCase_			:     List[str]									= StableDiffusionPipeline.from_pretrained(A_)
									lowerCAmelCase_			:     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    UpperCAmelCase__			(       self     :       int):
									return {k: getattr(self				,				A_) for k in self.config.keys() if not k.startswith('''_''')}




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




							def    UpperCAmelCase__			(       self     :       Optional[int]):
									self.enable_attention_slicing(A_)




							@torch.no_grad()
							def    UpperCAmelCase__			(       self     :       List[str]				,				A_     :       Union[str, List[str]]				,				A_     :       int = 5_1_2				,				A_     :       int = 5_1_2				,				A_     :       int = 5_0				,				A_     :       float = 7.5				,				A_     :       Optional[Union[str, List[str]]] = None				,				A_     :       Optional[int] = 1				,				A_     :       float = 0.0				,				A_     :       Optional[torch.Generator] = None				,				A_     :       Optional[torch.FloatTensor] = None				,				A_     :       Optional[str] = "pil"				,				A_     :       bool = True				,				A_     :       Optional[Callable[[int, int, torch.FloatTensor], None]] = None				,				A_     :       int = 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    UpperCAmelCase__			(       self     :       Dict				,				A_     :       Union[str, List[str]]				,				A_     :       int = 5_1_2				,				A_     :       int = 5_1_2				,				A_     :       int = 5_0				,				A_     :       float = 7.5				,				A_     :       Optional[Union[str, List[str]]] = None				,				A_     :       Optional[int] = 1				,				A_     :       float = 0.0				,				A_     :       Optional[torch.Generator] = None				,				A_     :       Optional[torch.FloatTensor] = None				,				A_     :       Optional[str] = "pil"				,				A_     :       bool = True				,				A_     :       Optional[Callable[[int, int, torch.FloatTensor], None]] = None				,				A_     :       int = 1				,				**A_     :       Union[str, 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    UpperCAmelCase__			(       self     :       List[str]				,				A_     :       Union[str, List[str]]				,				A_     :       int = 5_1_2				,				A_     :       int = 5_1_2				,				A_     :       int = 5_0				,				A_     :       float = 7.5				,				A_     :       Optional[Union[str, List[str]]] = None				,				A_     :       Optional[int] = 1				,				A_     :       float = 0.0				,				A_     :       Optional[torch.Generator] = None				,				A_     :       Optional[torch.FloatTensor] = None				,				A_     :       Optional[str] = "pil"				,				A_     :       bool = True				,				A_     :       Optional[Callable[[int, int, torch.FloatTensor], None]] = None				,				A_     :       int = 1				,				**A_     :       Tuple				,				):
									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    UpperCAmelCase__			(       self     :       Union[str, Any]				,				A_     :       Union[str, List[str]]				,				A_     :       int = 5_1_2				,				A_     :       int = 5_1_2				,				A_     :       int = 5_0				,				A_     :       float = 7.5				,				A_     :       Optional[Union[str, List[str]]] = None				,				A_     :       Optional[int] = 1				,				A_     :       float = 0.0				,				A_     :       Optional[torch.Generator] = None				,				A_     :       Optional[torch.FloatTensor] = None				,				A_     :       Optional[str] = "pil"				,				A_     :       bool = True				,				A_     :       Optional[Callable[[int, int, torch.FloatTensor], None]] = None				,				A_     :       int = 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    UpperCAmelCase__			(       self     :       int				,				A_     :       Union[str, List[str]]				,				A_     :       int = 5_1_2				,				A_     :       int = 5_1_2				,				A_     :       int = 5_0				,				A_     :       float = 7.5				,				A_     :       Optional[Union[str, List[str]]] = None				,				A_     :       Optional[int] = 1				,				A_     :       float = 0.0				,				A_     :       Optional[torch.Generator] = None				,				A_     :       Optional[torch.FloatTensor] = None				,				A_     :       Optional[str] = "pil"				,				A_     :       bool = True				,				A_     :       Optional[Callable[[int, int, torch.FloatTensor], None]] = None				,				A_     :       int = 1				,				**A_     :       List[str]				,				):
									lowerCAmelCase_			:     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
									lowerCAmelCase_			:     Optional[Any]									= 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
									lowerCAmelCase_			:     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 first result from Stable Diffusion Checkpoint v1.3
									lowerCAmelCase_			:     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 first result from Stable Diffusion Checkpoint v1.4
									lowerCAmelCase_			:     List[Any]									= 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 packaging import version

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


_a 						=      logging.get_logger(__name__)

_a 						=      {
    "hustvl/yolos-small": "https://huggingface.co/hustvl/yolos-small/resolve/main/config.json",
    # See all YOLOS models at https://huggingface.co/models?filter=yolos
}






class 					__A    (    lowerCAmelCase ):

			'''simple docstring'''







			lowerCAmelCase_							     =						"""yolos"""





			def __init__(    self       ,  __lowerCAmelCase=7_6_8       ,  __lowerCAmelCase=1_2       ,  __lowerCAmelCase=1_2       ,  __lowerCAmelCase=3_0_7_2       ,  __lowerCAmelCase="gelu"       ,  __lowerCAmelCase=0.0       ,  __lowerCAmelCase=0.0       ,  __lowerCAmelCase=0.02       ,  __lowerCAmelCase=1E-12       ,  __lowerCAmelCase=[5_1_2, 8_6_4]       ,  __lowerCAmelCase=1_6       ,  __lowerCAmelCase=3       ,  __lowerCAmelCase=True       ,  __lowerCAmelCase=1_0_0       ,  __lowerCAmelCase=True       ,  __lowerCAmelCase=False       ,  __lowerCAmelCase=1       ,  __lowerCAmelCase=5       ,  __lowerCAmelCase=2       ,  __lowerCAmelCase=5       ,  __lowerCAmelCase=2       ,  __lowerCAmelCase=0.1       ,  **__lowerCAmelCase       ,  ):



				'''simple docstring'''







				super().__init__(**__lowerCAmelCase							)

				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__								=		initializer_range
				lowerCamelCase__								=		layer_norm_eps
				lowerCamelCase__								=		image_size
				lowerCamelCase__								=		patch_size
				lowerCamelCase__								=		num_channels
				lowerCamelCase__								=		qkv_bias
				lowerCamelCase__								=		num_detection_tokens
				lowerCamelCase__								=		use_mid_position_embeddings
				lowerCamelCase__								=		auxiliary_loss
				# Hungarian matcher
				lowerCamelCase__								=		class_cost
				lowerCamelCase__								=		bbox_cost
				lowerCamelCase__								=		giou_cost
				# Loss coefficients
				lowerCamelCase__								=		bbox_loss_coefficient
				lowerCamelCase__								=		giou_loss_coefficient
				lowerCamelCase__								=		eos_coefficient






class 					__A    (    lowerCAmelCase ):

			'''simple docstring'''







			lowerCAmelCase_							     =						version.parse("""1.11""" )





			@property
			def 		__lowerCamelCase				(    self							):



				'''simple docstring'''







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





			@property
			def 		__lowerCamelCase				(    self							):



				'''simple docstring'''







				return 1E-4





			@property
			def 		__lowerCamelCase				(    self							):



				'''simple docstring'''







				return 1_2



