Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions end_to_end/tpu/run_wan_fast_inference.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
# v6e seed 777, 17.92 dB / 0.6556 on v6e seed 12345, and
# 17.69 dB / 0.6918 on tpu7x seed 12345 (visually clean).
# USE_FUSED_ROPE_KERNEL=false restores the XLA producer.
# WAN_CROSS_ATTN_KERNEL / WAN_PATCH_EMBED_MODE / WAN_ULYSSES_OUT_A2A
# override Wan fast-inference kernel/layout switches
# DP / CP / PER_DEVICE_BATCH / SEED
# override mesh parallelism, per-device batch, or RNG seed (default 12345)
set -euo pipefail
Expand Down Expand Up @@ -179,6 +181,9 @@ case "$TPU_PROFILE" in
DEFAULT_VAE_CHUNK=1
DEFAULT_VAE_SPATIAL=8
DEFAULT_FUSED_ROPE=true
DEFAULT_CROSS_ATTN_KERNEL=pallas
DEFAULT_PATCH_EMBED_MODE=tokens
DEFAULT_ULYSSES_OUT_A2A=chunked
;;
v7)
PLATFORM_LIBTPU="$V7_LIBTPU"
Expand All @@ -195,6 +200,9 @@ case "$TPU_PROFILE" in
DEFAULT_VAE_CHUNK=1
DEFAULT_VAE_SPATIAL=8
DEFAULT_FUSED_ROPE=true
DEFAULT_CROSS_ATTN_KERNEL=pallas
DEFAULT_PATCH_EMBED_MODE=tokens
DEFAULT_ULYSSES_OUT_A2A=chunked
;;
*)
echo "== warning: unrecognised or non-v6e/v7 accelerator '${ACCEL_TYPE:-unknown}';" \
Expand All @@ -213,6 +221,9 @@ case "$TPU_PROFILE" in
DEFAULT_VAE_CHUNK=1
DEFAULT_VAE_SPATIAL=8
DEFAULT_FUSED_ROPE=false
DEFAULT_CROSS_ATTN_KERNEL=xla
DEFAULT_PATCH_EMBED_MODE=tokens
DEFAULT_ULYSSES_OUT_A2A=flat
;;
esac

Expand Down Expand Up @@ -244,6 +255,9 @@ USE_FUSED_ROPE_KERNEL=${USE_FUSED_ROPE_KERNEL:-$DEFAULT_FUSED_ROPE}
FUSED_ROPE_ARGS=()
[ -n "${FUSED_ROPE_BLOCK_S:-}" ] && FUSED_ROPE_ARGS+=("fused_rope_block_s=$FUSED_ROPE_BLOCK_S")
[ -n "${FUSED_ROPE_HEAD_BLOCK:-}" ] && FUSED_ROPE_ARGS+=("fused_rope_head_block=$FUSED_ROPE_HEAD_BLOCK")
WAN_CROSS_ATTN_KERNEL=${WAN_CROSS_ATTN_KERNEL:-$DEFAULT_CROSS_ATTN_KERNEL}
WAN_PATCH_EMBED_MODE=${WAN_PATCH_EMBED_MODE:-$DEFAULT_PATCH_EMBED_MODE}
WAN_ULYSSES_OUT_A2A=${WAN_ULYSSES_OUT_A2A:-$DEFAULT_ULYSSES_OUT_A2A}

# Mesh: context parallelism carries the Ulysses shards, data parallelism takes
# whatever devices remain. Defaults to CP=4 / DP=2 on an 8-device slice. On a
Expand Down Expand Up @@ -310,6 +324,9 @@ python src/maxdiffusion/generate_wan.py "$CONFIG" \
use_kv_cache=true use_base2_exp=true use_experimental_scheduler=true \
use_fused_rope_kernel="$USE_FUSED_ROPE_KERNEL" \
${FUSED_ROPE_ARGS[@]+"${FUSED_ROPE_ARGS[@]}"} \
wan_cross_attn_kernel="$WAN_CROSS_ATTN_KERNEL" \
wan_patch_embed_mode="$WAN_PATCH_EMBED_MODE" \
wan_ulysses_out_a2a="$WAN_ULYSSES_OUT_A2A" \
fps=16 ${GUIDANCE_ARGS[@]+"${GUIDANCE_ARGS[@]}"} \
seed="${SEED:-12345}" \
flash_block_sizes="$FLASH_BLOCK_SIZES" \
Expand Down
6 changes: 6 additions & 0 deletions end_to_end/tpu/run_wan_stack_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,11 @@ TESTS=(
# Fused RMSNorm+RoPE producer, Wan switches in config (feat/wan-custom-kernels)
"$T/fused_rmsnorm_rope_pallas_test.py"
"$T/wan_runtime_options_test.py"
# Short-KV cross-attention Pallas kernel (feat/wan-cross-attn-pallas)
"$T/cross_attention_pallas_test.py"
# Token-sharded patch embedding (feat/wan-token-patch-embed)
"$T/wan_patch_embed_test.py"
# Shard-major Ulysses output A2A (feat/ulysses-shard-major-a2a)
"$T/ulysses_out_a2a_test.py"
)
PYTHONPATH="src${PYTHONPATH:+:$PYTHONPATH}" exec "${PYTHON:-python3}" -m pytest -q -rs "${TESTS[@]}" "$@"
15 changes: 15 additions & 0 deletions src/maxdiffusion/configs/base_wan_14b.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,21 @@ wan_cfg_before_unpatchify: True
wan_cross_attn_prescale_kv: False
# Fused RoPE accumulation: "auto" (measured per-platform default), "dtype", "f32".
wan_rope_accum: "auto"
# Text cross-attention backend where it would otherwise fall back to XLA dot-product
# (KV shorter than flash_min_seq_length): "xla", or "pallas" for the fused kernel that
# keeps the KV in VMEM (within bf16 rounding of "xla", not bit-identical).
wan_cross_attn_kernel: "xla"
# Patch embedding: "conv" (nnx.Conv; its channel-sharded output is resharded by
# token, an all-gather on tpu7x) or "tokens" (token-sharded patches times the
# replicated kernel, no activation collective; equal up to accumulation order).
wan_patch_embed_mode: "conv"
# Inverse Ulysses all-to-all (attention output, head-sharded -> sequence-sharded):
# "flat" splits the sequence axis directly; "chunked" exchanges over an explicit
# leading sequence-chunk axis so XLA does not relayout the output around the
# collective (and opportunistically uses the Pallas 4D-q / out_num_shards path
# when S_local % block_q == 0); "shard_major" strictly requires the Pallas
# 4D-q / out_num_shards path and raises if any kernel precondition fails.
wan_ulysses_out_a2a: "flat"
# For attention=ulysses_ring, hidden Ulysses shard count; ring shards are context / this.
ulysses_shards: -1
# Splits Ulysses all-to-all into head-group chunks. The last chunk carries any remainder.
Expand Down
15 changes: 15 additions & 0 deletions src/maxdiffusion/configs/base_wan_1_3b.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,21 @@ wan_cfg_before_unpatchify: True
wan_cross_attn_prescale_kv: False
# Fused RoPE accumulation: "auto" (measured per-platform default), "dtype", "f32".
wan_rope_accum: "auto"
# Text cross-attention backend where it would otherwise fall back to XLA dot-product
# (KV shorter than flash_min_seq_length): "xla", or "pallas" for the fused kernel that
# keeps the KV in VMEM (within bf16 rounding of "xla", not bit-identical).
wan_cross_attn_kernel: "xla"
# Patch embedding: "conv" (nnx.Conv; its channel-sharded output is resharded by
# token, an all-gather on tpu7x) or "tokens" (token-sharded patches times the
# replicated kernel, no activation collective; equal up to accumulation order).
wan_patch_embed_mode: "conv"
# Inverse Ulysses all-to-all (attention output, head-sharded -> sequence-sharded):
# "flat" splits the sequence axis directly; "chunked" exchanges over an explicit
# leading sequence-chunk axis so XLA does not relayout the output around the
# collective (and opportunistically uses the Pallas 4D-q / out_num_shards path
# when S_local % block_q == 0); "shard_major" strictly requires the Pallas
# 4D-q / out_num_shards path and raises if any kernel precondition fails.
wan_ulysses_out_a2a: "flat"
# For attention=ulysses_ring, hidden Ulysses shard count; ring shards are context / this.
ulysses_shards: -1
# Splits Ulysses all-to-all into head-group chunks. The last chunk carries any remainder.
Expand Down
15 changes: 15 additions & 0 deletions src/maxdiffusion/configs/base_wan_27b.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,21 @@ wan_cfg_before_unpatchify: True
wan_cross_attn_prescale_kv: False
# Fused RoPE accumulation: "auto" (measured per-platform default), "dtype", "f32".
wan_rope_accum: "auto"
# Text cross-attention backend where it would otherwise fall back to XLA dot-product
# (KV shorter than flash_min_seq_length): "xla", or "pallas" for the fused kernel that
# keeps the KV in VMEM (within bf16 rounding of "xla", not bit-identical).
wan_cross_attn_kernel: "xla"
# Patch embedding: "conv" (nnx.Conv; its channel-sharded output is resharded by
# token, an all-gather on tpu7x) or "tokens" (token-sharded patches times the
# replicated kernel, no activation collective; equal up to accumulation order).
wan_patch_embed_mode: "conv"
# Inverse Ulysses all-to-all (attention output, head-sharded -> sequence-sharded):
# "flat" splits the sequence axis directly; "chunked" exchanges over an explicit
# leading sequence-chunk axis so XLA does not relayout the output around the
# collective (and opportunistically uses the Pallas 4D-q / out_num_shards path
# when S_local % block_q == 0); "shard_major" strictly requires the Pallas
# 4D-q / out_num_shards path and raises if any kernel precondition fails.
wan_ulysses_out_a2a: "flat"
# For attention=ulysses_ring*, hidden Ulysses shard count; ring shards are context / this.
ulysses_shards: -1
# Splits Ulysses all-to-all into head-group chunks. The last chunk carries any remainder.
Expand Down
15 changes: 15 additions & 0 deletions src/maxdiffusion/configs/base_wan_animate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,21 @@ wan_cfg_before_unpatchify: True
wan_cross_attn_prescale_kv: False
# Fused RoPE accumulation: "auto" (measured per-platform default), "dtype", "f32".
wan_rope_accum: "auto"
# Text cross-attention backend where it would otherwise fall back to XLA dot-product
# (KV shorter than flash_min_seq_length): "xla", or "pallas" for the fused kernel that
# keeps the KV in VMEM (within bf16 rounding of "xla", not bit-identical).
wan_cross_attn_kernel: "xla"
# Patch embedding: "conv" (nnx.Conv; its channel-sharded output is resharded by
# token, an all-gather on tpu7x) or "tokens" (token-sharded patches times the
# replicated kernel, no activation collective; equal up to accumulation order).
wan_patch_embed_mode: "conv"
# Inverse Ulysses all-to-all (attention output, head-sharded -> sequence-sharded):
# "flat" splits the sequence axis directly; "chunked" exchanges over an explicit
# leading sequence-chunk axis so XLA does not relayout the output around the
# collective (and opportunistically uses the Pallas 4D-q / out_num_shards path
# when S_local % block_q == 0); "shard_major" strictly requires the Pallas
# 4D-q / out_num_shards path and raises if any kernel precondition fails.
wan_ulysses_out_a2a: "flat"
# For attention=ulysses_ring, hidden Ulysses shard count; ring shards are context / this.
ulysses_shards: -1
# Splits Ulysses all-to-all into head-group chunks. The last chunk carries any remainder.
Expand Down
15 changes: 15 additions & 0 deletions src/maxdiffusion/configs/base_wan_i2v_14b.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,21 @@ wan_cfg_before_unpatchify: True
wan_cross_attn_prescale_kv: False
# Fused RoPE accumulation: "auto" (measured per-platform default), "dtype", "f32".
wan_rope_accum: "auto"
# Text cross-attention backend where it would otherwise fall back to XLA dot-product
# (KV shorter than flash_min_seq_length): "xla", or "pallas" for the fused kernel that
# keeps the KV in VMEM (within bf16 rounding of "xla", not bit-identical).
wan_cross_attn_kernel: "xla"
# Patch embedding: "conv" (nnx.Conv; its channel-sharded output is resharded by
# token, an all-gather on tpu7x) or "tokens" (token-sharded patches times the
# replicated kernel, no activation collective; equal up to accumulation order).
wan_patch_embed_mode: "conv"
# Inverse Ulysses all-to-all (attention output, head-sharded -> sequence-sharded):
# "flat" splits the sequence axis directly; "chunked" exchanges over an explicit
# leading sequence-chunk axis so XLA does not relayout the output around the
# collective (and opportunistically uses the Pallas 4D-q / out_num_shards path
# when S_local % block_q == 0); "shard_major" strictly requires the Pallas
# 4D-q / out_num_shards path and raises if any kernel precondition fails.
wan_ulysses_out_a2a: "flat"
# For attention=ulysses_ring, hidden Ulysses shard count; ring shards are context / this.
ulysses_shards: -1
# Splits Ulysses all-to-all into head-group chunks. The last chunk carries any remainder.
Expand Down
15 changes: 15 additions & 0 deletions src/maxdiffusion/configs/base_wan_i2v_27b.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,21 @@ wan_cfg_before_unpatchify: True
wan_cross_attn_prescale_kv: False
# Fused RoPE accumulation: "auto" (measured per-platform default), "dtype", "f32".
wan_rope_accum: "auto"
# Text cross-attention backend where it would otherwise fall back to XLA dot-product
# (KV shorter than flash_min_seq_length): "xla", or "pallas" for the fused kernel that
# keeps the KV in VMEM (within bf16 rounding of "xla", not bit-identical).
wan_cross_attn_kernel: "xla"
# Patch embedding: "conv" (nnx.Conv; its channel-sharded output is resharded by
# token, an all-gather on tpu7x) or "tokens" (token-sharded patches times the
# replicated kernel, no activation collective; equal up to accumulation order).
wan_patch_embed_mode: "conv"
# Inverse Ulysses all-to-all (attention output, head-sharded -> sequence-sharded):
# "flat" splits the sequence axis directly; "chunked" exchanges over an explicit
# leading sequence-chunk axis so XLA does not relayout the output around the
# collective (and opportunistically uses the Pallas 4D-q / out_num_shards path
# when S_local % block_q == 0); "shard_major" strictly requires the Pallas
# 4D-q / out_num_shards path and raises if any kernel precondition fails.
wan_ulysses_out_a2a: "flat"
# For attention=ulysses_ring, hidden Ulysses shard count; ring shards are context / this.
ulysses_shards: -1
# Splits Ulysses all-to-all into head-group chunks. The last chunk carries any remainder.
Expand Down
Loading
Loading