forked from ecmulli/stable-diffusion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstable-diffusion-8g.py
executable file
·38 lines (30 loc) · 1016 Bytes
/
stable-diffusion-8g.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from diffusers import StableDiffusionPipeline, LMSDiscreteScheduler
from IPython.display import Image
import torch
import os
prompt = "a photo of an astronaut riding a horse on mars"
access_token = "enter access token"
# this will substitute the default PNDM scheduler for K-LMS
lms = LMSDiscreteScheduler(
beta_start=0.00085,
beta_end=0.012,
beta_schedule="scaled_linear"
)
pipe = StableDiffusionPipeline.from_pretrained(
"CompVis/stable-diffusion-v1-4",
revision="fp16",
torch_dtype=torch.float16,
use_auth_token=access_token
)
pipe = pipe.to("cuda")
pipe.enable_attention_slicing()
def get_image():
file_name = os.path.join(root_dir(), "data", prompt.replace(" ", "-")+".png")
with torch.autocast("cuda"):
image = pipe(prompt).images[0]
image.save(file_name)
torch.cuda.empty_cache()
def root_dir():
return os.path.abspath(os.path.dirname(__file__))
if __name__=="__main__":
get_image()