{"record":{"id":"9acb43cd57125f83","repo":"vllm-project/vllm","slug":"got-len-layers-per-layer-configs-for-a-model-wi","errorCode":null,"errorMessage":"got {len(layers)} per-layer configs for a model with {merged['total_num_hidden_layers']} layers","messagePattern":"got (.+?) per-layer configs for a model with (.+?) layers","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"vllm/config/model_arch.py","lineNumber":137,"sourceCode":"            # `bool` is an `int`, so an exact type check is what keeps a varying\n            # flag from collapsing to `any`. `is_deepseek_mla` doing that would\n            # make `use_mla` true model wide, and `get_num_kv_heads` then returns\n            # 1 for every layer, discarding the overrides built here.\n            if not all(type(value) in (int, float) for value in values):\n                raise ValueError(\n                    f\"{f.name!r} varies across layers and has no whole-model \"\n                    f\"value: {sorted(set(map(repr, values)))}. Only numeric \"\n                    f\"fields collapse (with `max`, to size buffers for the \"\n                    f\"largest layer); give this one an explicit rule in \"\n                    f\"ModelArchitectureConfig.from_layers.\"\n                )\n            merged[f.name] = max(values)\n            for override, value in zip(overrides, values):\n                if value != merged[f.name]:\n                    override[f.name] = value\n\n        if len(layers) != merged[\"total_num_hidden_layers\"]:\n            raise ValueError(\n                f\"got {len(layers)} per-layer configs for a model with \"\n                f\"{merged['total_num_hidden_layers']} layers\"\n            )\n        # A checkpoint can be heterogeneous over attributes vLLM never reads, in\n        # which case there is nothing to keep the layers apart for.\n        return cls(**merged, per_layer_overrides=overrides if any(overrides) else None)\n","sourceCodeStart":119,"sourceCodeEnd":144,"githubUrl":"https://github.com/vllm-project/vllm/blob/c794754062d49a8fdb63ab3c5215b488b865030c/vllm/config/model_arch.py#L119-L144","documentation":"After merging, from_layers cross-checks that the number of supplied per-layer configs equals total_num_hidden_layers in the merged config. A mismatch means the extracted layer list and the declared depth disagree — the merged config would describe the wrong shape.","triggerScenarios":"from_layers receives N configs while merged['total_num_hidden_layers'] is M != N — e.g. layer extraction dropped/added layers (regex missing tied or MoE expert layers), or total_num_hidden_layers itself varies and got max-collapsed.","commonSituations":"Checkpoints with shared/tied layer weights where extraction skips duplicates; safetensors indexes listing partial shards; heterogeneous checkpoints whose total_num_hidden_layers differs per component and max() picks the largest.","solutions":["Fix the layer extraction to emit exactly total_num_hidden_layers configs (account for tied/shared layers and MoE structure).","Verify the checkpoint's declared num_hidden_layers matches the actual weights present (re-download or re-convert if shards are missing).","If depth legitimately varies, give total_num_hidden_layers an explicit rule in from_layers rather than relying on max collapse."],"exampleFix":"# before\nlayer_cfgs = [cfg for cfg in all_cfgs if 'self_attn' in cfg]  # dropped hybrid layers\n# after\nlayer_cfgs = all_cfgs[:merged_total_num_hidden_layers]\nModelArchitectureConfig.from_layers(layer_cfgs)","handlingStrategy":"validation","validationCode":"def layer_count_ok(layer_cfgs, expected: int) -> bool:\n    return len(layer_cfgs) == expected\n# compare against the checkpoint's declared num_hidden_layers before from_layers","typeGuard":"def matches_declared_depth(layer_cfgs: list, declared: int) -> bool:\n    return len(layer_cfgs) == declared","tryCatchPattern":"except ValueError as e:\n    if 'per-layer configs for a model with' in str(e):\n        re-extract layers with a corrected filter (include tied/shared and MoE layers) and retry the build","preventionTips":["Validate len(extracted_layers) == config.num_hidden_layers immediately after extraction.","Account for tied/shared layers and MoE structure in layer filters.","Re-download partial or shard-incomplete checkpoints instead of patching counts."],"tags":["model-arch","heterogeneous-layers","checkpoint","internal-api"],"backgroundTag":null,"analyzedSha":"c794754062d49a8fdb63ab3c5215b488b865030c","analyzedAt":"2026-08-14T21:17:39.825Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}