{"record":{"id":"c2fb409786ea08bd","repo":"sgl-project/sglang","slug":"inkling-shared-sink-lora-outer-factors-must-have-e","errorCode":null,"errorMessage":"Inkling shared-sink LoRA outer factors must have expert dimension 1 or {self.n_shared_experts}","messagePattern":"Inkling shared-sink LoRA outer factors must have expert dimension 1 or (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/models/inkling_common/lora.py","lineNumber":55,"sourceCode":"        self,\n        gate_up_lora_a_weights: torch.Tensor,\n        gate_up_lora_b_weights: torch.Tensor,\n        down_lora_a_weights: torch.Tensor,\n        down_lora_b_weights: torch.Tensor,\n    ) -> None:\n        tensors = (\n            gate_up_lora_a_weights,\n            gate_up_lora_b_weights,\n            down_lora_a_weights,\n            down_lora_b_weights,\n        )\n        if any(weight.ndim != 4 for weight in tensors):\n            raise ValueError(\"Inkling shared-sink LoRA requires four 4D MoE buffers\")\n        gate_outer = gate_up_lora_a_weights.shape[1]\n        down_outer = down_lora_b_weights.shape[1]\n        valid_outer_dims = (1, self.n_shared_experts)\n        if gate_outer not in valid_outer_dims or down_outer not in valid_outer_dims:\n            raise ValueError(\n                \"Inkling shared-sink LoRA outer factors must have expert dimension \"\n                f\"1 or {self.n_shared_experts}\"\n            )\n        if gate_outer != down_outer:\n            raise ValueError(\n                \"Inkling shared-sink gate-up A and down B must use the same \"\n                \"expert layout\"\n            )\n        if (\n            gate_up_lora_b_weights.shape[1] != self.n_shared_experts\n            or down_lora_a_weights.shape[1] != self.n_shared_experts\n        ):\n            raise ValueError(\"Inkling shared-sink LoRA expert count does not match\")\n\n        max_rank = gate_up_lora_b_weights.shape[-1]\n        if (\n            gate_up_lora_a_weights.shape[2] != 2 * max_rank\n            or down_lora_a_weights.shape[2] != max_rank","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/models/inkling_common/lora.py#L37-L73","documentation":"After confirming all four buffers are 4D, set_lora_info checks the outer (expert) factor of gate_up_lora_a_weights.shape[1] and down_lora_b_weights.shape[1]; each must be 1 (shared across experts) or exactly n_shared_experts. Anything else means the expert layout of the supplied buffers disagrees with the module's shared-expert count.","triggerScenarios":"Calling set_lora_info where gate_up_lora_a or down_lora_b has shape[1] not in {1, n_shared_experts} — e.g. outer dim equal to the total MoE expert count or an arbitrary rank value.","commonSituations":"Adapters exported for a different model variant (different number of shared experts); misinterpreting dim 1 as the LoRA rank when packing tensors; model config changed n_shared_experts after adapter conversion.","solutions":["Rebuild/transpose the buffers so dim 1 is 1 or matches the model's n_shared_experts","Check the model config's shared-expert count and regenerate the LoRA for that variant","Add an assert on shape[1] in your adapter loader before calling set_lora_info"],"exampleFix":"# before\n# gate_up_lora_a.shape == (slots, num_local_experts, inner, rank)\n# after\nassert gate_up_lora_a.shape[1] in (1, module.n_shared_experts)\nmodule.set_lora_info(gate_up_lora_a, gate_up_b, down_a, down_b)","handlingStrategy":"validation","validationCode":"valid = (1, module.n_shared_experts)\nassert ga.shape[1] in valid and db.shape[1] in valid\nmodule.set_lora_info(ga, gb, da, db)","typeGuard":"def outer_dims_valid(module, ga, db) -> bool:\n    v = (1, module.n_shared_experts)\n    return ga.shape[1] in v and db.shape[1] in v","tryCatchPattern":null,"preventionTips":["Carry n_shared_experts in adapter metadata and check at load","Regenerate adapters when switching model variants","Log all four shapes before binding"],"tags":["sglang","lora","shape-validation","moe","shared-experts","inkling"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}