nx_f32_transformer.nx
buildroot/runtime/nx_f32_transformer.nx
about
nx_f32_transformer.nx -- bits-up f32 Llama-class transformer block
forward (single-token v1).
L8 integration brick. Composes EVERY shipped primitive from this
session arc:
nx_f32_rmsnorm (mul + add + sqrt + div + cvt)
nx_f32_matmul (mul + add)
nx_f32_softmax (exp + add + div + max)
nx_f32_silu (exp + mul + add + div)
nx_f32_mul/add (scalar L4)
All bits-up. No libm, no compiler-builtin float, no copied code.
Single-token, single-head v1. Multi-token + multi-head + GQA +
KV cache + RoPE are subsequent bricks (the structural scaffolding
for real Llama-7B+ inference; this brick proves the math chain).
Per-block formula (Llama-style, RMSNorm + SwiGLU FFN):
attn_in = RMSNorm(x, gamma_attn)
Q = matmul(attn_in, W_q) [1, head_dim]
K = matmul(attn_in, W_k)
V = matmul(attn_in, W_v)
scores = matmul(Q, K^T) * attn_scale [1, 1]
probs = softmax(scores)
attn_out = matmul(probs, V) [1, head_dim]
attn_proj = matmul(attn_out, W_o) [1, hidden_dim]
x = x + attn_proj
ffn_in = RMSNorm(x, gamma_ffn)
gate = SiLU(matmul(ffn_in, W_gate)) [1, ffn_dim]
up = matmul(ffn_in, W_up) [1, ffn_dim]
hidden = gate * up [1, ffn_dim]
ffn_proj = matmul(hidden, W_down) [1, hidden_dim]
x = x + ffn_proj
Weights bundle struct keeps the function signature under the
NishiLang 16-arg limit while making call-sites self-documenting.
dependencies 7 imports · 1 importers
imports: nx_syscalls.nxnx_tier.nxnx_f32.nxnx_f32_rmsnorm.nxnx_f32_matmul.nxnx_f32_softmax.nxnx_f32_activations.nx
imported by: nx_f32_transformer_test.nx
structs
| 60 | struct NxF32TransformerBlockWeights |
consts
| 49 | const NX_F32_TB_OK: nx_int = 0 |
| 50 | const NX_F32_TB_ERR_BAD_DIM: nx_int = 1 |
| 51 | const NX_F32_TB_N_VERDICTS: nx_int = 2 |
| 72 | const NX_F32_TBW_BYTES: nx_int = 72 // 9 * 8 |
functions
| 53 | func nx_f32_tb_verdict_is_valid(v: nx_int) -> nx_int called by 1: main |
| 87 | func nx_f32_transformer_block_forward( |