






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


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



class 					lowercase						(  __a ):


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

								UpperCAmelCase_		:      Tuple       	=					StableDiffusionPipeline.from_pretrained(a_)
								UpperCAmelCase_		:      int       	=					StableDiffusionPipeline.from_pretrained(a_)
								UpperCAmelCase_		:      Any       	=					StableDiffusionPipeline.from_pretrained(a_)
								UpperCAmelCase_		:      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 						_snake_case							(			self)							->				Tuple:
								return {k: getattr(self    ,			a_) for k in self.config.keys() if not k.startswith('_')}


							def 						_snake_case							(			self    ,			_snake_case = "auto")							->				int:



								if slice_size == "auto":
									# half the attention head size is usually a good trade-off between
									# speed and memory
									UpperCAmelCase_		:      Optional[int]       	=					self.unet.config.attention_head_dim // 2
								self.unet.set_attention_slice(a_)


							def 						_snake_case							(			self)							->				Optional[int]:
								self.enable_attention_slicing(a_)


							@torch.no_grad()
							def 						_snake_case							(			self    ,			_snake_case    ,			_snake_case = 512    ,			_snake_case = 512    ,			_snake_case = 50    ,			_snake_case = 7.5    ,			_snake_case = None    ,			_snake_case = 1    ,			_snake_case = 0.0    ,			_snake_case = None    ,			_snake_case = None    ,			_snake_case = "pil"    ,			_snake_case = True    ,			_snake_case = None    ,			_snake_case = 1    ,			**_snake_case    ,			)							->				Dict:
								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 						_snake_case							(			self    ,			_snake_case    ,			_snake_case = 512    ,			_snake_case = 512    ,			_snake_case = 50    ,			_snake_case = 7.5    ,			_snake_case = None    ,			_snake_case = 1    ,			_snake_case = 0.0    ,			_snake_case = None    ,			_snake_case = None    ,			_snake_case = "pil"    ,			_snake_case = True    ,			_snake_case = None    ,			_snake_case = 1    ,			**_snake_case    ,			)							->				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 						_snake_case							(			self    ,			_snake_case    ,			_snake_case = 512    ,			_snake_case = 512    ,			_snake_case = 50    ,			_snake_case = 7.5    ,			_snake_case = None    ,			_snake_case = 1    ,			_snake_case = 0.0    ,			_snake_case = None    ,			_snake_case = None    ,			_snake_case = "pil"    ,			_snake_case = True    ,			_snake_case = None    ,			_snake_case = 1    ,			**_snake_case    ,			)							->				Dict:
								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 						_snake_case							(			self    ,			_snake_case    ,			_snake_case = 512    ,			_snake_case = 512    ,			_snake_case = 50    ,			_snake_case = 7.5    ,			_snake_case = None    ,			_snake_case = 1    ,			_snake_case = 0.0    ,			_snake_case = None    ,			_snake_case = None    ,			_snake_case = "pil"    ,			_snake_case = True    ,			_snake_case = None    ,			_snake_case = 1    ,			**_snake_case    ,			)							->				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 						_snake_case							(			self    ,			_snake_case    ,			_snake_case = 512    ,			_snake_case = 512    ,			_snake_case = 50    ,			_snake_case = 7.5    ,			_snake_case = None    ,			_snake_case = 1    ,			_snake_case = 0.0    ,			_snake_case = None    ,			_snake_case = None    ,			_snake_case = "pil"    ,			_snake_case = True    ,			_snake_case = None    ,			_snake_case = 1    ,			**_snake_case    ,			)							->				Optional[Any]:
								UpperCAmelCase_		:      int       	=					"""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
								UpperCAmelCase_		:      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
								UpperCAmelCase_		:      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
								UpperCAmelCase_		:      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.4
								UpperCAmelCase_		:      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 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]])









'''simple docstring'''


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


lowerCAmelCase__										= logging.get_logger(__name__)

lowerCAmelCase__										= {
    "tanreinama/GPTSAN-2.8B-spout_is_uniform": (
        "https://huggingface.co/tanreinama/GPTSAN-2.8B-spout_is_uniform/resolve/main/config.json"
    ),
}



class 					lowercase						(  a_ ):
							_lowerCamelCase		:      Any=   "gptsan-japanese"
							_lowerCamelCase		:      List[Any]=   [
							    "past_key_values",
							]
							_lowerCamelCase		:      Tuple=   {
							    "hidden_size": "d_model",
							    "num_attention_heads": "num_heads",
							    "num_hidden_layers": "num_layers",
							}


							def __init__(			self    ,			_snake_case=3_6000    ,			_snake_case=1280    ,			_snake_case=1024    ,			_snake_case=8192    ,			_snake_case=4096    ,			_snake_case=128    ,			_snake_case=10    ,			_snake_case=0    ,			_snake_case=16    ,			_snake_case=16    ,			_snake_case=128    ,			_snake_case=0.0    ,			_snake_case=1e-5    ,			_snake_case=False    ,			_snake_case=0.0    ,			_snake_case="float32"    ,			_snake_case=False    ,			_snake_case=False    ,			_snake_case=False    ,			_snake_case=0.002    ,			_snake_case=False    ,			_snake_case=True    ,			_snake_case=3_5998    ,			_snake_case=3_5995    ,			_snake_case=3_5999    ,			**_snake_case    ,			)							->				Optional[int]:
								UpperCAmelCase_		:      Dict       	=					vocab_size
								UpperCAmelCase_		:      Optional[int]       	=					max_position_embeddings
								UpperCAmelCase_		:      Any       	=					d_model
								UpperCAmelCase_		:      int       	=					d_ff
								UpperCAmelCase_		:      Tuple       	=					d_ext
								UpperCAmelCase_		:      Tuple       	=					d_spout
								UpperCAmelCase_		:      List[Any]       	=					num_switch_layers
								UpperCAmelCase_		:      Tuple       	=					num_ext_layers
								UpperCAmelCase_		:      Optional[int]       	=					num_switch_layers + num_ext_layers
								UpperCAmelCase_		:      Tuple       	=					num_heads
								UpperCAmelCase_		:      List[str]       	=					num_experts
								UpperCAmelCase_		:      List[str]       	=					expert_capacity
								UpperCAmelCase_		:      Optional[int]       	=					dropout_rate
								UpperCAmelCase_		:      List[Any]       	=					layer_norm_epsilon
								UpperCAmelCase_		:      Any       	=					router_bias
								UpperCAmelCase_		:      Optional[Any]       	=					router_jitter_noise
								UpperCAmelCase_		:      str       	=					router_dtype
								UpperCAmelCase_		:      List[str]       	=					router_ignore_padding_tokens
								UpperCAmelCase_		:      Optional[int]       	=					output_hidden_states
								UpperCAmelCase_		:      Union[str, Any]       	=					output_attentions
								UpperCAmelCase_		:      Optional[int]       	=					initializer_factor
								UpperCAmelCase_		:      Optional[int]       	=					output_router_logits
								UpperCAmelCase_		:      List[str]       	=					use_cache

								super().__init__(
								    separator_token_id=_snake_case    ,			pad_token_id=_snake_case    ,			eos_token_id=_snake_case    ,			**_snake_case    ,			)






