Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -7,36 +7,42 @@ import spaces
|
|
7 |
|
8 |
### SDXL Turbo ####
|
9 |
pipe_turbo = StableDiffusionXLPipeline.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16")
|
10 |
-
pipe_turbo.to("cuda")
|
11 |
|
12 |
### SDXL Lightning ###
|
13 |
base = "stabilityai/stable-diffusion-xl-base-1.0"
|
14 |
repo = "ByteDance/SDXL-Lightning"
|
15 |
ckpt = "sdxl_lightning_1step_unet_x0.safetensors"
|
16 |
|
17 |
-
unet = UNet2DConditionModel.from_config(base, subfolder="unet").to(
|
18 |
unet.load_state_dict(load_file(hf_hub_download(repo, ckpt), device="cuda"))
|
19 |
-
pipe_lightning = StableDiffusionXLPipeline.from_pretrained(base, unet=unet, torch_dtype=torch.float16, variant="fp16")
|
20 |
del unet
|
21 |
pipe_lightning.scheduler = EulerDiscreteScheduler.from_config(pipe_lightning.scheduler.config, timestep_spacing="trailing", prediction_type="sample")
|
22 |
-
pipe_lightning.to("cuda")
|
23 |
|
24 |
### Hyper SDXL ###
|
25 |
repo_name = "ByteDance/Hyper-SD"
|
26 |
ckpt_name = "Hyper-SDXL-1step-Unet.safetensors"
|
27 |
|
28 |
-
unet = UNet2DConditionModel.from_config(base, subfolder="unet").to(
|
29 |
-
unet.load_state_dict(load_file(hf_hub_download(repo_name, ckpt_name)
|
30 |
-
pipe_hyper = StableDiffusionXLPipeline.from_pretrained(base, unet=unet, torch_dtype=torch.float16, variant="fp16")
|
31 |
pipe_hyper.scheduler = LCMScheduler.from_config(pipe_hyper.scheduler.config)
|
32 |
-
pipe_hyper.to("cuda")
|
33 |
del unet
|
34 |
|
35 |
@spaces.GPU
|
36 |
def run_comparison(prompt):
|
|
|
37 |
image_turbo=pipe_turbo(prompt=prompt, num_inference_steps=1, guidance_scale=0).images[0]
|
|
|
|
|
38 |
image_lightning=pipe_lightning(prompt=prompt, num_inference_steps=1, guidance_scale=0).images[0]
|
|
|
|
|
39 |
image_hyper=pipe_hyper(prompt=prompt, num_inference_steps=1, guidance_scale=0, timesteps=[800]).images[0]
|
|
|
40 |
return image_turbo, image_lightning, image_hyper
|
41 |
|
42 |
|
|
|
7 |
|
8 |
### SDXL Turbo ####
|
9 |
pipe_turbo = StableDiffusionXLPipeline.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16")
|
10 |
+
#pipe_turbo.to("cuda")
|
11 |
|
12 |
### SDXL Lightning ###
|
13 |
base = "stabilityai/stable-diffusion-xl-base-1.0"
|
14 |
repo = "ByteDance/SDXL-Lightning"
|
15 |
ckpt = "sdxl_lightning_1step_unet_x0.safetensors"
|
16 |
|
17 |
+
unet = UNet2DConditionModel.from_config(base, subfolder="unet").to(torch.float16)
|
18 |
unet.load_state_dict(load_file(hf_hub_download(repo, ckpt), device="cuda"))
|
19 |
+
pipe_lightning = StableDiffusionXLPipeline.from_pretrained(base, unet=unet, torch_dtype=torch.float16, variant="fp16")#.to("cuda")
|
20 |
del unet
|
21 |
pipe_lightning.scheduler = EulerDiscreteScheduler.from_config(pipe_lightning.scheduler.config, timestep_spacing="trailing", prediction_type="sample")
|
22 |
+
#pipe_lightning.to("cuda")
|
23 |
|
24 |
### Hyper SDXL ###
|
25 |
repo_name = "ByteDance/Hyper-SD"
|
26 |
ckpt_name = "Hyper-SDXL-1step-Unet.safetensors"
|
27 |
|
28 |
+
unet = UNet2DConditionModel.from_config(base, subfolder="unet").to(torch.float16)
|
29 |
+
unet.load_state_dict(load_file(hf_hub_download(repo_name, ckpt_name))
|
30 |
+
pipe_hyper = StableDiffusionXLPipeline.from_pretrained(base, unet=unet, torch_dtype=torch.float16, variant="fp16")#.to("cuda")
|
31 |
pipe_hyper.scheduler = LCMScheduler.from_config(pipe_hyper.scheduler.config)
|
32 |
+
#pipe_hyper.to("cuda")
|
33 |
del unet
|
34 |
|
35 |
@spaces.GPU
|
36 |
def run_comparison(prompt):
|
37 |
+
image_turbo.to("cuda")
|
38 |
image_turbo=pipe_turbo(prompt=prompt, num_inference_steps=1, guidance_scale=0).images[0]
|
39 |
+
image_turbo.to("cpu")
|
40 |
+
image_lightning.to("cuda")
|
41 |
image_lightning=pipe_lightning(prompt=prompt, num_inference_steps=1, guidance_scale=0).images[0]
|
42 |
+
image_lightning.to("cpu")
|
43 |
+
image_hyper.to("cuda")
|
44 |
image_hyper=pipe_hyper(prompt=prompt, num_inference_steps=1, guidance_scale=0, timesteps=[800]).images[0]
|
45 |
+
image_turbo.to("cpu")
|
46 |
return image_turbo, image_lightning, image_hyper
|
47 |
|
48 |
|