Skip to content

Instantly share code, notes, and snippets.

@loretoparisi
Created August 24, 2022 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loretoparisi/8fa61d791742789280ff22e669e4e160 to your computer and use it in GitHub Desktop.
Save loretoparisi/8fa61d791742789280ff22e669e4e160 to your computer and use it in GitHub Desktop.
Stable Diffusion Pipeline
# make sure you're logged in with `huggingface-cli login`
import os
from torch import autocast
from diffusers import StableDiffusionPipeline, LMSDiscreteScheduler
lms = LMSDiscreteScheduler(
beta_start=0.00085,
beta_end=0.012,
beta_schedule="scaled_linear"
)
pipe = StableDiffusionPipeline.from_pretrained(
"CompVis/stable-diffusion-v1-3",
scheduler=lms,
use_auth_token=True,
cache_dir=os.getenv("cache_dir", "./models")
).to("cpu")
prompt = "a photo of an astronaut riding a horse on mars"
with autocast("cpu"):
image = pipe(prompt)["sample"][0]
image.save("astronaut_rides_horse.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment