AndyPak commited on
Commit Β·
354174f
1
Parent(s): d5513a8
Fix: load model on CPU, move to GPU inside @spaces.GPU
Browse files
app.py
CHANGED
|
@@ -8,14 +8,12 @@ import torch
|
|
| 8 |
from diffusers import AutoencoderKLWan, WanPipeline
|
| 9 |
from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepScheduler
|
| 10 |
|
| 11 |
-
# ββ Load model
|
| 12 |
-
# 1.3B model β fast and fits easily in A10G (24GB)
|
| 13 |
MODEL_ID = "Wan-AI/Wan2.1-T2V-1.3B-Diffusers"
|
| 14 |
|
| 15 |
vae = AutoencoderKLWan.from_pretrained(MODEL_ID, subfolder="vae", torch_dtype=torch.float32)
|
| 16 |
pipe = WanPipeline.from_pretrained(MODEL_ID, vae=vae, torch_dtype=torch.bfloat16)
|
| 17 |
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config, flow_shift=3.0)
|
| 18 |
-
pipe.to("cuda")
|
| 19 |
|
| 20 |
# ββ Resolution presets ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 21 |
RESOLUTIONS = {
|
|
@@ -29,7 +27,9 @@ RESOLUTIONS = {
|
|
| 29 |
def generate(prompt, negative_prompt, resolution, steps, guidance, seed, progress=gr.Progress(track_tqdm=True)):
|
| 30 |
width, height = RESOLUTIONS.get(resolution, (480, 832))
|
| 31 |
|
| 32 |
-
|
|
|
|
|
|
|
| 33 |
|
| 34 |
output = pipe(
|
| 35 |
prompt=prompt,
|
|
|
|
| 8 |
from diffusers import AutoencoderKLWan, WanPipeline
|
| 9 |
from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepScheduler
|
| 10 |
|
| 11 |
+
# ββ Load model on CPU at startup (ZeroGPU moves to GPU automatically) βββ
|
|
|
|
| 12 |
MODEL_ID = "Wan-AI/Wan2.1-T2V-1.3B-Diffusers"
|
| 13 |
|
| 14 |
vae = AutoencoderKLWan.from_pretrained(MODEL_ID, subfolder="vae", torch_dtype=torch.float32)
|
| 15 |
pipe = WanPipeline.from_pretrained(MODEL_ID, vae=vae, torch_dtype=torch.bfloat16)
|
| 16 |
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config, flow_shift=3.0)
|
|
|
|
| 17 |
|
| 18 |
# ββ Resolution presets ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 19 |
RESOLUTIONS = {
|
|
|
|
| 27 |
def generate(prompt, negative_prompt, resolution, steps, guidance, seed, progress=gr.Progress(track_tqdm=True)):
|
| 28 |
width, height = RESOLUTIONS.get(resolution, (480, 832))
|
| 29 |
|
| 30 |
+
pipe.to("cuda")
|
| 31 |
+
|
| 32 |
+
generator = torch.Generator("cuda").manual_seed(int(seed)) if seed >= 0 else None
|
| 33 |
|
| 34 |
output = pipe(
|
| 35 |
prompt=prompt,
|