Spaces:
Running
on
Zero
Running
on
Zero
up
Browse files- app.py +0 -2
- optimization.py +2 -0
app.py
CHANGED
|
@@ -29,8 +29,6 @@ def push_to_hub(repo_id, filename, oauth_token: gr.OAuthToken, progress=gr.Progr
|
|
| 29 |
# --- Ahead-of-time compilation ---
|
| 30 |
start = time.perf_counter()
|
| 31 |
compiled_transformer = compile_transformer(pipe, prompt="prompt")
|
| 32 |
-
if torch.cuda.is_available():
|
| 33 |
-
torch.cuda.synchronize()
|
| 34 |
end = time.perf_counter()
|
| 35 |
print(f"Compilation took: {start - end} seconds.")
|
| 36 |
|
|
|
|
| 29 |
# --- Ahead-of-time compilation ---
|
| 30 |
start = time.perf_counter()
|
| 31 |
compiled_transformer = compile_transformer(pipe, prompt="prompt")
|
|
|
|
|
|
|
| 32 |
end = time.perf_counter()
|
| 33 |
print(f"Compilation took: {start - end} seconds.")
|
| 34 |
|
optimization.py
CHANGED
|
@@ -31,12 +31,14 @@ def compile_transformer(pipeline: Callable[P, Any], *args: P.args, **kwargs: P.k
|
|
| 31 |
with spaces.aoti_capture(pipeline.transformer) as call:
|
| 32 |
pipeline(*args, **kwargs)
|
| 33 |
|
|
|
|
| 34 |
dynamic_shapes = tree_map(lambda v: None, call.kwargs)
|
| 35 |
dynamic_shapes |= TRANSFORMER_DYNAMIC_SHAPES
|
| 36 |
|
| 37 |
exported = torch.export.export(
|
| 38 |
mod=pipeline.transformer, args=call.args, kwargs=call.kwargs, dynamic_shapes=dynamic_shapes
|
| 39 |
)
|
|
|
|
| 40 |
return spaces.aoti_compile(exported, INDUCTOR_CONFIGS)
|
| 41 |
|
| 42 |
compiled_transformer = f()
|
|
|
|
| 31 |
with spaces.aoti_capture(pipeline.transformer) as call:
|
| 32 |
pipeline(*args, **kwargs)
|
| 33 |
|
| 34 |
+
print("Inputs captured.")
|
| 35 |
dynamic_shapes = tree_map(lambda v: None, call.kwargs)
|
| 36 |
dynamic_shapes |= TRANSFORMER_DYNAMIC_SHAPES
|
| 37 |
|
| 38 |
exported = torch.export.export(
|
| 39 |
mod=pipeline.transformer, args=call.args, kwargs=call.kwargs, dynamic_shapes=dynamic_shapes
|
| 40 |
)
|
| 41 |
+
print("Export done.")
|
| 42 |
return spaces.aoti_compile(exported, INDUCTOR_CONFIGS)
|
| 43 |
|
| 44 |
compiled_transformer = f()
|