Skip to content

fix(wan): add the MagCache keys to the Wan 2.1 1.3B config - #527

Open
Deepolar wants to merge 1 commit into
AI-Hypercomputer:mainfrom
Deepolar:fix/wan-1-3b-magcache-config
Open

Deepolar wants to merge 1 commit into
AI-Hypercomputer:mainfrom
Deepolar:fix/wan-1-3b-magcache-config

Conversation

@Deepolar

Copy link
Copy Markdown

Problem

generate_wan.py reads use_magcache, magcache_thresh, magcache_K and retention_ratio for every
Wan 2.1 T2V run. base_wan_1_3b.yml does not define them (MagCache support in aba5f6a added them to
base_wan_14b.yml and base_wan_i2v_14b.yml only), so

python src/maxdiffusion/generate_wan.py src/maxdiffusion/configs/base_wan_1_3b.yml

fails with AttributeError: Requested key use_magcache, not in config. Passing the keys on the command
line does not help, because pyconfig only accepts keys defined in the yml.

Fix

Add the four keys to base_wan_1_3b.yml with the base_wan_14b.yml values, MagCache off.
base_wan_animate.yml also lacks them, but generate_wan_animate.py does not read them.

Testing

With the four keys added, Wan 2.1 T2V 1.3B (480x832, 81 frames, 30 steps) generates on one tpu7x chip.

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
(aba5f6a), 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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the configuration file src/maxdiffusion/configs/base_wan_1_3b.yml to introduce MagCache configuration parameters, including use_magcache, magcache_thresh, magcache_K, and retention_ratio for WAN 2.1 T2V. There are no review comments on this pull request, and I have no feedback to provide.

@entrpn entrpn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch @Deepolar! One missing key before we merge: base_wan_1_3b.yml also needs mag_ratios_base (the 5th key added to base_wan_14b.yml when MagCache landed), otherwise passing use_magcache=True fails in init_magcache with TypeError: len() of unsized object (getattr(config, 'mag_ratios_base', None) is None, and pyconfig rejects CLI overrides for keys absent from the YAML). Left a ready-to-apply suggestion below with the upstream T2V-1.3B calibrated ratios.

use_magcache: False
magcache_thresh: 0.12
magcache_K: 2
retention_ratio: 0.2

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without mag_ratios_base in the YAML, setting use_magcache=True passes mag_ratios_base=None from WanPipeline2_1 into init_magcache (wan_pipeline.py), which raises TypeError: len() of unsized object (and cannot be overridden from the CLI because pyconfig requires keys to exist in the YAML).

Here is the upstream calibrated T2V-1.3B curve from Zehong-Ma/MagCache (MagCache4Wan2.1/magcache_generate.py, matching how base_wan_14b.yml was seeded; init_magcache interpolates the 50-step curve to num_inference_steps: 30 automatically):

Suggested change
retention_ratio: 0.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]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants