code wiki / _hdl_build / nx_nofloat_kvcache_int8_gate.nx
nx_nofloat_kvcache_int8_gate.nx
buildroot/runtime/_hdl_build/nx_nofloat_kvcache_int8_gate.nx
about
nx_nofloat_kvcache_int8_gate.nx -- CAP-NF-KVCACHE-INT8: a QUANTIZED KV-cache (store cached K/V at int8 =
8x less cache memory, the standard long-context inference technique), pure integer Q16. Single-block causal
attention (random weights -- about cache fidelity, not model quality). Decode storing K/V at a configurable
precision: full (Q16) vs int8 (127 levels) vs ternary (teeth).
T1 int8 cache PRESERVES DECISIONS: argmax(int8-cache) == argmax(full-cache) at every position.
T2 MEMORY: int8 = 8 bits/value vs i64 = 64 bits = 8x smaller cache (the point of quantizing the cache).
T3 TEETH: a ternary cache FLIPS some decisions -> precision matters (int8 is the quality-preserving choice).
Sovereign: nx_nofloat_autograd (qmul/isqrt/sin/cos/exp) + nx_syscalls. expect_exit: 0
dependencies 3 imports · 0 importers
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
structs
| none |
consts
| 12 | const Q16: i64 = 65536 |
functions
| 15 | func dini(a: *i64, n: i64, sd: i64) -> i64 { var i: i64=0; while i<n { a[i]=(((i*7+sd*13+1)%11)-5)*9362; i=i+1 } return 0 } called by 1: main |
| 16 | func iabs(x: i64) -> i64 { if x<0 { return 0-x } return x } called by 1: quant_vec |
| 17 | func qround(src: i64, scale: i64) -> i64 { if scale<=0 { return 0 } if src>=0 { return (src+scale/2)/scale } return (src-scale/2)/scale } called by 1: quant_vec |
| 19 | func quant_vec(src: *i64, dst: *i64, n: i64, levels: i64) -> i64 |
| 26 | func matvec(x: *i64, W: *i64, rows: i64, cols: i64, out: *i64) -> i64 |
| 30 | func rmsnorm(x: *i64, n: i64, out: *i64) -> i64 |
| 36 | func dotq(a: *i64, b: *i64, n: i64) -> i64 { var acc: i64=0; var i: i64=0; while i<n { acc=acc + a[i]*b[i]; i=i+1 } return acc>>16 } called by 1: attend |
| 37 | func copyv(src: *i64, dst: *i64, n: i64) -> i64 { var i: i64=0; while i<n { dst[i]=src[i]; i=i+1 } return 0 } called by 1: project |
| 38 | func rope(v: *i64, pos: i64, dm: i64) -> i64 |
| 43 | func attend(q: *i64, Kc: *i64, Vc: *i64, t: i64, dm: i64, scale: i64, out: *i64) -> i64 |
| 53 | func project(E: *i64, Wq: *i64, Wk: *i64, Wv: *i64, tok: i64, pos: i64, dm: i64, qq: *i64, kk: *i64, vv: *i64) -> i64 |
| 60 | func head(E: *i64, Wo: *i64, Wlm: *i64, tok: i64, o: *i64, dm: i64, V: i64, logits: *i64) -> i64 |
| 67 | func amx(logits: *i64, V: i64) -> i64 { var b: i64=0; var bv: i64=logits[0]; var j: i64=1; while j<V { if logits[j]>bv { bv=logits[j]; b=j } j=j+1 } return b } called by 1: decode_q |
| 70 | func decode_q(E: *i64, Wq: *i64, Wk: *i64, Wv: *i64, Wo: *i64, Wlm: *i64, seq: *i64, T: i64, dm: i64, V: i64, scale: i64, levels: i64, corrupt: i64, logits_out: *i64, preds: *i64) -> i64 |
| 87 | func main() -> i64 |