



'''simple docstring'''




import argparse

import intel_extension_for_pytorch as ipex
import torch

from diffusers import DPMSolverMultistepScheduler, StableDiffusionPipeline


__lowerCamelCase   :					List[str]   							=					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''')
__lowerCamelCase   :					str   							=					parser.parse_args()


__lowerCamelCase   :					Any   							=					'''cpu'''
__lowerCamelCase   :					Union[str, Any]   							=					'''a lovely <dicoo> in red dress and hat, in the snowly and brightly night, with many brighly buildings'''

__lowerCamelCase   :					Union[str, Any]   							=					'''path-to-your-trained-model'''
__lowerCamelCase   :					int   							=					StableDiffusionPipeline.from_pretrained(model_id)
if args.dpm:
		__lowerCamelCase   :					List[str]   							=					DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
__lowerCamelCase   :					List[str]   							=					pipe.to(device)

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

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

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

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

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












'''simple docstring'''




def 	__UpperCAmelCase       ( __magic_name__						)->    list[int]:



			"""simple docstring"""



			if length <= 0 or not isinstance(__magic_name__     ,__magic_name__						):
						raise ValueError("Length must be a positive integer."						)
			return [n * (2 * n - 1) for n in range(__magic_name__						)]


if __name__ == "__main__":
		print(hexagonal_numbers(length=5))
		print(hexagonal_numbers(length=10))




