{"record":{"id":"08c8c385f59cf8b7","repo":"sgl-project/sglang","slug":"weight-prefix-must-be-w13-or-w2-got-weight","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_mxfp8_moe.py","lineNumber":49,"sourceCode":"    Offline MXFP8 MoE scheme that creates weights for either the\n    w13 (gate+up) or w2 (down) projection group.\n\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    The float8_e4m3fn weight dtype allocated here is what tells\n    ``NPUMXFP8MoEMethod.process_weights_after_loading`` to take its offline\n    (re-layout only) branch instead of quantising the weights itself.\n    \"\"\"\n\n    def __init__(\n        self,\n        quant_config: Dict[str, Any],\n        weight_prefix: str,  # \"w13\" or \"w2\"\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 = NPUMXFP8MoEMethod(weight_prefix)\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        self.num_experts = num_experts\n        extra_weight_attrs.update(","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/layers/quantization/modelslim/schemes/modelslim_mxfp8_moe.py#L31-L67","documentation":"ModelSlim MXFP8 MoE scheme constructor validates that weight_prefix is exactly 'w13' or 'w2' — the two weight groups of a fused MoE layer (fused gate/up vs down). Any other string (e.g. 'w1', 'w_gate_up', typo, or None-ish value) is rejected immediately at construction.","triggerScenarios":"Constructing ModelSlimMXFP8MoEScheme(quant_config, weight_prefix) with a prefix not in ('w13','w2'); in normal loading this is supplied by get_moe_scheme via instantiate(..., weight_group=...), so user code or a custom scheme map passing a wrong constant triggers it.","commonSituations":"Custom MoE models or plugins instantiating the scheme directly with their own naming; refactors renaming weight groups; copy-paste from W4A8 code paths using different group labels.","solutions":["Pass exactly 'w13' for the fused gate/up scheme or 'w2' for the down projection","Prefer letting ModelSlimConfig.get_moe_scheme instantiate schemes rather than constructing them manually","If adding a new weight group, extend the constructor's allowed tuple and the kernel mapping (NPUMXFP8MoEMethod) accordingly"],"exampleFix":"# before\nscheme = ModelSlimMXFP8MoEScheme(cfg, weight_prefix=\"w1\")\n# after\nscheme = ModelSlimMXFP8MoEScheme(cfg, weight_prefix=\"w13\")","handlingStrategy":"type-guard","validationCode":"if weight_prefix not in (\"w13\", \"w2\"):\n    raise ValueError(f\"bad weight_prefix {weight_prefix!r}; expected 'w13'/'w2'\")\nscheme = ModelSlimMXFP8MoEScheme(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 = ModelSlimMXFP8MoEScheme(cfg, weight_prefix)\nexcept ValueError as e:\n    if \"weight_prefix must be\" in str(e):\n        weight_prefix = \"w13\" if \"gate\" in weight_prefix else \"w2\"\n        scheme = ModelSlimMXFP8MoEScheme(cfg, weight_prefix)\n    else:\n        raise","preventionTips":["Centralize weight-group constants ('w13'/'w2') in one module and import them","Delegate scheme construction to get_moe_scheme rather than calling constructors manually","Unit-test custom MoE integrations against the allowed prefix set"],"tags":["modelslim","mxfp8","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"}