{"record":{"id":"7f528da0d20d542c","repo":"sgl-project/sglang","slug":"layer-is-not-backed-by-an-mla-kv-pool","errorCode":null,"errorMessage":"Layer {} is not backed by an MLA KV pool","messagePattern":"Layer (.+?) is not backed by an MLA KV pool","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"critical","filePath":"python/sglang/srt/mem_cache/swa_memory_pool.py","lineNumber":285,"sourceCode":"                v_scale,\n                layer_id_override=layer_id_pool,\n            )\n\n    def set_mla_kv_buffer(\n        self,\n        layer: RadixAttention,\n        loc_info,\n        cache_k_nope: torch.Tensor,\n        cache_k_rope: torch.Tensor,\n    ):\n        loc, swa_loc, _ = unwrap_write_loc(loc_info)\n        layer_id_pool, is_swa_layer = self.layers_mapping[layer.layer_id]\n        pool = self.swa_kv_pool if is_swa_layer else self.full_kv_pool\n        if is_swa_layer:\n            assert swa_loc is not None\n            loc = swa_loc\n        if not isinstance(pool, MLATokenToKVPool):\n            raise TypeError(f\"Layer {layer.layer_id} is not backed by an MLA KV pool\")\n        pool.set_mla_kv_buffer(\n            None,\n            loc,\n            cache_k_nope,\n            cache_k_rope,\n            layer_id_override=layer_id_pool,\n        )\n\n    def get_index_k_with_scale_buffer(self, layer_id: int) -> torch.Tensor:\n        layer_id_pool, is_swa_layer = self.layers_mapping[layer_id]\n        assert not is_swa_layer\n        return self.full_kv_pool.get_index_k_with_scale_buffer(layer_id_pool)\n\n    def get_index_k_continuous(self, layer_id: int, *args, **kwargs):\n        layer_id_pool, is_swa_layer = self.layers_mapping[layer_id]\n        assert not is_swa_layer\n        return self.full_kv_pool.get_index_k_continuous(layer_id_pool, *args, **kwargs)\n","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/mem_cache/swa_memory_pool.py#L267-L303","documentation":"SWA memory pool's set_mla_kv_buffer resolved the layer's backing pool and it is not an MLATokenToKVPool, so the MLA buffer API cannot be used for that layer.","triggerScenarios":"Constructing SWAKVPool with a full/swa pool that is a MHATokenToKVPool (or other non-MLA pool) and then calling set_mla_kv_buffer for a layer mapped to it — typical when an MLA model config is mismatched with non-MLA pool classes.","commonSituations":"Mixing MLA model support with non-MLA allocator classes, custom pool implementations missing the MLA interface, or wrong layers_mapping wiring.","solutions":["Ensure the model is actually MLA and the pools passed to the SWA pool are MLATokenToKVPool instances","If using custom pools, implement the MLATokenToKVPool interface (set_mla_kv_buffer)","Check layers_mapping/layer_id routing so MLA layers map to MLA-backed pools"],"exampleFix":"# before\npool = SWAKVPool(full_kv_pool=MHATokenToKVPool(...), ...)\npool.set_mla_kv_buffer(layer, ...)\n# after\nfrom sglang.srt.mem_cache.memory_pool import MLATokenToKVPool\npool = SWAKVPool(full_kv_pool=MLATokenToKVPool(...), ...)\npool.set_mla_kv_buffer(layer, ...)","handlingStrategy":"type-guard","validationCode":"from sglang.srt.mem_cache.memory_pool import MLATokenToKVPool\nassert isinstance(pool.full_kv_pool, MLATokenToKVPool) and isinstance(pool.swa_kv_pool, MLATokenToKVPool)","typeGuard":"def is_mla_pool(p) -> bool:\n    from sglang.srt.mem_cache.memory_pool import MLATokenToKVPool\n    return isinstance(p, MLATokenToKVPool)","tryCatchPattern":null,"preventionTips":["Assert pool classes match model type (MLA vs MHA) at construction","Custom pools must implement the full MLATokenToKVPool interface for MLA models"],"tags":["swa","mla","type-mismatch","memory-pool"],"backgroundTag":"interface-not-implemented","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}