From 540dc850558a62742e1bce591ea732b6f1898389 Mon Sep 17 00:00:00 2001 From: Deepolar Date: Mon, 23 Nov 2026 23:50:17 -0500 Subject: [PATCH 1/3] fix(wan): add the MagCache keys to the Wan 2.1 1.3B config generate_wan.py passes use_magcache, magcache_thresh, magcache_K and retention_ratio to the Wan 2.1 T2V pipeline on every run, but base_wan_1_3b.yml never got these keys when MagCache support landed (aba5f6a6), so generate_wan.py with this config fails with "Requested key use_magcache, not in config". The keys can't be passed on the command line either, since only keys in the yml can be overridden. Add them with the base_wan_14b.yml values, MagCache off. --- src/maxdiffusion/configs/base_wan_1_3b.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/maxdiffusion/configs/base_wan_1_3b.yml b/src/maxdiffusion/configs/base_wan_1_3b.yml index 97c1317c7..70ae18db6 100644 --- a/src/maxdiffusion/configs/base_wan_1_3b.yml +++ b/src/maxdiffusion/configs/base_wan_1_3b.yml @@ -420,6 +420,11 @@ flow_shift: 3.0 # Diffusion CFG cache (FasterCache-style, WAN 2.1 T2V only) use_cfg_cache: False use_kv_cache: False +# MagCache (WAN 2.1 T2V); generate_wan.py reads these keys on every T2V run. +use_magcache: False +magcache_thresh: 0.12 +magcache_K: 2 +retention_ratio: 0.2 # WAN-VACE training: compute the VACE hints from zero latents at timestep 999, the first inference timestep, # instead of from the noisy latents. This fine-tunes the model for use_vace_cache=True in the VACE pipeline, which # computes the hints once and reuses them at every denoising step. From 56d4bb1d5f9ce31a44328be61afc551da57a26ff Mon Sep 17 00:00:00 2001 From: Deepolar Date: Thu, 26 Nov 2026 02:53:17 -0500 Subject: [PATCH 2/3] fix(wan): add mag_ratios_base to the Wan 2.1 1.3B config Without it, use_magcache=True fails in init_magcache because mag_ratios_base is None, and pyconfig rejects CLI overrides for keys that are not in the YAML. The values are the calibrated T2V-1.3B ratios from the upstream MagCache repository. --- src/maxdiffusion/configs/base_wan_1_3b.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/maxdiffusion/configs/base_wan_1_3b.yml b/src/maxdiffusion/configs/base_wan_1_3b.yml index 70ae18db6..8b5670f81 100644 --- a/src/maxdiffusion/configs/base_wan_1_3b.yml +++ b/src/maxdiffusion/configs/base_wan_1_3b.yml @@ -425,6 +425,7 @@ use_magcache: False magcache_thresh: 0.12 magcache_K: 2 retention_ratio: 0.2 +mag_ratios_base: [1.0, 1.0, 1.0124, 1.02213, 1.00166, 1.0041, 0.99791, 1.00061, 0.99682, 0.99762, 0.99634, 0.99685, 0.99567, 0.99586, 0.99416, 0.99422, 0.99578, 0.99575, 0.9957, 0.99563, 0.99511, 0.99506, 0.99535, 0.99531, 0.99552, 0.99549, 0.99541, 0.99539, 0.9954, 0.99536, 0.99489, 0.99485, 0.99518, 0.99514, 0.99484, 0.99478, 0.99481, 0.99479, 0.99415, 0.99413, 0.99419, 0.99416, 0.99396, 0.99393, 0.99388, 0.99386, 0.99349, 0.99349, 0.99309, 0.99304, 0.9927, 0.9927, 0.99228, 0.99226, 0.99171, 0.9917, 0.99137, 0.99135, 0.99068, 0.99063, 0.99005, 0.99003, 0.98944, 0.98942, 0.98849, 0.98849, 0.98758, 0.98757, 0.98644, 0.98643, 0.98504, 0.98503, 0.9836, 0.98359, 0.98202, 0.98201, 0.97977, 0.97978, 0.97717, 0.97718, 0.9741, 0.97411, 0.97003, 0.97002, 0.96538, 0.96541, 0.9593, 0.95933, 0.95086, 0.95089, 0.94013, 0.94019, 0.92402, 0.92414, 0.90241, 0.9026, 0.86821, 0.86868, 0.81838, 0.81939] # WAN-VACE training: compute the VACE hints from zero latents at timestep 999, the first inference timestep, # instead of from the noisy latents. This fine-tunes the model for use_vace_cache=True in the VACE pipeline, which # computes the hints once and reuses them at every denoising step. From ac48ebc90fa54c0cdf5ef8cc21e578acc3e46724 Mon Sep 17 00:00:00 2001 From: Deepolar Date: Fri, 27 Nov 2026 20:52:44 -0500 Subject: [PATCH 3/3] fix(wan): do not skip blocks before a MagCache residual exists With few denoising steps (e.g. the 2-step compile warmup), skip_warmup = int(steps * retention_ratio) is 0, so magcache_step can decide to skip step 0 before any residual has been cached and the transformer raises "cached_residual must be provided when skip_blocks is True". Force a full forward until a residual exists, as the Wan 2.2 pipeline already does, in both Wan 2.1 pipelines. --- src/maxdiffusion/pipelines/wan/wan_pipeline_2_1.py | 2 ++ src/maxdiffusion/pipelines/wan/wan_pipeline_i2v_2p1.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/maxdiffusion/pipelines/wan/wan_pipeline_2_1.py b/src/maxdiffusion/pipelines/wan/wan_pipeline_2_1.py index b40cddc96..5650b35b8 100644 --- a/src/maxdiffusion/pipelines/wan/wan_pipeline_2_1.py +++ b/src/maxdiffusion/pipelines/wan/wan_pipeline_2_1.py @@ -436,6 +436,8 @@ def scan_body(carry, t): magcache_thresh, magcache_K, skip_warmup, + # Never skip before a residual has been cached (e.g. the 2-step compile warmup). + use_magcache=False if cached_residual is None else None, ) noise_pred, residual_x_cur = transformer_forward_pass( diff --git a/src/maxdiffusion/pipelines/wan/wan_pipeline_i2v_2p1.py b/src/maxdiffusion/pipelines/wan/wan_pipeline_i2v_2p1.py index 3ee802e9d..6e7979c46 100644 --- a/src/maxdiffusion/pipelines/wan/wan_pipeline_i2v_2p1.py +++ b/src/maxdiffusion/pipelines/wan/wan_pipeline_i2v_2p1.py @@ -465,6 +465,8 @@ def scan_body(carry, t): magcache_thresh, magcache_K, skip_warmup, + # Never skip before a residual has been cached (e.g. the 2-step compile warmup). + use_magcache=False if cached_residual is None else None, ) latents_input = latents