Skip to content

[Feat][KV offloading][WIP] The prototype implementation of a KV offloader used in CPU KV server #22608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ApostaC
Copy link
Collaborator

@ApostaC ApostaC commented Aug 10, 2025

Essential Elements of an Effective PR Description Checklist

  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.

Purpose

This PR is part of #22605.

This PR gives a (WIP) prototype implementation for the KV cache offloader running in the CPU KV process.

The functionality in this PR will be replaced with a vLLM-native implementation in the future

Test Plan

Test Result

(Optional) Documentation Update

Copy link

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

🚀

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a prototype implementation of a KV offloader for a CPU KV server using LMCache. The implementation includes a new abstract class BlockingKVInterface and a concrete class LMCacheBlockingKVMgr. My review identified a few critical issues in LMCacheBlockingKVMgr that need to be addressed. These include a potential crash on CPU-only servers due to a hardcoded .cuda() call, an incorrect boundary check for the worker rank, and a bug in the lookup_internal method that prevents it from correctly iterating over all ranks.

(num_blocks, 1)) * block_size).flatten()

# TODO: compatibility with multiple cuda devices
return slot_mapping[:len(token_ids)].cuda()
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The .cuda() call here will cause a crash if this code is run on a CPU-only machine, which is the expected environment for a 'CPU KV server'. The LMCacheEngine should handle the necessary data transfers between devices. Please remove the explicit .cuda() call and let the underlying library manage device placement.

Suggested change
return slot_mapping[:len(token_ids)].cuda()
return slot_mapping[:len(token_ids)]

def lookup_internal(self, token_ids: list[int], pin: bool) -> int:
lengths = []
for i in range(self.world_size):
length = self.lmcache_engines[0].lookup(token_ids, pin=pin)
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

There is a bug in this loop. It iterates with i from 0 to self.world_size - 1, but it always accesses self.lmcache_engines[0]. It should use self.lmcache_engines[i] to query the engine for each rank.

Suggested change
length = self.lmcache_engines[0].lookup(token_ids, pin=pin)
length = self.lmcache_engines[i].lookup(token_ids, pin=pin)

Comment on lines +132 to +134
if rank > self.world_size:
raise ValueError(
f"Rank {rank} exceeds world size {self.world_size}.")
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The check for rank validity is incorrect. Ranks are 0-indexed, so a rank equal to self.world_size is also out of bounds. The condition should be rank >= self.world_size.

Suggested change
if rank > self.world_size:
raise ValueError(
f"Rank {rank} exceeds world size {self.world_size}.")
if rank >= self.world_size:
raise ValueError(
f"Rank {rank} exceeds world size {self.world_size}.")

@ApostaC ApostaC marked this pull request as draft August 11, 2025 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant