Repository navigation
[sft] Count context parallelism in the batch-size check - #2523
Open
dyurk-lila wants to merge 1 commit into
Open
dyurk-lila wants to merge 1 commit into
dyurk-lila wants to merge 1 commit into
Conversation
The non-packing path of SFTTrainer._validate_batch_parallelism computed the Megatron DP size as world / (tp * pp) and left out context parallelism. With CP > 1 it required the batch to be divisible by a number that was too large: 16 GPUs at TP2/CP8 (real DP=1) rejected batch_size=2 with "must be divisible by data-parallel size (8)". Use _dp_size(), which already divides by tp * pp * cp. The per-DP micro-batch check that follows used the same value and is fixed as well. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors the _validate_batch_parallelism method in SFTTrainer to use the internal _dp_size() helper method instead of manually calculating the data-parallel size. This ensures context parallelism is properly accounted for. Unit tests have also been added to verify the validation logic under various parallel configurations. There are no review comments to address, and we have no further feedback to provide.
Contributor
[Medium impact] This PR appears safe to merge. Reviews (1) · Last reviewed commit: "[sft] Count context parallelism in the b..." · Reviewed by Greptile |
This branch was successfully 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.
What
The non-packing path of
SFTTrainer._validate_batch_parallelismcomputed the Megatron DP size astotal_gpus // (tp * pp), which leaves out context parallelism. It now calls the existingself._dp_size(), which divides bytp * pp * cp. The packing path already usesself._dp_size(). Theper_dp_batch/ micro-batch check right after used the same wrong value, so it is fixed too.Why
Megatron's DP size is
world / (tp * pp * cp). With CP > 1, the old check required the batch size to be divisible by a number that was too large. For example, 16 GPUs at TP2/CP8 has a real DP size of 1, butbatch_size=2was rejected:Tests
Added
test_validate_batch_parallelism_counts_context_parallelismtotests/train/sft/test_sft_trainer.py. It is a CPU-only test that builds a bare trainer holding only the config the check reads. It covers:batch_size=2is accepted. On the old code it fails with the error above.batch_size=4is accepted, andbatch_size=2is still rejected with "data-parallel size (4)".pytest tests/train/sft/test_sft_trainer.py: 3 passed.ruff(v0.11.9) andblack(24.10.0) are clean.🤖 Generated with Claude Code
Note
Low Risk
Narrows a startup validation bug for Megatron CP; behavior change only affects configs that were incorrectly rejected before.
Overview
Fixes Megatron SFT startup validation so data-parallel size includes context parallelism, matching Megatron’s real DP group size.
In
_validate_batch_parallelism, the non–sequence-packing Megatron path no longer usestotal_gpus // (tp * pp); it callsself._dp_size()(tp * pp * cp). That same DP value drives theper_dp_batch/ micro-batch divisibility check, so configs with CP > 1 are not rejected with an inflated DP size (e.g.batch_size=2on 16 GPUs at TP2/CP8).Adds a CPU-only test that exercises accept/reject cases for TP/CP combinations.
Reviewed by Cursor Bugbot for commit 5953ecf. Bugbot is set up for automated code reviews on this repo. Configure here.