Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion tests/v1/kv_connector/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def test_kv_connector(
def _build_config(
*,
kv_connector: str | None,
kv_connector_extra_config: dict | None = None,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
enable_sleep_mode: bool = False,
enable_cumem_allocator: bool = False,
) -> VllmConfig:
Expand All @@ -109,7 +110,11 @@ def _build_config(
from types import SimpleNamespace

kv_transfer_config = (
KVTransferConfig(kv_connector=kv_connector, kv_role="kv_both")
KVTransferConfig(
kv_connector=kv_connector,
kv_role="kv_both",
kv_connector_extra_config=kv_connector_extra_config or {},
)
if kv_connector is not None
else None
)
Expand Down Expand Up @@ -137,6 +142,33 @@ def test_kv_connector_rejects_expandable_segments(monkeypatch, kv_connector):
_build_config(kv_connector=kv_connector)


def test_lmcache_mp_engine_driven_allows_expandable_segments(monkeypatch):
monkeypatch.setenv("PYTORCH_CUDA_ALLOC_CONF", "expandable_segments:True")
_build_config(
kv_connector="LMCacheMPConnector",
kv_connector_extra_config={
"lmcache.mp.mp_transfer_mode": "engine_driven",
},
)


@pytest.mark.parametrize("transfer_mode", [None, "auto", "lmcache_driven"])
def test_lmcache_mp_non_engine_driven_rejects_expandable_segments(
monkeypatch, transfer_mode
):
monkeypatch.setenv("PYTORCH_CUDA_ALLOC_CONF", "expandable_segments:True")
extra_config = (
{}
if transfer_mode is None
else {"lmcache.mp.mp_transfer_mode": transfer_mode}
)
with pytest.raises(ValueError, match="expandable_segments"):
_build_config(
kv_connector="LMCacheMPConnector",
kv_connector_extra_config=extra_config,
)


def test_kv_connector_allows_expandable_segments_with_sleep_mode(monkeypatch):
"""Sleep mode routes KV allocations through CuMemAllocator's pool, which
auto-disables expandable_segments (see #40812)."""
Expand Down
11 changes: 11 additions & 0 deletions vllm/config/vllm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,17 @@ def _verify_kv_transfer_compat(self) -> None:
if self.model_config is not None and (self.model_config.enable_cumem_allocator):
return

# Engine-driven LMCache MP transport does not pin or register KV
# addresses; GPU gather/scatter remains in the vLLM worker.
if (
self.kv_transfer_config.kv_connector == "LMCacheMPConnector"
and self.kv_transfer_config.kv_connector_extra_config.get(
"lmcache.mp.mp_transfer_mode"
)
== "engine_driven"
):
return

raise ValueError(
f"KV connector {self.kv_transfer_config.kv_connector} is "
"incompatible with PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True "
Expand Down