Skip to content

fix(wan): port six feature-caching modes to the current infer API - #1715

Open
klin-amd wants to merge 1 commit into
ModelTC:mainfrom
klin-amd:dev/klin/wan-feature-caching-api
Open

klin-amd wants to merge 1 commit into
ModelTC:mainfrom
klin-amd:dev/klin/wan-feature-caching-api

Conversation

@klin-amd

@klin-amd klin-amd commented Nov 14, 2026 •

Copy link
Copy Markdown

Fixes #466, fixes #738.

Problem

Six of the eight Wan feature-caching modes crash on the first DiT step:

TypeError: WanTransformerInfer<Mode>.infer() missing 6 required positional arguments: 'embed', 'x', 'embed0', 'seq_lens', 'freqs', and 'context'

TaylorSeer, Ada, Custom, FirstBlock, DualBlock and DynamicBlock in lightx2v/models/networks/wan/infer/feature_caching/transformer_infer.py still define the old infer(weights, grid_sizes, embed, x, embed0, seq_lens, freqs, context). TaylorSeer, Ada and Custom also call infer_modulation(), which no longer exists, and FirstBlock, DualBlock and DynamicBlock call infer_block() with its old arguments. WanModel now calls transformer_infer.infer(weights, pre_infer_out). Tea and Mag already use the current API and work.

Fix

  • Override infer_main_blocks(blocks, pre_infer_out), as Tea and Mag do.
  • Use the current block API: pre_process() on the self-attention phase's modulation, compute_phases[0..2], and post_process(..., pre_infer_out).
  • Custom reuses super().infer_main_blocks, so it keeps the offload path.
  • FirstBlock, DualBlock and DynamicBlock run block ranges through a shared infer_block_range helper.

The caching decisions are unchanged. Gates use .squeeze() like the base block; with TI2V's per-token timesteps .squeeze(0) would broadcast to the wrong shape.

Test

The Wan2.1 T2V 1.3B config of each mode under configs/caching/, unchanged (480x832, 81 frames, 50 steps, seed 42), one H100, compared with the same config set to NoCaching.

Mode main This PR DiT time (NoCaching ~51.3 s) PSNR vs. NoCaching
Tea runs runs 16.5 s 14.5 dB
Mag runs runs 24.6 s 17.1 dB
TaylorSeer TypeError runs 21.6 s 10.9 dB
Ada TypeError runs 22.1 s 10.5 dB
Custom TypeError runs 15.4 s 11.3 dB
FirstBlock TypeError runs 34.0 s 13.9 dB
DualBlock TypeError runs 51.4 s identical (no step skipped)
DynamicBlock TypeError runs 53.3 s identical (no step skipped)

The setups of the linked issues, same seed, one H100:

Issue Setup main This PR
#466 Wan2.1-I2V-14B-480P, configs/caching/adacache/wan_i2v_ada.json, img_0.jpg, the issue's prompt TypeError (the issue's infer_modulation error on older code) runs; DiT 214.8 s -> 79.5 s vs. NoCaching; PSNR 17.6 dB, no visible artifacts
#738 Wan2.2-TI2V-5B, configs/wan22/wan_ti2v.json + Ada, t2v and i2v TypeError: ...infer() missing 6 required positional arguments runs; DiT 100.5 s -> 46.4 s (t2v), 97.2 s -> 45.6 s (i2v); coherent
#738 same + TaylorSeer same TypeError runs at 480x832, 41 frames; at the official 704x1280, 121 frames it runs out of memory on 80 GB

TaylorSeer's out-of-memory at the official TI2V size and its degraded t2v output at 480x832 come from its cache size and schedule, which this PR does not change; with every step computed it matches NoCaching exactly.

All outputs in the first table are coherent videos. With the shipped thresholds DualBlock skips no step and DynamicBlock no block; with lower thresholds both run their cached branch (DualBlock 0.04: DiT 37.3 s, PSNR 15.8 dB, coherent; DynamicBlock 0.01: 34.0 s, visibly degraded, same skip logic as before). Ada, FirstBlock, DualBlock and DynamicBlock decide from rank-local tensors, so under sequence parallel ranks could in principle decide differently; Ada and FirstBlock ran to completion under Ulysses SP2.

pre-commit run passes on the changed file.

TaylorSeer, Ada, Custom, FirstBlock, DualBlock and DynamicBlock still
defined infer(weights, grid_sizes, embed, x, embed0, seq_lens, freqs,
context) and called infer_modulation(), which no longer exists. WanModel
calls transformer_infer.infer(weights, pre_infer_out), so all six crashed
on the first step with "infer() missing 6 required positional arguments".

Override infer_main_blocks(blocks, pre_infer_out) like the Tea and Mag
modes do, and use the current block API: pre_process() on the
self-attention phase's modulation, compute_phases[0..2], and post_process()
with pre_infer_out. Custom reuses super().infer_main_blocks, so it keeps the
offload path. FirstBlock, DualBlock and DynamicBlock run block ranges
through a shared infer_block_range helper. The Taylor and DynamicBlock
helpers that shadowed infer_block are renamed. The caching decisions and
math are unchanged.

Fixes ModelTC#466
Fixes ModelTC#738

Signed-off-by: Lin, KuanTing <Kuanting.Lin@amd.com>
@klin-amd
klin-amd marked this pull request as ready for review November 15, 2026 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant