[RL][Frontend] Return token-level weight-version spans on final outputs (#59582)

Signed-off-by: Shuolei Wang <shuoleiwang123@gmail.com>
Signed-off-by: Shuolei Wang <948904026@qq.com>
Co-authored-by: aoshen02 <aoshen@inferact.ai>
This commit is contained in:
Shuolei Wang
2026-10-11 11:33:29 +08:00
committed by GitHub
co-authored by aoshen02
parent 3c062d391d
commit b89852aad0
14 changed files with 169 additions and 28 deletions
+3
View File
@@ -282,6 +282,9 @@ class EngineCoreOutputs(
# "old" wave, so the next wave needs to be started in other engines.
start_wave: int | None = None
# Weight version used for this step.
weight_version: str | None = None
def __post_init__(self):
if self.timestamp == 0.0:
self.timestamp = time.monotonic()
+4 -1
View File
@@ -855,7 +855,10 @@ class AsyncLLM(EngineClient):
outputs_slice = engine_core_outputs[start:end]
# 2) Process EngineCoreOutputs.
processed_outputs = output_processor.process_outputs(
outputs_slice, outputs.timestamp, iteration_stats
outputs_slice,
outputs.timestamp,
iteration_stats,
weight_version=outputs.weight_version,
)
# NOTE: RequestOutputs are pushed to their queues.
assert not processed_outputs.request_outputs
+7
View File
@@ -639,6 +639,11 @@ class EngineCore:
else:
eco.scheduler_stats.iteration_details = iteration_details
def _attach_weight_version(self, outputs: dict[int, EngineCoreOutputs]) -> None:
# Weight versions change only while generation is paused.
for eco in outputs.values():
eco.weight_version = self._weight_version
def _should_throttle_prefills(self) -> bool:
"""Whether to defer new prefills this step (DP prefill balancing).
Overridden by the DP engine core; never throttles otherwise."""
@@ -672,6 +677,7 @@ class EngineCore:
scheduler_output, model_output
)
self._attach_iteration_details(engine_core_outputs, iteration_details)
self._attach_weight_version(engine_core_outputs)
return engine_core_outputs, scheduler_output.total_num_scheduled_tokens > 0
@@ -773,6 +779,7 @@ class EngineCore:
scheduler_output, model_output
)
self._attach_iteration_details(engine_core_outputs, iteration_details)
self._attach_weight_version(engine_core_outputs)
# NOTE(nick): We can either handle the deferred tasks here or save
# in a field and do it immediately once step_with_batch_queue is
+1
View File
@@ -335,6 +335,7 @@ class LLMEngine:
outputs.outputs,
engine_core_timestamp=outputs.timestamp,
iteration_stats=iteration_stats,
weight_version=outputs.weight_version,
)
mm_processor_cache = self.renderer.mm_processor_cache
+23
View File
@@ -19,6 +19,7 @@ from vllm.outputs import (
RequestError,
RequestOutput,
SamplingMask,
WeightVersionSpan,
)
from vllm.sampling_params import RequestOutputKind
from vllm.tokenizers import TokenizerLike
@@ -190,6 +191,8 @@ class RequestState:
# Routed experts accumulation (prompt + sample chunks)
self.routed_experts_chunks: list[np.ndarray] = []
self.sampling_mask_chunks: list[SamplingMaskLists] = []
# (weight version, first output-token index) for each span.
self.weight_version_starts: list[tuple[str, int]] = []
# Stream Interval
self.stream_interval = stream_interval
@@ -471,8 +474,25 @@ class RequestState:
finish_reason=str(finish_reason) if finished else None,
stop_reason=stop_reason if finished else None,
spec_decode_metrics=self.spec_decode_metrics if finished else None,
weight_versions=self._weight_version_spans() if finished else None,
)
def track_weight_version(self, weight_version: str) -> None:
"""Start a span when the weight version changes."""
assert self.detokenizer is not None
starts = self.weight_version_starts
if not starts or starts[-1][0] != weight_version:
starts.append((weight_version, self.detokenizer.num_output_tokens()))
def _weight_version_spans(self) -> list[WeightVersionSpan] | None:
assert self.detokenizer is not None
num_tokens = self.detokenizer.num_output_tokens()
starts = self.weight_version_starts
if not starts and num_tokens:
return None # No label was reported for these tokens.
ends = [start for _, start in starts[1:]] + [num_tokens]
return [WeightVersionSpan(v, s, e) for (v, s), e in zip(starts, ends)]
def _new_pooling_output(self, pooling_output: torch.Tensor) -> PoolingOutput:
return PoolingOutput(data=pooling_output)
@@ -659,6 +679,7 @@ class OutputProcessor:
engine_core_outputs: list[EngineCoreOutput],
engine_core_timestamp: float | None = None,
iteration_stats: IterationStats | None = None,
weight_version: str | None = None,
) -> OutputProcessorOutput:
"""Process the EngineCoreOutputs:
1) Compute stats for logging
@@ -736,6 +757,8 @@ class OutputProcessor:
if pooling_output is None:
assert req_state.detokenizer is not None
assert req_state.logprobs_processor is not None
if new_token_ids and weight_version is not None:
req_state.track_weight_version(weight_version)
# 2) Detokenize the token ids into text and perform stop checks.
num_prev_tokens = req_state.detokenizer.num_output_tokens()
stop_string = req_state.detokenizer.update(