code wiki / _hdl_build / nx_nofloat_lm_gate.nx

nx_nofloat_lm_gate.nx

buildroot/runtime/_hdl_build/nx_nofloat_lm_gate.nx

17415 B295 linesdepth 3pulls 4 transitivereach 0 importersview sourcekind gate/prooftopic nofloat
docsdependenciesstructsconstsfunctions

about

nx_nofloat_lm_gate.nx -- THE CAPSTONE: a tiny TRANSFORMER LANGUAGE MODEL trains END-TO-END on next-token prediction, in PURE INTEGER Q16 (CAP-NF-LM). Full LM forward: X = embed(E, ids) -> pre-norm transformer block (attn+RoPE+causal-softmax+SwiGLU-FFN+residuals) -> rmsnorm_rows -> logits = H_n . W_lm -> loss = softmax-cross-entropy(logits, next-token ids) Composed ENTIRELY from gradcheck-verified ops + the two new LM-head ops (embed gather/scatter, fused softce). A1 embed gradcheck : dE (gather backward = scatter-add) == finite difference. A2 softce gradcheck : dlogits (fused CE identity softmax-onehot) == finite difference. A3 full-LM gradcheck wrt W_lm : the LM-head gradient through CE == finite diff. A4 full-LM gradcheck wrt E : the LONGEST chain -- E's gradient flows back through head+norm+FFN+attention +RoPE+softmax+embed (the WHOLE model) == finite diff. This proves end-to-end backprop of the LM. D neg-control teeth ; C bit-exact. B THE LM FITS (memorizes a FIXED sequence) : train E + W_lm (through the full forward; gradient traverses the whole block) on a next-token task (ids 0,1,2,3 -> 1,2,3,0); assert CE loss drops substantially from ~ln(V). Evidence -> knowledge/status/nofloat_lm.log. Sovereign: nx_nofloat_autograd + nx_syscalls (pure integer). HONEST scope: single-head, single-block, tiny vocab; multi-head/GQA + deeper stack + scale remain. expect_exit: 0

dependencies 3 imports · 0 importers

nx_nofloat_autograd.nx nx_syscalls.nx nx_gate_emit_lib.nx nx_nofloat_lm_gate.nx

imports: nx_nofloat_autograd.nxnx_syscalls.nxnx_gate_emit_lib.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 sys_mmap lm_init emb_loss nfa_leaf nfa_new nfa_embed nfa_new ↻ nfa_mse nfa_new ↻ nfa_backward nfa_qmul nfa_silud nfa_sigmoid nfa_fxexp nfa_qmul ↻ nfa_isqrt nfa_fxexp ↻ nfa_cosf nfa_reduce2pi nfa_cosq nfa_qmul ↻ nfa_sinf nfa_reduce2pi ↻ nfa_sinq nfa_qmul ↻ nfa_grad emb_lossval sys_mmap ↻ emb_loss ↻ nfa_val g_abs g_pn sys_mmap ↻ sys_write ↻ g_check g_puts ↻ ce_loss

structs

none

consts

22const LLOG: *u8 = "knowledge/status/nofloat_lm.log"
23const Q16: i64 = 65536

functions

26func g_abs(v: i64) -> i64 { if v < 0 { return 0 - v } return v }
called by 2: lm_gc_wmain
27func l_ws(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 }
called by 1: main calls 1: sys_write
28func l_wn(fd: i64, v: i64) -> i64 { let b: *u8=sys_mmap(28); var m: i64=v; if m<0{sys_write(fd,"-" as *u8,1);m=0-m} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(fd,b,k); return 0 }
called by 1: main calls 2: sys_mmapsys_write
30func lm_init(arr: *i64, n: i64, seed: i64) -> i64 { var i: i64=0; while i<n { arr[i] = (((i*7 + seed*13 + 1) % 11) - 5) * 3277; i=i+1 } return 0 }
called by 1: main
33func lm_fwd(tape: *i64, vals: *i64, st: *i64, W: *i64, ids: *i64, tgt: *i64, T: i64, dm: i64, ffn: i64, V: i64, scale: i64, leaves: *i64) -> i64
73func lm_lossval(tape: *i64, vals: *i64, st: *i64, W: *i64, ids: *i64, tgt: *i64, T: i64, dm: i64, ffn: i64, V: i64, scale: i64) -> i64
called by 2: lm_gc_wmain calls 3: sys_mmaplm_fwdnfa_val
79func lm_gc_w(tape: *i64, vals: *i64, grads: *i64, st: *i64, W: *i64, ids: *i64, tgt: *i64, T: i64, dm: i64, ffn: i64, V: i64, scale: i64, leaves: *i64, widx: i64, h: i64, tol_q: i64, floor_q: i64, worst: *i64) -> i64
107func emb_loss(tape: *i64, vals: *i64, st: *i64, E: *i64, ids: *i64, Tg: *i64, V: i64, dm: i64, T: i64, leaves: *i64) -> i64
116func emb_lossval(tape: *i64, vals: *i64, st: *i64, E: *i64, ids: *i64, Tg: *i64, V: i64, dm: i64, T: i64) -> i64
called by 1: main calls 3: sys_mmapemb_lossnfa_val
123func ce_loss(tape: *i64, vals: *i64, st: *i64, L: *i64, tgt: *i64, T: i64, V: i64, leaves: *i64) -> i64
130func ce_lossval(tape: *i64, vals: *i64, st: *i64, L: *i64, tgt: *i64, T: i64, V: i64) -> i64
called by 1: main calls 3: sys_mmapce_lossnfa_val
136func main() -> i64