Fix vLLM server-mode generation in OnlineDPOTrainer#6228
Merged
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
8 tasks
Collaborator
|
thanks! checking |
kashif
approved these changes
Jul 2, 2026
Collaborator
|
great catch! |
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.
Fixes #5514
Background
OnlineDPOTrainergenerates 2 completions per prompt to form a preference pair, and everything downstream (reward computation,rewards.split(batch_size), the chosen/rejected split) assumes a block layout: the first half of the batch is one completion per prompt, the second half the other (promptiat rowsiandi+N). The colocate and transformers generation paths both produce exactly this layout.Unlike GRPO, Online DPO does not duplicate prompts in the batch (no
RepeatSampler).The vLLM server path (
_generate_vllm_server) was copy-pasted from GRPO and never adapted to these semantics. As a result it has been broken since the feature was introduced in #3783: it ran without crashing but trained on meaningless data.The bugs
Three compounding issues in
_generate_vllm_server:Double-flatten (OnlineDPOTrainer._generate_vllm_server() flattens vllm-serve completion_ids twice #5514).
VLLMClient.generate(...)["completion_ids"]already returnslist[list[int]](one token-id list per completion), but the trainer re-flattened it, turning every token into its own single-token completion.Wrong prompt subsampling.
all_prompts[::self.num_generations]de-duplicates prompts (correct for GRPO, itsRepeatSamplerduplicates them), but it silently drops half the batch in Online DPO, where prompts are unique.Interleaved vs block ordering. The server returns completions interleaved (grouped by prompt), and the trainer built
prompt_idsinterleaved to match. But the loss splits the batch in half (rewards.split(batch_size)), which assumes block order. Preference pairs were therefore formed across different prompts.Bug 1 masked bug 2: flattening produced enough single-token entries to fill the per-process slice, so the count happened to line up and nothing crashed. Removing only the flatten (the minimal fix proposed in the issue) instead surfaces a crash at
torch.cat((prompt_ids, completion_ids)).Verification
Real
OnlineDPOTrainerrun in vLLM server mode on 2 GPUs,Qwen/Qwen2-0.5B-Instruct, a length reward, batch size 2:Note
The existing
test_train_with_vllm_servernever caught this: it is@pytest.mark.slow, requires an external running server, and only asserts"train_loss" in log_history(which passes even on garbage data). A stronger server-mode test that checks completion shape and pairing would be a good follow-up.Note
Medium Risk
Touches the experimental Online DPO training loop and reward pairing semantics; incorrect layout would silently train on wrong preferences, but the change aligns server mode with existing colocate/Transformers behavior.
Overview
Fixes vLLM server-mode generation in
OnlineDPOTrainerso preference pairs match the same block batch layout used by colocate and Transformers paths (rewards.split(batch_size)pairs rowiwith rowi+N)._generate_vllm_serverno longer de-duplicates gathered prompts withall_prompts[::num_generations](GRPO-style; Online DPO keeps unique prompts). It callsVLLMClient.generatewith the fullall_promptslist and drops the extra flatten that turned each completion token into a fake one-token completion.After the per-process slice, completions are reordered from server interleaved order to block order via
completion_ids[0::2] + completion_ids[1::2], andprompt_idsare built in the same layout (duplicate the tokenized prompt list once instead of interleaving per row).Reviewed by Cursor Bugbot for commit 96d543d. Bugbot is set up for automated code reviews on this repo. Configure here.