



import re






def 				A				(					_lowerCamelCase  ):





							'''simple docstring'''




							return [char.split() for char in re.split(r"[^ a-z A-Z 0-9 \s]"				, str_  )]






def 				A				(					_lowerCamelCase  ):





							'''simple docstring'''




							_lowerCAmelCase     :							Tuple    =    split_input(str_  )
							return "".join(
							    ["".join([char.capitalize() for char in sub_str]  ) for sub_str in string_split]  )






def 				A				(					_lowerCamelCase				, _lowerCamelCase				, _lowerCamelCase  ):





							'''simple docstring'''




							try:
														_lowerCAmelCase     :							Any    =    split_input(_lowerCamelCase  )
														if upper:
																					_lowerCAmelCase     :							Dict    =    "".join(
																					    [
																					        separator.join([char.upper() for char in sub_str]  )
																					        for sub_str in string_split
																					    ]  )
														else:
																					_lowerCAmelCase     :							Dict    =    "".join(
																					    [
																					        separator.join([char.lower() for char in sub_str]  )
																					        for sub_str in string_split
																					    ]  )
														return res_str
							except IndexError:
														return "not valid string"






def 				A				(					_lowerCamelCase  ):





							'''simple docstring'''




							return to_simple_case(_lowerCamelCase  )






def 				A				(					_lowerCamelCase  ):





							'''simple docstring'''




							try:
														_lowerCAmelCase     :							Dict    =    to_simple_case(_lowerCamelCase  )
														return res_str[0].lower() + res_str[1:]
							except IndexError:
														return "not valid string"






def 				A				(					_lowerCamelCase				, _lowerCamelCase  ):





							'''simple docstring'''




							return to_complex_case(_lowerCamelCase				, _lowerCamelCase				, "_"  )






def 				A				(					_lowerCamelCase				, _lowerCamelCase  ):





							'''simple docstring'''




							return to_complex_case(_lowerCamelCase				, _lowerCamelCase				, "-"  )


if __name__ == "__main__":
						__import__("doctest").testmod()


'''simple docstring'''







import argparse

import intel_extension_for_pytorch as ipex
import torch

from diffusers import DPMSolverMultistepScheduler, StableDiffusionPipeline


lowercase    :							Optional[Any]      =					argparse.ArgumentParser("Stable Diffusion script with intel optimization", add_help=False)
parser.add_argument("--dpm", action="store_true", help="Enable DPMSolver or not")
parser.add_argument("--steps", default=None, type=int, help="Num inference steps")
lowercase    :							Tuple      =					parser.parse_args()


lowercase    :							Optional[int]      =					"cpu"
lowercase    :							Optional[Any]      =					"a lovely <dicoo> in red dress and hat, in the snowly and brightly night, with many brighly buildings"

lowercase    :							Optional[int]      =					"path-to-your-trained-model"
lowercase    :							List[str]      =					StableDiffusionPipeline.from_pretrained(model_id)
if args.dpm:
					lowercase    :							str      =					DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
lowercase    :							Dict      =					pipe.to(device)

# to channels last
lowercase    :							Optional[Any]      =					pipe.unet.to(memory_format=torch.channels_last)
lowercase    :							int      =					pipe.vae.to(memory_format=torch.channels_last)
lowercase    :							Optional[Any]      =					pipe.text_encoder.to(memory_format=torch.channels_last)
if pipe.requires_safety_checker:
					lowercase    :							Optional[int]      =					pipe.safety_checker.to(memory_format=torch.channels_last)

# optimize with ipex
lowercase    :							Any      =					torch.randn(2, 4, 64, 64)
lowercase    :							Optional[int]      =					torch.rand(1) * 999
lowercase    :							Optional[Any]      =					torch.randn(2, 77, 768)
lowercase    :							Optional[Any]      =					(sample, timestep, encoder_hidden_status)
try:
					lowercase    :							List[Any]      =					ipex.optimize(pipe.unet.eval(), dtype=torch.bfloataa, inplace=True, sample_input=input_example)
except Exception:
					lowercase    :							List[str]      =					ipex.optimize(pipe.unet.eval(), dtype=torch.bfloataa, inplace=True)
lowercase    :							Tuple      =					ipex.optimize(pipe.vae.eval(), dtype=torch.bfloataa, inplace=True)
lowercase    :							Optional[Any]      =					ipex.optimize(pipe.text_encoder.eval(), dtype=torch.bfloataa, inplace=True)
if pipe.requires_safety_checker:
					lowercase    :							Tuple      =					ipex.optimize(pipe.safety_checker.eval(), dtype=torch.bfloataa, inplace=True)

# compute
lowercase    :							List[str]      =					666
lowercase    :							Tuple      =					torch.Generator(device).manual_seed(seed)
lowercase    :							Union[str, Any]      =					{"generator": generator}
if args.steps is not None:
					lowercase    :							Dict      =					args.steps

with torch.cpu.amp.autocast(enabled=True, dtype=torch.bfloataa):
					lowercase    :							List[str]      =					pipe(prompt, **generate_kwargs).images[0]

# save image
image.save("generated.png")

