{"record":{"id":"979e4d0f051dfa63","repo":"sgl-project/sglang","slug":"weight-prefix-must-be-w13-or-w2-got-weight-979e4d","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_w4a8_int8_moe.py","lineNumber":40,"sourceCode":"\n    Two instances of this class are created per MoE layer:\n      - weight_prefix=\"w13\"  → handles gate + up projections\n      - weight_prefix=\"w2\"   → handles down projection\n\n    Configuration flags (``is_per_channel_weight``, ``activation_use_clip``)\n    are passed to the underlying NPU kernel.\n    \"\"\"\n\n    def __init__(\n        self,\n        quant_config: Dict[str, Any],\n        weight_prefix: str,\n        group_size: int = 0,\n        tp_size: int = 1,\n        activation_use_clip: bool = False,\n    ) -> None:\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        self.quant_config = quant_config\n        self.weight_prefix = weight_prefix\n        self.group_size = group_size\n        self.tp_size = tp_size\n        self.is_per_channel_weight = group_size == 0\n        self.activation_use_clip = activation_use_clip\n        self.kernel = NPUW4A8Int8MoEMethod(\n            is_per_channel_weight=self.is_per_channel_weight,\n            activation_use_clip=self.activation_use_clip,\n        )\n\n    def create_weights(\n        self,\n        layer: torch.nn.Module,\n        num_experts: int,\n        hidden_size: int,","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/layers/quantization/modelslim/schemes/modelslim_w4a8_int8_moe.py#L22-L58","documentation":"The ModelSlim W4A8 INT8 MoE scheme constructor validates its weight_prefix argument and only accepts 'w13' or 'w2'. Because group_size, tp_size, and activation clipping behavior depend on which weight group the scheme targets, an invalid prefix is rejected immediately.","triggerScenarios":"Calling ModelSlimW4A8Int4MoEScheme(...) (INT8 MoE scheme __init__) with a weight_prefix outside ('w13','w2'); standard loading passes the correct value via instantiate(weight_group=...), so custom code or a patched scheme map triggers this.","commonSituations":"Reusing W4A8 instantiation snippets with a new model's naming; dynamic prefix derivation with typos; forks adding new weight groups without updating the validation.","solutions":["Use exactly 'w13' for gate/up and 'w2' for down when constructing the scheme","Validate the value at the call site (assert weight_prefix in ('w13','w2')) if it comes from config or user input","Extend the allowed values plus kernel logic if a genuinely new weight group is required"],"exampleFix":"# before\nscheme = ModelSlimW4A8Int8MoEScheme(cfg, weight_prefix=\"down\")\n# after\nscheme = ModelSlimW4A8Int8MoEScheme(cfg, weight_prefix=\"w2\")","handlingStrategy":"type-guard","validationCode":"assert weight_prefix in (\"w13\", \"w2\"), f\"bad weight_prefix {weight_prefix!r}\"\nscheme = ModelSlimW4A8Int8MoEScheme(cfg, weight_prefix, group_size, tp_size, activation_use_clip)","typeGuard":"def is_valid_weight_prefix(v: str) -> bool:\n    return isinstance(v, str) and v in (\"w13\", \"w2\")","tryCatchPattern":"try:\n    scheme = ModelSlimW4A8Int8MoEScheme(cfg, weight_prefix, group_size, tp_size, use_clip)\nexcept ValueError as e:\n    if \"weight_prefix must be\" in str(e):\n        raise ValueError(\"pass 'w13' (gate/up) or 'w2' (down)\")\n    raise","preventionTips":["Map semantic names to 'w13'/'w2' at the boundary of custom code","Keep a single enum/constants module for MoE weight groups","Add constructor-argument checks in tests for custom scheme wiring"],"tags":["modelslim","int8","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"}