Qwen3-0.6B inference (12 KB), bare-metal bootable OS (22 KB), and from-scratch Mini-GPT trainer with live Braille TUI (32 KB) in 100% pure x86-64 NASM assembly. Zero C, zero libc, zero dependencies.
"""Negative control: corrupt one dump tensor and assert the harness fails.
A verifier that cannot fail is worthless. This proves the gates are live.
Usage:
python _negative_test.py <dump-dir>
<dump-dir> must be a directory produced by `asm-gpt-train --dump-debug`
(or by verify_train_np.py --bin ... --keep-dump). The dump is copied to a
temporary directory and corrupted there, so the original is never modified.
"""
import os
import shutil
import struct
import subprocess
import sys
import tempfile
HERE = os.path.dirname(os.path.abspath(__file__))
def main(argv):
if len(argv) != 2:
print("usage: python _negative_test.py <dump-dir>", file=sys.stderr)
print(" <dump-dir> must be a dump produced by "
"asm-gpt-train --dump-debug", file=sys.stderr)
return 2
src = os.path.abspath(argv[1])
if not os.path.isdir(src):
print(f"no such dump dir: {src}", file=sys.stderr)
return 2
work = tempfile.mkdtemp(prefix="npneg-")
dst = os.path.join(work, "dump")
shutil.copytree(src, dst)
# Corrupt the step-0 gradient block: add a 1e-2 offset to the first 64
# float32 entries. Nominal rel_rms is 6.1e-07, so this must trip the gate.
gp = os.path.join(dst, "step0_grads.bin")
with open(gp, "rb") as f:
buf = bytearray(f.read())
n = min(64, len(buf) // 4)
for i in range(n):
v = struct.unpack_from("<f", buf, i * 4)[0]
struct.pack_into("<f", buf, i * 4, v + 1e-2)
with open(gp, "wb") as f:
f.write(buf)
print(f"corrupted : {gp} (+1e-2 on first {n} float32)")
print(f"size : {os.path.getsize(gp)} B")
cmd = [sys.executable, os.path.join(HERE, "verify_train_np.py"),
"--dump-dir", dst]
p = subprocess.run(cmd, capture_output=True, text=True)
out = p.stdout + p.stderr
# Count gate verdicts only; the summary line contains the same words and
# would otherwise be double-counted.
failed_gates = [l for l in out.splitlines()
if "FAIL" in l and "overall" not in l]
passed_gates = [l for l in out.splitlines()
if "PASS" in l and "overall" not in l]
print(f"rc : {p.returncode}")
print(f"gates PASS : {len(passed_gates)}")
print(f"gates FAIL : {len(failed_gates)}")
for l in failed_gates[:8]:
print(" ", l.strip())
ok = (p.returncode == 1) and len(failed_gates) > 0
print("\nNEGATIVE CONTROL:", "PASS (harness rejects bad data)" if ok
else "FAIL (harness accepted corrupted dump -- gates are dead)")
shutil.rmtree(work, ignore_errors=True)
return 0 if ok else 1
if __name__ == "__main__":
sys.exit(main(sys.argv))