-
Notifications
You must be signed in to change notification settings - Fork 91
Wan 2.2 training #470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Toshi-31
wants to merge
8
commits into
AI-Hypercomputer:main
Choose a base branch
from
Toshi-31:wan-2.2-training
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Wan 2.2 training #470
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1648e07
Merge pull request #454 from richaguptaa17:fix-lazy-module-import
Google-ML-Automation aefa0f0
Implement Wan 2.2 training pipeline with joint timestep routing
863e091
Merge remote-tracking branch 'origin/main' into wan-2.2-training
2f45b41
Address code-assist bot review comments
9c44794
Fix ruff linting errors (unused imports and trailing whitespaces)
0524c2e
Move VAE sharding overrides to a dedicated training config (training_…
80b0c3b
Add initialization and tflops smoke tests for WanTrainer2_2
4ffe7dc
Revert local debugging changes to docker and setup scripts
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| """ | ||
| Copyright 2025 Google LLC | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| https://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| """ | ||
|
|
||
| import os | ||
| import unittest | ||
| from absl.testing import absltest | ||
| from maxdiffusion import pyconfig | ||
| from maxdiffusion.trainers.wan_trainer_2_2 import WanTrainer2_2 | ||
|
|
||
| IN_GITHUB_ACTIONS = os.getenv("GITHUB_ACTIONS") == "true" | ||
| THIS_DIR = os.path.dirname(os.path.abspath(__file__)) | ||
|
|
||
| class WanTrainer22Test(unittest.TestCase): | ||
|
|
||
| def test_wan_trainer_2_2_initialization(self): | ||
| """Smoke test to ensure WanTrainer2_2 can be initialized with config.""" | ||
| pyconfig.initialize([ | ||
| None, | ||
| os.path.join(THIS_DIR, "..", "..", "configs", "base_wan_27b.yml"), | ||
| "max_train_steps=10", | ||
| "per_device_batch_size=1", | ||
| "dataset_type=synthetic", | ||
| "cache_latents_text_encoder_outputs=True", | ||
| ], unittest=True) | ||
|
|
||
| config = pyconfig.config | ||
| trainer = WanTrainer2_2(config) | ||
| self.assertIsNotNone(trainer) | ||
| # Check that checkpointer is created | ||
| checkpointer = trainer._get_checkpointer() | ||
| self.assertIsNotNone(checkpointer) | ||
|
|
||
|
|
||
| def test_calculate_tflops(self): | ||
| from unittest.mock import MagicMock | ||
| pyconfig.initialize([ | ||
| None, | ||
| os.path.join(THIS_DIR, "..", "..", "configs", "base_wan_27b.yml"), | ||
| "max_train_steps=10", | ||
| "per_device_batch_size=1", | ||
| ], unittest=True) | ||
|
|
||
| trainer = WanTrainer2_2(pyconfig.config) | ||
|
|
||
| mock_pipeline = MagicMock() | ||
| mock_pipeline.config.height = 256 | ||
| mock_pipeline.config.width = 256 | ||
| mock_pipeline.config.num_frames = 1 | ||
| mock_pipeline.vae_scale_factor_temporal = 4 | ||
| mock_pipeline.config.per_device_batch_size = 1 | ||
|
|
||
| mock_transformer_config = MagicMock() | ||
| mock_transformer_config.num_layers = 2 | ||
| mock_transformer_config.num_attention_heads = 4 | ||
| mock_transformer_config.attention_head_dim = 64 | ||
| mock_transformer_config.ffn_dim = 256 | ||
|
|
||
| mock_pipeline.low_noise_transformer.config = mock_transformer_config | ||
|
|
||
| train_tflops, total_attn_flops, seq_len = trainer.calculate_tflops(mock_pipeline) | ||
|
|
||
| self.assertIsNotNone(train_tflops) | ||
| self.assertIsNotNone(total_attn_flops) | ||
| self.assertIsNotNone(seq_len) | ||
| self.assertGreater(train_tflops, 0.0) | ||
|
|
||
| if __name__ == "__main__": | ||
| absltest.main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| """ | ||
| Copyright 2025 Google LLC | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| https://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| """ | ||
|
|
||
| from typing import Sequence | ||
|
|
||
| import jax | ||
| from absl import app | ||
| from maxdiffusion import max_logging, pyconfig, max_utils | ||
| from maxdiffusion.train_utils import ( | ||
| validate_train_config, | ||
| transformer_engine_context, | ||
| ) | ||
| import flax | ||
|
|
||
|
|
||
| def train(config): | ||
| from maxdiffusion.trainers.wan_trainer_2_2 import WanTrainer2_2 | ||
|
|
||
| trainer = WanTrainer2_2(config) | ||
| trainer.start_training() | ||
|
|
||
|
|
||
| def main(argv: Sequence[str]) -> None: | ||
| pyconfig.initialize(argv, validate_training=True) | ||
| config = pyconfig.config | ||
| max_utils.ensure_machinelearning_job_runs(pyconfig.config) | ||
| validate_train_config(config) | ||
| max_logging.log(f"Found {jax.device_count()} devices.") | ||
| try: | ||
| flax.config.update("flax_always_shard_variable", False) | ||
| except LookupError: | ||
| pass | ||
| train(config) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| with transformer_engine_context(): | ||
| app.run(main) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.