Spaces:
Running
on
A10G
Running
on
A10G
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,8 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
import random
|
4 |
-
|
5 |
import spaces
|
6 |
from diffusers import DiffusionPipeline, FlowMatchEulerDiscreteScheduler
|
7 |
import torch
|
@@ -15,9 +16,32 @@ if torch.cuda.is_available():
|
|
15 |
else:
|
16 |
torch_dtype = torch.bfloat16
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
pipe = pipe.to(device)
|
23 |
|
|
|
1 |
+
import os, gc
|
2 |
import gradio as gr
|
3 |
import numpy as np
|
4 |
import random
|
5 |
+
from transformers import AutoTokenizer, AutoFeatureExtractor
|
6 |
import spaces
|
7 |
from diffusers import DiffusionPipeline, FlowMatchEulerDiscreteScheduler
|
8 |
import torch
|
|
|
16 |
else:
|
17 |
torch_dtype = torch.bfloat16
|
18 |
|
19 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
20 |
+
model_repo_id,
|
21 |
+
trust_remote_code=True,
|
22 |
+
use_fast=True
|
23 |
+
)
|
24 |
+
feature_extractor = AutoFeatureExtractor.from_pretrained(
|
25 |
+
model_repo_id,
|
26 |
+
trust_remote_code=True
|
27 |
+
)
|
28 |
+
|
29 |
+
# 3) Dispatch & load in FP16 with offloading
|
30 |
+
pipe = DiffusionPipeline.from_pretrained(
|
31 |
+
model_repo_id,
|
32 |
+
scheduler=FlowMatchEulerDiscreteScheduler.from_pretrained(
|
33 |
+
model_repo_id,
|
34 |
+
subfolder="scheduler",
|
35 |
+
shift=5,
|
36 |
+
use_safetensors=True
|
37 |
+
),
|
38 |
+
tokenizer=tokenizer,
|
39 |
+
feature_extractor=feature_extractor,
|
40 |
+
torch_dtype=torch.bfloat16,
|
41 |
+
use_safetensors=True,
|
42 |
+
device_map="auto", # automatically spreads submodules CPU/GPU
|
43 |
+
offload_folder="offload" # where to spill CPU-offloaded weights
|
44 |
+
)
|
45 |
|
46 |
pipe = pipe.to(device)
|
47 |
|