code wiki / (root) / nx_reader_squad_gate.nx

nx_reader_squad_gate.nx

buildroot/runtime/nx_reader_squad_gate.nx

26562 B546 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind gate/prooftopic reader
docsdependenciesstructsconstsfunctions

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

nx_nofloat_autograd.nx nx_syscalls.nx nx_reader_squad_gate.nx

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

main rq_puts sys_write sys_openat_rd sys_mmap sys_read sys_close rq_pn sys_mmap ↻ sys_write ↻ rq_tok sys_mmap ↻ rq_lc rq_isal rq_ehash rq_vid rq_bsearch nfa_qmul nfa_isqrt rq_init rq_train sys_mmap ↻ rq_fwd nfa_leaf nfa_new nfa_rmsnorm_rows nfa_new ↻ nfa_qmul ↻ nfa_isqrt ↻ nfa_matmul nfa_new ↻ nfa_rope nfa_new ↻ nfa_fxexp nfa_cosf nfa_reduce2pi nfa_cosq nfa_qmul ↻ nfa_sinf nfa_reduce2pi ↻

structs

none

consts

25const RQ_E: i64 = 24 // = SGNS embedding dim (embed_v1.bin)
26const RQ_F: i64 = 48
27const RQ_MAXT: i64 = 96
28const RQ_MAXQ: i64 = 20
29const RQ_MAXG: i64 = 8
30const RQ_SCALE: i64 = 13378 // 1/sqrt(24) in Q16
31const RQ_NROWS: i64 = 960
32const RQ_MAXV: i64 = 16384 // exact-word vocab cap (id 0 = SEP; words 1..nw)
33const RQ_MAPN: i64 = 32768 // open-addressing map slots (power of 2)
35const QOFF_EMB: i64 = 0 // [MAXV,E] 393216 (FROZEN; SGNS-initialized)
36const QOFF_WQ: i64 = 393216 // [E,E] 576
37const QOFF_WK: i64 = 393792
38const QOFF_WV: i64 = 394368
39const QOFF_WO: i64 = 394944
40const QOFF_WG: i64 = 395520 // [E,F] 1152
41const QOFF_WU: i64 = 396672
42const QOFF_WD: i64 = 397824 // [F,E] 1152
43const QOFF_US: i64 = 398976 // [1,E] 24
44const QOFF_UE: i64 = 399000 // [1,E] 24
45const RQ_NP: i64 = 399024

functions

21func 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 }
called by 3: rq_ckrq_trainmain calls 1: sys_write
22func 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 }
called by 2: rq_trainmain calls 2: sys_mmapsys_write
23func 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 }
called by 1: main calls 1: rq_puts
48func rq_ehash(buf: *u8, off: i64, len: i64) -> i64
called by 1: rq_tok
55func rq_bsearch(a: *i64, n: i64, v: i64) -> i64
called by 1: main
61func rq_lc(c: i64) -> i64 { if c >= 65 { if c <= 90 { return c + 32 } } return c }
called by 1: rq_tok
62func 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
65func rq_tok(buf: *u8, n: i64, hout: *i64, cap: i64) -> i64
called by 1: main calls 4: sys_mmaprq_lcrq_isalrq_ehash
89func rq_vid(map: *i64, vhash: *i64, vst: *i64, h: i64) -> i64
called by 1: main
113func rq_fwd(tape: *i64, vals: *i64, st: *i64, W: *i64, Xg: *i64, tgts: *i64, tgte: *i64, T: i64, useattn: i64, out: *i64) -> i64
175func rq_grab_emb(tape: *i64, grads: *i64, out: *i64, G: *i64, ids: *i64, T: i64) -> i64
called by 1: rq_train
187func rq_grab(tape: *i64, grads: *i64, out: *i64, G: *i64) -> i64
called by 1: rq_train
211func rq_init(W: *i64) -> i64
called by 1: main
221func rq_span_f1(ids: *i64, a: i64, b: i64, gs: i64, ge: i64) -> i64
called by 1: rq_eval calls 1: sys_mmap
244func rq_eval(tape: *i64, vals: *i64, st: *i64, W: *i64, dat: *i64, meta: *i64, r0: i64, r1: i64, useattn: i64, res: *i64) -> i64
287func 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
345func main() -> i64