




'''simple docstring'''







import argparse

import intel_extension_for_pytorch as ipex
import torch

from diffusers import DPMSolverMultistepScheduler, StableDiffusionPipeline


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


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

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

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

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

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

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

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





"""simple docstring"""




# NOTE: This file is deprecated and will be removed in a future version.
# It only exists so that temporarely `from diffusers.pipelines import DiffusionPipeline` works
from ...utils import deprecate
from ..controlnet.multicontrolnet import MultiControlNetModel  # noqa: F401
from ..controlnet.pipeline_controlnet import StableDiffusionControlNetPipeline  # noqa: F401


deprecate(
    'stable diffusion controlnet',
    '0.22.0',
    'Importing `StableDiffusionControlNetPipeline` or `MultiControlNetModel` from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_controlnet is deprecated. Please import `from diffusers import StableDiffusionControlNetPipeline` instead.',
    standard_warn=False,
    stacklevel=3,
)




