code wiki / (root) / nx_reader_quantize_gate.nx

nx_reader_quantize_gate.nx

buildroot/runtime/nx_reader_quantize_gate.nx

19301 B387 linesdepth 6pulls 16 transitivereach 0 importersview sourcekind gate/prooftopic reader
docsdependenciesstructsconstsfunctions

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

nx_autograd_tensor.nx nx_nofloat_autograd.nx nx_syscalls.nx nx_reader_quantize_gate.nx

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

main qz_puts sys_write sys_openat_rd sys_mmap sys_read sys_close qz_pn sys_mmap ↻ sys_write ↻ nx_i32_to_f32 _sc_f32_to_i32_rne nx_f32_classify nx_f32_exp_field nx_f32_mant_field nx_f32_sign nx_f32_exp_field ↻ nx_f32_mant_field ↻ nx_f32_mul nx_f32_classify ↻ nx_f32_sign ↻ nx_f32_mant_field ↻ nx_f32_exp_field ↻ qz_tok sys_mmap ↻ qz_lc qz_isal qz_ehash qz_vid ta_rope_build_tab ta_rope_ang nx_f32_log nx_f32_classify ↻ nx_f32_sign ↻ nx_f32_exp_field ↻ nx_f32_mant_field ↻ nx_f32_sub nx_f32_add nx_f32_classify ↻ nx_f32_sign ↻

structs

none

consts

21const QZ_E: i64 = 24
22const QZ_F: i64 = 48
23const QZ_MAXT: i64 = 96
24const QZ_MAXQ: i64 = 20
25const QZ_MAXG: i64 = 8
26const QZ_NROWS: i64 = 1200
27const QZ_MAXV: i64 = 16384
28const QZ_MAPN: i64 = 32768
29const QOFF_EMB: i64 = 0
30const QOFF_WQ: i64 = 393216
31const QOFF_WK: i64 = 393792
32const QOFF_WV: i64 = 394368
33const QOFF_WO: i64 = 394944
34const QOFF_WG: i64 = 395520
35const QOFF_WU: i64 = 396672
36const QOFF_WD: i64 = 397824
37const QOFF_US: i64 = 398976
38const QOFF_UE: i64 = 399000
39const QZ_NP: i64 = 399024
40const QZ_SCALE_Q16: i64 = 13378 // 1/sqrt(24) in Q16 (matches nfa)

functions

17func 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 }
called by 2: qz_ckmain calls 1: sys_write
18func 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 }
called by 1: main calls 2: sys_mmapsys_write
19func 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 }
called by 1: main calls 1: qz_puts
43func qz_ehash(buf: *u8, off: i64, len: i64) -> i64
called by 1: qz_tok
50func qz_bsearch(a: *i64, n: i64, v: i64) -> i64
56func qz_lc(c: i64) -> i64 { if c >= 65 { if c <= 90 { return c + 32 } } return c }
called by 1: qz_tok
57func 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
58func qz_tok(buf: *u8, n: i64, hout: *i64, cap: i64) -> i64
called by 1: main calls 4: sys_mmapqz_lcqz_isalqz_ehash
80func qz_vid(map: *i64, vhash: *i64, vst: *i64, h: i64) -> i64
called by 1: main
95func qz_fwd_f32(tape: *i64, vals: *i64, st: *i64, W: *i64, Xg: *i64, T: i64, rtab: *i64, ls: *i64, le: *i64) -> i64
137func qz_fwd_q16(tape: *i64, vals: *i64, st: *i64, W: *i64, Xg: *i64, T: i64, ls: *i64, le: *i64) -> i64
178func qz_span(ls: *i64, le: *i64, qn: i64, T: i64, isf32: i64) -> i64
called by 1: main calls 1: nx_f32_gt
202func qz_f1(ids: *i64, a: i64, b: i64, gs: i64, ge: i64) -> i64
called by 1: main calls 1: sys_mmap
222func main() -> i64