vllm.entrypoints.generate.generative_scoring.serving
¶
Generative Scoring implementation for generative models.
This module implements generative scoring functionality that computes the probability of specified token IDs appearing as the next token after a given query+item prompt. This works on any generative model that produces logits (task="generate").
Classes:
-
GenerativeScoringItemResult–Result for a single item in the generative scoring response.
-
GenerativeScoringRequest–Request for computing generative scoring.
-
GenerativeScoringResponse–Response from the generative scoring computation.
-
ServingGenerativeScoring–Serving class for generative scoring computation.
GenerativeScoringItemResult
¶
GenerativeScoringRequest
¶
Bases: OpenAIBaseModel
Request for computing generative scoring.
Attributes:
-
model(str | None) –The model to use for scoring. Optional, follows existing patterns.
-
query(str | list[int]) –The query text or pre-tokenized query token IDs.
-
items(list[str] | list[list[int]]) –The item text(s) or pre-tokenized item token IDs.
-
label_token_ids(list[int]) –List of token IDs to compute probabilities for.
-
apply_softmax(bool) –Whether to normalize probabilities using softmax over only the label_token_ids (True) or return true model probabilities over the full vocab for those ids (False).
-
item_first(bool) –If True, prepend items to query. Otherwise append items to query.
-
add_special_tokens(bool) –Whether to add special tokens when tokenizing.
-
cache_salt(str | None) –Optional salt for prefix caching.
GenerativeScoringResponse
¶
Bases: OpenAIBaseModel
Response from the generative scoring computation.
Attributes:
-
id(str) –Unique identifier for this response.
-
object(Literal['list']) –Type of object, always "list".
-
created(int) –Unix timestamp of when the response was created.
-
model(str) –The model used for scoring.
-
data(list[GenerativeScoringItemResult]) –List of scoring results, one per input item.
-
usage(UsageInfo) –Token usage information.
ServingGenerativeScoring
¶
Bases: BaseServing
Serving class for generative scoring computation.
This class handles computing the probability of specified token IDs appearing as the next token after concatenating query and item prompts.
The key operation is: 1. For each item, build a prompt: query + item (or item + query if item_first) 2. Run a forward pass to get the next token distribution 3. Extract probabilities for the specified label_token_ids 4. Normalize either over the full vocab (apply_softmax=False) or over just the label_token_ids (apply_softmax=True)
Methods:
-
create_generative_scoring–Create generative scoring for the given request.
_build_prompts(request, tokenizer, max_model_len)
async
¶
Build prompts by concatenating query and items.
Uses the Renderer's tokenizer to tokenize text inputs, then creates EngineInput via tokens_input() for engine consumption.
Parameters:
-
(request¶GenerativeScoringRequest) –The request containing query, items, and settings.
-
(tokenizer¶TokenizerLike) –The tokenizer to use.
-
(max_model_len¶int) –Maximum model context length for truncation.
Returns:
-
tuple[list[EngineInput], list[int]]–Tuple of (list of EngineInput, list of prompt token counts).
_compute_probabilities(label_logprobs, apply_softmax)
¶
create_generative_scoring(request, raw_request=None)
async
¶
Create generative scoring for the given request.
Parameters:
-
(request¶GenerativeScoringRequest) –The GenerativeScoringRequest containing query, items, and label_token_ids.
-
(raw_request¶Request | None, default:None) –The raw FastAPI request object.
Returns:
-
GenerativeScoringResponse | ErrorResponse–GenerativeScoringResponse with probabilities for each item, or
-
GenerativeScoringResponse | ErrorResponse–ErrorResponse if an error occurred.