





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


__lowerCamelCase						: Optional[int]		=   '''cpu'''
__lowerCamelCase						: List[str]		=   '''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						: Tuple		=   StableDiffusionPipeline.from_pretrained(model_id)
if args.dpm:
      __lowerCamelCase						: Tuple		=   DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
__lowerCamelCase						: Tuple		=   pipe.to(device)

# to channels last
__lowerCamelCase						: List[str]		=   pipe.unet.to(memory_format=torch.channels_last)
__lowerCamelCase						: Tuple		=   pipe.vae.to(memory_format=torch.channels_last)
__lowerCamelCase						: Tuple		=   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						: Any		=   torch.randn(2, 4, 64, 64)
__lowerCamelCase						: Union[str, Any]		=   torch.rand(1) * 999
__lowerCamelCase						: str		=   torch.randn(2, 77, 768)
__lowerCamelCase						: Optional[Any]		=   (sample, timestep, encoder_hidden_status)
try:
      __lowerCamelCase						: Union[str, Any]		=   ipex.optimize(pipe.unet.eval(), dtype=torch.bfloataa, inplace=True, sample_input=input_example)
except Exception:
      __lowerCamelCase						: Tuple		=   ipex.optimize(pipe.unet.eval(), dtype=torch.bfloataa, inplace=True)
__lowerCamelCase						: Optional[int]		=   ipex.optimize(pipe.vae.eval(), dtype=torch.bfloataa, inplace=True)
__lowerCamelCase						: Tuple		=   ipex.optimize(pipe.text_encoder.eval(), dtype=torch.bfloataa, inplace=True)
if pipe.requires_safety_checker:
      __lowerCamelCase						: Union[str, Any]		=   ipex.optimize(pipe.safety_checker.eval(), dtype=torch.bfloataa, inplace=True)

# compute
__lowerCamelCase						: int		=   666
__lowerCamelCase						: Union[str, Any]		=   torch.Generator(device).manual_seed(seed)
__lowerCamelCase						: int		=   {'''generator''': generator}
if args.steps is not None:
      __lowerCamelCase						: 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')








'''simple docstring'''






def 					_a   (__SCREAMING_SNAKE_CASE   ):


  """simple docstring"""

  return 1 if digit in (0, 1) else (digit * factorial(digit - 1   ))


def 					_a   (__SCREAMING_SNAKE_CASE   ):


  """simple docstring"""

  _UpperCamelCase       			=0
  _UpperCamelCase       			=number
  while duplicate > 0:
    _UpperCamelCase			,     _UpperCamelCase       			=divmod(__SCREAMING_SNAKE_CASE  ,      10   )
    fact_sum += factorial(__SCREAMING_SNAKE_CASE   )
  return fact_sum == number


if __name__ == "__main__":
      print('Program to check whether a number is a Krisnamurthy Number or not.')
      __lowerCamelCase						: Optional[Any]		=   int(input('Enter number: ').strip())
      print(
          F"""{number} is {'' if krishnamurthy(number) else 'not '}a Krishnamurthy Number."""
      )






