vllm.distributed.kv_transfer.kv_connector.v1.mooncake.store.data ¶
Data classes for MooncakeStoreConnector.
Classes:
-
BlobBlockHashes–Lazy view over a flat buffer of fixed-size block hashes to avoid the overhead
-
ChunkedTokenDatabase–Enumerates logical token chunks and their hashes.
-
KeyMetadata–Metadata for constructing pool keys.
-
LBHNCStoreLayout–Native head-major layout shared by divisible TP sizes.
-
LBNHCStoreLayout–Native token-major layout shared by divisible TP sizes.
-
LoadSpec–Specification for loading KV cache from external store.
-
MooncakeLookupResult–Lookup result used to build the subsequent load request.
-
MooncakeStoreConnectorMetadata–Metadata passed from scheduler to worker.
-
MooncakeStoreWorkerMetadata–Maps
ReqMeta.store_job_idto the number of ranks done with that job. -
PoolKey–Key for addressing KV cache blocks in the distributed store.
-
RankLocalStoreLayout–Historical rank-local Store payload layout.
-
ReqMeta–Per-request metadata for store put/get operations.
-
RequestTracker–Tracks per-request state across scheduler ticks.
-
StoreLayout–Store payload layout for one KV-cache group on one local TP rank.
-
TPShardedStoreLayout–Store layout shared by divisible TP sizes.
-
TailKeyBoundary–Hash boundary used to key a group's tail block in the store.
Functions:
-
chunk_hashes_for_block_size–Map
hash_block_size-granular block hashes to one compact hash per
BlobBlockHashes ¶
Bases: Sequence[BlockHash]
Lazy view over a flat buffer of fixed-size block hashes to avoid the overhead of materializing all hashes upfront.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/data.py
ChunkedTokenDatabase ¶
Enumerates logical token chunks and their hashes.
Methods:
-
prepare_value_for_block–Return addresses and sizes for one physical block slot.
-
process_tokens–Process tokens and yield (start_idx, end_idx, block_hash) tuples.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/data.py
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 | |
prepare_value_for_block(block_id) ¶
Return addresses and sizes for one physical block slot.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/data.py
process_tokens(token_len, block_hashes, mask_num=0, *, chunk_mask=None, put_step=1, put_step_rank=0) ¶
Process tokens and yield (start_idx, end_idx, block_hash) tuples.
When there are fewer KV heads than TP ranks, chunks are distributed across TP ranks to avoid duplicate load/store. The assignment keys off the absolute chunk_id so a given chunk always lands on the same rank regardless of where the processed suffix begins.
Parameters:
-
(token_len¶int) –Total number of tokens. Must be hash-block aligned and covered by
block_hasheswhen hashes are present. -
(block_hashes¶list[BlockHash]) –Block hashes computed at
hash_block_sizegranularity. Whenblock_size > hash_block_sizeeach group'sblock_sizechunk is keyed by its last sub-hash viachunk_hashes_for_block_size. -
(mask_num¶int, default:0) –Number of tokens to skip from the beginning.
-
(chunk_mask¶list[bool] | None, default:None) –Optional mask relative to the first chunk after
mask_num. False entries are skipped before hash access. -
(put_step¶int, default:1) –Stride for distributing chunks across ranks.
-
(put_step_rank¶int, default:0) –chunk_id % put_stepvalue this rank stores.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/data.py
KeyMetadata dataclass ¶
Metadata for constructing pool keys.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/data.py
LBHNCStoreLayout ¶
Bases: TPShardedStoreLayout
Native head-major layout shared by divisible TP sizes.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/data.py
LBNHCStoreLayout ¶
Bases: TPShardedStoreLayout
Native token-major layout shared by divisible TP sizes.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/data.py
LoadSpec dataclass ¶
Specification for loading KV cache from external store.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/data.py
MooncakeLookupResult dataclass ¶
Lookup result used to build the subsequent load request.
Attributes:
-
hit_length(int) –Longest prefix that every KV-cache group can reuse after their individual cache hits converge.
-
tail_key_boundaries(tuple[TailKeyBoundary, ...]) –Hash boundary used to store each cache group's tail block when
hit_lengthdoes not identify its store key. There is one entry per group for every nonzero hit.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/data.py
MooncakeStoreConnectorMetadata ¶
Bases: KVConnectorMetadata
Metadata passed from scheduler to worker.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/data.py
MooncakeStoreWorkerMetadata dataclass ¶
Bases: KVConnectorWorkerMetadata
Maps ReqMeta.store_job_id to the number of ranks done with that job.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/data.py
PoolKey dataclass ¶
Key for addressing KV cache blocks in the distributed store.
Methods:
-
build_prefix–Return the stable prefix for a Mooncake pool key.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/data.py
build_prefix(key_metadata, *, tp_rank=None, pcp_rank=None, dcp_rank=None, pp_rank=None) staticmethod ¶
Return the stable prefix for a Mooncake pool key.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/data.py
RankLocalStoreLayout ¶
Bases: StoreLayout
Historical rank-local Store payload layout.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/data.py
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 | |
ReqMeta dataclass ¶
Per-request metadata for store put/get operations.
Methods:
-
from_request_tracker–Create ReqMeta from a RequestTracker.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/data.py
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 | |
from_request_tracker(tracker, block_size, load_spec=None, skip_save=False, block_hashes=None) staticmethod ¶
Create ReqMeta from a RequestTracker.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/data.py
RequestTracker dataclass ¶
Tracks per-request state across scheduler ticks.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/data.py
StoreLayout ¶
Store payload layout for one KV-cache group on one local TP rank.
Methods:
-
lookup_key_prefixes–Prefixes that must exist for a logical block to be reusable.
-
prepare_values–Build Store multi-buffer descriptors for logical chunks.
-
register_kv_caches–Build descriptors from the local KV cache tensors.
Attributes:
-
local_shard_ids(tuple[StoreShardId, ...]) –Store objects contributed or consumed by this local rank.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/data.py
local_shard_ids property ¶
Store objects contributed or consumed by this local rank.
lookup_key_prefixes(rank_namespaces) ¶
Prefixes that must exist for a logical block to be reusable.
prepare_values(chunks, block_ids, shard_ids) ¶
Build Store multi-buffer descriptors for logical chunks.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/data.py
register_kv_caches(kv_caches, num_blocks) ¶
Build descriptors from the local KV cache tensors.
TPShardedStoreLayout ¶
Bases: StoreLayout
Store layout shared by divisible TP sizes.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/data.py
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 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 | |
TailKeyBoundary dataclass ¶
Hash boundary used to key a group's tail block in the store.
Attributes:
-
group_id(int) –KV-cache group containing the tail block.
-
num_tokens(int) –Token boundary whose prefix hash identifies the matched stored block. The loader uses
block_hashes[num_tokens // hash_block_size - 1]instead of the hash implied byMooncakeLookupResult.hit_length. This changes only the load key, not the reusable prefix.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/data.py
_CompactChunkHashList ¶
Bases: BlockHashListWithBlockSize
View that keys each block_size chunk by the last constituent hash_block_size hash instead of concatenating all of them.
The engine chains block hashes (each hash folds in the previous one), so the final sub-block hash of a chunk already uniquely identifies the whole chunk and its prefix. Using it keeps a Mooncake key at a single hash digest regardless of the block_size / hash_block_size ratio, instead of growing the key linearly with it (e.g. 64x for block_size=256, hash_block_size=4).
Source code in vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/data.py
chunk_hashes_for_block_size(block_hashes, hash_block_size, block_size) ¶
Map hash_block_size-granular block hashes to one compact hash per block_size chunk (the chunk's last sub-hash). Returns block_hashes unchanged when the two sizes are equal.