#!/usr/bin/env python3 """Offline independent archive decode and FP64 expert oracle; no serving use. Consumes private output from strata-kar-expert-probe. It does not compare with the source GGUF or establish model quality, native arithmetic parity or speed. """ import argparse import hashlib import json import os from pathlib import Path import numpy as np def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--archive", type=Path, required=True) parser.add_argument("--result", type=Path, required=True) args = parser.parse_args() os.umask(0o077) root = args.result.resolve(strict=True) repo = Path(__file__).resolve().parent.parent if root == repo or repo in root.parents: parser.error("qualification outputs must remain outside Git") m = json.loads((root / "metadata.json").read_text()) h, ff, tokens, level, expert = (m[k] for k in ("hidden", "intermediate", "tokens", "level", "expert")) if not (0 < h <= 16384 and 0 < ff <= 16384 and h * ff <= 16777216 and h % 32 == 0 and ff % 32 == 0 and 1 <= tokens <= 8 and 1 <= level <= 8 and 0 <= expert < 65536): raise ValueError("invalid evidence geometry") words = h * ff // 32 matrices, checks = [], [] with args.archive.open("rb") as archive: def read(offset, size, dtype): if not isinstance(offset, int) or offset < 0: raise ValueError("invalid archive offset") archive.seek(offset) raw = archive.read(size) if len(raw) != size: raise ValueError("short archive slice") return np.frombuffer(raw, dtype=dtype) for role, t in zip(("gate", "up", "down"), m["tensors"], strict=True): book = read(t["books_offset"] + ((1 << level) - 2) * 2, (1 << level) * 2, "> np.arange(32, dtype=np.uint32)) & 1) values = (book[codes] * scale[:, None]).astype("= 0 sigmoid[positive] = 1 / (1 + np.exp(-gate[positive])) exp = np.exp(gate[~positive]) sigmoid[~positive] = exp / (1 + exp) expected = (gate * sigmoid * up) @ matrices[2].T actual = np.fromfile(root / "output.f32", dtype="