{"record":{"id":"2a1cd0ec3da6475e","repo":"xai-org/x-algorithm","slug":"key-got-arr-shape-arr-dtype-manifest-says","errorCode":null,"errorMessage":"{key}: got {arr.shape}/{arr.dtype}, manifest says {meta['shape']}/{meta['dtype']}","messagePattern":"(.+?): got (.+?)/(.+?), manifest says (.+?)/(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"bdsm/runtime/load_backbone.py","lineNumber":26,"sourceCode":"\ndef load_params(\n    npz_path: str, manifest_path: str | None = None, verify_hashes: bool = False\n) -> dict:\n    z = np.load(npz_path)\n    flat = {key: z[key] for key in z.files}\n\n    if manifest_path is not None:\n        with open(manifest_path) as f:\n            manifest = json.load(f)\n        entries = manifest[\"params\"]\n        if set(entries) != set(flat):\n            missing = sorted(set(entries) - set(flat))\n            extra = sorted(set(flat) - set(entries))\n            raise ValueError(f\"key mismatch vs manifest: missing={missing} extra={extra}\")\n        for key, arr in flat.items():\n            meta = entries[key]\n            if list(arr.shape) != meta[\"shape\"] or str(arr.dtype) != meta[\"dtype\"]:\n                raise ValueError(\n                    f\"{key}: got {arr.shape}/{arr.dtype}, \"\n                    f\"manifest says {meta['shape']}/{meta['dtype']}\"\n                )\n            if verify_hashes:\n                digest = hashlib.sha256(np.ascontiguousarray(arr).tobytes()).hexdigest()\n                if digest != meta[\"sha256\"]:\n                    raise ValueError(f\"{key}: sha256 mismatch\")\n\n    params: dict[str, dict[str, np.ndarray]] = {}\n    for key, arr in flat.items():\n        module, _, name = key.partition(\"/\")\n        params.setdefault(module, {})[name] = arr\n    return params\n","sourceCodeStart":8,"sourceCodeEnd":40,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/bdsm/runtime/load_backbone.py#L8-L40","documentation":"For each parameter key, load_params checks the array's shape and dtype against the manifest metadata. A mismatch (e.g. reshaped layer, float32 vs float16) raises immediately, catching architecture drift before inference.","triggerScenarios":"Loading weights saved from a model with different layer sizes (e.g. hidden dim changed from 768 to 1024) against the old manifest; quantized or dt-cast npz paired with an unquantized manifest; transposed export.","commonSituations":"Architecture hyperparameter change without regenerating the manifest; mixed-precision export pipeline update; loading a fine-tuned variant whose shapes differ.","solutions":["Compare the failing key's arr.shape/arr.dtype to the manifest entry named in the message","If architecture legitimately changed, regenerate MANIFEST.json from the new weights","If dtype differs due to precision export, re-save the npz in the manifest's dtype or update both","Never hand-edit the manifest; regenerate it from the artifact"],"exampleFix":"# after changing hidden_dim, regenerate the manifest:\npython -m bdsm.runtime.audit_manifest --backbone_dir /models/backbone --write","handlingStrategy":"validation","validationCode":"for k, arr in np.load(npz_path).items():\n    meta = manifest['params'][k]\n    assert list(arr.shape) == meta['shape'] and str(arr.dtype) == meta['dtype'], k","typeGuard":null,"tryCatchPattern":"try:\n    load_params(...)\nexcept ValueError as e:\n    if 'manifest says' in str(e):\n        raise RuntimeError(f\"architecture drift: {e}; regenerate manifest or re-export\")\n    raise","preventionTips":["Regenerate manifests on every architecture change","Pin dtypes explicitly in the export pipeline","Treat shape mismatches as release blockers, not warnings"],"tags":["python","model-loading","shape-mismatch","dtype"],"backgroundTag":"model-shape-mismatch","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}