nx_reader_squad_gate.nx
buildroot/runtime/nx_reader_squad_gate.nx
about
nx_reader_squad_gate.nx -- RUNG 3 (a/b/c) of the NEURAL PASSAGE READER arc: the reader trains on REAL SQuAD.
R3c = ERROR-FEEDBACK SGD (nfa_sgd_ef): R3b's three runs all froze in a Q16 uniform-collapse absorbing state
because sub-quantum updates truncate to zero; error-feedback keeps the residuals so no gradient is lost.
R3a (2889ff525f) measured the from-scratch wall honestly: the pipeline + STABLE Q16 training work (grad-clip
+ LR-decay; loss 8401->2286) but at 664 rows the reader MEMORIZES without out-generalizing a question-blind
token-prior baseline -- because 131k of 133k params were COLD-START embeddings.
R3b (this version) = the measured lever: PRETRAINED SOVEREIGN EMBEDDINGS. The vocab is exact-word (61-bit
ehash, same hash as the PPMI/SGNS vocab); the embedding table is INITIALIZED from R1's trained SGNS
embeddings (knowledge/index/embed_v1.bin, full-data run) and FROZEN -- trainable params drop 133k -> ~7k
(attention block + FFN + span heads only), attacking the memorization directly. Attention alignment
(Wq/Wk bilinear) now operates on MEANINGFUL word geometry (question<->context similarity = SGNS cosine).
T1 held-out span token-F1: reader > question-blind ablation + 100 permille (liar-kill at pretrained parity)
T2 held-out exact-start > 60 permille (chance ~11)
T3 pretraining helps: reader F1 > R3a's from-scratch 56 + 50
T4 deterministic re-eval
Consumes: reader_rows.bin (nx_qabench 'dt'), semppmi_v1.bin (vocab hashes), embed_v1.bin (SGNS Q10).
expect_exit: 0 license_tier: ORIGINAL Sovereign: nx_nofloat_autograd + nx_syscalls.
dependencies 2 imports · 0 importers
imports: nx_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
| 25 | const RQ_E: i64 = 24 // = SGNS embedding dim (embed_v1.bin) |
| 26 | const RQ_F: i64 = 48 |
| 27 | const RQ_MAXT: i64 = 96 |
| 28 | const RQ_MAXQ: i64 = 20 |
| 29 | const RQ_MAXG: i64 = 8 |
| 30 | const RQ_SCALE: i64 = 13378 // 1/sqrt(24) in Q16 |
| 31 | const RQ_NROWS: i64 = 960 |
| 32 | const RQ_MAXV: i64 = 16384 // exact-word vocab cap (id 0 = SEP; words 1..nw) |
| 33 | const RQ_MAPN: i64 = 32768 // open-addressing map slots (power of 2) |
| 35 | const QOFF_EMB: i64 = 0 // [MAXV,E] 393216 (FROZEN; SGNS-initialized) |
| 36 | const QOFF_WQ: i64 = 393216 // [E,E] 576 |
| 37 | const QOFF_WK: i64 = 393792 |
| 38 | const QOFF_WV: i64 = 394368 |
| 39 | const QOFF_WO: i64 = 394944 |
| 40 | const QOFF_WG: i64 = 395520 // [E,F] 1152 |
| 41 | const QOFF_WU: i64 = 396672 |
| 42 | const QOFF_WD: i64 = 397824 // [F,E] 1152 |
| 43 | const QOFF_US: i64 = 398976 // [1,E] 24 |
| 44 | const QOFF_UE: i64 = 399000 // [1,E] 24 |
| 45 | const RQ_NP: i64 = 399024 |
functions
| 21 | func rq_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 22 | func rq_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 } |
| 23 | func rq_ck(name: *u8, c: i64) -> i64 { if c==1 { rq_puts(" PASS " as *u8) } else { rq_puts(" FAIL " as *u8) } rq_puts(name); rq_puts("\n" as *u8); return c } |
| 48 | func rq_ehash(buf: *u8, off: i64, len: i64) -> i64 called by 1: rq_tok |
| 55 | func rq_bsearch(a: *i64, n: i64, v: i64) -> i64 called by 1: main |
| 61 | func rq_lc(c: i64) -> i64 { if c >= 65 { if c <= 90 { return c + 32 } } return c } called by 1: rq_tok |
| 62 | func rq_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: rq_tok |
| 65 | func rq_tok(buf: *u8, n: i64, hout: *i64, cap: i64) -> i64 |
| 89 | func rq_vid(map: *i64, vhash: *i64, vst: *i64, h: i64) -> i64 called by 1: main |
| 113 | func rq_fwd(tape: *i64, vals: *i64, st: *i64, W: *i64, Xg: *i64, tgts: *i64, tgte: *i64, T: i64, useattn: i64, out: *i64) -> i64 called by 2: rq_evalrq_train calls 11: nfa_leafnfa_rmsnorm_rowsnfa_matmulnfa_ropenfa_matmul_ntnfa_cmul+5 |
| 175 | func rq_grab_emb(tape: *i64, grads: *i64, out: *i64, G: *i64, ids: *i64, T: i64) -> i64 called by 1: rq_train |
| 187 | func rq_grab(tape: *i64, grads: *i64, out: *i64, G: *i64) -> i64 called by 1: rq_train |
| 211 | func rq_init(W: *i64) -> i64 called by 1: main |
| 221 | func rq_span_f1(ids: *i64, a: i64, b: i64, gs: i64, ge: i64) -> i64 |
| 244 | func rq_eval(tape: *i64, vals: *i64, st: *i64, W: *i64, dat: *i64, meta: *i64, r0: i64, r1: i64, useattn: i64, res: *i64) -> i64 |
| 287 | func rq_train(tape: *i64, vals: *i64, grads: *i64, st: *i64, W: *i64, dat: *i64, meta: *i64, ntrain: i64, useattn: i64, EP: i64, lr: i64, verbose: i64) -> i64 |
| 345 | func main() -> i64 |