{"record":{"id":"fe0e616691037e12","repo":"sgl-project/sglang","slug":"weight-prefix-must-be-w13-or-w2-got-weight-fe0e61","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_mxfp4_moe.py","lineNumber":29,"sourceCode":")\nfrom sglang.srt.layers.quantization.modelslim.schemes import ModelSlimMoEScheme\nfrom sglang.srt.utils import set_weight_attrs\n\nMXFP4_BLOCK_SIZE = 32\n\n__all__ = [\"ModelSlimW4A4MXFP4MoE\"]\n\n\nclass ModelSlimW4A4MXFP4MoE(ModelSlimMoEScheme):\n    \"\"\"Create one ModelSlim MXFP4 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 = NPUW4A4MXFP4MoEMethod()\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":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/layers/quantization/modelslim/schemes/modelslim_w4a4_mxfp4_moe.py#L11-L47","documentation":"The ModelSlim W4A4 MXFP4 MoE scheme constructor enforces that weight_prefix is 'w13' (fused gate/up projections) or 'w2' (down projection). It fails fast on any other label before building the NPUW4A4MXFP4MoEMethod kernel.","triggerScenarios":"Instantiating ModelSlimW4A4MXFP4MoEScheme with an unexpected weight_prefix string; the stock loader always passes 'w13'/'w2' via get_moe_scheme, so this appears in custom or modified code paths.","commonSituations":"Custom MoE integrations, forks renaming weight groups, or glue code that derives weight_prefix dynamically and produces an off-by-one/typo like 'w12' or 'W13' (case-sensitive).","solutions":["Pass 'w13' or 'w2' verbatim (case-sensitive, no extra characters)","Log or assert the computed weight_prefix before construction if it is derived dynamically","Delegate instantiation to get_moe_scheme's scheme map instead of manual construction"],"exampleFix":"# before\nscheme = ModelSlimW4A4MXFP4MoEScheme(cfg, weight_prefix=\"W13\")\n# after\nscheme = ModelSlimW4A4MXFP4MoEScheme(cfg, weight_prefix=\"w13\")","handlingStrategy":"type-guard","validationCode":"if weight_prefix not in (\"w13\", \"w2\"):\n    raise ValueError(\"expected 'w13' or 'w2'\")\nscheme = ModelSlimW4A4MXFP4MoEScheme(quant_config, weight_prefix)","typeGuard":"def is_valid_weight_prefix(v: str) -> bool:\n    return isinstance(v, str) and v in (\"w13\", \"w2\")","tryCatchPattern":"try:\n    scheme = ModelSlimW4A4MXFP4MoEScheme(cfg, weight_prefix)\nexcept ValueError as e:\n    if \"weight_prefix must be\" in str(e):\n        logger.error(\"normalize weight_prefix to 'w13'/'w2' (case-sensitive)\")\n    raise","preventionTips":["Remember the check is case-sensitive: 'W13' fails","Validate dynamically computed prefixes with an assertion before constructing schemes","Route through get_moe_scheme's instantiate() in stock flows"],"tags":["modelslim","mxfp4","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"}