{"record":{"id":"119aa78a37166fe7","repo":"sgl-project/sglang","slug":"layer-id-not-in-full-attention-layers-self-fu","errorCode":null,"errorMessage":"{layer_id=} not in full attention layers: {self.full_attention_layer_id_mapping.keys()}","messagePattern":"(.+?) not in full attention layers: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/mem_cache/memory_pool.py","lineNumber":3879,"sourceCode":"\n    def get_state_layer_ids(self):\n        \"\"\"Global layer id per mamba state entry, aligned with get_state_buf_infos().\"\"\"\n        return self.mamba_pool.get_state_layer_ids()\n\n    def get_state_slice_outer_counts(self):\n        \"\"\"Get the row count preceding each mamba state slice axis.\"\"\"\n        return self.mamba_pool.get_state_slice_outer_counts()\n\n    def get_state_conv_shard_groups(self):\n        \"\"\"Per-tensor conv sub-block dims (GDN) aligned with the state list.\"\"\"\n        return self.mamba_pool.get_state_conv_shard_groups()\n\n    def maybe_get_custom_mem_pool(self):\n        return self.full_kv_pool.maybe_get_custom_mem_pool()\n\n    def _transfer_full_attention_id(self, layer_id: int):\n        if layer_id not in self.full_attention_layer_id_mapping:\n            raise ValueError(\n                f\"{layer_id=} not in full attention layers: {self.full_attention_layer_id_mapping.keys()}\"\n            )\n        return self.full_attention_layer_id_mapping[layer_id]\n\n    def register_layer_transfer_counter(self, layer_transfer_counter: LayerDoneCounter):\n        self.layer_transfer_counter = layer_transfer_counter\n        # The layer-wise wait logic is executed at the Hybrid LinearPool level;\n        # no additional wait is needed in the full_kv_pool\n        self.full_kv_pool.register_layer_transfer_counter(None)\n\n    def _wait_for_layer(self, layer_id: int):\n        if self.layer_transfer_counter is not None:\n            self.layer_transfer_counter.wait_until(layer_id - self.start_layer)\n\n    def get_key_buffer(self, layer_id: int, scale: Optional[float] = None):\n        self._wait_for_layer(layer_id)\n        layer_id = self._transfer_full_attention_id(layer_id)\n        if scale is not None:","sourceCodeStart":3861,"sourceCodeEnd":3897,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/mem_cache/memory_pool.py#L3861-L3897","documentation":"Hybrid KV pool layer remapping error: _transfer_full_attention_id was given a layer_id that is not a full-attention layer registered in full_attention_layer_id_mapping. Hybrid models (e.g. sliding-window + full attention, or linear-attention hybrids) store full-attention layers in a sub-pool indexed by a compact remapped id, so an unknown id cannot be translated.","triggerScenarios":"Calling transfer/async-transfer APIs (e.g. HiCache layer transfer scheduling) with a layer_id belonging to a non-full-attention (sliding/linear) layer, or a layer id mismatch after model config changes altered the full-attention layer set.","commonSituations":"Running hierarchical cache / KV transfer on a hybrid attention model; a model definition whose full_attention_layer_ids list disagrees with the layers actually iterated; version changes in how hybrid layer ids are enumerated.","solutions":["Check the model's full_attention_layer_id_mapping (log self.full_attention_layer_id_mapping.keys()) and only pass ids present there","Fix the construction of the hybrid pool so full-attention layer ids from the model config match the mapping","Update the caller (transfer scheduler loop) to skip non-full-attention layers"],"exampleFix":"// before\nself._transfer_full_attention_id(layer_id)  # layer_id from a sliding-window layer\n// after\nif layer_id in self.full_attention_layer_id_mapping:\n    self._transfer_full_attention_id(layer_id)","handlingStrategy":"type-guard","validationCode":"if layer_id not in pool.full_attention_layer_id_mapping:\n    raise ValueError(f'{layer_id} is not full-attention; skipping transfer')","typeGuard":"def is_full_attention_layer(pool, layer_id: int) -> bool:\n    return layer_id in pool.full_attention_layer_id_mapping","tryCatchPattern":null,"preventionTips":["Derive transfer layer lists from full_attention_layer_id_mapping, never hardcode","Add unit tests asserting mapping covers exactly the model's full-attention layers"],"tags":["kv-cache","hybrid-attention","layer-id","mapping","sglang"],"backgroundTag":"invalid-layer-id-mapping","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}