{"record":{"id":"c02c987c9bea3a0e","repo":"sgl-project/sglang","slug":"shared-sink-lora-slot-out-of-range-sorted-slot-i","errorCode":null,"errorMessage":"Shared-sink LoRA slot out of range: {sorted(slot_ids)}","messagePattern":"Shared-sink LoRA slot out of range: (.+?)","errorType":"exception","errorClass":"IndexError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/models/inkling_common/lora.py","lineNumber":123,"sourceCode":"                \"Shared-sink LoRA pool shape changed after initialization: \"\n                f\"gate-up {tuple(self._w1_delta.shape)} -> {expected_gate_up}, \"\n                f\"down-A {tuple(self._a_cat.shape)} -> {expected_down}\"\n            )\n\n    def on_lora_slots_updated(self, slot_ids: set[int] | None) -> None:\n        self._refresh_lora_operands(slot_ids)\n\n    def _refresh_lora_operands(self, slot_ids: set[int] | None = None) -> None:\n        if not self.set_lora or self._w1_delta is None or self._a_cat is None:\n            return\n        b_gate_up = self.gate_up_lora_b_weights\n        a_down = self.down_lora_a_weights\n        slots, n, two_f, rank = b_gate_up.shape\n        f = two_f // 2\n        if slot_ids is None:\n            slot_ids = set(range(slots))\n        elif any(slot < 0 or slot >= slots for slot in slot_ids):\n            raise IndexError(f\"Shared-sink LoRA slot out of range: {sorted(slot_ids)}\")\n        with torch.no_grad():\n            gate_up = self._w1_delta.view(slots, n, f, 2, 2 * rank)\n            a_cat = self._a_cat.view(slots, rank, n, a_down.shape[3])\n            for slot in slot_ids:\n                gate_up[slot].zero_()\n                gate_up[slot, :, :, 0, :rank].copy_(b_gate_up[slot, :, :f, :])\n                gate_up[slot, :, :, 1, rank:].copy_(b_gate_up[slot, :, f:, :])\n                a_cat[slot].copy_(a_down[slot].permute(1, 0, 2))\n\n    def slice_moe_lora_a_weights(\n        self,\n        weights: torch.Tensor | dict[int, torch.Tensor],\n        tp_rank: int,\n        target_module: str,\n    ) -> torch.Tensor | dict[int, torch.Tensor]:\n        if isinstance(weights, torch.Tensor) and weights.dim() == 2:\n            if target_module == \"gate_up_proj_moe\":\n                weights = weights.unsqueeze(0)","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/models/inkling_common/lora.py#L105-L141","documentation":"Raised by _refresh_lora_operands when a requested shared-sink LoRA slot index is negative or >= the number of slots in the b_gate_up tensor (slots = b_gate_up.shape[0]). The slot pool size is fixed by the weight tensor, so any out-of-range id is rejected before buffers are zeroed/copied.","triggerScenarios":"Calling set_lora_info or on_lora_slots_updated with slot_ids containing an index outside range(b_gate_up.shape[0]); e.g. adapter metadata advertises more LoRA slots than the shared-sink buffer was allocated with.","commonSituations":"Mismatch between the number of LoRA slots configured at model init and the ids supplied by the LoRA scheduler after a config change; stale slot registry after resizing the LoRA pool.","solutions":["Check the slot count: ensure every id in slot_ids satisfies 0 <= slot < b_gate_up.shape[0] before calling set_lora_info/on_lora_slots_updated","Re-align the LoRA slot allocation so the buffer's first dimension matches the scheduler's slot ids","If passing None is intended, omit slot_ids so all slots are refreshed"],"exampleFix":"# before\nmodel.set_lora_info(slot_ids=[0, 1, 2])  # buffer only has 2 slots\n# after\nassert all(0 <= s < b_gate_up.shape[0] for s in slot_ids)\nmodel.set_lora_info(slot_ids=slot_ids)","handlingStrategy":"validation","validationCode":"n_slots = b_gate_up.shape[0]\nslot_ids = [s for s in slot_ids if 0 <= s < n_slots]  # or assert\nassert all(0 <= s < n_slots for s in slot_ids), f\"slots must be in [0, {n_slots})\"","typeGuard":null,"tryCatchPattern":"try:\n    model.set_lora_info(...)\nexcept IndexError as e:\n    if 'LoRA slot out of range' in str(e):\n        logger.error('Realigning LoRA slot pool'); raise","preventionTips":["Keep the LoRA slot registry and buffer allocation derived from a single config source","Assert slot bounds before scheduler callbacks"],"tags":["lora","index-error","slot-management","sglang"],"backgroundTag":"index-out-of-range","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}