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

9082 B129 linesdepth 3pulls 4 transitivereach 0 importersview sourcekind gate/prooftopic nofloat
docsdependenciesstructsconstsfunctions

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

nx_nofloat_autograd.nx nx_syscalls.nx nx_gate_emit_lib.nx nx_nofloat_kvcache_int8_gate.n

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 dini decode_q sys_mmap ↻ project sys_mmap ↻ copyv rmsnorm nfa_isqrt matvec rope nfa_cosf nfa_reduce2pi nfa_cosq nfa_qmul nfa_sinf nfa_reduce2pi ↻ nfa_sinq nfa_qmul ↻ nfa_qmul ↻ quant_vec iabs qround attend sys_mmap ↻ nfa_qmul ↻ dotq nfa_fxexp head sys_mmap ↻ matvec ↻ rmsnorm ↻ amx g_pn sys_mmap ↻ sys_write ↻ g_check

structs

none

consts

12const Q16: i64 = 65536

functions

15func 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
16func iabs(x: i64) -> i64 { if x<0 { return 0-x } return x }
called by 1: quant_vec
17func 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
19func quant_vec(src: *i64, dst: *i64, n: i64, levels: i64) -> i64
called by 1: decode_q calls 2: iabsqround
26func matvec(x: *i64, W: *i64, rows: i64, cols: i64, out: *i64) -> i64
called by 2: projecthead
30func rmsnorm(x: *i64, n: i64, out: *i64) -> i64
called by 2: projecthead calls 1: nfa_isqrt
36func 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
37func 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
38func rope(v: *i64, pos: i64, dm: i64) -> i64
called by 1: project calls 3: nfa_cosfnfa_sinfnfa_qmul
43func attend(q: *i64, Kc: *i64, Vc: *i64, t: i64, dm: i64, scale: i64, out: *i64) -> i64
53func project(E: *i64, Wq: *i64, Wk: *i64, Wv: *i64, tok: i64, pos: i64, dm: i64, qq: *i64, kk: *i64, vv: *i64) -> i64
60func head(E: *i64, Wo: *i64, Wlm: *i64, tok: i64, o: *i64, dm: i64, V: i64, logits: *i64) -> i64
called by 1: decode_q calls 3: sys_mmapmatvecrmsnorm
67func 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
70func 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
87func main() -> i64