Documented tree replacement (the history has no git-subtree metadata): 3-way merge of the old subtree (570201a:engine/strata) against upstream 41cf05a06a25dd29103b7b27a2279a3f60c21876 (2026-10-25), merge base = the old pin d9ab8435 (tree-identical to upstream 5b734e42; d9ab8435 is not an ancestor of upstream main). Local patches re-applied by hand where they conflicted (15 files): STRATA_CUDA_STATIC profile, experimental KAR experts and KAR PLE arms, keyless V-only arm (now beside upstream's K8V4 hybrid KV and fused norm+rope). Details, conflict table and left-out files are in docs/upstream.md. Left out (weights, captures, logs, media): new bench/results (2022 files), binary media and app assets (61), docs/work/evidence (24), *.bin / *.gguf data files, and the 7 files the first import already left out. scripts/build-cpu.sh: build the 11 CPU tests upstream registered since the old pin (they ran as "Not Run"). Checked: build-cpu.sh 16/16 ctest in WSL; sm_86 CUDA objects of the patched files compile, also with the KAR macros on. No GPU run, no quality gate. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
35 lines
1.5 KiB
Python
35 lines
1.5 KiB
Python
"""metal/tools/check_ref.py - checks metal/src/ref_quant.cpp's dequantizers against gguf-py's (and Q2_0 against
|
|
tools/gguf_writer.py's codec) on the files tests/ref_dump wrote:
|
|
|
|
python metal/tools/check_ref.py <dir>
|
|
|
|
Prints the max |difference| per type; the reference passes when every one is 0 (bitwise: both decode to float32).
|
|
"""
|
|
import pathlib
|
|
import sys
|
|
|
|
import numpy as np
|
|
|
|
ROOT = pathlib.Path(__file__).resolve().parents[2]
|
|
sys.path.insert(0, str(ROOT / "tools"))
|
|
from gguf.quants import dequantize # noqa: E402
|
|
from gguf.constants import GGMLQuantizationType as Q # noqa: E402
|
|
|
|
ROWS, COLS = 16, 2560
|
|
d = pathlib.Path(sys.argv[1] if len(sys.argv) > 1 else ".")
|
|
bad = 0
|
|
for name in ("Q2_0", "Q4_0", "Q5_0", "Q8_0", "Q3_K", "Q4_K", "Q5_K", "Q6_K", "IQ2_XXS", "IQ2_XS", "IQ2_S", "IQ3_XXS",
|
|
"IQ3_S", "IQ4_NL", "IQ4_XS", "BF16", "F16"):
|
|
raw = np.fromfile(d / f"{name}.bin", dtype=np.uint8)
|
|
ref = np.fromfile(d / f"{name}.f32", dtype=np.float32).reshape(ROWS, COLS)
|
|
if name == "Q2_0":
|
|
from gguf_writer import dequantize_q2_0 # noqa: E402
|
|
got = np.asarray(dequantize_q2_0(raw.tobytes()), dtype=np.float32).reshape(ROWS, COLS)
|
|
else:
|
|
got = dequantize(raw.reshape(ROWS, -1), Q[name]).astype(np.float32).reshape(ROWS, COLS)
|
|
diff = float(np.max(np.abs(got - ref)))
|
|
scale = float(np.max(np.abs(got)))
|
|
print(f"{name:8s} max |ref_quant - gguf-py| = {diff:.3e} (max |w| {scale:.3e}) {'ok' if diff == 0 else 'DIFF'}")
|
|
bad += diff != 0
|
|
sys.exit(1 if bad else 0)
|