Skip to content

Send the generated response when continuing a multimodal partial rollout - #2500

Open
apex-mochen wants to merge 1 commit into
THUDM:mainfrom
apex-mochen:fix/multimodal-partial-rollout-continuation
Open

apex-mochen wants to merge 1 commit into
THUDM:mainfrom
apex-mochen:fix/multimodal-partial-rollout-continuation

Conversation

@apex-mochen

Copy link
Copy Markdown

Problem

With --partial-rollout, a sample aborted mid-generation goes back to the data buffer and is resumed later. generate() resumes it with a max_new_tokens budget reduced by sample.response_length and appends the new tokens after the existing response, so the request must be conditioned on that response.

For samples with images, the request is built as:

payload["image_data"] = [...]
payload["text"] = sample.prompt

sample.prompt does not include the response generated so far, so SGLang starts a fresh response from the prompt. The new tokens are then appended after the old partial response. The resulting trajectory is spliced: its second half was not generated after its first half, and its rollout log probabilities are taken under a different context. generate_streaming() builds the request the same way.

Nothing rejects --partial-rollout with multimodal data, and abort() recycles any aborted group with a non-empty response, including groups with images.

A test that resumes an image sample after one generated token shows it: the request carries text="describe the picture", no input_ids, and max_new_tokens=7 (8 - 1). The generated token is appended as [9, 3, 4].

Fix

Send text only for the first segment (response_length == 0), so SGLang still expands the image placeholders with its own processor rules. A continuation sends input_ids=list(sample.tokens) with the images. sample.tokens holds the prompt and the response so far. This is the form on_policy_distillation.reward_func already sends to SGLang.

I used sample.tokens rather than prompt_ids on purpose. For an image sample without multimodal_train_inputs, _prepare_prompt_ids re-processes the prompt, and the result does not include the response.

Test

tests/test_multimodal_partial_rollout.py runs the real sglang_rollout.generate with post, GenerateState and image encoding mocked:

  • resuming after one generated token sends input_ids == [9, 3], the images, no text, and max_new_tokens == 7;
  • a first segment still sends text and no input_ids.

The first case fails on main (540ea91) and passes with this change.

python -m pytest -q tests/test_multimodal_partial_rollout.py tests/test_score_centering_transport.py tests/test_streaming_rollout.py

CPU only, with this machine's dependencies:

  • main: 20 failed, 46 passed;
  • this change: 19 failed, 47 passed.

The only difference between the two failure lists is the new test. The other 19 fail the same way on both trees because of the environment.

Not covered: I did not run a real SGLang server, and the new test does not cover generate_streaming, which has the same one-line change.

🤖 Generated with Claude Code

With --partial-rollout, an aborted sample is resumed with its accumulated
sample.tokens and a max_new_tokens budget reduced by response_length. For
samples with images, generate() and generate_streaming() still sent only
text=sample.prompt, so SGLang generated a fresh response from the prompt and
the new tokens were appended after the old partial response.

Send text only for the first segment, so SGLang still expands the image
placeholders with its own processor; continuations send sample.tokens with
the images, the form on_policy_distillation already sends to SGLang.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant