Add external trainer integration helpers#3813
Merged
Merged
Conversation
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
8 tasks
There was a problem hiding this comment.
Pull request overview
This PR adds low-level, composable integration helpers intended for external training loops (e.g., verl) that want to reuse Megatron-Bridge pieces (provider config, PEFT setup, DDP config, adapter loading) without adopting Bridge’s full training lifecycle.
Changes:
- Added
ModelProviderMixin.configure(...)to apply dtype and model-parallel sizes (from initializedparallel_state), apply caller overrides, run pre-finalize hooks, and finalize the provider. - Added
megatron.bridge.training.integrationwith helper utilities for PEFT creation/hooks, PEFT adapter checkpoint loading, and DDP config construction. - Added unit tests covering the new provider configuration behavior and integration helpers.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/megatron/bridge/models/model_provider.py |
Adds ModelProviderMixin.configure(...) helper for external integration workflows. |
src/megatron/bridge/training/integration.py |
New integration helper module for PEFT/DDP setup and adapter checkpoint loading. |
tests/unit_tests/models/test_model_provider_mixin.py |
Adds unit tests for provider configure(...). |
tests/unit_tests/training/test_integration.py |
Adds unit tests for the new integration helper functions. |
Comments suppressed due to low confidence (1)
src/megatron/bridge/training/integration.py:213
_to_torch_dtype()uses dict indexing, so unsupported dtype inputs raise aKeyError. Since this is a public integration helper, raise aValueError(or similar) with a clear message listing supported dtype encodings instead of leakingKeyError.
def _to_torch_dtype(dtype: torch.dtype | str | int | None) -> torch.dtype | None:
if dtype is None or isinstance(dtype, torch.dtype):
return dtype
return {
16: torch.float16,
"16": torch.float16,
"fp16": torch.float16,
"float16": torch.float16,
32: torch.float32,
"32": torch.float32,
"fp32": torch.float32,
"float32": torch.float32,
"bf16": torch.bfloat16,
"bfloat16": torch.bfloat16,
}[dtype]
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This PR adds small, composable integration helpers for external training loops that use Megatron-Bridge but own their own rollout/trainer/checkpoint scheduling. External frameworks such as verl need Bridge for provider construction, PEFT setup, DDP config construction, adapter loading, and checkpoint path wrappers, but they do not want a full lifecycle setup function. This change keeps the API low-level and additive. - Added ModelProviderMixin.configure(...) to apply dtype, model-parallel sizes from initialized parallel_state, caller overrides, pre-finalize hooks, and finalization in one provider-owned method. - Added megatron.bridge.training.integration with helper functions for: - provider configuration - PEFT object creation - PEFT pre-wrap hook creation - PEFT adapter checkpoint loading - model state dict generation - DDP config construction - explicit-path checkpoint save/load wrappers - post-setup model config finalization - Added unit coverage for provider configuration and the new integration helpers. This is intended to be additive. Existing Bridge training paths continue to use their current setup/checkpoint flows. This PR does not rename or add public aliases for existing private checkpoint helpers. Signed-off-by: Hollow Man <hollowman@opensuse.org>
Signed-off-by: Hollow Man <hollowman@opensuse.org>
Signed-off-by: Hollow Man <hollowman@opensuse.org>
Signed-off-by: Hollow Man <hollowman@opensuse.org>
Signed-off-by: Hollow Man <hollowman@opensuse.org>
Signed-off-by: Hollow Man <hollowman@opensuse.org>
yaoyu-33
approved these changes
May 20, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This is intended to be additive. Existing Bridge training paths continue to use their current setup/checkpoint flows. This PR does not rename or add public aliases for existing private checkpoint helpers.
Check the refactor on verl side
verl-project/verl#6335
What does this PR do ?
This PR adds small, composable integration helpers for external training loops that use Megatron-Bridge but own their own rollout/trainer/checkpoint scheduling. External frameworks such as verl need Bridge for provider construction, PEFT setup, DDP config construction, adapter loading, and checkpoint path wrappers, but they do not want a full lifecycle setup function. This change keeps the API low-level and additive.
Changelog
GitHub Actions CI
See the CI sectionin the Contributing doc for how to trigger the CI. A Nvidia developer will need to approve and trigger the CI for external contributors.
Before your PR is "Ready for review"
Pre checks:
If you haven't finished some of the above items you can still open "Draft" PR.
Additional Information