Spaces:
Runtime error
Runtime error
use_precompiled = True
Browse files- optimization.py +10 -1
optimization.py
CHANGED
|
@@ -22,6 +22,10 @@ from optimization_utils import ZeroGPUCompiledModel
|
|
| 22 |
|
| 23 |
P = ParamSpec('P')
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
LATENT_FRAMES_DIM = torch.export.Dim('num_latent_frames', min=8, max=81)
|
| 26 |
LATENT_PATCHED_HEIGHT_DIM = torch.export.Dim('latent_patched_height', min=30, max=52)
|
| 27 |
LATENT_PATCHED_WIDTH_DIM = torch.export.Dim('latent_patched_width', min=30, max=52)
|
|
@@ -79,6 +83,7 @@ def optimize_pipeline_(pipeline: Callable[P, Any], *args: P.args, **kwargs: P.kw
|
|
| 79 |
Si ça échoue (format incompatible, etc.), fallback compilation GPU.
|
| 80 |
- Sinon -> compile sur GPU.
|
| 81 |
"""
|
|
|
|
| 82 |
|
| 83 |
@spaces.GPU(duration=1500)
|
| 84 |
def compile_transformer():
|
|
@@ -128,7 +133,7 @@ def optimize_pipeline_(pipeline: Callable[P, Any], *args: P.args, **kwargs: P.kw
|
|
| 128 |
# Quantize text encoder
|
| 129 |
quantize_(pipeline.text_encoder, Int8WeightOnlyConfig())
|
| 130 |
|
| 131 |
-
use_precompiled =
|
| 132 |
precompiled_repo = os.getenv("WAN_PRECOMPILED_REPO", "Fabrice-TIERCELIN/Wan_2.2_compiled")
|
| 133 |
|
| 134 |
compiled_transformer_1 = None
|
|
@@ -147,6 +152,10 @@ def optimize_pipeline_(pipeline: Callable[P, Any], *args: P.args, **kwargs: P.kw
|
|
| 147 |
else:
|
| 148 |
compiled_transformer_1, compiled_transformer_2 = compile_transformer()
|
| 149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
pipeline.transformer.forward = compiled_transformer_1
|
| 151 |
drain_module_parameters(pipeline.transformer)
|
| 152 |
|
|
|
|
| 22 |
|
| 23 |
P = ParamSpec('P')
|
| 24 |
|
| 25 |
+
# Expose compiled models so app.py can offer them for download
|
| 26 |
+
COMPILED_TRANSFORMER_1 = None
|
| 27 |
+
COMPILED_TRANSFORMER_2 = None
|
| 28 |
+
|
| 29 |
LATENT_FRAMES_DIM = torch.export.Dim('num_latent_frames', min=8, max=81)
|
| 30 |
LATENT_PATCHED_HEIGHT_DIM = torch.export.Dim('latent_patched_height', min=30, max=52)
|
| 31 |
LATENT_PATCHED_WIDTH_DIM = torch.export.Dim('latent_patched_width', min=30, max=52)
|
|
|
|
| 83 |
Si ça échoue (format incompatible, etc.), fallback compilation GPU.
|
| 84 |
- Sinon -> compile sur GPU.
|
| 85 |
"""
|
| 86 |
+
global COMPILED_TRANSFORMER_1, COMPILED_TRANSFORMER_2
|
| 87 |
|
| 88 |
@spaces.GPU(duration=1500)
|
| 89 |
def compile_transformer():
|
|
|
|
| 133 |
# Quantize text encoder
|
| 134 |
quantize_(pipeline.text_encoder, Int8WeightOnlyConfig())
|
| 135 |
|
| 136 |
+
use_precompiled = True
|
| 137 |
precompiled_repo = os.getenv("WAN_PRECOMPILED_REPO", "Fabrice-TIERCELIN/Wan_2.2_compiled")
|
| 138 |
|
| 139 |
compiled_transformer_1 = None
|
|
|
|
| 152 |
else:
|
| 153 |
compiled_transformer_1, compiled_transformer_2 = compile_transformer()
|
| 154 |
|
| 155 |
+
# expose for downloads
|
| 156 |
+
COMPILED_TRANSFORMER_1 = compiled_transformer_1
|
| 157 |
+
COMPILED_TRANSFORMER_2 = compiled_transformer_2
|
| 158 |
+
|
| 159 |
pipeline.transformer.forward = compiled_transformer_1
|
| 160 |
drain_module_parameters(pipeline.transformer)
|
| 161 |
|