code wiki / _hdl_build / nx_ssm_lm_gate.nx
nx_ssm_lm_gate.nx
buildroot/runtime/_hdl_build/nx_ssm_lm_gate.nx
about
nx_ssm_lm_gate.nx -- GATE for MODEL-003: a CAUSAL AUTOREGRESSIVE next-token language model (GPT-shaped,
decoder) with NO attention. The causal SSM scan makes next-token prediction legal (each position's state
sees only the past):
tokens -> EMBED(trained) -> TA_SSM causal mix -> per-position SLICE -> shared relu-FFN head -> softmax-CE
predicting token t+1 from tokens 0..t.
AdamW trains the embedding + the SSM decay + the head jointly. Corpus = 4 cyclic-shift sequences over vocab 4
(a simple deterministic language, next = (cur+1) mod 4); 12 next-token predictions.
G_train next-token accuracy >= 11/12 AND final loss < first loss.
G_repro bit-exact: train twice -> identical accuracy + final-loss bits.
Evidence -> knowledge/status/ssm_lm.log (SSMLMGATE authored=organ ... verdict=GREEN). license_tier: ORIGINAL
dependencies 2 imports · 0 importers
imports: nx_autograd_tensor.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
| 16 | const LV: i64 = 4 // vocab |
| 17 | const LN: i64 = 4 // sequence length |
| 18 | const LD: i64 = 4 // d_model |
| 19 | const LH: i64 = 8 // FFN hidden |
| 20 | const LP: i64 = 3 // predictions per sequence (positions 0..LN-2) |
| 21 | const LM_LOG: *u8 = "knowledge/status/ssm_lm.log" |
functions
| 23 | func lm_w(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 } |
| 24 | func lm_wn(fd: i64, v: i64) -> i64 |
| 35 | func lm_embed(E: *i64, seq: *i64, soff: i64, xout: *i64) -> i64 |
| 47 | func lm_head(tape: *i64, vals: *i64, st: *i64, row: i64, nW1: i64, nb1: i64, nW2: i64, nb2: i64) -> i64 |
| 52 | func lm_build(tape: *i64, vals: *i64, st: *i64, E: *i64, ad: *i64, W1: *i64, b1: *i64, W2: *i64, b2: *i64, |
| 88 | func lm_predict(tape: *i64, vals: *i64, st: *i64, E: *i64, ad: *i64, W1: *i64, b1: *i64, W2: *i64, b2: *i64, seqs: *i64, s: i64, pos: i64) -> i64 |
| 111 | func lm_adamw(p: *i64, m: *i64, v: *i64, g: *i64, n: i64, lr: i64, beta1: i64, beta2: i64, om1: i64, om2: i64, eps: i64, c1: i64, c2: i64) -> i64 |
| 123 | func lm_zero(a: *i64, n: i64) -> i64 { var i: i64 = 0; while i < n { a[i] = TA_F32_ZERO; i = i + 1 } return 0 } called by 1: lm_train |
| 125 | func lm_train(tape: *i64, vals: *i64, grads: *i64, st: *i64, E: *i64, ad: *i64, W1: *i64, b1: *i64, W2: *i64, b2: *i64, |
| 196 | func lm_accuracy(tape: *i64, vals: *i64, st: *i64, E: *i64, ad: *i64, W1: *i64, b1: *i64, W2: *i64, b2: *i64, seqs: *i64) -> i64 |
| 210 | func main() -> i64 |