


"""simple docstring"""







import argparse

import intel_extension_for_pytorch as ipex
import torch

from diffusers import DPMSolverMultistepScheduler, StableDiffusionPipeline


lowerCAmelCase__      				=   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__      				=   parser.parse_args()


lowerCAmelCase__      				=   '''cpu'''
lowerCAmelCase__      				=   '''a lovely <dicoo> in red dress and hat, in the snowly and brightly night, with many brighly buildings'''

lowerCAmelCase__      				=   '''path-to-your-trained-model'''
lowerCAmelCase__      				=   StableDiffusionPipeline.from_pretrained(model_id)
if args.dpm:
     lowerCAmelCase__      				=   DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
lowerCAmelCase__      				=   pipe.to(device)

# to channels last
lowerCAmelCase__      				=   pipe.unet.to(memory_format=torch.channels_last)
lowerCAmelCase__      				=   pipe.vae.to(memory_format=torch.channels_last)
lowerCAmelCase__      				=   pipe.text_encoder.to(memory_format=torch.channels_last)
if pipe.requires_safety_checker:
     lowerCAmelCase__      				=   pipe.safety_checker.to(memory_format=torch.channels_last)

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

# compute
lowerCAmelCase__      				=   666
lowerCAmelCase__      				=   torch.Generator(device).manual_seed(seed)
lowerCAmelCase__      				=   {'''generator''': generator}
if args.steps is not None:
     lowerCAmelCase__      				=   args.steps

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

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












from __future__ import annotations
def      _A       (		SCREAMING_SNAKE_CASE     :   list						):





  """simple docstring"""



  if len(SCREAMING_SNAKE_CASE						) == 0:
    return []
  a__					,							a__	:					int										=min(SCREAMING_SNAKE_CASE						), max(SCREAMING_SNAKE_CASE						)
  a__	:					Optional[int]										=int(max_value - min_value						) + 1
  a__	:					list[list]										=[[] for _ in range(SCREAMING_SNAKE_CASE						)]

  for i in my_list:
    buckets[int(i - min_value						)].append(SCREAMING_SNAKE_CASE						)

  return [v for bucket in buckets for v in sorted(SCREAMING_SNAKE_CASE						)]


if __name__ == "__main__":
     from doctest import testmod

     testmod()
     assert bucket_sort([4, 5, 3, 2, 1]) == [1, 2, 3, 4, 5]
     assert bucket_sort([0, 1, -10, 15, 2, -2]) == [-10, -2, 0, 1, 2, 15]






