Spaces:
Running
on
Zero
Running
on
Zero
up
Browse files- app.py +2 -2
- optimization.py +15 -20
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import gradio as gr
|
|
| 2 |
import torch
|
| 3 |
from diffusers import QwenImagePipeline
|
| 4 |
from qwenimage.qwen_fa3_processor import QwenDoubleStreamAttnProcessorFA3
|
| 5 |
-
from optimization import
|
| 6 |
from hub_utils import _push_compiled_graph_to_hub
|
| 7 |
from huggingface_hub import whoami
|
| 8 |
import spaces
|
|
@@ -16,7 +16,7 @@ pipe = QwenImagePipeline.from_pretrained("Qwen/Qwen-Image", torch_dtype=dtype).t
|
|
| 16 |
pipe.transformer.set_attn_processor(QwenDoubleStreamAttnProcessorFA3())
|
| 17 |
|
| 18 |
# --- Ahead-of-time compilation ---
|
| 19 |
-
compiled_transformer =
|
| 20 |
|
| 21 |
@spaces.GPU(duration=120)
|
| 22 |
def push_to_hub(repo_id, filename, oauth_token: gr.OAuthToken):
|
|
|
|
| 2 |
import torch
|
| 3 |
from diffusers import QwenImagePipeline
|
| 4 |
from qwenimage.qwen_fa3_processor import QwenDoubleStreamAttnProcessorFA3
|
| 5 |
+
from optimization import compile_transformer
|
| 6 |
from hub_utils import _push_compiled_graph_to_hub
|
| 7 |
from huggingface_hub import whoami
|
| 8 |
import spaces
|
|
|
|
| 16 |
pipe.transformer.set_attn_processor(QwenDoubleStreamAttnProcessorFA3())
|
| 17 |
|
| 18 |
# --- Ahead-of-time compilation ---
|
| 19 |
+
compiled_transformer = compile_transformer(pipe, prompt="prompt")
|
| 20 |
|
| 21 |
@spaces.GPU(duration=120)
|
| 22 |
def push_to_hub(repo_id, filename, oauth_token: gr.OAuthToken):
|
optimization.py
CHANGED
|
@@ -38,23 +38,18 @@ INDUCTOR_CONFIGS = {
|
|
| 38 |
}
|
| 39 |
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
)
|
| 57 |
-
return spaces.aoti_compile(exported, INDUCTOR_CONFIGS)
|
| 58 |
-
|
| 59 |
-
compiled = compile_transformer()
|
| 60 |
-
return compiled
|
|
|
|
| 38 |
}
|
| 39 |
|
| 40 |
|
| 41 |
+
@spaces.GPU(duration=1500)
|
| 42 |
+
def compile_transformer(pipeline: Callable[P, Any], *args: P.args, **kwargs: P.kwargs):
|
| 43 |
+
with spaces.aoti_capture(pipeline.transformer) as call:
|
| 44 |
+
pipeline(*args, **kwargs)
|
| 45 |
+
|
| 46 |
+
dynamic_shapes = tree_map(lambda t: None, call.kwargs)
|
| 47 |
+
dynamic_shapes |= TRANSFORMER_DYNAMIC_SHAPES
|
| 48 |
+
|
| 49 |
+
exported = torch.export.export(
|
| 50 |
+
mod=pipeline.transformer,
|
| 51 |
+
args=call.args,
|
| 52 |
+
kwargs=call.kwargs,
|
| 53 |
+
dynamic_shapes=dynamic_shapes,
|
| 54 |
+
)
|
| 55 |
+
return spaces.aoti_compile(exported, INDUCTOR_CONFIGS)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|