File size: 877 Bytes
ea151b9 |
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 |
#!/usr/bin/env python3
from diffusers import StableDiffusionPipeline, UniPCMultistepScheduler
import time
import torch
import sys
path = sys.argv[1]
use_device_map = bool(int(sys.argv[2]))
start_time = time.time()
if use_device_map:
print("Load directly on GPU")
pipe = StableDiffusionPipeline.from_pretrained(path, torch_dtype=torch.float16, device_map="auto")
else:
print("Load directly on CPU")
pipe = StableDiffusionPipeline.from_pretrained(path, torch_dtype=torch.float16)
pipe = pipe.to("cuda")
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
prompt = "a highly realistic photo of green turtle"
print("Loading Time", time.time() - start_time)
generator = torch.Generator(device="cuda").manual_seed(0)
image = pipe(prompt, generator=generator, num_inference_steps=15).images[0]
print("Time", time.time() - start_time)
|