fix(megatron): synchronize complete accumulation windows - #2146
Draft
bvolpato wants to merge 1 commit into
Draft
Conversation
Signed-off-by: bvolpato <brunocvcunha@gmail.com>
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.
Megatron gradient overlap can reduce an incomplete optimizer window when the number of microbatches changes. SkyRL defers
finalize_model_gradsuntiloptim_step, but DDP backward hooks can still dispatch earlier. The pinned Megatron implementation learns the first window's ready counts: after a two-microbatch window, a one-microbatch window can fail withCommunication call has not been issued, while a three-microbatch window can dispatch before its final backward.This holds DDP synchronization disabled throughout each training schedule, including multiple
forward_backwardrequests in one optimizer window, and explicitly starts asynchronous reductions atoptim_step. Schedule callbacks are temporarily cleared so nested schedule contexts cannot re-enable the hooks; callbacks and DDP state are restored on exceptions. Forward-only execution is unchanged.Related to #2008; this addresses the overlap-enabled accumulation path.
Reproduction and validation
CPU tests cover changing request sizes, shared model configuration, callback restoration, exceptions, and synchronous reduction ownership:
The GPU regression has not run on this host, which has no GPUs. Keeping this draft pending distributed validation.
Downsides
Reductions still use the asynchronous DDP path, but they start after all backward calls in the optimizer window. This gives up backward/communication overlap for correctness. Restoring that overlap needs an explicit final-request boundary in the accumulation API.
Risk and rollback
This changes Megatron training synchronization timing, including Tinker accumulation. The GPU parity test is the remaining validation gate. If distributed parity fails, keep
overlap_grad_reduce=falseand revert the change before continuing training.