Repository navigation
[training] fix: Clean up failed pretrain sessions - #5013
Merged
yaoyu-33 merged 1 commit intoJul 22, 2026
Merged
Conversation
Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
Contributor
Author
|
/ok to test 4af184b |
Contributor
|
LGTM Clean, well-scoped change that adds failure cleanup to _pretrain without altering the success path. Control flow is correct across all three ownership scenarios:
Minor notes (non-blocking):
Suggested test cases:
No perf tests impacted. |
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.
Problem
When the public
pretrain()path initializes distributed and Megatron global state, an exception from setup, training, evaluation, checkpoint finalization, or a documented callback bypasses the success-only cleanup. If the caller catches that exception, the framework-created default process group and Megatron globals remain live, so a retry can reuse stale state, report an already-initialized group, leak resources, or hang.Caller-created process groups are not affected by this ownership bug.
Root cause
_finish_train()and_maybe_destroy_process_group()ran only after the full pretrain body completed successfully. The ordinary exception path had no corresponding cleanup, while the in-process-restart path has separate NVRx lifecycle ownership.Fix
Validation
Fail before the production fix:
The same deterministic one-rank Gloo reproducer also failed on the unmodified base because the framework-owned real process group remained initialized, then passed with the fix.
Pass after the fix and expanded regression coverage:
Adjacent lifecycle tests:
Static checks:
Scope
This changes only exceptional cleanup for ordinary
pretrain()execution. Successful cleanup behavior, caller-owned process groups, and NVRx-managed in-process restart cleanup remain unchanged. No full-suite, convergence, performance, or multi-rank training claim is made.