{"record":{"id":"1c480f0fa8ec333e","repo":"sgl-project/sglang","slug":"weight-prefix-must-be-w13-or-w2-got-weight-1c480f","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_mxfp4_moe.py","lineNumber":30,"sourceCode":"from sglang.srt.layers.quantization.modelslim.schemes import ModelSlimMoEScheme\nfrom sglang.srt.utils import set_weight_attrs\n\nW4A8_MXFP4_BLOCK_SIZE = 32\nW4A8_MXFP4_PACK_FACTOR = 2\n\n__all__ = [\"ModelSlimW4A8MXFP4MoE\"]\n\n\nclass ModelSlimW4A8MXFP4MoE(ModelSlimMoEScheme):\n    \"\"\"Create one ModelSlim W4A8 MXFP expert-weight group (w13 or w2).\"\"\"\n\n    def __init__(\n        self,\n        quant_config: Dict[str, Any],\n        weight_prefix: str,\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.kernel = NPUW4A8MXFP4MoEMethod()\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        from sglang.srt.layers.moe.fused_moe_triton import FusedMoeWeightScaleSupported\n\n        extra_weight_attrs.update(\n            {\"quant_method\": FusedMoeWeightScaleSupported.BLOCK.value}","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/layers/quantization/modelslim/schemes/modelslim_w4a8_mxfp4_moe.py#L12-L48","documentation":"This error is raised by the constructor of the ModelSlim W4A8 MXFP4 MoE quantization scheme in SGLang. The class handles exactly two weight matrices in a fused MoE layer: 'w13' (the fused gate/up projection) and 'w2' (the down projection). Passing any other prefix string means the caller constructed the quantizer for a layer it cannot handle.","triggerScenarios":"Instantiating ModelSlimW4A8MXFP4MoEQuantizer (or the config class that wraps it) with a weight_prefix argument that is not exactly 'w13' or 'w2' — e.g. passing 'w1', 'gate_up_proj', 'w3', or a typo like 'W13'.","commonSituations":"Happens when porting a new MoE model to SGLang's NPU ModelSlim path and naming the layer prefix inconsistently with the fused-MoE convention, or when adapting an existing quant scheme class into a custom one and forgetting to update the allowed prefixes.","solutions":["Check the call site that constructs the quantizer and pass exactly 'w13' for the gate/up projection or 'w2' for the down projection","If you are adding support for a new projection name, extend the tuple ('w13', 'w2') in the check AND make sure the downstream kernel actually supports it","Verify the model's MoE implementation maps its layer names onto the FusedMoE w13/w2 convention before wiring in ModelSlim"],"exampleFix":"// before\nquant = ModelSlimW4A8MXFP4MoEQuantizer(cfg, weight_prefix=\"gate_up\")\n// after\nquant = ModelSlimW4A8MXFP4MoEQuantizer(cfg, weight_prefix=\"w13\")","handlingStrategy":"validation","validationCode":"allowed = (\"w13\", \"w2\")\nif prefix not in allowed:\n    raise ValueError(f\"bad prefix {prefix!r}; expected one of {allowed}\")\nquant = ModelSlimW4A8MXFP4MoEQuantizer(cfg, weight_prefix=prefix)","typeGuard":"from typing import Literal\nWeightPrefix = Literal[\"w13\", \"w2\"]\n\ndef is_weight_prefix(v: str) -> TypeGuard[WeightPrefix]:\n    return v in (\"w13\", \"w2\")","tryCatchPattern":null,"preventionTips":["Standardize MoE layer prefixes on the fused w13/w2 convention at model-integration time","Centralize the allowed-prefix tuple in one constant shared by checkers and callers"],"tags":["quantization","moe","npu","modelslim","validation"],"backgroundTag":"invalid-enum-argument","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}