Repository navigation
Commit bc11953
committed
feat(wan): fast serving with persistent AOT caching and tuned inference recipe
Persistent per-shape AOT executable cache, converted-weights cache and a
tuned launcher for Wan inference on TPU.
User-visible changes
- AOT caching is opt-in. By default `generate_wan.run()` installs no cache
directory and every call is plain jax.jit. When `aot_cache_dir` is set, the
source revision must be reusable (`get_git_commit_hash()` or an explicit
clean `aot_build_revision`, combined with the package content hash); a dirty
or unversioned tree downgrades to an ephemeral temp dir rather than writing or
reading stale persistent executables. `enable_zero_execution_warmup: True`
(False in all 6 Wan ymls) uses an ephemeral temp dir that is removed in a
`try/finally` block.
- `aot_cache_dir` must be a local filesystem path (`gs://` URLs raise
`ValueError`), and `purge_compiled_cache` refuses symlink targets that resolve
outside the cache root.
- `_prune_stale_generations` prunes `.aotx` files from older fingerprint
generations beyond `_DEFAULT_KEEP_GENERATIONS = 3`.
- Converted-weights cache format is v3. Format v2 manifests whose
`legacy_source_fingerprint` matches are migrated in place to v3 via
`_migrate_manifest_header`; older or mismatched manifests are rejected and
re-converted once. `try_load_converted_weights` validates leaf keys, shapes,
and dtypes against `eval_shapes`.
AOT cache (aot_cache.py, generate_wan.py)
- Signatures key non-static Python scalars by type (jit traces them), so e.g.
guidance values share one executable; statics are keyed by value; nnx
GraphDef statics get a process-deterministic digest.
- Metadata fingerprint covers model/attention/tiles/mesh/VAE/dtype/remat/
cache options, device kind, process count, jax/jaxlib/libtpu/flax/qwix/
tokamax versions, matmul precision, PRNG impl, x64, threefry,
LIBTPU_INIT_ARGS and XLA_FLAGS, plus the source revision.
- Multi-host: per-host `-p{idx}` .aotx files.
- `_align_inputs` raises on a leaf-count mismatch instead of truncating.
- The .aotx pickle envelope is loaded with an exact (module, name) allowlist.
Warmup & Denoise helpers (wan_denoise_utils.py)
- When aot_cache is in warmup mode, `compile_experts` compiles both experts'
forward passes without executing them. Without an installed cache, warmup is
an ordinary 2-step run.
- `InflightWindow` bounds queued denoise steps (`MAXD_QUEUE_MAX_INFLIGHT`,
default 4, validated `>= 1`), shared by T2V and I2V.
Other
- Unpatchify: when p_t == 1, reshape/transpose through a 7D tensor instead of
8D (same result; avoids an 8D strided copy).
- `use_k_centering` is plumbed from the Wan config to the attention layer;
`use_k_centering`, `aot_build_revision`, and `enable_zero_execution_warmup`
added to the Wan ymls.
- Dot-product attention: float32_qk_product uses preferred_element_type=f32
on the QK einsum instead of upcasting Q/K (memory-efficient path unchanged).
- Video export is atomic (temp file + os.replace), process-0 only, and shared
by `run()` and `inference_generate_video`; trainers print SSIM on process 0.
- Launcher (`end_to_end/tpu/run_wan_fast_inference.sh`): platform-detected v6e
/ v7 profiles, generic profile for everything else; derives `TPU_DEVICES`
only for per-chip families (`v5litepod | v5e | v6e | v7* | tpu7*`) and exits
with an error for other families unless `DP` and `CP` are set explicitly;
DVFS pin is opt-in (`PIN_DVFS_P_STATE`).
Performance, measured with this PR at the top of the stack (without #488-#491;
Wan 2.2 T2V-A14B, 720p/81f/40 steps, CP=4, DP=2, warm AOT, launcher defaults):
v6e-8: generate 140.1s, denoise 137.0s
tpu7x-8: generate 115.5s, denoise 112.8s (DVFS unpinned)
generate 102.0s, denoise 99.4s (`PIN_DVFS_P_STATE=true`)
Tests
- aot_cache_test.py and converted_weights_cache_test.py: restricted-unpickler
allowlist, dirty-tree ephemeral downgrade and symlink-escape purge guards,
stale-generation pruning, float32_qk_product keeping bf16 QK operands,
v2-to-v3 manifest migration and fail-closed mismatched/fingerprint-less
manifests, leaf dtype validation, disk-space checks, warm start before the
network, revision captured through HF symlinks, and distinct fingerprints for
subfolders with identical index files.
- wan/wan_warmup_coverage_test.py (28): all tests run unconditionally in GitHub
Actions; wan/wan_transformer_test.py adds `FlaxWanAttention` k-centering
parity and dispatch tests.1 parent ef5f36b commit bc11953
29 files changed
Lines changed: 3201 additions & 356 deletions
File tree
- end_to_end/tpu
- src/maxdiffusion
- configs
- models
- wan
- transformers
- pipelines/wan
- tests
- wan
- trainers
- utils
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
40 | 45 | | |
41 | 46 | | |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| 108 | + | |
108 | 109 | | |
109 | 110 | | |
110 | 111 | | |
| |||
309 | 310 | | |
310 | 311 | | |
311 | 312 | | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
312 | 319 | | |
313 | 320 | | |
314 | 321 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
105 | 106 | | |
106 | 107 | | |
107 | 108 | | |
| |||
262 | 263 | | |
263 | 264 | | |
264 | 265 | | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
265 | 272 | | |
266 | 273 | | |
267 | 274 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
132 | | - | |
133 | | - | |
134 | 132 | | |
135 | 133 | | |
136 | 134 | | |
| |||
304 | 302 | | |
305 | 303 | | |
306 | 304 | | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
307 | 311 | | |
308 | 312 | | |
309 | 313 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
| 84 | + | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
| |||
253 | 254 | | |
254 | 255 | | |
255 | 256 | | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
256 | 263 | | |
257 | 264 | | |
258 | 265 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
| 86 | + | |
87 | 87 | | |
88 | 88 | | |
| 89 | + | |
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
| |||
256 | 257 | | |
257 | 258 | | |
258 | 259 | | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
259 | 266 | | |
260 | 267 | | |
261 | 268 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
| 86 | + | |
87 | 87 | | |
88 | 88 | | |
| 89 | + | |
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
| |||
257 | 258 | | |
258 | 259 | | |
259 | 260 | | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
260 | 267 | | |
261 | 268 | | |
262 | 269 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | 22 | | |
24 | 23 | | |
25 | 24 | | |
| |||
149 | 148 | | |
150 | 149 | | |
151 | 150 | | |
152 | | - | |
| 151 | + | |
153 | 152 | | |
154 | 153 | | |
155 | 154 | | |
| |||
161 | 160 | | |
162 | 161 | | |
163 | 162 | | |
164 | | - | |
165 | | - | |
166 | | - | |
| 163 | + | |
167 | 164 | | |
168 | 165 | | |
169 | 166 | | |
| |||
0 commit comments