vllm.v1.kv_offload.cpu.region_mirror
¶
Mirror worker slots of a multi-node CPU offload region onto the head node.
The tiering scheduler and its secondary tiers run in the engine core, which shares a node with worker rank 0 (the head node), and address only that node's shared region. A worker on another node allocates no CPU region: its copy plan addresses its slot of each chunk in the head region, and it moves its GPU blocks straight to and from there with one-sided NIXL transfers (RDMA WRITE and READ), which the head serves without taking part: it only registers its region. A store is reported only after the worker's slot of every stored chunk is in the head region, and a load writes the worker's GPU blocks before the request runs. The scheduler counts a transfer complete once every worker reports it, so a secondary tier never reads a chunk before all its slots arrived.
The transfers need GPUDirect RDMA to run at network speed; without it UCX emulates them through host memory.
Copies run on a background thread, split into transfers of about
_MAX_TRANSFER_BYTES; loads go ahead of stores, so a load waits for at most
one transfer of a large store. A copy that fails is reported as a failed
transfer. A transfer that ends in no terminal state may still land later, onto
a chunk or block that was reassigned, so it stops the engine instead.
Registered memory is reachable by any peer on the RDMA network that holds the head's metadata: the mirror needs an isolated network.
Classes:
-
MirrorStuckError–A slot transfer reached no terminal state and may still land.
-
MirrorTopology–Placement of this worker relative to the head node (worker rank 0).
-
RegionMirrorClient–Moves one remote worker's GPU blocks to and from its slot of the head
-
RegionMirrorHead–Registers the head node's region for the remote workers' transfers.
-
RegionMirrorHeadWorker–Worker rank 0's CPU offloading worker, keeping the head region registered
-
RegionMirrorWorker–Offloading worker on a node other than the head's.
-
SlotLayout–Byte range of each worker slot inside every chunk row of a region.
Functions:
-
attach_region_mirror–Connect this worker to the head region through the mirror.
-
gather_construction_errors–Raise on every worker if any worker failed to build its offloading worker.
-
mirror_topology–Locate this worker relative to the head node.
-
slot_planners–Store and load copy planners between this worker's GPU blocks and its
MirrorStuckError
¶
Bases: RuntimeError
A slot transfer reached no terminal state and may still land.
MirrorTopology
dataclass
¶
Placement of this worker relative to the head node (worker rank 0).
Source code in vllm/v1/kv_offload/cpu/region_mirror.py
RegionMirrorClient
¶
Moves one remote worker's GPU blocks to and from its slot of the head region.
Each transfer takes (GPU address, head region address, size) triples.
stop aborts waiting transfers.
Methods:
-
restore_kv_caches–Register the GPU memory again, at its addresses after the remap.
-
stop–Make waiting and later transfers fail at once.
-
unregister_kv_caches–Release the GPU memory registration, which a remap of the KV cache
Source code in vllm/v1/kv_offload/cpu/region_mirror.py
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 | |
_run(handle, what)
¶
Post a transfer and wait for its terminal state.
Source code in vllm/v1/kv_offload/cpu/region_mirror.py
restore_kv_caches()
¶
Register the GPU memory again, at its addresses after the remap.
Source code in vllm/v1/kv_offload/cpu/region_mirror.py
stop(reason='is shutting down')
¶
unregister_kv_caches()
¶
Release the GPU memory registration, which a remap of the KV cache (sleep mode, or lending it to a weight update) would leave pointing at stale pages.
Source code in vllm/v1/kv_offload/cpu/region_mirror.py
RegionMirrorHead
¶
Registers the head node's region for the remote workers' transfers.
Source code in vllm/v1/kv_offload/cpu/region_mirror.py
RegionMirrorHeadWorker
¶
Bases: OffloadingWorker
Worker rank 0's CPU offloading worker, keeping the head region registered for the remote workers until it shuts down.
Source code in vllm/v1/kv_offload/cpu/region_mirror.py
RegionMirrorWorker
¶
Bases: OffloadingWorker
Offloading worker on a node other than the head's.
A background thread copies the GPU blocks of each transfer to or from this
worker's slot of the head region, so wait covers those copies.
Source code in vllm/v1/kv_offload/cpu/region_mirror.py
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 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 | |
_finish_copy(copy)
¶
Report a completed copy.
A failed copy reports its job as failed: the scheduler drops a failed store's chunks, and a failed load's blocks become load errors.
Source code in vllm/v1/kv_offload/cpu/region_mirror.py
SlotLayout
dataclass
¶
Byte range of each worker slot inside every chunk row of a region.
Source code in vllm/v1/kv_offload/cpu/region_mirror.py
_gather_raising(topology, error, value, what)
¶
All-gather value; raise on every worker if any worker failed.
Source code in vllm/v1/kv_offload/cpu/region_mirror.py
_is_remote_disconnect(error)
¶
Whether a NIXL raise ends the transfer: its peer is gone.
Any other raise says nothing about the transfer itself (see the p2p
tier's _is_terminal_state_error).
Source code in vllm/v1/kv_offload/cpu/region_mirror.py
_storage_ranges(kv_caches)
¶
(address, size, device) of each storage behind the KV cache tensors.
A strided view (HiSparse keeps per-layer views of block-outermost caches)
reaches past numel() * element_size(), so its whole storage is
registered; views of one storage share one range.
Source code in vllm/v1/kv_offload/cpu/region_mirror.py
attach_region_mirror(worker, region, kv_caches, blocks_per_chunk, head_layout, topology, engine_id, *, timeout_s=_TRANSFER_TIMEOUT_S, remaps_kv_cache=False)
¶
Connect this worker to the head region through the mirror.
Collective over the engine's workers: every rank takes part in the same
exchanges, and any failure raises on all of them. Workers whose head
layouts differ are rejected. On failure the caller still owns worker.
Parameters:
-
(worker¶CPUOffloadingWorker | None) –The CPU offloading worker on the head node; None elsewhere.
-
(region¶SharedOffloadRegion | None) –Its shared region; None off the head node.
-
(kv_caches¶CanonicalKVCaches) –This worker's GPU KV caches.
-
(blocks_per_chunk¶int) –GPU blocks per offloaded chunk.
-
(head_layout¶SlotLayout) –Slot geometry of the head node's region.
-
(topology¶MirrorTopology) –This worker's placement.
-
(engine_id¶str) –Names the NIXL agents of this engine.
-
(timeout_s¶float, default:_TRANSFER_TIMEOUT_S) –Wait for one transfer before the mirror counts it stuck.
-
(remaps_kv_cache¶bool, default:False) –The engine may release and remap the GPU KV cache memory, so the client's UCX backend must not cache its VRAM registrations.
Source code in vllm/v1/kv_offload/cpu/region_mirror.py
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 750 751 752 753 754 755 756 757 758 | |
gather_construction_errors(topology, error)
¶
Raise on every worker if any worker failed to build its offloading worker.
Collective over the engine's workers, so a failure on one rank cannot leave the others blocked in a later collective.
Source code in vllm/v1/kv_offload/cpu/region_mirror.py
mirror_topology()
¶
Locate this worker relative to the head node.
Collective over the world group, which holds exactly the engine's workers when there is one data parallel replica. Returns None when every worker shares the head node.
Source code in vllm/v1/kv_offload/cpu/region_mirror.py
slot_planners(kv_caches, blocks_per_chunk, layout, slot_base)
¶
Store and load copy planners between this worker's GPU blocks and its
slot of the head region, which starts at slot_base.
The slot holds each KV tensor's chunk page in turn, as on the head node.