sgl-project/sglang · error · ValueError
layer.layer_id={layer.layer_id} does not have an index V cac
Error message
layer.layer_id={layer.layer_id} does not have an index V cache (either dense, or in the K-only group). index_kv layers: {list(self.index_kv_layer_id_mapping.keys())} What it means
set_index_kv_buffer on MiniMaxSparseKVPool only accepts layers registered in index_kv_layer_id_mapping. The given layer.layer_id is dense or K-only, so there is no index-V pool slot to write into and the call is rejected before touching buffers.
Source
Thrown at python/sglang/srt/mem_cache/memory_pool.py:5014
loc,
cache_k,
cache_v,
k_scale,
v_scale,
)
def set_index_kv_buffer(
self,
layer: RadixAttention,
loc: torch.Tensor,
cache_idx_k: torch.Tensor,
cache_idx_v: torch.Tensor,
k_scale: Optional[float] = None,
v_scale: Optional[float] = None,
) -> None:
mapped_id = self.index_kv_layer_id_mapping.get(layer.layer_id)
if mapped_id is None:
raise ValueError(
f"layer.layer_id={layer.layer_id} does not have an index V "
f"cache (either dense, or in the K-only group). "
f"index_kv layers: {list(self.index_kv_layer_id_mapping.keys())}"
)
self.index_kv_pool.set_kv_buffer(
layer,
loc,
cache_idx_k,
cache_idx_v,
k_scale,
v_scale,
layer_id_override=mapped_id,
)
def set_index_k_buffer(
self,
layer: RadixAttention,
loc: torch.Tensor,View on GitHub (pinned to 0132848349)
Solutions
- Branch per layer group: use set_index_kv_buffer only for index-KV layers and set_index_k_buffer for K-only layers
- Verify layer.layer_id against index_kv_layer_id_mapping before the call
- Rebuild the pool with correct sparse layer classification if the layer should be index-KV
Example fix
# before
sparse_pool.set_index_kv_buffer(layer, loc, cache_k, cache_v) # K-only layer
# after
if layer.layer_id in sparse_pool.index_kv_layer_id_mapping:
sparse_pool.set_index_kv_buffer(layer, loc, cache_k, cache_v)
else:
sparse_pool.set_index_k_buffer(layer, loc, cache_k, k_scale=layer.k_scale) Defensive patterns
Strategy: validation
Validate before calling
if layer.layer_id not in sparse_pool.index_kv_layer_id_mapping:
raise ValueError(f'{layer.layer_id} is not index-KV; use set_index_k_buffer or main pool') Type guard
def is_index_kv_layer(sparse_pool, layer) -> bool:
return sparse_pool.index_kv_layer_id_mapping.get(layer.layer_id) is not None Prevention
- Split the write path by layer group (K-only vs index-KV vs dense)
- Add a startup assertion that the model's layer partition matches the pool mappings
When it happens
Trigger: Calling set_index_kv_buffer(layer, loc, cache_idx_k, cache_idx_v, ...) with a layer whose id is not in index_kv_layer_id_mapping (dense layer or K-only sparse layer).
Common situations: Model code that uses one code path for all sparse layers instead of branching between set_index_k_buffer (K-only) and set_index_kv_buffer; layer partition config mismatches after model definition edits.
Related errors
- layer.layer_id={layer.layer_id} is not in the K-only sparse
- layer_id={layer_id} does not have an index V cache (either d
- layer_id={layer_id} is not a sparse attention layer; sparse
- MHATokenToKOnlyPool does not allocate V
- MHATokenToKOnlyPool: use set_index_k_buffer on the parent Mi
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/92125304db08da63.
Report an issue: GitHub.