[Bug] MP mode: TRT-LLM register_kv_cache fails with 'list' object has no attribute 'shape' (NB_NL_TWO_NH_BS_HS)
MP-mode KV cache registration from TensorRT-LLM fails on the server, so every later store/lookup for that instance fails too.
Environment
- LMCache 0.5.5 and 0.5.4 (
lmcache/standaloneimages); the same line is ondevtoday (lmcache/v1/kv_layer_groups.py:408) - TensorRT-LLM 1.3.0rc28 (
nvcr.io/nvidia/tensorrt-llm/release:1.3.0rc28),lmcache==0.5.5pip-installed in that container - Qwen/Qwen3-8B, TP 1, 1x L40S
Repro
Server, exactly as in the TRT-LLM integration docs:
python -m lmcache.v1.multiprocess.server --host 0.0.0.0 --port 5555 \
--l1-size-gb 10 --eviction-policy LRU --max-workers 4 --chunk-size 256Engine:
kv_cache_config:
enable_block_reuse: true
kv_connector_config:
connector: lmcache-mp
server_url: tcp://localhost:5555trtllm-serve Qwen/Qwen3-8B --port 8200 --config cfg.yamlServer log on REGISTER_KV_CACHE (trace from a 0.5.4 server; 0.5.5 fails identically, only the line numbers shift):
File ".../lmcache/v1/multiprocess/modules/lmcache_driven_transfer.py", line 921, in register_kv_cache
File ".../lmcache/v1/platform/cuda/cache_context.py", line 369, in __init__
File ".../lmcache/v1/kv_layer_groups.py", line 376, in __init__
group_num_blocks = get_num_blocks([kv_caches[indices[0]]], group_format)
File ".../lmcache/v1/gpu_connector/kv_format/specs/nb_nl_two_nh_bs_hs.py", line 32, in num_blocks
return self.kv_caches.shape[0]
AttributeError: 'list' object has no attribute 'shape'The worker then times out (KV cache registration timed out after 300.0s) and every request fails with KV caches must be registered before submitting transfer requests.
Cause
TRT-LLM registers one cross-layer pool, which is normalized to a single 6-D tensor [NB, NL, 2, NH, BS, HS] (NB_NL_TWO_NH_BS_HS). For that format kv_caches in KVLayerGroupsManager.__init__ is the tensor itself, not a per-layer list, so:
kv_caches[indices[0]]indexes the block axis, not a layer, and- wrapping it in a list hands
NB_NL_TWO_NH_BS_HS_Spec.num_blocks()a list.
The neighbouring calls in the same loop (resolve_block_stride_and_log_layout, make_page_buffer_shape_desc) already take the whole kv_caches plus layer_idx, which is why only this line breaks.
Fix
group_num_blocks = get_num_blocks(
kv_caches if isinstance(kv_caches, torch.Tensor) else [kv_caches[indices[0]]],
group_format,
)Per-layer list layouts (vLLM, SGLang) keep the current path.
Verified
With this change applied to the server, plus the client-side trim from #4879 (the store otherwise hits the #3917 assertion, len(block_ids[0]) should be a multiple of total_blocks_per_chunk (8), but got 76), on 2x L40S, one server, two TRT-LLM engines on separate GPUs:
- engine A, 2401-token prompt:
Stored 2304 tokens in 0.262 seconds - engine B, same prompt, cold GPU cache:
Retrieved 2304 tokens in 0.008 seconds,cached_tokens: 2304, 0.18 s end to end vs 0.40 s for a different prompt of the same length
Happy to open a PR with the fix and a regression test if that helps.
Source: LMCache/LMCache