xai-org/x-algorithm · critical · ValueError

{key}: sha256 mismatch

Error message

{key}: sha256 mismatch

What it means

With verify_hashes enabled, each parameter array is serialized (ascontiguousarray + tobytes) and sha256-hashed; a digest differing from the manifest's recorded sha256 means the weight bytes changed (silent corruption or a different checkpoint) and loading fails.

Source

Thrown at bdsm/runtime/load_backbone.py:33

    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. Re-download/re-sync the backbone artifacts (npz + MANIFEST.json) from the source of truth
  2. If weights legitimately changed, regenerate the manifest so hashes match
  3. Verify disk/filesystem health if corruption is suspected
  4. Keep verify_hashes=True in production; only bypass in trusted local debugging

Example fix

# integrity check outside the loader:
python -c "import hashlib,numpy as np; a=np.load('/m/backbone.npz')[key]; print(hashlib.sha256(np.ascontiguousarray(a).tobytes()).hexdigest())"
Defensive patterns

Strategy: validation

Validate before calling

import hashlib, numpy as np
for k, arr in np.load(npz_path).items():
    d = hashlib.sha256(np.ascontiguousarray(arr).tobytes()).hexdigest()
    assert d == manifest['params'][k]['sha256'], k

Try / catch

try:
    load_params(npz_path, manifest_path, verify_hashes=True)
except ValueError as e:
    if 'sha256 mismatch' in str(e):
        re_download_artifacts()
    raise

Prevention

When it happens

Trigger: Bit-level corruption of the npz (bad disk, interrupted write); weights re-saved with identical shapes/dtypes but different values; mixed artifacts where the manifest belongs to another checkpoint; different memory layout producing different bytes.

Common situations: Partial download/sync of model artifacts; storage-level corruption; tamper detection working as intended; cross-platform export differences.

Related errors


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