vllm.entrypoints.openai.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").
GenerativeScoringItemResult ¶
Bases: OpenAIBaseModel
Result for a single item in the generative scoring response.
Attributes:
| Name | Type | Description |
|---|---|---|
index | int | The index of this item in the input items list. |
object | Literal['score'] | Type of object, always "score". |
score | float | The probability score for the first label token. |
Source code in vllm/entrypoints/openai/generative_scoring/serving.py
GenerativeScoringRequest ¶
Bases: OpenAIBaseModel
Request for computing generative scoring.
Attributes:
| Name | Type | Description |
|---|---|---|
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. |
Source code in vllm/entrypoints/openai/generative_scoring/serving.py
GenerativeScoringResponse ¶
Bases: OpenAIBaseModel
Response from the generative scoring computation.
Attributes:
| Name | Type | Description |
|---|---|---|
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. |
Source code in vllm/entrypoints/openai/generative_scoring/serving.py
OpenAIServingGenerativeScoring ¶
Bases: OpenAIServing
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)
Source code in vllm/entrypoints/openai/generative_scoring/serving.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 | |
_build_prompts async ¶
_build_prompts(
request: GenerativeScoringRequest,
tokenizer: TokenizerLike,
max_model_len: int,
) -> tuple[list[EngineInput], list[int]]
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:
| Name | Type | Description | Default |
|---|---|---|---|
request | GenerativeScoringRequest | The request containing query, items, and settings. | required |
tokenizer | TokenizerLike | The tokenizer to use. | required |
max_model_len | int | Maximum model context length for truncation. | required |
Returns:
| Type | Description |
|---|---|
tuple[list[EngineInput], list[int]] | Tuple of (list of EngineInput, list of prompt token counts). |
Source code in vllm/entrypoints/openai/generative_scoring/serving.py
_compute_probabilities ¶
Compute probabilities from logprobs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label_logprobs | dict[int, float] | Dictionary mapping token_id to logprob. | required |
apply_softmax | bool | If True, normalize over only the label tokens. If False, return true model probabilities (exp(logprob)). | required |
Returns:
| Type | Description |
|---|---|
dict[int, float] | Dictionary mapping token_id to probability. |
Source code in vllm/entrypoints/openai/generative_scoring/serving.py
_get_trace_headers async ¶
Extract trace headers from request headers.
Source code in vllm/entrypoints/openai/generative_scoring/serving.py
create_generative_scoring async ¶
create_generative_scoring(
request: GenerativeScoringRequest,
raw_request: Request | None = None,
) -> GenerativeScoringResponse | ErrorResponse
Create generative scoring for the given request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request | GenerativeScoringRequest | The GenerativeScoringRequest containing query, items, and label_token_ids. | required |
raw_request | Request | None | The raw FastAPI request object. | None |
Returns:
| Type | Description |
|---|---|
GenerativeScoringResponse | ErrorResponse | GenerativeScoringResponse with probabilities for each item, or |
GenerativeScoringResponse | ErrorResponse | ErrorResponse if an error occurred. |
Source code in vllm/entrypoints/openai/generative_scoring/serving.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | |