{"record":{"id":"316caa5d20562505","repo":"sgl-project/sglang","slug":"layer-types-has-len-self-layer-types-entries-bu","errorCode":null,"errorMessage":"layer_types has {len(self.layer_types)} entries but num_hidden_layers is {self.num_hidden_layers}","messagePattern":"layer_types has (.+?) entries but num_hidden_layers is (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/hardware_backend/mlx/models/muse_glimmer_mlx.py","lineNumber":297,"sourceCode":"                    f\"num_hidden_layers is {self.num_hidden_layers}\"\n                )\n            bad_flags = sorted(set(self.no_rope_layers) - {0, 1})\n            if bad_flags:\n                raise ValueError(\n                    f\"no_rope_layers contains non-binary entries {bad_flags}; \"\n                    \"each entry must be 0 (NoPE) or 1 (RoPE)\"\n                )\n\n        # NoPE layers are the full-attention layers; the rest slide.\n        derived_layer_types = [\n            \"full_attention\" if rope_flag == 0 else \"sliding_attention\"\n            for rope_flag in self.no_rope_layers\n        ]\n        if self.layer_types is None:\n            self.layer_types = derived_layer_types\n        else:\n            if len(self.layer_types) != self.num_hidden_layers:\n                raise ValueError(\n                    f\"layer_types has {len(self.layer_types)} entries but \"\n                    f\"num_hidden_layers is {self.num_hidden_layers}\"\n                )\n            bad = sorted(\n                set(self.layer_types) - {\"full_attention\", \"sliding_attention\"}\n            )\n            if bad:\n                raise ValueError(\n                    f\"layer_types contains unknown entries {bad}; expected only \"\n                    \"'full_attention' or 'sliding_attention'\"\n                )\n            if self.layer_types != derived_layer_types:\n                mismatches = [\n                    i\n                    for i, (got, want) in enumerate(\n                        zip(self.layer_types, derived_layer_types)\n                    )\n                    if got != want","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/hardware_backend/mlx/models/muse_glimmer_mlx.py#L279-L315","documentation":"When layer_types is explicitly provided it must have exactly num_hidden_layers entries, one per transformer layer. The validator only derives layer_types from no_rope_layers when it is None; otherwise the length is checked against num_hidden_layers and this error fires on mismatch.","triggerScenarios":"Passing a layer_types list whose len differs from num_hidden_layers — e.g. truncating the list, adding an entry, or using a layer_types array copied from a model with a different layer count.","commonSituations":"Copying config.json between model variants (7B vs 3B with different depths), editing num_hidden_layers without updating layer_types, or partial manual merges of configs.","solutions":["Either omit layer_types so it is derived from no_rope_layers","Or pad/trim layer_types so len == num_hidden_layers","Verify num_hidden_layers matches the actual checkpoint depth before loading"],"exampleFix":"// before (num_hidden_layers=24, but only 12 entries)\n\"layer_types\": [\"full_attention\", \"sliding_attention\", ...12 total]\n// after\n\"layer_types\": null  // derived from no_rope_layers","handlingStrategy":"validation","validationCode":"assert cfg.get(\"layer_types\") is None or len(cfg[\"layer_types\"]) == cfg[\"num_hidden_layers\"]","typeGuard":"def layer_types_len_ok(cfg: dict) -> bool:\n    lt = cfg.get(\"layer_types\")\n    return lt is None or (isinstance(lt, list) and len(lt) == cfg[\"num_hidden_layers\"])","tryCatchPattern":null,"preventionTips":["Prefer omitting layer_types and letting it derive from no_rope_layers","Update both fields together when changing depth"],"tags":["config-validation","layer-types","muse-glimmer"],"backgroundTag":"config-length-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}