{"record":{"id":"9355109b2784978c","repo":"sgl-project/sglang","slug":"num-nextn-predict-layers-is-not-in-the-config-935510","errorCode":null,"errorMessage":"num nextn_predict_layers is not in the config","messagePattern":"num nextn_predict_layers is not in the config","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"python/sglang/srt/models/bailing_moe_v3.py","lineNumber":249,"sourceCode":"        return layer_group_size[layer_idx] == 1\n    if layer_group_size > 0:\n        return (layer_idx + 1) % layer_group_size != 0\n    else:\n        return False\n\n\n_NEXTN_SPEC_WEIGHT_NAMES = (\n    \"final_layernorm\",\n    \"eh_proj\",\n    \"enorm\",\n    \"hnorm\",\n)\n\n\ndef resolve_nextn_layer_id(config: PretrainedConfig) -> int:\n    \"\"\"Locate the nextn predict layer index in the HF checkpoint name space.\"\"\"\n    if not hasattr(config, \"num_nextn_predict_layers\"):\n        raise ValueError(\"num nextn_predict_layers is not in the config\")\n    assert config.num_nextn_predict_layers == 1, \"Only 1 nextn layer is supported\"\n    return 0 if config.num_hidden_layers == 1 else config.num_hidden_layers\n\n\ndef rewrite_nextn_weight_name(name: str, nextn_layer_prefix: str) -> Optional[str]:\n    \"\"\"Map a HF nextn-layer weight name onto the local NextN module namespace.\n\n    The caller must already have ensured ``name.startswith(nextn_layer_prefix)``.\n    Returns the rewritten name, or None to signal the weight should be skipped\n    (e.g. shared head / embed tokens which are reused from the target model).\n    \"\"\"\n    if \"shared_head.head\" in name or \"embed_tokens\" in name:\n        return None\n    for spec in _NEXTN_SPEC_WEIGHT_NAMES:\n        if spec in name:\n            return name.replace(nextn_layer_prefix, \"model\")\n    return name.replace(nextn_layer_prefix, \"model.decoder\")\n","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/models/bailing_moe_v3.py#L231-L267","documentation":"Shared helper resolve_nextn_layer_id requires config.num_nextn_predict_layers to exist (and equal 1) to locate the MTP/nextn layer index in HF checkpoint naming. It is called from load_weights of bailing_moe_v3.","triggerScenarios":"Loading a Bailing v3 MoE checkpoint that contains nextn weights when the config lacks num_nextn_predict_layers.","commonSituations":"Speculative decoding setup with an older or edited config.json.","solutions":["Add \"num_nextn_predict_layers\": 1 to config.json","Disable MTP/speculative decoding so the nextn path is never hit"],"exampleFix":"// before\nresolve_nextn_layer_id(cfg)  # cfg has no field\n// after\ncfg.num_nextn_predict_layers = 1\nresolve_nextn_layer_id(cfg)","handlingStrategy":"validation","validationCode":"assert getattr(config, \"num_nextn_predict_layers\", 0) == 1","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate MTP config fields before load_weights"],"tags":["mtp","speculative-decoding","bailing","weight-loading"],"backgroundTag":"missing-config-field","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}