code wiki / _hdl_build / nx_fnet_model_gate.nx
nx_fnet_model_gate.nx
buildroot/runtime/_hdl_build/nx_fnet_model_gate.nx
about
nx_fnet_model_gate.nx -- GATE for MODEL-001: the FIRST end-to-end sovereign SUB-QUADRATIC MODEL. A real
sequence classifier with no attention anywhere:
tokens -> EMBED (trained) -> FNET token-mix (sub-quadratic) -> relu FFN -> linear -> softmax-CE
Trained by AdamW JOINTLY over the embedding table + FFN/head weights. The embedding has no attention matrix
and no quadratic cost -- token mixing is the parameter-free Fourier transform. Embeddings are trained without
a dedicated op: the tape yields dL/dx at the input leaf, which is SCATTERED back into the embedding rows.
Task: classify whether token[0] > token[3] over 8 length-4 sequences (vocab 4). This genuinely needs the FNet
to MIX positions 0 and 3 and the relu to compare -- a bag-of-words linear model cannot do it.
G_train the model learns: accuracy >= 7/8 AND final loss < first loss.
G_repro bit-exact: train twice -> identical accuracy + final loss bits.
Evidence -> knowledge/status/fnet_model.log (FNETMODELGATE 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
| 18 | const MV: i64 = 4 // vocab |
| 19 | const MN: i64 = 4 // sequence length |
| 20 | const MD: i64 = 4 // d_model |
| 21 | const MH: i64 = 8 // FFN hidden |
| 22 | const MC: i64 = 2 // classes |
| 23 | const MND: i64 = 16 // MN*MD (flattened FNet output) |
| 25 | const MO_LOG: *u8 = "knowledge/status/fnet_model.log" |
functions
| 27 | func mo_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 } |
| 28 | func mo_wn(fd: i64, v: i64) -> i64 |
| 40 | func mo_embed(E: *i64, seq: *i64, soff: i64, xout: *i64) -> i64 |
| 52 | func mo_fwd(tape: *i64, vals: *i64, st: *i64, x: *i64, nW1: i64, nb1: i64, nW2: i64, nb2: i64) -> i64 |
| 61 | func mo_build(tape: *i64, vals: *i64, st: *i64, E: *i64, W1: *i64, b1: *i64, W2: *i64, b2: *i64, |
| 92 | func mo_predict(tape: *i64, vals: *i64, st: *i64, E: *i64, W1: *i64, b1: *i64, W2: *i64, b2: *i64, seqs: *i64, s: i64) -> i64 |
| 106 | func mo_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 |
| 121 | func mo_train(tape: *i64, vals: *i64, grads: *i64, st: *i64, E: *i64, W1: *i64, b1: *i64, W2: *i64, b2: *i64, |
| 207 | func main() -> i64 |