


"""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							:    Union[str, Any]					   =	parser.parse_args()


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

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

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

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

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

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

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






def 				_UpperCAmelCase			(    A     ):




   '''simple docstring'''

   for i in range(len(A     ) - 1				,							0				,							-1     ):
      UpperCAmelCase__						=False

      for j in range(A				,							0				,							-1     ):
         if unsorted[j] < unsorted[j - 1]:
            UpperCAmelCase__			,							UpperCAmelCase__						=unsorted[j - 1], unsorted[j]
            UpperCAmelCase__						=True

      for j in range(A     ):
         if unsorted[j] > unsorted[j + 1]:
            UpperCAmelCase__			,							UpperCAmelCase__						=unsorted[j + 1], unsorted[j]
            UpperCAmelCase__						=True

      if not swapped:
         break
   return unsorted


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    UpperCamelCase_												=	input('Enter numbers separated by a comma:\n').strip()
    UpperCamelCase_												=	[int(item) for item in user_input.split(',')]
    print(f"""{cocktail_shaker_sort(unsorted) = }""")



