nx_reader_span_gate.nx
buildroot/runtime/nx_reader_span_gate.nx
about
nx_reader_span_gate.nx -- RUNG 2 of the NEURAL PASSAGE READER arc (deep-research R2): the READER-SHAPED
MODEL trains END-TO-END on the verified sovereign no-float stack. Composes nx_nofloat_autograd's PROVEN
transformer block (the exact blk_fwd shape from the green blockfloat gates: embed -> rmsnorm -> Q/K/V ->
RoPE -> QK^T -> causal softmax -> A.V -> Wo -> residual -> rmsnorm -> SwiGLU FFN -> residual) + a SPAN HEAD
(matmul_nt of a trained probe against the contextual states -> [1,L] position logits) + fused softmax-CE.
TASK (question-conditioned span pointing = the reader mechanism): passage = 3 (key,value) pairs in random
order; question = one key token; GOLD SPAN = the position where the queried key occurs in the passage. To
point there the model must ALIGN the question to the context (attention); a QUESTION-BLIND ablation (same
params/budget, attention removed -> h_i sees only its own token, exactly the isolated-candidate reader that
plateaued at 251/148/101) can at best fire on one fixed key = ~333 permille -> liar-kill.
T1 reader (attention block) span accuracy > 700 permille held-out
T2 question-blind ablation < 450 permille AND reader beats it by > 250 (liar-kill)
T3 descent: one nfa_backward+nfa_sgd step on fresh weights DECREASES that example's loss (real gradients)
T4 deterministic re-eval (integer stack -> bit-identical)
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
| 24 | const RS_V: i64 = 7 // tokens: keys 0..2, values 3..5, SEP 6 |
| 25 | const RS_E: i64 = 8 // model dim (even, for RoPE) |
| 26 | const RS_F: i64 = 16 // FFN dim |
| 27 | const RS_L: i64 = 8 // sequence: [q, SEP, k,v, k,v, k,v] |
| 28 | const RS_SCALE: i64 = 23170 // 1/sqrt(E) in Q16 |
| 30 | const OFF_EMB: i64 = 0 // [V,E] 56 |
| 31 | const OFF_WQ: i64 = 56 // [E,E] 64 |
| 32 | const OFF_WK: i64 = 120 |
| 33 | const OFF_WV: i64 = 184 |
| 34 | const OFF_WO: i64 = 248 |
| 35 | const OFF_WG: i64 = 312 // [E,F] 128 |
| 36 | const OFF_WU: i64 = 440 // [E,F] 128 |
| 37 | const OFF_WD: i64 = 568 // [F,E] 128 |
| 38 | const OFF_U: i64 = 696 // [1,E] 8 (span probe) |
| 39 | const RS_NP: i64 = 704 |
functions
| 20 | func rs_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 21 | func rs_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 } |
| 22 | func rs_ck(name: *u8, c: i64) -> i64 { if c==1 { rs_puts(" PASS " as *u8) } else { rs_puts(" FAIL " as *u8) } rs_puts(name); rs_puts("\n" as *u8); return c } |
| 41 | func rs_lcg(x: i64) -> i64 { return ((x*1103515245+12345) & 2147483647) } called by 1: rs_gen |
| 44 | func rs_perms(pm: *i64) -> i64 called by 1: main |
| 51 | func rs_gen(s: i64, pm: *i64, ids: *i64, tgt: *i64) -> i64 |
| 71 | func rs_init(W: *i64) -> i64 called by 1: main |
| 96 | func rs_fwd(tape: *i64, vals: *i64, st: *i64, W: *i64, ids: *i64, tgt: *i64, useattn: i64, out: *i64) -> i64 called by 3: rs_trainrs_evalmain calls 12: nfa_leafnfa_embednfa_rmsnorm_rowsnfa_matmulnfa_ropenfa_matmul_nt+6 |
| 150 | func rs_grab(tape: *i64, grads: *i64, out: *i64, G: *i64) -> i64 |
| 174 | func rs_train(tape: *i64, vals: *i64, grads: *i64, st: *i64, W: *i64, pm: *i64, useattn: i64, EP: i64, lr: i64, verbose: i64) -> i64 |
| 204 | func rs_eval(tape: *i64, vals: *i64, st: *i64, W: *i64, pm: *i64, useattn: i64) -> i64 |
| 224 | func main() -> i64 |