


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


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

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

# to channels last
lowerCAmelCase    :     Optional[int]					=						pipe.unet.to(memory_format=torch.channels_last)
lowerCAmelCase    :     Dict					=						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    :     Optional[int]					=						pipe.safety_checker.to(memory_format=torch.channels_last)

# optimize with ipex
lowerCAmelCase    :     Dict					=						torch.randn(2, 4, 64, 64)
lowerCAmelCase    :     List[Any]					=						torch.rand(1) * 9_99
lowerCAmelCase    :     str					=						torch.randn(2, 77, 7_68)
lowerCAmelCase    :     Union[str, Any]					=						(sample, timestep, encoder_hidden_status)
try:
       lowerCAmelCase    :     List[str]					=						ipex.optimize(pipe.unet.eval(), dtype=torch.bfloataa, inplace=True, sample_input=input_example)
except Exception:
       lowerCAmelCase    :     List[str]					=						ipex.optimize(pipe.unet.eval(), dtype=torch.bfloataa, inplace=True)
lowerCAmelCase    :     int					=						ipex.optimize(pipe.vae.eval(), dtype=torch.bfloataa, inplace=True)
lowerCAmelCase    :     Dict					=						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    :     Optional[int]					=						6_66
lowerCAmelCase    :     str					=						torch.Generator(device).manual_seed(seed)
lowerCAmelCase    :     Any					=						{"""generator""": generator}
if args.steps is not None:
       lowerCAmelCase    :     List[str]					=						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'''







lowerCAmelCase    :     Optional[int]					=						[sum(int(c, 10) ** 2 for c in i.__str__()) for i in range(10_00_00)]






def 			lowercase				(_A					):







       """simple docstring"""







       _lowerCAmelCase    :							str   			=       0
       while number:
              # Increased Speed Slightly by checking every 5 digits together.
              sum_of_digits_squared += DIGITS_SQUARED[number % 1_0_0_0_0_0]
              number //= 1_0_0_0_0_0

       return sum_of_digits_squared


# There are 2 Chains made,
# One ends with 89 with the chain member 58 being the one which when declared first,
# there will be the least number of iterations for all the members to be checked.

# The other one ends with 1 and has only one element 1.

# So 58 and 1 are chosen to be declared at the starting.

# Changed dictionary to an array to quicken the solution
lowerCAmelCase    :     list[bool | None]					=						[None] * 10_00_00_00
lowerCAmelCase    :     List[str]					=						True
lowerCAmelCase    :     Union[str, Any]					=						False






def 			lowercase				(_A					):







       """simple docstring"""







       if CHAINS[number - 1] is not None:
              return CHAINS[number - 1]  # type: ignore

       _lowerCAmelCase    :							Any   			=       chain(next_number(_A					)					)
       _lowerCAmelCase    :							List[str]   			=       number_chain

       while number < 1_0_0_0_0_0_0_0:
              _lowerCAmelCase    :							Tuple   			=       number_chain
              number *= 1_0

       return number_chain






def 			lowercase				(_A = 1_0_0_0_0_0_0_0					):







       """simple docstring"""







       for i in range(1   ,						_A					):
              if CHAINS[i] is None:
                     chain(i + 1					)

       return CHAINS[:number].count(_A					)


if __name__ == "__main__":
       import doctest

       doctest.testmod()
       print(F'''{solution() = }''')

