Skip to content

[KV Offload] Refactor the CPU offload worker behind a per-platform API - #70073

Open
orozery wants to merge 1 commit into
vllm-project:mainfrom
orozery:cpu-offload-worker-refactor-pr
Open

orozery wants to merge 1 commit into
vllm-project:mainfrom
orozery:cpu-offload-worker-refactor-pr

Conversation

@orozery

@orozery orozery commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Refactor the worker side of the CPU KV offload tier so common code lives in cpu/worker.py and platform-specific calls sit behind a small API. Prepares for TPU and non-CUDA copy mechanisms while preserving behavior. Related to #62933.

Claims

  • Deletes gpu_worker.py, host_register.py and swap_blocks_triton.py; CUDA/ROCm/XPU now share worker.py + engines/ + platforms/.
  • No platform predicates or GPU calls remain in the worker; each platform is a runtime profile.
  • Transfer ordering, failure semantics, pooling, deferred pre-fault/pin and region cleanup are unchanged; the existing offload tests pass.

Validation

Ran on the OpenShift GPU cluster (1 GPU, torch 2.14.0+cu132, CUDA available):

pytest tests/v1/kv_offload/cpu tests/v1/kv_offload/test_factory.py -q
341 passed, 5 skipped, 6 warnings in 187.84s (0:03:07)
  • PR head 088613af63, rebased onto origin/main 7bca9fafe2; tested with the 7bca9fafe2 CI image plus a Python overlay of this commit (PYOV ok for all files; 3 deletions, 7 test files).
  • CUDA only. ROCm/XPU paths are preserved by construction (same copy functions, dtypes and host-registration calls); ROCm-only tests are skipped on this NVIDIA cluster, so ROCm/XPU CI is needed for those paths.
  • No model evaluation is required: this is an internal refactor with no output, accuracy or serving-path change. The offload tests verify byte-exact KV movement for both direct and canonical layouts.

Details

  • cpu/worker.py — copy planning (TensorRows/CopyPlanner), per-direction queues, host-memory setup, deferred pre-fault/pin.
  • cpu/engines/base.py — CopyEngine/CopyStream contract (device_to_cpu, submit, done, synchronize, abort, elapsed_seconds; RuntimeError = failed job, anything else fatal).
  • cpu/engines/torch.py — the torch mechanism (streams/events, descriptors, pointer dtype). The platform supplies the device module and copy function.
  • cpu/platforms/base.py — DeviceRuntime contract: capabilities, host registration, capture relaxation, engine configuration.
  • cpu/platforms/{cuda,rocm,xpu}.py — per-platform profiles. CUDA owns the H100-tuned Triton fast path; ROCm is a thin subclass; XPU supplies torch.xpu and uint64 descriptors.
  • cpu/engines/factory.py, cpu/platforms/factory.py — mechanism and platform selection. Host registration is a runtime method.

Why this is not a duplicate: #62933 (open) independently moves copy planning into CopyPlanner/TensorRows inside gpu_worker.py for its multi-node mirror. This PR makes the same planner split as part of a broader worker refactor and provides the platform/engine seams that mirror needs; #62933 can rebase on this and reuse worker.py + engines/ + platforms/, with its region mirror as a new copy mechanism. Other open PRs touch the copy path (#65519, #66527, #67644, #66511) or DevicePointers (#69389) but target different fixes; this change is structural, and any textual conflicts are mechanical.

Design fit and complexity: the change is worker-local under vllm/v1/kv_offload/cpu; no scheduler, model-runner or public config changes. Most of the diff is moved code. The new abstractions are deliberately small: CopyEngine has two methods, CopyStream seven, DeviceRuntime four. They are the seams for a future TPU implementation and for non-CUDA copy mechanisms; the NIXL work is a follow-up and is not part of this PR. No CPU/GPU synchronization is added to steady-state inference; the existing compute-stream and previous-transfer waits are preserved.


Pull Request Checklist
  • I used vLLM's /pr-checklist skill. (Mandatory for agents, optional for humans).

  • AI assistance was used during the creation of this PR.

  • Design Fit: Minimizes impact on core components, reuses existing functionality, and justifies added complexity.

  • Testing and Validation: Validates the change and ensures any added tests are meaningful and reliable, with CI coverage or documented CI resource constraints and validation performed outside CI.

  • Code Quality and Style: Keeps code and comments clear and concise, and updates relevant documentation and examples.

  • Pull Request Contents: Includes a brief summary and relevant links, supports claims with evidence, explains root causes and implementation trade-offs, and follows the contributing guide.

AI assistance. AI assistance (Claude) was used to write this change and its tests. The submitting human reviewed every changed line and confirmed the validation above.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@mergify mergify Bot added nvidia nixl NIXL KV connector / multi-tiered KV offloading (KVCR) labels Nov 26, 2026
@mergify

mergify Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @orozery.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase label Nov 26, 2026
@orozery orozery added the ready ONLY add when PR is ready to merge/full CI is needed label Nov 26, 2026
Move all common worker code to worker.py and route every device call
through the engine and platform abstractions:

- cpu/engines/base.py: CopyEngine/CopyStream contract; engines/torch.py
  implements the torch mechanism (streams/events, DMA or Triton, pointer
  dtype).
- cpu/platforms/base.py: DeviceRuntime contract; platforms/{cuda,rocm,xpu}.py
  provide capabilities, host registration, capture relaxation and the
  engine configuration.
- cpu/engines/factory.py and cpu/platforms/factory.py select the copy
  mechanism and the platform runtime; unregistered platforms resolve to
  UnsupportedRuntime.

Delete gpu_worker.py, host_register.py and swap_blocks_triton.py; host
registration becomes a runtime method.

Copy planning is split into TensorRows/CopyPlanner so the planner never
touches platform dtypes. The worker direction is device-neutral
(device_to_cpu). Behavior is unchanged: per-direction FIFO, compute and
previous-job waits, failure reporting after the stream drains, pooling,
deferred prefault/pin, and region cleanup ordering. Descriptor buffers use
the platform pointer dtype for addresses and sizes (uint64 on XPU), and
pinning pairs with the region's registrar.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Signed-off-by: Or Ozeri <oro@il.ibm.com>
@orozery
orozery force-pushed the cpu-offload-worker-refactor-pr branch from a65a849 to 088613a Compare November 26, 2026 07:44

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-rebase nixl NIXL KV connector / multi-tiered KV offloading (KVCR) nvidia ready ONLY add when PR is ready to merge/full CI is needed

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant