Repository navigation
[KV Offload] Move CPUOffloadingSpec onto SharedOffloadRegion - #50094
Merged
Merged
Conversation
Back the default KV-offload backend's worker CPU buffer with the shared SharedOffloadRegion mmap on CUDA/ROCm instead of a per-rank pinned tensor, taking PyTorch's CUDACachingHostAllocator (and its power-of-2 rounding of large pinned allocations, per vllm-project#48436) off the allocation path. Non-CUDA-alike platforms keep the existing pinned-tensor path. Block accounting is page-size aligned on both scheduler and worker so num_blocks stays consistent. This is the allocation-swap prerequisite for the TP-dedup feature in vllm-project#47929; it introduces no deduplication semantics. Co-authored-by: Cursor Agent <cursor-agent@cursor.com> Signed-off-by: Change72 <changg@nvidia.com>
Change72
marked this pull request as draft
July 28, 2026 13:31
Change72
marked this pull request as ready for review
July 28, 2026 15:11
orozery
approved these changes
Jul 29, 2026
This was referenced Aug 4, 2026
Closed
lukealonso
pushed a commit
to local-inference-lab/vllm
that referenced
this pull request
Aug 11, 2026
* fix(kv-offload): backport shared CPU region allocation Backport the allocation semantics of upstream vLLM vllm-project#50094 onto the Gilded Gnosis offload configuration boundary and adapt its coverage to the heterogeneous KV layout tests. Co-authored-by: Chang Guo <changg@nvidia.com> Assisted-by: OpenAI Codex <noreply@openai.com> * fix(kv-offload): clear failed host registration error * fix(kv-offload): segment failed host registrations * docs(cuda): document cleared runtime error code * fix(kv-offload): isolate host registration failures * fix(kv-offload): unlink shared regions after mapping * fix(kv-offload): align host registration segments to KV rows * docs(kv-offload): document host registration helpers * fix(kv-offload): preserve tiering shared backing Keep the named mmap alive until the delayed scheduler has joined it, avoid redundant full-region prefaulting in the scheduler, and clean constructor resources plus rendezvous markers on failure. Add direct and multiprocess coverage for the delayed scheduler contract.
randomvariable
pushed a commit
to randomvariable/vllm
that referenced
this pull request
Aug 19, 2026
…ct#217) * fix(kv-offload): backport shared CPU region allocation Backport the allocation semantics of upstream vLLM vllm-project#50094 onto the Gilded Gnosis offload configuration boundary and adapt its coverage to the heterogeneous KV layout tests. Co-authored-by: Chang Guo <changg@nvidia.com> Assisted-by: OpenAI Codex <noreply@openai.com> * fix(kv-offload): clear failed host registration error * fix(kv-offload): segment failed host registrations * docs(cuda): document cleared runtime error code * fix(kv-offload): isolate host registration failures * fix(kv-offload): unlink shared regions after mapping * fix(kv-offload): align host registration segments to KV rows * docs(kv-offload): document host registration helpers * fix(kv-offload): preserve tiering shared backing Keep the named mmap alive until the delayed scheduler has joined it, avoid redundant full-region prefaulting in the scheduler, and clean constructor resources plus rendezvous markers on failure. Add direct and multiprocess coverage for the delayed scheduler contract.
michael-gpu
pushed a commit
to practical-inference/vllm-ampere-extended
that referenced
this pull request
Oct 20, 2026
…oject#50094) Signed-off-by: Change72 <changg@nvidia.com> Co-authored-by: Cursor Agent <cursor-agent@cursor.com>
6 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Move the default KV-offload backend
CPUOffloadingSpec's worker-side CPU buffer from a per-rank private pinnedtorchtensor onto the existing sharedSharedOffloadRegionmmap, on CUDA/ROCm. This is the allocation-swap prerequisite for the TP-deduplication feature requested in #47929; it introduces no deduplication semantics on its own.Maintainer authorization (upstream reviewers do not see the issue thread, so the requests are linked directly):
What changes
CPUOffloadingSpec.create_workernow builds aSharedOffloadRegionand passes it toCPUOffloadingWorkerwhen running on CUDA/ROCm (current_platform.is_cuda_alike()), folding the physical device index into this replica's[0, world_size)slot range. This is the same allocationTieringOffloadingSpec.create_workeralready performs. The mmap is host registered (pinned) only whenPIN_MEMORYis set andcudaHostRegistersucceeds; a failed registration falls back to unpinned DMA with a warning. A degenerate empty cache (num_blocks == 0) keeps the tensor path, since a zero-byte region cannot be mmap'd.CPUOffloadingSpec.BLOCK_SIZE_ALIGNMENTmoves from1to the region's page size (SharedOffloadRegion.BLOCK_SIZE_ALIGNMENT), so block accounting rounds each offloaded row up to the mmap page size. This is applied unconditionally (scheduler and worker) because the scheduler computesnum_blockswithout knowing the worker platform; both sides must agree on the count.Behavior changes
CUDACachingHostAllocatoroff the allocation path; its power-of-2 rounding of large pinned allocations is the root cause of the host-memory blow-up diagnosed in [KV Offload] Bypass power-of-2 rounding in KV offload CPU pinned allocation #48436. Credit to @procr1337 for that diagnosis.num_blockscan be marginally lower when an offloaded row is not already a page multiple.TieringOffloadingSpec(a subclass) is unchanged: it already used the shared region and page-size alignment./dev/shm).Not in this PR (planned follow-up)
SUPPORTS_REPLICATED_LAYOUTstaysFalse. The TP-dedup itself (the [Feature]: Deduplicate replicated MLA KV across TP ranks in native offloading #47929 feature) is a separate follow-up.pin_mmap_region,TieringOffloadingSpec, or XPU pinning.Duplicate-work check
Searched open PRs (
47929 in:body,CPUOffloadingSpec,SharedOffloadRegion, pinned-host-memory keywords) and the history of the touched paths. No open PR performs this default-backend allocation swap. Nearest non-duplicates:CUDACachingHostAllocatorpower-of-2 rounding inside the private-tensor path (touches onlycpu/gpu_worker.py, allocating unpinned thencudaHostRegister). This PR instead removes that tensor for the default backend on CUDA/ROCm, taking the caching host allocator off the path entirely, so it addresses the same symptom at the root and supersedes [KV Offload] Bypass power-of-2 rounding in KV offload CPU pinned allocation #48436. The author has indicated they lack a GPU environment to continue; whether to close [KV Offload] Bypass power-of-2 rounding in KV offload CPU pinned allocation #48436 is left to the maintainers.sharding.py, and changes totiering/spec.pyandshared_offload_region.py). That is complementary layout infrastructure, not the default-backend allocation swap; the only file it shares with this PR istests/v1/kv_offload/test_factory.py.Test Plan
Run on a CUDA host:
Host-memory reproduction of the #48436 symptom (TP=2, single node). Serve with the CPU offload tier sized to straddle a per-worker power-of-2 boundary and record per-worker RSS before/after this change:
Test Result
Verified on an NVIDIA L4 host (torch 2.13.0+cu130, CUDA 13.0, Python 3.12.3).
Unit tests —
pytest tests/v1/kv_offload/test_factory.py tests/v1/kv_offload/cpu/:116 passed, 1 skipped. Covers the newcreate_workerplatform-split and empty-cache/sizing tests, plus the existing worker suite whosetest_transfer[use_shared_memory=True]cases perform byte-exact GPU↔mmap round-trips.Lint / type —
pre-commit run --files vllm/v1/kv_offload/cpu/spec.py tests/v1/kv_offload/test_factory.py: ruff, ruff-format, mypy, SPDX-header check, and thetorch.cuda-API guard all pass.Allocation behavior (the #48436 mechanism), measured directly — resident-set (VmRSS) delta of one host allocation of the given size, per path:
torch.zeros(pin_memory=True)(old tensor path)cudaHostRegister(this PR's path)The pinned-tensor path rounds each allocation up to the next power of two (PyTorch's
CUDACachingHostAllocator); the shared-region path tracks the requested size. This is the same rounding #48436 reports at production sizes (e.g. an 80 GiB-per-worker request rounding up to 128 GiB).The change has no GPU-architecture-specific path — the
current_platform.is_cuda_alike()branch is identical across CUDA/ROCm GPUs — so this L4 micro-benchmark isolates the per-allocation rounding. The A100 TP=2 results below measure the end-to-end host-memory effect at scale (where the right metric is total physical memory, not per-worker RSS — see the note there).A100 TP=2 E2E. 2× A100-SXM4-80GB, image
vllm/vllm-openai:nightly-d223c900d8(vLLM0.26.1rc1.dev18+gd223c900d, whosev1/kv_offload/is byte-identical to this PR's base — onlycpu/spec.pyis swapped between the baseline and branch runs),-tp 2 --load-format dummy --enforce-eager, Qwen3-0.6B.Total host memory for the CPU offload tier (cgroup
memory.current, cross-checked with summed PSS — both count the shared region once):cpu_bytes_to_useThe default backend allocates one pinned
torch.zerosper layer (28 for this model);CUDACachingHostAllocatorrounds each to the next power of two, so a 64 GiB budget resides as ~118 GiB (and an 80 GiB budget lands at ~118 GiB too — both per-tensor sizes fall in the same 2 GiB bucket). The shared-region path packs all layers and workers into one page-aligned/dev/shmregion and stays at roughly the configured budget plus fixed runtime overhead. (Per-worker RSS is not the right metric here: the region is shared across workers, so summed RSS double-counts it — cgroup/PSS count it once.)Correctness (TP=2, greedy, 4 prompts sharing a long prefix; the connector offloaded blocks — ~45 MB stored, 72% prefix-cache hit): generated text is identical with offloading on (shared-mmap path) vs off.
This PR was developed with AI assistance (implementation and tests). The unit tests, lint/type checks, and the allocation micro-benchmark were run on the submitter's NVIDIA L4 workstation; the A100 TP=2 memory and correctness results were measured on 2× A100-80GB (nightly image noted above).