[Feature] Add fixed-token prefill scoring (#54335)

Signed-off-by: aoshen02 <aoshen@inferact.ai>
Signed-off-by: aoshen02 <aoshen02@users.noreply.github.com>
Co-authored-by: aoshen02 <aoshen02@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
aoshen02
2026-09-28 07:50:09 -07:00
committed by GitHub
co-authored by aoshen02 Claude Opus 5
parent a7ff44355c
commit b721a4c709
36 changed files with 768 additions and 8 deletions
+3
View File
@@ -236,6 +236,9 @@ class EngineCoreOutput(
# Appended last so `array_like` positional serialization stays compatible.
spec_decode_metrics: RequestSpecDecodeMetrics | None = None
# [num_scored_rows, num_token_ids]; appended last for array_like compatibility.
prompt_token_id_logprobs: torch.Tensor | None = None
@property
def finished(self) -> bool:
return self.finish_reason is not None
+13
View File
@@ -131,6 +131,19 @@ class InputProcessor:
self.structured_outputs_config,
self.tokenizer,
)
if params.prompt_logprob_token_ids is not None:
if not self.vllm_config.use_v2_model_runner:
raise VLLMValidationError(
"prompt_logprob_token_ids requires the V2 model runner "
"(VLLM_USE_V2_MODEL_RUNNER=1).",
parameter="prompt_logprob_token_ids",
)
if self.vllm_config.cache_config.kv_sharing_fast_prefill:
raise VLLMValidationError(
"prompt_logprob_token_ids is incorrect with "
"--kv-sharing-fast-prefill; disable it for scoring.",
parameter="prompt_logprob_token_ids",
)
self.validate_logits_processors_params(params)
+12
View File
@@ -5,6 +5,8 @@ import itertools
from collections.abc import Iterable
from dataclasses import dataclass
import numpy as np
from vllm.logger import init_logger
from vllm.logprobs import (
FlatLogprobs,
@@ -38,6 +40,8 @@ class LogprobsProcessor:
cumulative_logprob: float | None
num_logprobs: int | None
num_prompt_logprobs: int | None
# [num_scored_rows, num_token_ids], set once on the final prefill chunk.
prompt_token_id_logprobs: np.ndarray | None = None
@classmethod
def from_new_request(
@@ -204,6 +208,12 @@ class LogprobsProcessor:
self.prompt_logprobs = []
return plp
def pop_prompt_token_id_logprobs(self) -> np.ndarray | None:
"""Pop and return the fixed-ID prompt scores."""
scores = self.prompt_token_id_logprobs
self.prompt_token_id_logprobs = None
return scores
@staticmethod
def _get_sampled_context_ids(
logprobs_source: SampleLogprobs | PromptLogprobs | None,
@@ -352,3 +362,5 @@ class LogprobsProcessor:
self._update_sample_logprobs(output.new_logprobs)
if output.new_prompt_logprobs_tensors is not None:
self._update_prompt_logprobs(output.new_prompt_logprobs_tensors)
if output.prompt_token_id_logprobs is not None:
self.prompt_token_id_logprobs = output.prompt_token_id_logprobs.numpy()
+5
View File
@@ -390,8 +390,12 @@ class RequestState:
if self.output_kind == RequestOutputKind.DELTA:
# Side effect: logprobs processor forgets prompt logprobs
prompt_logprobs = self.logprobs_processor.pop_prompt_logprobs()
prompt_token_id_logprobs = (
self.logprobs_processor.pop_prompt_token_id_logprobs()
)
else:
prompt_logprobs = self.logprobs_processor.prompt_logprobs
prompt_token_id_logprobs = self.logprobs_processor.prompt_token_id_logprobs
return RequestOutput(
request_id=external_req_id, # request_id is what was provided externally
@@ -399,6 +403,7 @@ class RequestState:
prompt=self.prompt,
prompt_token_ids=prompt_token_ids,
prompt_logprobs=prompt_logprobs,
prompt_token_id_logprobs=prompt_token_id_logprobs,
outputs=cast(list[CompletionOutput], outputs),
finished=finished,
kv_transfer_params=kv_transfer_params,