vllm.distributed.kv_transfer.kv_connector.v1.decode_bench_connector
¶
DecodeBenchConnector: A KV Connector for decode instance performance testing.
This connector emulates a prefill-decode disaggregated setting by filling the KV cache with dummy values, allowing measurement of decoder performance under larger input sequence lengths (ISL) in resource-limited environments.
Usage
To use this connector for benchmarking, configure it in the kv_transfer_config:
Example
vllm serve
Then run your benchmark with desired input/output lengths:
vllm bench serve --base-url http://127.0.0.1:8000 --model <model> \
--dataset-name random --random-input-len 40000 \
--random-output-len 100 --max-concurrency 10
Configuration options (via kv_connector_extra_config):
- fill_mean (float): Mean value for random normal fill (default: 0.015)
- fill_std (float): Standard deviation for random fill (default: 0.0)
Set to 0 for constant values, >0 for random sampling
- startup_fill (bool): Fill the whole KV cache once at startup instead
of filling each new request's blocks in the step that schedules it
(default: False). Circular-buffer caches are still zeroed per
request, and attention caches whose new blocks the engine zeroes
before use (hybrid Mamba or mixed-precision KV caches) are still
filled per request. The fill is not redone after sleep mode
discards the KV cache.
The dummy KV cache is only meant for performance measurement; outputs are
not meaningful for accuracy evaluation.
Classes:
-
DecodeBenchConnector–A KV Connector for decode instance performance testing.
-
DecodeBenchConnectorMetadata–Metadata for DecodeBenchConnector.
-
DecodeBenchConnectorScheduler–Scheduler-side implementation for DecodeBenchConnector.
-
DecodeBenchConnectorWorker–Worker-side implementation for DecodeBenchConnector.
DecodeBenchConnector
¶
Bases: KVConnectorBase_V1, SupportsHMA
A KV Connector for decode instance performance testing.
This connector fills the KV cache with dummy values to emulate a prefill-decode disaggregated setting, enabling performance testing of the decoder with larger input sequence lengths.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/decode_bench_connector.py
138 139 140 141 142 143 144 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 | |
DecodeBenchConnectorMetadata
dataclass
¶
Bases: KVConnectorMetadata
Metadata for DecodeBenchConnector.
Contains information about which requests need their KV cache filled with dummy values for benchmarking purposes.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/decode_bench_connector.py
DecodeBenchConnectorScheduler
¶
Scheduler-side implementation for DecodeBenchConnector.
Methods:
-
build_connector_meta–Build metadata containing information about which blocks to fill
-
get_num_new_matched_tokens–For new requests, return the number of tokens that should be filled
-
request_finished–Called when a request has finished. Clean up any state.
-
update_state_after_alloc–Called after blocks are allocated. Store the block IDs so we can
Source code in vllm/distributed/kv_transfer/kv_connector/v1/decode_bench_connector.py
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 | |
build_connector_meta(scheduler_output)
¶
Build metadata containing information about which blocks to fill with dummy KV values.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/decode_bench_connector.py
get_num_new_matched_tokens(request, num_computed_tokens)
¶
For new requests, return the number of tokens that should be filled with dummy KV cache values.
Returns:
-
int–(num_tokens_to_fill, is_async)
-
bool–- num_tokens_to_fill: number of uncomputed tokens minus 1 (we fill everything except the last token for decode)
-
tuple[int, bool]–- is_async: False (synchronous filling)
Source code in vllm/distributed/kv_transfer/kv_connector/v1/decode_bench_connector.py
request_finished(request)
¶
Called when a request has finished. Clean up any state.
update_state_after_alloc(request, blocks, num_external_tokens)
¶
Called after blocks are allocated. Store the block IDs so we can fill them with dummy values.
Supports both single- and multi-group KV cache configurations.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/decode_bench_connector.py
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 | |
DecodeBenchConnectorWorker
¶
Worker-side implementation for DecodeBenchConnector.
Methods:
-
register_kv_caches–Store references to the KV cache tensors.
-
start_fill_kv–Fill the allocated KV cache blocks with dummy values.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/decode_bench_connector.py
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 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 | |
_fill_all_kv_caches()
¶
Fill the KV cache tensors of the startup-filled groups once, in place, with dummy values, so that no per-request fill is needed.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/decode_bench_connector.py
_fill_block_tensor(kv_cache, block_ids, fill_mean, fill_std, fill_dtype)
¶
Fill the requested block rows of a block-indexed KV cache tensor.
Parameters:
-
(kv_cache¶Tensor) –A KV cache tensor whose first dim is num_blocks.
-
(block_ids¶list[int]) –Block IDs to fill. IDs that are out of range for this tensor's first dim are ignored.
-
(fill_mean¶float) –Mean value for the fill.
-
(fill_std¶float) –Standard deviation for the fill.
-
(fill_dtype¶dtype) –Dtype the values are encoded as, e.g. the fp8 dtype of a uint8 fp8 cache.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/decode_bench_connector.py
_fill_blocks(group_idx, block_ids, num_tokens)
¶
Fill specified blocks with dummy values for a specific KV cache group.
Parameters:
-
(group_idx¶int) –The KV cache group index to fill
-
(block_ids¶list[int]) –List of block IDs to fill in this group
-
(num_tokens¶int) –Total number of tokens to fill across these blocks
Source code in vllm/distributed/kv_transfer/kv_connector/v1/decode_bench_connector.py
_fill_tensor(kv_cache, fill_mean, fill_std, fill_dtype)
¶
Fill an entire tensor in place with dummy values.
Used for startup fills, and for hybrid / linear-attention layers (e.g. Mamba, Kimi Delta Attention) whose per-layer state tensors are filled in their entirety with the same constant or random values used for block fills, rather than selected block rows.
Parameters:
-
(kv_cache¶Tensor) –A tensor to fill in its entirety.
-
(fill_mean¶float) –Mean value for the fill.
-
(fill_std¶float) –Standard deviation for the fill.
-
(fill_dtype¶dtype) –Dtype the values are encoded as, e.g. the fp8 dtype of a uint8 fp8 cache.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/decode_bench_connector.py
_make_fill_values(size, device, dtype, fill_mean, fill_std)
¶
Create constant or random fill values of dtype, clamped to its
finite range. Non-floating dtypes (packed layouts) are filled with
zeros.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/decode_bench_connector.py
register_kv_caches(kv_caches)
¶
Store references to the KV cache tensors.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/decode_bench_connector.py
start_fill_kv(metadata)
¶
Fill the allocated KV cache blocks with dummy values.
This simulates having a populated KV cache from a prefill phase, allowing decode performance testing with larger context sizes.
Supports both single- and multi-group KV cache configurations.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/decode_bench_connector.py
_get_fp8_dtype(spec, cache_dtype)
¶
The fp8 dtype of a KV cache that stores plain fp8 values as uint8.
Returns None for other layouts, including packed ones that embed scales or other metadata in the uint8 page.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/decode_bench_connector.py
_get_startup_fill_group_ids(kv_cache_config)
¶
KV cache groups that startup fill covers.
Circular buffers are zero-filled per request. Attention groups whose new blocks the engine zeroes before use are filled per request, since the zeroing would wipe the startup fill.