nx_lowrank_kv_budget.nx
buildroot/runtime/nx_lowrank_kv_budget.nx
about
nx_lowrank_kv_budget.nx -- the HARDWARE PAYOFF of data-driven low-rank KV (nx_lowrank_rank_plan) on the
operator's real budget: RTX 5080, 16 GiB VRAM (rule #21 resource awareness; telos = capable AI on
AFFORDABLE consumer hardware). KV cache is the context-length bottleneck: full KV grows O(n_layers * 2 *
kv_dim) per token; data-driven low-rank KV grows O(n_layers * (r_K + r_V)) per token. This computes the
MAX CONTEXT LENGTH full-vs-low-rank for a given model on a given VRAM budget. Pure integer math, NO slow
forward. Real Qwen2.5-0.5B config + ranks (measured); 7B shown as an honest illustrative extrapolation.
100% sovereign (nx_cc->nxasm, no gcc). license_tier: ORIGINAL
⚠ SUPERSEDED 2026-06-17: the context-multipliers here (42x for 0.5B, 170x for 7B) used K=1/V=5 ranks from a
DEGENERATE-context KV spectrum. The definitive seq=64 measurement (nx_lowrank_kv_real M4d) shows real KV
needs avg rank K=27/V=37 of 64 for 90% energy => the real KV VRAM win is ~2-3x, NOT 42x. The budget MATH
here is valid; the input ranks were wrong. WEIGHTS are heterogeneous too (attn low-rank but small, big ffn
NOT low-rank) => weight-SVD also modest. BOTH low-rank VRAM levers are MODEST on real Qwen-0.5B.
dependencies 1 imports · 0 importers
imports: nx_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
| 14 | const K_MAGIC_1048576: i64 = 1048576 |
| 15 | const K_MAGIC_491400032: i64 = 491400032 |
| 16 | const K_MAGIC_5046586573: i64 = 5046586573 |
| 18 | const GIB: i64 = 1073741824 |
| 19 | const VRAM: i64 = 17179869184 // 16 GiB (RTX 5080) |
| 20 | const KVB: i64 = 4 // KV cache element bytes (f32, matches our sovereign forward; f16 would 2x the absolute token counts, ratio unchanged) |
functions
| 22 | func bp_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } |
| 23 | func bp_putn(v: i64) -> i64 |
| 33 | func bp_putM(bytes: i64) -> i64 { bp_putn(bytes / K_MAGIC_1048576); bp_puts(" MiB"); return 0 } |
| 36 | func bp_ctx_full(kv_budget: i64, L: i64, kv_dim: i64) -> i64 { return kv_budget / (L * 2 * kv_dim * KVB) } |
| 39 | func bp_ctx_low(kv_budget: i64, L: i64, kv_dim: i64, rK: i64, rV: i64) -> i64 |
| 46 | func bp_model(name: *u8, weights: i64, L: i64, kv_dim: i64, rK: i64, rV: i64, measured: i64) -> i64 |
| 61 | func main() -> i64 |