code wiki / _hdl_build / nx_nofloat_generalize_gate.nx

nx_nofloat_generalize_gate.nx

buildroot/runtime/_hdl_build/nx_nofloat_generalize_gate.nx

8380 B115 linesdepth 3pulls 4 transitivereach 0 importersview sourcekind gate/prooftopic nofloat
docsdependenciesstructsconstsfunctions

about

nx_nofloat_generalize_gate.nx -- HELD-OUT RULE GENERALIZATION in pure integer Q16 (CAP-NF-GENERALIZE). The real test of learning vs memorization: train the no-float char-LM on a periodic sequence "abcabc..." (it must learn the first-order RULE a->b, b->c, c->a), then evaluate on data it NEVER trained on: T1 a HELD-OUT string "cabcab..." (SAME rule, DIFFERENT string) -> high next-char accuracy (>> chance 1/3). Succeeding on a SHIFTED string proves the model learned the CHAR-rule, not position-by-position memorization. T2 (teeth) a CONTROL "acbacb..." (DIFFERENT rule a->c,c->b,b->a) -> ~chance accuracy. Proves the model applies the SPECIFIC learned rule (it is not outputting constants or trivially-correct). Lean (nx_cc .s ceiling): exactly 2 clm_fwd call sites -- do_train (helper) + eval_acc (helper, called twice). HONEST: first-order periodic rule on a tiny task = a real but modest generalization (not deep in-context learning). Sovereign: nx_nofloat_autograd + nx_syscalls. expect_exit: 0

dependencies 3 imports · 0 importers

nx_nofloat_autograd.nx nx_g_puts_lib.nx nx_syscalls.nx nx_nofloat_generalize_gate.nx

imports: nx_nofloat_autograd.nxnx_g_puts_lib.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 g_puts sys_write slen sys_mmap g_pn sys_mmap ↻ sys_write ↻ dini do_train clm_fwd nfa_leaf nfa_new nfa_embed 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 ↻ nfa_sinq nfa_qmul ↻ nfa_qmul ↻ nfa_matmul_nt nfa_new ↻ nfa_cmul nfa_new ↻ nfa_qmul ↻ nfa_softmax_rows nfa_new ↻

structs

none

consts

14const Q16: i64 = 65536

functions

16func g_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
17func slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
called by 1: main
18func dini(a: *i64, n: i64, sd: i64) -> i64 { var i: i64=0; while i<n { a[i]=(((i*7+sd*13+1)%11)-5)*13107; i=i+1 } return 0 }
called by 1: main
19func amx(tape: *i64, vals: *i64, logn: i64, r: i64, V: i64) -> i64 { let o: i64=tape[7*logn+5]; var b: i64=0; var bv: i64=vals[o+r*V]; var j: i64=1; while j<V { if vals[o+r*V+j]>bv { bv=vals[o+r*V+j]; b=j } j=j+1 } return b }
called by 1: eval_acc
21func clm_fwd(tape: *i64, vals: *i64, st: *i64, W: *i64, ids: *i64, tgt: *i64, T: i64, dm: i64, V: i64, scale: i64, leaves: *i64) -> i64
49func step_all(tape: *i64, grads: *i64, W: *i64, WN: *i64, leaves: *i64, nW: i64, lr: i64, clip: i64, gb: *i64) -> i64
called by 1: do_train calls 2: nfa_gradnfa_sgd
55func do_train(tape: *i64, vals: *i64, grads: *i64, st: *i64, W: *i64, WN: *i64, ids: *i64, tgt: *i64, T: i64, dm: i64, V: i64, scale: i64, leaves: *i64, gb: *i64, steps: i64) -> i64
called by 1: main calls 3: clm_fwdnfa_backwardstep_all
61func eval_acc(tape: *i64, vals: *i64, st: *i64, W: *i64, ids2: *i64, T: i64, dm: i64, V: i64, scale: i64, leaves: *i64) -> i64
called by 1: main calls 2: clm_fwdamx
68func main() -> i64