xai-org/x-algorithm · error · ValueError

{key}: got {arr.shape}/{arr.dtype}, manifest says {meta['sha

Error message

{key}: got {arr.shape}/{arr.dtype}, manifest says {meta['shape']}/{meta['dtype']}

What it means

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.

Source

Thrown at bdsm/runtime/load_backbone.py:26

def load_params(
    npz_path: str, manifest_path: str | None = None, verify_hashes: bool = False
) -> dict:
    z = np.load(npz_path)
    flat = {key: z[key] for key in z.files}

    if manifest_path is not None:
        with open(manifest_path) as f:
            manifest = json.load(f)
        entries = manifest["params"]
        if set(entries) != set(flat):
            missing = sorted(set(entries) - set(flat))
            extra = sorted(set(flat) - set(entries))
            raise ValueError(f"key mismatch vs manifest: missing={missing} extra={extra}")
        for key, arr in flat.items():
            meta = entries[key]
            if list(arr.shape) != meta["shape"] or str(arr.dtype) != meta["dtype"]:
                raise ValueError(
                    f"{key}: got {arr.shape}/{arr.dtype}, "
                    f"manifest says {meta['shape']}/{meta['dtype']}"
                )
            if verify_hashes:
                digest = hashlib.sha256(np.ascontiguousarray(arr).tobytes()).hexdigest()
                if digest != meta["sha256"]:
                    raise ValueError(f"{key}: sha256 mismatch")

    params: dict[str, dict[str, np.ndarray]] = {}
    for key, arr in flat.items():
        module, _, name = key.partition("/")
        params.setdefault(module, {})[name] = arr
    return params

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Compare the failing key's arr.shape/arr.dtype to the manifest entry named in the message
  2. If architecture legitimately changed, regenerate MANIFEST.json from the new weights
  3. If dtype differs due to precision export, re-save the npz in the manifest's dtype or update both
  4. Never hand-edit the manifest; regenerate it from the artifact

Example fix

# after changing hidden_dim, regenerate the manifest:
python -m bdsm.runtime.audit_manifest --backbone_dir /models/backbone --write
Defensive patterns

Strategy: validation

Validate before calling

for k, arr in np.load(npz_path).items():
    meta = manifest['params'][k]
    assert list(arr.shape) == meta['shape'] and str(arr.dtype) == meta['dtype'], k

Try / catch

try:
    load_params(...)
except ValueError as e:
    if 'manifest says' in str(e):
        raise RuntimeError(f"architecture drift: {e}; regenerate manifest or re-export")
    raise

Prevention

When it happens

Trigger: 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.

Common situations: Architecture hyperparameter change without regenerating the manifest; mixed-precision export pipeline update; loading a fine-tuned variant whose shapes differ.

Related errors


AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28). Data as JSON: /api/errors/2a1cd0ec3da6475e. Report an issue: GitHub.