Skip to content

Commit add2d8d

Browse files
committed
feat(wan): fast serving with persistent AOT caching and tuned inference recipe
Delivers production-grade fast serving for Wan 2.2 T2V-A14B on Cloud TPU: - Persistent AOT Compilation Caching with source hash and static graphdef metadata - AOT signatures key non-static Python scalars by type, so guidance values share one executable - Shared Wan 2.2 warmup for T2V and I2V: compile both experts without executing them, bounded in-flight steps - Tuned Serving Recipe: Production launcher with platform-specific v6e and v7 profiles - Clean Key-Centering & 4-Operand Kernel (mk, q, k, v) without VMEM register pressure - Merged Pre-A2A Norm Reduction (pmax) removing ring all_gather relayout barrier - Hoisted scalar-prefetch metadata in _lse_scan eliminating collective-permute stalls - Lossless 6D unpatchify transpose optimization (collapsing p_t=1 to avoid 8D stride copies)
1 parent 94dbf51 commit add2d8d

25 files changed

Lines changed: 2156 additions & 309 deletions

‎end_to_end/tpu/run_wan_fast_inference.sh‎

Lines changed: 223 additions & 42 deletions
Large diffs are not rendered by default.

‎src/maxdiffusion/aot_cache.py‎

Lines changed: 283 additions & 75 deletions
Large diffs are not rendered by default.

‎src/maxdiffusion/configs/base_wan_14b.yml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@ svg_low_noise_density: -1.0
101101
# compute blocks and the sparse kernel for small ones. Must stay a dict so the
102102
# command line can override it with JSON.
103103
svg_flash_block_sizes: {}
104-
attention: 'flash' # Supported attention: dot_product, flash, tokamax_flash, cudnn_flash_te, ring, tokamax_ring, ulysses, ulysses_custom, ulysses_ring
104+
attention: 'flash' # Supported attention: dot_product, flash, tokamax_flash, cudnn_flash_te, ring, tokamax_ring, tokamax_ring_custom, ulysses, ulysses_custom, ulysses_custom_fixed_m, ulysses_custom_fixed_m_per_q_block, ulysses_ring, ulysses_ring_custom, ulysses_ring_custom_fixed_m, ulysses_ring_custom_fixed_m_per_q_block, ulysses_ring_custom_bidir
105105

106106
use_base2_exp: True
107107
use_experimental_scheduler: True
108+
use_k_centering: "auto" # auto: on for non-ring ulysses_custom_fixed_m* (free, virtual), off for ring paths (pmean + HBM copy)
108109
# For attention=ulysses_ring, hidden Ulysses shard count; ring shards are context / this.
109110
ulysses_shards: -1
110111
# Splits Ulysses all-to-all into head-group chunks. The last chunk carries any remainder.
@@ -309,6 +310,8 @@ dataset_config_name: ''
309310
jax_cache_dir: ''
310311
# Directory for per-shape AOT serialized executables ('' = disabled).
311312
aot_cache_dir: ''
313+
aot_build_revision: ''
314+
wan_debug_cond_timers: False
312315
# Directory for memoized torch->flax converted weights ('' = disabled).
313316
converted_weights_dir: ''
314317
hf_data_dir: ''

‎src/maxdiffusion/configs/base_wan_1_3b.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ dataset_config_name: ''
262262
jax_cache_dir: ''
263263
# Directory for per-shape AOT serialized executables ('' = disabled).
264264
aot_cache_dir: ''
265+
aot_build_revision: ''
266+
wan_debug_cond_timers: False
265267
# Directory for memoized torch->flax converted weights ('' = disabled).
266268
converted_weights_dir: ''
267269
hf_data_dir: ''

‎src/maxdiffusion/configs/base_wan_27b.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ use_base2_exp: True
127127
use_experimental_scheduler: True
128128
# auto: on for non-ring ulysses_custom_fixed_m* (virtual, no copy), off for ring
129129
# paths (materialized K - mean: an HBM copy, plus a pmean when R>1).
130-
# Note: the Wan pipelines do not pass this key to the attention layer yet, so
131-
# the layer's default ("auto") applies.
132130
use_k_centering: "auto"
133131
# For attention=ulysses_ring*, hidden Ulysses shard count; ring shards are context / this.
134132
ulysses_shards: -1
@@ -302,6 +300,8 @@ dataset_config_name: ''
302300
jax_cache_dir: ''
303301
# Directory for per-shape AOT serialized executables ('' = disabled).
304302
aot_cache_dir: ''
303+
aot_build_revision: ''
304+
wan_debug_cond_timers: False
305305
# Directory for memoized torch->flax converted weights ('' = disabled).
306306
converted_weights_dir: ''
307307
hf_data_dir: ''

‎src/maxdiffusion/configs/base_wan_animate.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ jit_initializers: True
8181
# Set true to load weights from pytorch
8282
from_pt: True
8383
split_head_dim: True
84-
attention: 'flash' # Supported attention: dot_product, flash, tokamax_flash, cudnn_flash_te, ring, tokamax_ring, ulysses, ulysses_custom, ulysses_ring
84+
attention: 'flash' # Supported attention: dot_product, flash, tokamax_flash, cudnn_flash_te, ring, tokamax_ring, ulysses, ulysses_custom, ulysses_custom_fixed_m, ulysses_custom_fixed_m_per_q_block, ulysses_ring, ulysses_ring_custom, ulysses_ring_custom_fixed_m, ulysses_ring_custom_fixed_m_per_q_block
8585
use_base2_exp: True
8686
use_experimental_scheduler: True
8787
# For attention=ulysses_ring, hidden Ulysses shard count; ring shards are context / this.
@@ -253,6 +253,8 @@ dataset_config_name: ''
253253
jax_cache_dir: '.jax_cache'
254254
# Directory for per-shape AOT serialized executables ('' = disabled).
255255
aot_cache_dir: ''
256+
aot_build_revision: ''
257+
wan_debug_cond_timers: False
256258
# Directory for memoized torch->flax converted weights ('' = disabled).
257259
converted_weights_dir: ''
258260
hf_data_dir: ''

‎src/maxdiffusion/configs/base_wan_i2v_14b.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jit_initializers: True
8383
# Set true to load weights from pytorch
8484
from_pt: True
8585
split_head_dim: True
86-
attention: 'flash' # Supported attention: dot_product, flash, tokamax_flash, cudnn_flash_te, ring, tokamax_ring, ulysses, ulysses_custom, ulysses_ring
86+
attention: 'flash' # Supported attention: dot_product, flash, tokamax_flash, cudnn_flash_te, ring, tokamax_ring, ulysses, ulysses_custom, ulysses_custom_fixed_m, ulysses_custom_fixed_m_per_q_block, ulysses_ring, ulysses_ring_custom, ulysses_ring_custom_fixed_m, ulysses_ring_custom_fixed_m_per_q_block
8787
use_base2_exp: True
8888
use_experimental_scheduler: True
8989
# For attention=ulysses_ring, hidden Ulysses shard count; ring shards are context / this.
@@ -256,6 +256,8 @@ dataset_config_name: ''
256256
jax_cache_dir: ''
257257
# Directory for per-shape AOT serialized executables ('' = disabled).
258258
aot_cache_dir: ''
259+
aot_build_revision: ''
260+
wan_debug_cond_timers: False
259261
# Directory for memoized torch->flax converted weights ('' = disabled).
260262
converted_weights_dir: ''
261263
hf_data_dir: ''

‎src/maxdiffusion/configs/base_wan_i2v_27b.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jit_initializers: True
8383
# Set true to load weights from pytorch
8484
from_pt: True
8585
split_head_dim: True
86-
attention: 'flash' # Supported attention: dot_product, flash, tokamax_flash, cudnn_flash_te, ring, tokamax_ring, ulysses, ulysses_custom, ulysses_ring
86+
attention: 'flash' # Supported attention: dot_product, flash, tokamax_flash, cudnn_flash_te, ring, tokamax_ring, ulysses, ulysses_custom, ulysses_custom_fixed_m, ulysses_custom_fixed_m_per_q_block, ulysses_ring, ulysses_ring_custom, ulysses_ring_custom_fixed_m, ulysses_ring_custom_fixed_m_per_q_block
8787
use_base2_exp: True
8888
use_experimental_scheduler: True
8989
# For attention=ulysses_ring, hidden Ulysses shard count; ring shards are context / this.
@@ -257,6 +257,8 @@ dataset_config_name: ''
257257
jax_cache_dir: ''
258258
# Directory for per-shape AOT serialized executables ('' = disabled).
259259
aot_cache_dir: ''
260+
aot_build_revision: ''
261+
wan_debug_cond_timers: False
260262
# Directory for memoized torch->flax converted weights ('' = disabled).
261263
converted_weights_dir: ''
262264
hf_data_dir: ''

0 commit comments

Comments
 (0)