

from ...configuration_utils import PretrainedConfig
from ...utils import logging


_a:    Dict 							=			logging.get_logger(__name__)

_a:    Optional[Any] 							=			{
    '''tiiuae/falcon-40b''': '''https://huggingface.co/tiiuae/falcon-40b/resolve/main/config.json''',
    '''tiiuae/falcon-7b''': '''https://huggingface.co/tiiuae/falcon-7b/resolve/main/config.json''',
}

class 						__UpperCamelCase    (					__UpperCAmelCase						):
	SCREAMING_SNAKE_CASE__    				=     '''falcon'''
	SCREAMING_SNAKE_CASE__    				=     ['''past_key_values''']




	def __init__(		self	:						Tuple		,	lowerCAmelCase	:						Optional[Any]=65_024		,	lowerCAmelCase	:						int=4_544		,	lowerCAmelCase	:						Dict=32		,	lowerCAmelCase	:						Optional[Any]=71		,	lowerCAmelCase	:						Tuple=1e-5		,	lowerCAmelCase	:						Union[str, Any]=0.02		,	lowerCAmelCase	:						Optional[int]=True		,	lowerCAmelCase	:						Optional[int]=0.0		,	lowerCAmelCase	:						List[str]=0.0		,	lowerCAmelCase	:						List[Any]=None		,	lowerCAmelCase	:						Any=False		,	lowerCAmelCase	:						Optional[int]=False		,	lowerCAmelCase	:						Optional[int]=True		,	lowerCAmelCase	:						Optional[int]=True		,	lowerCAmelCase	:						Dict=False		,	lowerCAmelCase	:						Union[str, Any]=11		,	lowerCAmelCase	:						List[Any]=11		,	**lowerCAmelCase	:						Optional[Any]		,	):


		'''simple docstring'''







		UpperCAmelCase_       				=			vocab_size
		# Backward compatibility with n_embed kwarg
		UpperCAmelCase_       				=			kwargs.pop("n_embed"		,	__SCREAMING_SNAKE_CASE							)
		UpperCAmelCase_       				=			hidden_size if n_embed is None else n_embed
		UpperCAmelCase_       				=			num_hidden_layers
		UpperCAmelCase_       				=			num_attention_heads
		UpperCAmelCase_       				=			layer_norm_epsilon
		UpperCAmelCase_       				=			initializer_range
		UpperCAmelCase_       				=			use_cache
		UpperCAmelCase_       				=			hidden_dropout
		UpperCAmelCase_       				=			attention_dropout

		UpperCAmelCase_       				=			bos_token_id
		UpperCAmelCase_       				=			eos_token_id
		UpperCAmelCase_       				=			num_attention_heads if num_kv_heads is None else num_kv_heads
		UpperCAmelCase_       				=			alibi
		UpperCAmelCase_       				=			new_decoder_architecture
		UpperCAmelCase_       				=			multi_query  # Ignored when new_decoder_architecture is True
		UpperCAmelCase_       				=			parallel_attn
		UpperCAmelCase_       				=			bias

		super().__init__(bos_token_id=__SCREAMING_SNAKE_CASE		,	eos_token_id=__SCREAMING_SNAKE_CASE		,	**__SCREAMING_SNAKE_CASE							)




	@property
	def       __A					(		self	:						List[str]							):


		'''simple docstring'''







		return self.hidden_size // self.num_attention_heads




	@property
	def       __A					(		self	:						Any							):


		'''simple docstring'''







		return not self.alibi


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:    Dict 							=			"""CompVis/stable-diffusion-v1-2"""
_a:    Optional[Any] 							=			"""CompVis/stable-diffusion-v1-3"""
_a:    str 							=			"""CompVis/stable-diffusion-v1-4"""

class 						__UpperCamelCase    (					lowercase						):




	def __init__(		self	:						Union[str, Any]		,	lowerCAmelCase	:						AutoencoderKL		,	lowerCAmelCase	:						CLIPTextModel		,	lowerCAmelCase	:						CLIPTokenizer		,	lowerCAmelCase	:						UNetaDConditionModel		,	lowerCAmelCase	:						Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler]		,	lowerCAmelCase	:						StableDiffusionSafetyChecker		,	lowerCAmelCase	:						CLIPImageProcessor		,	lowerCAmelCase	:						bool = True		,	):


		'''simple docstring'''







		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       __A					(		self	:						Tuple							):


		'''simple docstring'''







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




	def       __A					(		self	:						Dict		,	lowerCAmelCase	:						Optional[Union[str, int]] = "auto"							):


		'''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(lowerCAmelCase							)




	def       __A					(		self	:						int							):


		'''simple docstring'''







		self.enable_attention_slicing(lowerCAmelCase							)




	@torch.no_grad()
	def       __A					(		self	:						Union[str, 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	:						Tuple		,	):


		'''simple docstring'''







		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       __A					(		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]		,	):


		'''simple docstring'''







		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       __A					(		self	:						List[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	:						Union[str, Any]		,	):


		'''simple docstring'''







		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       __A					(		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	:						Optional[Any]		,	):


		'''simple docstring'''







		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       __A					(		self	:						Union[str, 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	:						Union[str, Any]		,	):


		'''simple docstring'''







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