Skip to content

fix(maru_vllm): adapt LMCache kernel integration to relocated KV-type enums - #72

Open
seohui-XCENA wants to merge 2 commits into
xcena-dev:mainfrom
seohui-XCENA:fix/lmcache-cops-shim-guard
Open

fix(maru_vllm): adapt LMCache kernel integration to relocated KV-type enums#72
seohui-XCENA wants to merge 2 commits into
xcena-dev:mainfrom
seohui-XCENA:fix/lmcache-cops-shim-guard

Conversation

@seohui-XCENA

@seohui-XCENA seohui-XCENA commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

Symptom

With current upstream LMCache installed, the first inference request kills the vLLM EngineCore:

File "maru_vllm/connector.py", line 2431, in _packed_load_kernel_ctx
    kv_format = getattr(ops.EngineKVFormat, layout.format_name, None)
AttributeError: 'CudaDeviceOps' object has no attribute 'EngineKVFormat'

The exception escapes save_kv_layer inside the model forward, so the whole engine dies and every request through the frontend returns 500.

Background: why the direct connector touches LMCache at all

MaruKVConnector is a direct vLLM↔maru integration — all cache decisions (chunk keys, placement, metadata, retrieval) are maru's, and no LMCache connector/engine/service ever runs. The only thing borrowed from the lmcache package is its compiled CUDA kernels (multi_layer_kv_transfer / single_layer_kv_transfer), used purely as a library to gather/scatter paged GPU KV blocks to/from contiguous CXL slabs in one kernel launch. This is optional by design: without the kernels the connector uses its per-layer fallback. (Unrelated to maru_lmcache, which is the opposite integration — running the real LMCache connector with maru as its storage backend.)

Root cause

The kernel resolution handled two cases: lmcache not installed (ImportError guard → fallback) and installed-but-missing-a-format (getattr(enum, name, None) → fallback). Upstream LMCache created a third: the KV-type enums (EngineKVFormat, TransferDirection) were relocated out of c_ops into the lmcache.lmcache_native extension (LMCache/LMCache#4453), and the backward-compat forward was removed in #4473 (2026-08-12). lmcache.c_ops now resolves through a device-ops shim that carries the kernels but not the enums, so the outer attribute access raises before the guarded inner lookup runs.

Fix

Two layers, one commit each:

  1. Guard the enum lookup itself at both resolution sites (fused single-layer path and the packed load/store kernel ctx), so a c_ops handle without the enum takes the existing per-layer fallback instead of crashing.
  2. Resolve the enums from their new home. A _resolve_lmc_ops() helper bundles whichever combination is present — kernels from lmcache.c_ops; enums from c_ops attributes (old builds, including the xcena fork) or from lmcache.lmcache_native (new upstream) — into one namespace with the legacy ops.<name> shape, so all call sites work unchanged against either LMCache generation and the fused path stays active on new upstream.

New config: maru_use_lmcache_kernels

Added to kv_connector_extra_config. Type bool, default true.

Value Behavior
true (default) Use LMCache's compiled transfer kernels for the packed GPU↔CXL copies when they can be resolved. If the kernels or enums are unavailable, the connector still degrades to the per-layer paths on its own.
false Never touch lmcache — force the pure-torch per-layer paths even when lmcache is installed.

Set false to benchmark the fallback paths or to isolate lmcache-related issues. Interaction: the experimental maru_enable_fused_load=true requires the kernels, so with this flag off it is disabled with a warning.

"kv_connector_extra_config": { "maru_use_lmcache_kernels": false }

Validation

  • Unit: 9 new tests — shim-crash regressions (fail with the exact production AttributeError pre-fix), resolver across LMCache generations, toggle behavior. Full connector suite passes (172).
  • E2E on real hardware (upstream LMCache post-#4473, Dynamo frontend + 2 dynamo.vllm workers, Qwen2.5-32B, CXL /dev/dax pool): previously crashed on the first request. With the fix, cross-instance KV reuse works and the fused kernels engage — the per-load fallback warning is absent, and against the guard-only fallback baseline the medians improved: cold (prefill+store) 1.374s → 1.062s, warm (CXL→GPU load) 0.135s → 0.124s. Fallback-path cross-instance speedup was 10.2× TTFT; the kernel path improves on it mainly on the store side at this KV size (1.1 GB/request).
  • Correctness: examples/vllm/p2p_sharing/p2p_example.sh passes on the kernel path (Cache Hit: Yes).

@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown

@seohui-XCENA
seohui-XCENA marked this pull request as ready for review August 14, 2026 08:34
@seohui-XCENA seohui-XCENA changed the title fix(maru_vllm): guard EngineKVFormat lookup against LMCache device-ops shim fix(maru_vllm): adapt LMCache kernel integration to relocated KV-type enums Aug 19, 2026

@kihwan-XCENA kihwan-XCENA left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM!

충돌만 해결하면 될 것 같군요.

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.

2 participants