Repository navigation
[model] fix: Preserve distributed context during export - #5696
Merged
Merged
Conversation
Signed-off-by: Yu Yao <yaoyu.094@gmail.com>
Contributor
Author
|
/ok to test 6bf4f9d |
Contributor
|
LGTM The export_ckpt fix correctly reuses caller-owned distributed state via nullcontext() when dist.is_initialized(), avoiding a re-init crash. This matches the identical pattern already used in import_ckpt (line 1468) and export_adapter_ckpt (line 1695), so the three conversion entry points are now consistent. The new test_export_ckpt_preserves_existing_distributed_context test exercises the caller-owned path and tears the process group down in a finally. Suggested test cases
|
This branch was previously deployed
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.
Summary
AutoBridge.export_ckptSupported trigger and impact
AutoBridge.export_ckptis a documented one-call export API. If a supported in-process caller already owns the default process group, export unconditionally tries to create another default group and fails before checkpoint loading or Hugging Face saving with:The focused validated case is world-size-one Gloo, which the downstream CPU checkpoint load path supports. This PR does not claim new multi-rank export topology support.
Root cause and fix
export_ckptalways enteredtemporary_distributed_context, even though adjacentimport_ckptandload_megatron_modelpaths reuse caller-owned distributed state. The fix selectsnullcontext()when distributed is already initialized and otherwise keeps the existing temporary Gloo context.Regression evidence
A deterministic private reproducer AST-loaded the exact production definitions and used real PyTorch Gloo while mocking only checkpoint load/save and MCore initialization beyond the failing boundary:
ValueErrorbefore load/save.The committed unit test encodes the caller-owned-state contract with a real world-size-one Gloo group. Local collection of the full test module was blocked before test execution by unrelated CPU optional-package imports that require CUDA; the exact-source reproducer above was used for local runtime evidence.
Validation
Passed:
No dependency, public signature, CI workflow, checkpoint-format, or multi-rank behavior changes are included.