verl icon indicating copy to clipboard operation
verl copied to clipboard

[RFC] Selected-token rollout log probabilities for the reward

Open eteluna opened this issue 3 months ago • 5 comments

Companion to #7712 (actor-side selected_token_logprobs + auxiliary objectives). This RFC covers the rollout side: letting the reward function see the policy's probability mass on specific tokens, not only the token it sampled.

Draft implementation on my fork: https://github.com/eteluna/verl/pull/2 (about 2.2k lines: ~900 source, ~1.2k tests, ~100 docs).

Motivation

A growing class of RL tasks scores the distribution rather than the sample. Generative rankers and judges emit their answer through a handful of tokens (a yes/no relevance judgement as in Qwen3-Reranker, or per-item rating digits), and the reward wants P(yes) or the expected rating at those positions: a soft, calibrated signal instead of an argmax that throws the confidence away. Today verl only exposes the sampled token's logprob (rollout_log_probs), so users either re-run a forward pass in the reward or patch the rollout adapter (we maintain such a patch).

vLLM already computes this cheaply: SamplingParams.logprob_token_ids returns the logprobs of up to 128 explicit token IDs per decode step without enabling top-k capture. The missing piece is a first-class, typed way to request it and get it to the reward.

Proposal

actor_rollout_ref:
  rollout:
    selected_token_logprobs:
      token_ids: [9454, 2753]   # e.g. "yes", "no"
      positions: null           # every response position, or e.g. [0, 3, 7]
      max_payload_bytes_per_sample: 4194304
  • Dense by default. positions: null keeps every response position. Many selectors are token-dependent ("the digit after each colon"), so the reward resolves them from the response_ids carried in the payload. A position list is an optimisation for the fixed-format case.
  • Mode follows the engine. Values are whatever rollout.logprobs_mode produces (processed_logprobs by default, i.e. after temperature and other processors) and the mode in force is recorded in the payload. The feature does not flip the engine-global mode, so rollout_log_probs, rollout correction and bypass mode are unaffected.
  • Typed transport. SelectedTokenLogprobs (token_ids, response_ids, int32 positions [P], float32 logprobs [P, M], logprobs_mode, backend provenance) on TokenOutput and AgentLoopOutput. The single-turn loop re-aligns it to the truncated response (strict prefix check, missing rows are errors, short responses give a present-but-empty payload).
  • Reward handoff only. Copied into the streaming reward call as extra_info["selected_token_logprobs"]; excluded from as_dict() and rollout traces; never enters the actor batch. Actor-side needs are served by #7712, which recomputes the columns from the training forward pass and therefore does not need the rollout values.
  • Fail closed. Per-sample byte cap checked at config time from response_length; hard errors for unsupported combinations (below).

Scope of the first revision

Supported: vLLM, single-turn agent loop, streaming reward workers, calculate_log_probs on or off, any logprobs_mode, rollout correction.

Rejected with explicit errors, to be lifted in follow-ups: multi-turn/tool loops, custom agent-loop registries or managers, FullyAsync partial resume, speculative decoding, prefill/decode disaggregation, structured outputs, colocated reward, the built-in discriminative reward path, SGLang.

Cost

Per decode step vLLM gathers M extra columns from the already computed logprob tensor (no top-k). The transported payload is P × M float32 plus P int32 per sample, e.g. 80 KB for a 4k response and 5 tokens; the cap makes any larger configuration an explicit decision.

PR split

  1. Payload type, config, vLLM adapter, single-turn alignment, reward handoff, docs, CPU tests (the draft above).
  2. SGLang adapter (needs its equivalent of logprob_token_ids).
  3. Multi-turn / tool agent loop alignment (per-turn segments).

Questions for maintainers

  1. Is extra_info["selected_token_logprobs"] the right handoff key, or should rollout-produced evidence live under a reserved namespace (e.g. extra_info["verl_rollout"]) to avoid collisions with dataset fields?
  2. Dense-by-default vs. mandatory positions: dense is simpler for users and bounded by the byte cap; is there a reason to prefer mandatory positions?
  3. Should the payload also be offered on the v1 (TransferQueue) path in this revision, or is v0 + streaming reward the right first target?

eteluna avatar Sep 04 '26 03:09 eteluna

cc @vermouth1992 @zhtmike @wuxibin89 — rollout-side companion of #7712; same token-ID contract, independent code path. Happy to adjust the handoff key / dense default per your preference before the PR leaves draft.

eteluna avatar Sep 04 '26 03:09 eteluna

Update: verl-genrank now implements this downstream without changes to verl. verl-project/verl-genrank#4 subclasses vLLMHttpServer and vLLMReplica at e42d6af6. Its generate override cannot call super().generate(), because upstream keeps only the sampled token's log probability from each row and drops the requested columns. The override therefore repeats the server's admission bookkeeping and reads private state (_submission_paused, _resume_event, _admitting) so that selected-token requests stay out during weight swaps. SHA-256 fingerprints of workers/rollout/replica.py and workers/rollout/vllm_rollout/vllm_async_server.py detect changes to these files, but they are not a supported interface.

In review, @yueyiming2009 suggested an upstream change smaller than this RFC that would let the downstream code stop overriding generate: two documented hooks in the existing vLLM generation path. They could be two public methods on vLLMHttpServer with no-op defaults that a subclass overrides. No registry is needed, because vLLMReplica.server_class already selects the server class.

  1. prepare_sampling_params(self, prompt_ids, sampling_params) -> dict: called in generate after upstream fills its defaults, before SamplingParams is built and before the admission gate. It returns the parameters to use (for selected-token scores, it adds logprob_token_ids). An exception fails the request before admission.
  2. finalize_output(self, output, final_res) -> TokenOutput: called for every finished request, including aborted ones with empty outputs, after upstream builds the TokenOutput and before it is returned. It returns the output to send (for verl-genrank, the evidence in extra_fields and log_probs read from the same rows). An exception fails the request; the admission counter has already been released at that point.

Admission, pause/resume, cancellation cleanup and weight-sync coordination stay inside upstream generate; the hooks neither see nor change them. Ranking-specific logic (which IDs to request, validation, the evidence format) stays in verl-genrank.

Migration: once the hooks exist and an integration test exercises them, verl-genrank removes its generate override and the fingerprint check; the exact dependency pins stay for reproducibility.

@vermouth1992 @wuxibin89 would you accept these two hooks as a smaller first step? If so, I can open a PR with the hooks and a test.

eteluna avatar Sep 27 '26 22:09 eteluna

@eteluna The hook based proposal looks good to me. As a reference, you can check how verl-omni override vLLMHttpServer to support diffusion models:

  • https://github.com/verl-project/verl-omni/blob/main/verl_omni/workers/rollout/vllm_rollout/vllm_omni_async_server.py#L53
  • https://github.com/verl-project/verl-omni/blob/main/verl_omni/workers/rollout/replica.py#L41

wuxibin89 avatar Sep 29 '26 05:09 wuxibin89

Thanks @wuxibin89 for the pointers! I'll follow the existing "Hook methods for subclass overrides" section of vLLMHttpServer: underscore methods whose defaults keep today's behavior. Planned hooks, named like _preprocess_engine_kwargs (exact signatures in the PR):

  • _preprocess_sampling_params(self, sampling_params: dict) -> None: called in generate after the upstream defaults are filled, before SamplingParams is built and before the request is admitted.
  • _postprocess_output(self, output: TokenOutput, final_res: RequestOutput) -> TokenOutput: called before generate returns, including for aborted requests. The PR will include CPU tests showing that a subclass can request logprob_token_ids and attach the results to extra_fields without overriding generate.

One question on registration: verl-omni registers a separate rollout name (vllm_omni), while verl-genrank replaces the vllm loader so that upstream workers that dispatch on rollout.name keep working. Is a separate name the preferred pattern, and does the trainer support a non-vllm name for weight sync and checkpointing?

eteluna avatar Sep 30 '26 18:09 eteluna

Hello @wuxibin89 , I opened #8082 with the two hooks, _preprocess_sampling_params and _postprocess_output. One change from the plan above: _postprocess_output also receives the built SamplingParams, so a subclass can read what it requested (for example logprob_token_ids) when it builds the output.

eteluna avatar Sep 30 '26 18:09 eteluna