{"record":{"id":"bf2f45bb7de5b130","repo":"sgl-project/sglang","slug":"mhatokentokonlypool-use-set-index-k-buffer-on-the","errorCode":null,"errorMessage":"MHATokenToKOnlyPool: use set_index_k_buffer on the parent MiniMaxSparseKVPool — this pool does not store V","messagePattern":"MHATokenToKOnlyPool: use set_index_k_buffer on the parent MiniMaxSparseKVPool — this pool does not store V","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/mem_cache/memory_pool.py","lineNumber":4799,"sourceCode":"\n    def get_value_buffer(self, layer_id: int) -> torch.Tensor:\n        raise NotImplementedError(\"MHATokenToKOnlyPool does not allocate V\")\n\n    def get_kv_buffer(self, layer_id: int) -> Tuple[torch.Tensor, torch.Tensor]:\n        raise NotImplementedError(\"MHATokenToKOnlyPool does not allocate V\")\n\n    def set_kv_buffer(\n        self,\n        layer: RadixAttention,\n        loc: torch.Tensor,\n        cache_k: torch.Tensor,\n        cache_v: torch.Tensor,\n        k_scale: Optional[float] = None,\n        v_scale: Optional[float] = None,\n        layer_id_override: Optional[int] = None,\n    ) -> None:\n        # Routed through MiniMaxSparseKVPool.set_index_k_buffer instead.\n        raise NotImplementedError(\n            \"MHATokenToKOnlyPool: use set_index_k_buffer on the parent \"\n            \"MiniMaxSparseKVPool — this pool does not store V\"\n        )\n\n    def get_kv_size_bytes(self):\n        k_size_bytes = sum(get_tensor_size_bytes(k) for k in self.k_buffer)\n        return k_size_bytes, 0\n\n\nclass MiniMaxSparseKVPool(KVCache):\n    def __init__(\n        self,\n        size: int,\n        page_size: int,\n        dtype: torch.dtype,\n        head_num: int,\n        head_dim: int,\n        idx_head_dim: int,","sourceCodeStart":4781,"sourceCodeEnd":4817,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/mem_cache/memory_pool.py#L4781-L4817","documentation":"MHATokenToKOnlyPool.set_kv_buffer is intentionally disabled: writing K (and V) for K-only sparse layers must go through MiniMaxSparseKVPool.set_index_k_buffer, which handles dtype conversion and the layer-id remapping. Calling the generic setter directly is a misuse of the sub-pool.","triggerScenarios":"Calling set_kv_buffer(layer, loc, cache_k, cache_v, ...) directly on an MHATokenToKOnlyPool instead of on the parent MiniMaxSparseKVPool or its set_index_k_buffer entry point.","commonSituations":"Custom model code or refactored attention layers that grab the sub-pool directly; version changes that moved the set_index_k_buffer entry point.","solutions":["Call MiniMaxSparseKVPool.set_index_k_buffer(layer, loc, cache_idx_k, k_scale) for K-only layers","Ensure the model's attention layers call the parent pool's set_kv_buffer dispatcher, which routes K-only layers correctly"],"exampleFix":"// before\nk_only_pool.set_kv_buffer(layer, loc, cache_k, cache_v)\n// after\nsparse_pool.set_index_k_buffer(layer, loc, cache_k, k_scale=layer.k_scale)","handlingStrategy":"validation","validationCode":"# always write through the parent dispatcher\nsparse_pool.set_kv_buffer(layer, loc, cache_k, cache_v, k_scale=layer.k_scale, v_scale=layer.v_scale)","typeGuard":null,"tryCatchPattern":"try:\n    sub_pool.set_kv_buffer(layer, loc, cache_k, cache_v)\nexcept NotImplementedError as e:\n    raise RuntimeError('use MiniMaxSparseKVPool.set_index_k_buffer for K-only layers') from e","preventionTips":["Never hold references to sub-pools in model code; use the top-level pool API","Assert the pool type before generic set_kv_buffer calls"],"tags":["kv-cache","k-only-pool","sparse-attention","minimax","api-misuse","sglang"],"backgroundTag":"wrong-api-entrypoint","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}