Repository navigation
Thread MIMO support through the stock training loop (schedule + optimizer) #5333
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
Merged
yashaswikarnati
merged 4 commits into
NVIDIA:main
from
yashaswikarnati:ykarnati/upstream-trainloop-tl-bridge
Jun 16, 2026
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8cbbd1b
training: thread p2p_communicator and schedule pg_collection into tra…
yashaswikarnati 95de128
optimizer: dispatch MimoModel to get_mimo_optimizer; thread pg_collec…
yashaswikarnati bef2ea1
Fix lint formatting for MIMO train loop PR
yashaswikarnati 065c920
test: synchronize dist checkpointing integrity file writes
yashaswikarnati 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
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
21 changes: 21 additions & 0 deletions
21
tests/unit_tests/training/test_setup_model_and_optimizer_mimo.py
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,21 @@ | ||
| # Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||
|
|
||
| """get_megatron_optimizer dispatches a MimoModel to get_mimo_optimizer.""" | ||
|
|
||
| from types import SimpleNamespace | ||
| from unittest import mock | ||
|
|
||
| from megatron.core.models.mimo.model.base import MimoModel | ||
| from megatron.core.optimizer import get_megatron_optimizer | ||
|
|
||
|
|
||
| def test_get_megatron_optimizer_dispatches_mimo_model(): | ||
| # __new__ gives an isinstance-true MimoModel without running its heavy __init__. | ||
| fake_mimo = MimoModel.__new__(MimoModel) | ||
| sentinel = object() | ||
| with mock.patch( | ||
| "megatron.core.models.mimo.optimizer.get_mimo_optimizer", return_value=sentinel | ||
| ) as get_mimo: | ||
| result = get_megatron_optimizer(SimpleNamespace(optimizer="adam"), [fake_mimo]) | ||
| get_mimo.assert_called_once() | ||
| assert result is sentinel |
69 changes: 69 additions & 0 deletions
69
tests/unit_tests/training/test_train_step_schedule_plumbing.py
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,69 @@ | ||
| # Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
|
yashaswikarnati marked this conversation as resolved.
Resolved
|
||
|
|
||
| """train_step forwards p2p_communicator and schedule pg_collection to forward_backward_func.""" | ||
|
|
||
| from types import SimpleNamespace | ||
| from unittest import mock | ||
|
|
||
| from megatron.training import training as training_mod | ||
|
|
||
|
|
||
| class _Rerun: | ||
| """Run the forward/backward body once, then ask train_step to exit before optimizer.step.""" | ||
|
|
||
| _ran = False | ||
|
|
||
| def should_run_forward_backward(self, data_iterator): | ||
| run, self._ran = not self._ran, True | ||
| return run | ||
|
|
||
| def should_checkpoint_and_exit(self): | ||
| return False, True, 0 # (checkpoint, exit, code) | ||
|
|
||
|
|
||
| def _run(**kwargs): | ||
| args = SimpleNamespace( | ||
| save_params_interval=None, | ||
| save_activations_interval=None, | ||
| save_tokens_per_expert_interval=None, | ||
| save_wgrads_interval=None, | ||
| save_dgrads_interval=None, | ||
| reuse_grad_buf_for_mxfp8_param_ag=False, | ||
| overlap_param_gather=False, | ||
| seq_length=8, | ||
| micro_batch_size=1, | ||
| decoder_seq_length=None, | ||
| empty_unused_memory_level=0, | ||
| ) | ||
| captured = {} | ||
| model = [SimpleNamespace(force_all_reduce=False, zero_grad_buffer=lambda: None)] | ||
| with ( | ||
| mock.patch.object(training_mod, "get_args", return_value=args), | ||
| mock.patch.object(training_mod, "get_timers", return_value=mock.MagicMock()), | ||
| mock.patch.object(training_mod, "get_rerun_state_machine", return_value=_Rerun()), | ||
| mock.patch.object(training_mod, "get_num_microbatches", return_value=1), | ||
| mock.patch.object(training_mod, "has_nvidia_modelopt", False), | ||
| ): | ||
| training_mod.train_step( | ||
| forward_step_func=lambda *a, **k: None, | ||
| data_iterator=iter([]), | ||
| model=model, | ||
| optimizer=SimpleNamespace(zero_grad=lambda: None), | ||
| opt_param_scheduler=None, | ||
| config=SimpleNamespace(), | ||
| forward_backward_func=lambda **kw: captured.update(kw) or [], | ||
| iteration=0, | ||
| **kwargs, | ||
| ) | ||
| return captured | ||
|
|
||
|
|
||
| def test_train_step_forwards_schedule_plumbing(): | ||
| p2p, pg = object(), object() | ||
| captured = _run(p2p_communicator=p2p, schedule_pg_collection=pg) | ||
| assert captured["p2p_communicator"] is p2p and captured["pg_collection"] is pg | ||
|
|
||
|
|
||
| def test_train_step_defaults_to_none(): | ||
| captured = _run() | ||
| assert captured["p2p_communicator"] is None and captured["pg_collection"] is None | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why pass in only the first chunk?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for now VPP is not supported yet, added an assert