





'''simple docstring'''

import argparse

import intel_extension_for_pytorch as ipex
import torch

from diffusers import DPMSolverMultistepScheduler, StableDiffusionPipeline


__lowerCamelCase : 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")
__lowerCamelCase : Any				=			parser.parse_args()


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

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

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

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

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

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

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











'''simple docstring'''

# Algorithm for the pigeonhole sorting









def 							UpperCAmelCase_    (	lowerCAmelCase_							):

				"""simple docstring"""






				lowercase         = min(lowerCAmelCase_							)  # min() finds the minimum value
				lowercase         = max(lowerCAmelCase_							)  # max() finds the maximum value

				lowercase         = max_val - min_val + 1  # size is difference of max and min values plus one

				# list of pigeonholes of size equal to the variable size
				lowercase         = [0] * size

				# Populate the pigeonholes.
				for x in a:
								assert isinstance(lowerCAmelCase_		,							lowerCAmelCase_							), "integers only please"
								holes[x - min_val] += 1

				# Putting the elements back into the array in an order.
				lowercase         = 0
				for count in range(lowerCAmelCase_							):
								while holes[count] > 0:
												holes[count] -= 1
												lowercase         = count + min_val
												i += 1







def 							UpperCAmelCase_    (	):

				"""simple docstring"""






				lowercase         = [8, 3, 2, 7, 4, 6, 8]
				pigeonhole_sort(lowerCAmelCase_							)
				print("Sorted order is:"		,							" ".join(lowerCAmelCase_							)							)


if __name__ == "__main__":
			main()




