[trainer, data] fix: do not drop_last SFT validation batches - #7467
Open
YeonwooSung wants to merge 1 commit into
Open
[trainer, data] fix: do not drop_last SFT validation batches#7467YeonwooSung wants to merge 1 commit into
YeonwooSung wants to merge 1 commit into
Conversation
Fixes verl-project#7464 Co-authored-by: Grok <grok@x.ai> Signed-off-by: YeonwooSung <neos960518@gmail.com>
YeonwooSung
requested review from
PeterSH6,
eric-haibin-lin,
tongyx361 and
vermouth1992
as code owners
August 19, 2026 02:04
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 does this PR do?
Fixes #7464.
Both SFT trainers built the validation loader with
train_batch_sizeanddrop_last=True. A val set smaller than that batch (default 256 on Ray SFT) produced zero val batches. The trainer then didtorch.mean(torch.tensor([]))and loggedval/loss = NaNwith exit code 0.The config comment said
micro_batch_size_per_gpuwas also the val batch size, but that field was never used for val. PPO already usesdrop_last=Falseand a dedicated val batch size.This PR:
data.val_batch_size>data.micro_batch_size_per_gpu>len(val_dataset).drop_last=Falseon the val sampler and dataloader.val/losswhen no val batches exist (SPMD path still all-reduces counts so ranks stay aligned).data.val_batch_sizetosft_trainer_engine.yaml.Not a duplicate of #7401 (epoch-boundary resume) or #467 / #6319 (train-loss NaN).
Checklist Before Starting
[{modules}] {type}: {description}(This will be checked by the CI)Test
The helper was also executed via a direct module load on this machine (no
torch/rayin the login Python). Ruff passed on the touched files.API and Usage Example
# optional explicit val batch; otherwise micro_batch_size_per_gpu (default 4) is used data.val_batch_size=8 data.val_files=/path/to/val.parquetA 200-sample val set with
train_batch_size=256now runs validation instead of logging NaN.Design & Code Changes
resolve_sft_val_batch_size()lives inverl/trainer/sft_val_utils.pyso both the SPMD and Ray SFT trainers share one rule without importing each other.Checklist Before Submitting
pre-commit install && pre-commit run --all-files --show-diff-on-failure --color=alwaysci-requestchannel in theverlSlack workspace.recipesubmodule, please also update the reference to the submodule commit viagit submodule update --remoteorcd recipe && git pull origin main.AI assistance was used to locate the bug and draft the patch. A human author reviewed every changed line.