nx_reader_quantize_gate.nx
buildroot/runtime/nx_reader_quantize_gate.nx
about
nx_reader_quantize_gate.nx -- R4 of the neural-reader arc: QUANTIZE-AFTER. Takes the f32-TRAINED reader
(reader_neural_f32*.bin, our own from-scratch model), quantizes its weights to Q16, and runs PURE-INTEGER
(nfa_*) inference -- the train-float / infer-int split, completed for a SOVEREIGN-TRAINED model. Proves the
no-float reader is FAITHFUL to the f32 model by running BOTH forwards on the same real held-out SQuAD split
and comparing span predictions + gold-F1. (The nfa_* Q16 forward has NO collapse risk -- collapse was a
TRAINING dynamics artifact; inference of trained weights is exact-enough in Q16.)
T1 no-float (Q16) held-out span-F1 within 60 permille of the f32 reader's F1 (quantization faithful)
T2 Q16-vs-f32 span-prediction AGREEMENT > 800 permille (same model, integer vs float)
T3 the Q16 path is PURE INTEGER (structural: only nfa_* Q16 ops, zero nx_f32 in the inference)
T4 deterministic
Consumes: reader_neural_f32.bin (f32 W), semppmi_v1.bin (vocab hashes), reader_rows.bin (same rows/vocab as
training so token ids address the trained embedding rows). expect_exit: 0 license_tier: ORIGINAL
dependencies 3 imports · 0 importers
imports: nx_autograd_tensor.nxnx_nofloat_autograd.nxnx_syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 21 | const QZ_E: i64 = 24 |
| 22 | const QZ_F: i64 = 48 |
| 23 | const QZ_MAXT: i64 = 96 |
| 24 | const QZ_MAXQ: i64 = 20 |
| 25 | const QZ_MAXG: i64 = 8 |
| 26 | const QZ_NROWS: i64 = 1200 |
| 27 | const QZ_MAXV: i64 = 16384 |
| 28 | const QZ_MAPN: i64 = 32768 |
| 29 | const QOFF_EMB: i64 = 0 |
| 30 | const QOFF_WQ: i64 = 393216 |
| 31 | const QOFF_WK: i64 = 393792 |
| 32 | const QOFF_WV: i64 = 394368 |
| 33 | const QOFF_WO: i64 = 394944 |
| 34 | const QOFF_WG: i64 = 395520 |
| 35 | const QOFF_WU: i64 = 396672 |
| 36 | const QOFF_WD: i64 = 397824 |
| 37 | const QOFF_US: i64 = 398976 |
| 38 | const QOFF_UE: i64 = 399000 |
| 39 | const QZ_NP: i64 = 399024 |
| 40 | const QZ_SCALE_Q16: i64 = 13378 // 1/sqrt(24) in Q16 (matches nfa) |
functions
| 17 | func qz_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 18 | func qz_pn(v: i64) -> i64 { let b: *u8=sys_mmap(28); var x: i64=v; if x<0{b[0]=45;sys_write(1,b,1);x=0-x} if x==0{b[0]=48;sys_write(1,b,1);return 0} var d: i64=0; var y: i64=x; while y>0{d=d+1;y=y/10} var i: i64=d-1; y=x; while i>=0{b[i]=(48+(y%10)) as u8;y=y/10;i=i-1} sys_write(1,b,d); return 0 } |
| 19 | func qz_ck(name: *u8, c: i64) -> i64 { if c==1 { qz_puts(" PASS " as *u8) } else { qz_puts(" FAIL " as *u8) } qz_puts(name); qz_puts("\n" as *u8); return c } |
| 43 | func qz_ehash(buf: *u8, off: i64, len: i64) -> i64 called by 1: qz_tok |
| 50 | func qz_bsearch(a: *i64, n: i64, v: i64) -> i64 |
| 56 | func qz_lc(c: i64) -> i64 { if c >= 65 { if c <= 90 { return c + 32 } } return c } called by 1: qz_tok |
| 57 | func qz_isal(c: i64) -> i64 { if c >= 97 { if c <= 122 { return 1 } } if c >= 48 { if c <= 57 { return 1 } } return 0 } called by 1: qz_tok |
| 58 | func qz_tok(buf: *u8, n: i64, hout: *i64, cap: i64) -> i64 |
| 80 | func qz_vid(map: *i64, vhash: *i64, vst: *i64, h: i64) -> i64 called by 1: main |
| 95 | func qz_fwd_f32(tape: *i64, vals: *i64, st: *i64, W: *i64, Xg: *i64, T: i64, rtab: *i64, ls: *i64, le: *i64) -> i64 |
| 137 | func qz_fwd_q16(tape: *i64, vals: *i64, st: *i64, W: *i64, Xg: *i64, T: i64, ls: *i64, le: *i64) -> i64 |
| 178 | func qz_span(ls: *i64, le: *i64, qn: i64, T: i64, isf32: i64) -> i64 |
| 202 | func qz_f1(ids: *i64, a: i64, b: i64, gs: i64, ge: i64) -> i64 |
| 222 | func main() -> i64 |