Skip to content

Wan 2.2 training - #470

Open
Toshi-31 wants to merge 8 commits into
AI-Hypercomputer:mainfrom
Toshi-31:wan-2.2-training
Open

Wan 2.2 training#470
Toshi-31 wants to merge 8 commits into
AI-Hypercomputer:mainfrom
Toshi-31:wan-2.2-training

Conversation

@Toshi-31

@Toshi-31 Toshi-31 commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Title:
Add Wan 2.2 Training Pipeline with Joint Timestep Routing

Description:
This PR introduces full training support for the Wan 2.2 models into MaxDiffusion.

1. Joint Timestep Routing
This implementation utilizes a unified, joint-pipeline training strategy. During each training step, the pipeline dynamically samples a timestep and routes the forward pass to either the high-noise or low-noise transformer based on the configured boundary ratio:

is_high_noise = jax.random.uniform(cond_rng) > config.boundary_ratio
This ensures a seamless and efficient training execution graph without needing separate high/low training loops.

2. Pipeline Inheritance & Code Reuse
The new wan_trainer_2_2.py relies directly on the WanPipeline2_2 class to bootstrap the models and load checkpoints. Because WanPipeline2_2 cleanly inherits from the base WanPipeline, the training loop seamlessly reuses all existing weight conversion and fast-loading logic that was previously established for inference.

3. Native Training Quantization Support
Because the trainer hooks directly into the unified WanPipeline.from_pretrained() (and from_checkpoint()) initialization sequence, quantization is automatically supported out-of-the-box for training. By passing use_qwix_quantization=True (and e.g., quantization="fp8"), the pipeline's innate quantize_transformer() loop executes before handing the model over to the trainer. This seamlessly delivers a quantized transformer straight to the optimizer with zero additional training code overhead. (Note: LoRA remains inference-only).

The loss graphs were plotted for around 260 steps, and show a clear downward trend.

For graphs and other artefacts: https://docs.google.com/document/d/1svzC8cVZxb2XxyypeFcoJig13_1ptu6wYIe5QwnC_Lo/edit?usp=sharing

Step time: Around 39.7 seconds per device.

@Toshi-31
Toshi-31 requested a review from entrpn as a code owner September 1, 2026 10:32

@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 introduces training support for the Wan 2.2 model, including a new trainer (WanTrainer2_2), training script, configuration updates, and import smoke tests. It also switches GCS model downloads to use gcloud storage to prevent SSL segfaults, and optimizes disk usage during shard conversion by deleting shards after processing. The code review identified several critical issues and improvement opportunities: a logical error in the dataset validation check in WanTrainer2_2 where 'and' was used instead of 'or'; a JAX purity violation caused by mutating the input dictionary in-place inside the JIT-compiled train_step_2_2; incorrect evaluation routing for mixed-timestep batches, which should be resolved using jnp.where instead of checking only the first timestep; potential out-of-memory errors from downloading large models to /dev/shm instead of /tmp; performance overhead from recreating a ThreadPoolExecutor inside a loop during shard conversion; and the use of a mutable default argument in training_loop_2_2.

Comment thread src/maxdiffusion/trainers/wan_trainer_2_2.py Outdated
Comment thread src/maxdiffusion/trainers/wan_trainer_2_2.py Outdated
Comment thread src/maxdiffusion/trainers/wan_trainer_2_2.py Outdated
Comment thread src/maxdiffusion/pyconfig.py Outdated
Comment thread src/maxdiffusion/models/wan/wan_utils.py Outdated
Comment thread src/maxdiffusion/trainers/wan_trainer_2_2.py Outdated
Toshi Pahadia added 2 commits September 1, 2026 16:05
@prishajain1

Copy link
Copy Markdown
Collaborator

Can you please add the current timestep in the PR description

Comment thread src/maxdiffusion/configs/base_wan_27b.yml Outdated
Comment thread src/maxdiffusion/trainers/wan_trainer_2_2.py Outdated
Comment thread setup.sh
@prishajain1

Copy link
Copy Markdown
Collaborator

Please add relevant unittests

Comment thread src/maxdiffusion/pyconfig.py Outdated
Comment thread src/maxdiffusion/models/wan/wan_utils.py
Comment thread src/maxdiffusion/trainers/wan_trainer_2_2.py Outdated
@Toshi-31

Toshi-31 commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator Author

Can you please add the current timestep in the PR description

Done!

@Toshi-31

Toshi-31 commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator Author

Please add relevant unittests

Done!

@Toshi-31
Toshi-31 force-pushed the wan-2.2-training branch 2 times, most recently from 5761ff6 to ff2a971 Compare September 2, 2026 11:19
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.

4 participants