You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- run_inference_2_2: MagCache skip path with per-phase retention (forced-compute)
zones and an explicit residual reset at the high->low transformer boundary,
driven by a single interleaved mag_ratios_base curve spanning both phases
- generate_wan.py: pass use_magcache / magcache_thresh / magcache_K /
retention_ratio through to the 2.2 pipeline
- base_wan_27b.yml: default flow_shift=12.0 (official A14B sampling shift; sets
the high->low boundary the ratios are aligned to) + MagCache params and the
official mag_ratios_base
- README: document MagCache for Wan2.2 (flow_shift requirement, ~1.82x speedup,
SSIM/PSNR vs dense)
- tests: wan_mag_cache_test.py (host-side validation/schedule/core tests + a
TPU-only end-to-end smoke test)
Copy file name to clipboardExpand all lines: README.md
+16-1Lines changed: 16 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -607,6 +607,13 @@ To generate images, run the following command:
607
607
| --- | --- | --- | --- | --- |
608
608
|**CFG Cache**|`use_cfg_cache: True`| Wan 2.1 T2V, Wan 2.2 T2V/I2V |~1.2x | FasterCache-style: caches the unconditional branch and applies FFT frequency-domain compensation on skipped steps. |
609
609
|**SenCache**|`use_sen_cache: True`| Wan 2.2 T2V/I2V |~1.4x | Sensitivity-Aware Caching ([arXiv:2602.24208](https://arxiv.org/abs/2602.24208)): predicts output change via first-order sensitivity S = α_x·‖Δx‖ + α_t·\|Δt\|. Skips the full CFG forward pass when predicted change is below tolerance ε. |
610
+
|**MagCache**|`use_magcache: True`| Wan 2.1 T2V, Wan 2.2 T2V |~1.8–1.9x |[MagCache](https://github.com/Zehong-Ma/MagCache): skips the transformer blocks and reuses the cached block residual when the accumulated magnitude-ratio error stays below `magcache_thresh`, capped at `magcache_K` consecutive skips. Uses a precalibrated per-step `mag_ratios_base` curve, so the skip schedule is deterministic (no data-dependent control flow). |
611
+
612
+
For Wan 2.2 (dual-transformer), MagCache keeps a single `mag_ratios_base` curve spanning both the high-noise and low-noise phases, forces a full recompute for the first `retention_ratio` fraction of each phase, and resets the cached residual at the high→low boundary. The shipped `mag_ratios_base` in `base_wan_27b.yml` are seeded from the official Wan2.2 values; recalibrating them for your exact setup (model dtype / attention kernel) improves the speedup/quality trade-off.
613
+
614
+
> **Wan 2.2 T2V requires `flow_shift=12.0`** (the official A14B sampling shift; `base_wan_27b.yml` now defaults to it). `flow_shift` controls where the high→low noise boundary lands, which is the boundary the `mag_ratios_base` curve is calibrated against — a lower shift (e.g. the old `5.0`) moves the boundary several steps out of phase, so MagCache skips at the wrong steps and quality drops. This also corrects the off-spec dense baseline.
615
+
616
+
Measured on a v7x (Wan 2.2 A14B T2V, 720×1280, 81 frames, 40 steps, `flow_shift=12.0`, seeded ratios at `magcache_thresh=0.04`, `magcache_K=2`): **~1.82× speedup** (18/40 steps skipped, denoise 360s → 198s) at **SSIM ≈ 0.72 / PSNR ≈ 21.8 dB** versus the dense (`use_magcache=False`) render with the same seed/config. These reference-based metrics mostly reflect *trajectory divergence* — caching nudges the sampler onto a different but equally plausible sample — rather than visible degradation; the cached clips are visually hard to tell apart from dense. Recalibrating `mag_ratios_base` for your exact dtype/attention kernel tightens the metric gap further.
610
617
611
618
To enable a caching mechanism, set the corresponding flag in your config YAML or pass it as a command-line override:
612
619
@@ -622,6 +629,14 @@ To generate images, run the following command:
622
629
src/maxdiffusion/configs/base_wan_i2v_27b.yml \
623
630
use_cfg_cache=True \
624
631
...
632
+
633
+
# Example: enable MagCache for Wan 2.2 T2V
634
+
python src/maxdiffusion/generate_wan.py \
635
+
src/maxdiffusion/configs/base_wan_27b.yml \
636
+
use_magcache=True \
637
+
magcache_thresh=0.04 \
638
+
magcache_K=2 \
639
+
...
625
640
```
626
641
627
642
### Ring Attention
@@ -819,4 +834,4 @@ This script will automatically format your code with `pyink` and help you identi
819
834
The full suite of -end-to end tests is in`tests` and `src/maxdiffusion/tests`. We run them with a nightly cadance.
820
835
821
836
## Profiling
822
-
To learn how to enable ML Diagnostics and XProf profiling for your runs, please see our [ML Diagnostics Guide](docs/profiling.md).
837
+
To learn how to enable ML Diagnostics and XProf profiling for your runs, please see our [ML Diagnostics Guide](docs/profiling.md).
0 commit comments