

def 						__SCREAMING_SNAKE_CASE      (SCREAMING_SNAKE_CASE__ ):
						if not isinstance(SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__ ):
												snake_case_     =			F'''Input value of [number={number}] must be an integer'''
												raise TypeError(SCREAMING_SNAKE_CASE__ )
						if number < 1:
												raise ValueError('''Input must be a positive integer''' )
						return number * (2 * number - 1)


if __name__ == "__main__":
					import doctest

					doctest.testmod()


from typing import Any, Callable, Dict, List, Optional, Union

import PIL.Image
import torch
from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DiffusionPipeline,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionImgaImgPipeline,
    StableDiffusionInpaintPipelineLegacy,
    StableDiffusionPipeline,
    UNetaDConditionModel,
)
from diffusers.configuration_utils import FrozenDict
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker
from diffusers.utils import deprecate, logging


lowerCAmelCase_ 			=			logging.get_logger(__name__)  # pylint: disable=invalid-name





class 			snake_case_     (	__A      ):







			'''simple docstring'''

			SCREAMING_SNAKE_CASE  :     str		    =       ["safety_checker", "feature_extractor"]







			def __init__(  self				:       Any							,     _UpperCamelCase				:       AutoencoderKL							,     _UpperCamelCase				:       CLIPTextModel							,     _UpperCamelCase				:       CLIPTokenizer							,     _UpperCamelCase				:       UNetaDConditionModel							,     _UpperCamelCase				:       Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler]							,     _UpperCamelCase				:       StableDiffusionSafetyChecker							,     _UpperCamelCase				:       CLIPImageProcessor							,     _UpperCamelCase				:       bool = True							,     )   ->Any:
									super().__init__()
									if hasattr(scheduler.config							,     '''steps_offset'''							) and scheduler.config.steps_offset != 1:
															snake_case_     =			(
															    f'''The configuration file of this scheduler: {scheduler} is outdated. `steps_offset`'''
															    f''' should be set to 1 instead of {scheduler.config.steps_offset}. Please make sure '''
															    '''to update the config accordingly as leaving `steps_offset` might led to incorrect results'''
															    ''' in future versions. If you have downloaded this checkpoint from the Hugging Face Hub,'''
															    ''' it would be very nice if you could open a Pull request for the `scheduler/scheduler_config.json`'''
															    ''' file'''
															)
															deprecate('''steps_offset!=1'''							,     '''1.0.0'''							,     _UpperCamelCase							,     standard_warn=_UpperCamelCase							)
															snake_case_     =			dict(scheduler.config							)
															snake_case_     =			1
															snake_case_     =			FrozenDict(_UpperCamelCase							)

									self.register_modules(
									    vae=_UpperCamelCase							,     text_encoder=_UpperCamelCase							,     tokenizer=_UpperCamelCase							,     unet=_UpperCamelCase							,     scheduler=_UpperCamelCase							,     safety_checker=_UpperCamelCase							,     feature_extractor=_UpperCamelCase							,     )
									self.register_to_config(requires_safety_checker=_UpperCamelCase							)







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







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







			def        snake_case__(  self				:       str							)   ->Tuple:
									self.enable_attention_slicing(_UpperCamelCase							)







			@torch.no_grad()
			def        snake_case__(  self				:       Tuple							,     _UpperCamelCase				:       Union[str, List[str]]							,     _UpperCamelCase				:       Union[torch.FloatTensor, PIL.Image.Image]							,     _UpperCamelCase				:       Union[torch.FloatTensor, PIL.Image.Image]							,     _UpperCamelCase				:       float = 0.8							,     _UpperCamelCase				:       Optional[int] = 5_0							,     _UpperCamelCase				:       Optional[float] = 7.5							,     _UpperCamelCase				:       Optional[Union[str, List[str]]] = None							,     _UpperCamelCase				:       Optional[int] = 1							,     _UpperCamelCase				:       Optional[float] = 0.0							,     _UpperCamelCase				:       Optional[torch.Generator] = None							,     _UpperCamelCase				:       Optional[str] = "pil"							,     _UpperCamelCase				:       bool = True							,     _UpperCamelCase				:       Optional[Callable[[int, int, torch.FloatTensor], None]] = None							,     _UpperCamelCase				:       int = 1							,     )   ->Dict:
									# For more information on how this function works, please see: https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion#diffusers.StableDiffusionImg2ImgPipeline
									return StableDiffusionInpaintPipelineLegacy(**self.components							)(
									    prompt=_UpperCamelCase							,     image=_UpperCamelCase							,     mask_image=_UpperCamelCase							,     strength=_UpperCamelCase							,     num_inference_steps=_UpperCamelCase							,     guidance_scale=_UpperCamelCase							,     negative_prompt=_UpperCamelCase							,     num_images_per_prompt=_UpperCamelCase							,     eta=_UpperCamelCase							,     generator=_UpperCamelCase							,     output_type=_UpperCamelCase							,     return_dict=_UpperCamelCase							,     callback=_UpperCamelCase							,     )







			@torch.no_grad()
			def        snake_case__(  self				:       Optional[Any]							,     _UpperCamelCase				:       Union[str, List[str]]							,     _UpperCamelCase				:       Union[torch.FloatTensor, PIL.Image.Image]							,     _UpperCamelCase				:       float = 0.8							,     _UpperCamelCase				:       Optional[int] = 5_0							,     _UpperCamelCase				:       Optional[float] = 7.5							,     _UpperCamelCase				:       Optional[Union[str, List[str]]] = None							,     _UpperCamelCase				:       Optional[int] = 1							,     _UpperCamelCase				:       Optional[float] = 0.0							,     _UpperCamelCase				:       Optional[torch.Generator] = None							,     _UpperCamelCase				:       Optional[str] = "pil"							,     _UpperCamelCase				:       bool = True							,     _UpperCamelCase				:       Optional[Callable[[int, int, torch.FloatTensor], None]] = None							,     _UpperCamelCase				:       int = 1							,     **_UpperCamelCase				:       Tuple							,     )   ->Union[str, Any]:
									# For more information on how this function works, please see: https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion#diffusers.StableDiffusionImg2ImgPipeline
									return StableDiffusionImgaImgPipeline(**self.components							)(
									    prompt=_UpperCamelCase							,     image=_UpperCamelCase							,     strength=_UpperCamelCase							,     num_inference_steps=_UpperCamelCase							,     guidance_scale=_UpperCamelCase							,     negative_prompt=_UpperCamelCase							,     num_images_per_prompt=_UpperCamelCase							,     eta=_UpperCamelCase							,     generator=_UpperCamelCase							,     output_type=_UpperCamelCase							,     return_dict=_UpperCamelCase							,     callback=_UpperCamelCase							,     callback_steps=_UpperCamelCase							,     )







			@torch.no_grad()
			def        snake_case__(  self				:       Union[str, Any]							,     _UpperCamelCase				:       Union[str, List[str]]							,     _UpperCamelCase				:       int = 5_1_2							,     _UpperCamelCase				:       int = 5_1_2							,     _UpperCamelCase				:       int = 5_0							,     _UpperCamelCase				:       float = 7.5							,     _UpperCamelCase				:       Optional[Union[str, List[str]]] = None							,     _UpperCamelCase				:       Optional[int] = 1							,     _UpperCamelCase				:       float = 0.0							,     _UpperCamelCase				:       Optional[torch.Generator] = None							,     _UpperCamelCase				:       Optional[torch.FloatTensor] = None							,     _UpperCamelCase				:       Optional[str] = "pil"							,     _UpperCamelCase				:       bool = True							,     _UpperCamelCase				:       Optional[Callable[[int, int, torch.FloatTensor], None]] = None							,     _UpperCamelCase				:       int = 1							,     )   ->List[Any]:
									# For more information on how this function https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion#diffusers.StableDiffusionPipeline
									return StableDiffusionPipeline(**self.components							)(
									    prompt=_UpperCamelCase							,     height=_UpperCamelCase							,     width=_UpperCamelCase							,     num_inference_steps=_UpperCamelCase							,     guidance_scale=_UpperCamelCase							,     negative_prompt=_UpperCamelCase							,     num_images_per_prompt=_UpperCamelCase							,     eta=_UpperCamelCase							,     generator=_UpperCamelCase							,     latents=_UpperCamelCase							,     output_type=_UpperCamelCase							,     return_dict=_UpperCamelCase							,     callback=_UpperCamelCase							,     callback_steps=_UpperCamelCase							,     )