{"record":{"id":"98ed233f1d47ec4a","repo":"sgl-project/sglang","slug":"weight-prefix-must-be-w13-or-w2-got-weight-98ed23","errorCode":null,"errorMessage":"weight_prefix must be 'w13' or 'w2', got '{weight_prefix}'","messagePattern":"weight_prefix must be 'w13' or 'w2', got '(.+?)'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/layers/quantization/modelslim/schemes/modelslim_w4a4_int4_moe.py","lineNumber":44,"sourceCode":"\n    Two instances of this class are used per MoE layer:\n      - weight_prefix=\"w13\"   → handles the fused gate_proj + up_proj weights\n      - weight_prefix=\"w2\"    → handles the down_proj weights\n    \"\"\"\n\n    def __init__(\n        self,\n        quant_config: Dict[str, Any],\n        weight_prefix: str,  # \"w13\" or \"w2\"\n        group_size: int = 0,\n    ) -> None:\n        self.quant_config = quant_config\n        self.kernel = NPUW4A4Int4MoEMethod()\n        self.weight_prefix = weight_prefix\n        self.group_size = group_size\n        self.is_per_channel_weight = group_size == 0\n        if weight_prefix not in (\"w13\", \"w2\"):\n            raise ValueError(\n                f\"weight_prefix must be 'w13' or 'w2', got '{weight_prefix}'\"\n            )\n\n    def create_weights(\n        self,\n        layer: torch.nn.Module,\n        num_experts: int,\n        hidden_size: int,\n        intermediate_size_per_partition: int,\n        **extra_weight_attrs,\n    ) -> None:\n        \"\"\"\n        Create and register weight, scale, and offset parameters for the layer.\n        Shape depends on the W4A4 packing environment flag and whether the weight\n        prefix is \"w13\" or \"w2\".\n        \"\"\"\n        from sglang.srt.layers.moe.fused_moe_triton import FusedMoeWeightScaleSupported\n","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/layers/quantization/modelslim/schemes/modelslim_w4a4_int4_moe.py#L26-L62","documentation":"The ModelSlim W4A4 INT4 MoE scheme validates weight_prefix at construction and only accepts 'w13' (fused gate/up) or 'w2' (down projection). Any other value raises before any weights are created. Note this check runs after several attributes are already assigned, but the outcome is the same immediate ValueError.","triggerScenarios":"Constructing ModelSlimW4A4Int4MoEScheme with weight_prefix not in ('w13','w2'); typically from custom instantiation code, a modified scheme map, or a fork that passes a different weight-group label.","commonSituations":"Integrating a new NPU MoE model with different weight naming; copy-pasting instantiation from another quant framework that uses 'gate_up'/'down' labels; refactors changing weight-group constants.","solutions":["Use 'w13' or 'w2' exactly when constructing the scheme","Route scheme creation through get_moe_scheme/instantiate so the correct weight_group is passed","If your model genuinely needs a third group, extend the validation and the NPUW4A4Int4MoEMethod kernel to handle it"],"exampleFix":"# before\nscheme = ModelSlimW4A4Int4MoEScheme(cfg, weight_prefix=\"gate_up\")\n# after\nscheme = ModelSlimW4A4Int4MoEScheme(cfg, weight_prefix=\"w13\")","handlingStrategy":"type-guard","validationCode":"assert weight_prefix in (\"w13\", \"w2\"), f\"bad weight_prefix {weight_prefix!r}\"\nscheme = ModelSlimW4A4Int4MoEScheme(cfg, weight_prefix, group_size=group_size)","typeGuard":"def is_valid_weight_prefix(v: str) -> bool:\n    return isinstance(v, str) and v in (\"w13\", \"w2\")","tryCatchPattern":"try:\n    scheme = ModelSlimW4A4Int4MoEScheme(cfg, weight_prefix, group_size)\nexcept ValueError as e:\n    if \"weight_prefix must be\" in str(e):\n        raise TypeError(f\"map {weight_prefix!r} to 'w13'/'w2' before construction\")\n    raise","preventionTips":["Use shared constants for weight groups across the MoE codebase","Never derive weight_prefix from human-readable layer names without mapping","Add a startup assertion in custom loaders validating the prefix set"],"tags":["modelslim","int4","moe","constructor-validation","ascend-npu"],"backgroundTag":"invalid-enum-argument-value","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}