code wiki / (root) / nx_lowrank_rank_plan.nx

nx_lowrank_rank_plan.nx

buildroot/runtime/nx_lowrank_rank_plan.nx

7482 B96 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tooltopic lowrank
docsdependenciesstructsconstsfunctions

about

nx_lowrank_rank_plan.nx -- DATA-DRIVEN per-tensor/per-layer KV rank sizing. Bridges M2 ("the optimal bottleneck rank MATCHES the data's true rank") + M4c-1 (the REAL Qwen2.5-0.5B KV spectrum is per-tensor: K steep, V shallow) into an ACTIONABLE rule -- with NO magic ranks (rule #11): the energy threshold is the ONLY knob; each (layer,tensor) rank is DERIVED from its measured cumulative-covariance-energy spectrum. rank(layer,tensor) = min r such that cumulative_energy(top-r) >= threshold Pure integer math on permille energy -> NO slow LLM forward (operator: "sized from the already-measured spectrum, no slow forward needed"). Validated on controlled spectra; applied to M4c-1's real anchors. 100% sovereign (nx_cc->nxasm, no gcc). license_tier: ORIGINAL ⚠ SUPERSEDED 2026-06-17: the real-data figures here (K=1/V=5 @90% -> 34x) came from a DEGENERATE-context KV spectrum (M4c-1 anchors). The definitive seq=64 measurement (nx_lowrank_kv_real M4d) shows real KV is only ~2-3x compressible at 90% energy (avg rank K=27/V=37 of 64). The data-driven RULE below is VALID; the MAGNITUDES are wrong. WEIGHTS are heterogeneous too (nx_lowrank_weight_spectrum): attn_q is low-rank but SMALL, the big ffn weights (most params) are NOT low-rank -- so weight-SVD also saves little OVERALL. BOTH low-rank VRAM levers are MODEST on this real model. Kept as the RULE/method demonstration only.

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_itoa_lib.nx nx_lowrank_rank_plan.nx

imports: nx_syscalls.nxnx_itoa_lib.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main rp_puts sys_write sys_mmap rp_min_rank rp_putn nxi_out nxi_fd sys_mmap ↻ ccz_cat_num sys_write ↻ sys_munmap rp_cells sys_exit

structs

none

consts

none

functions

18func rp_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
called by 1: main calls 1: sys_write
23func rp_putn(v: i64) -> i64 { nxi_out(v); return 0 }
called by 1: main calls 1: nxi_out
27func rp_min_rank(cum: *i64, n: i64, thresh: i64) -> i64
called by 1: main
37func rp_cells(r: i64, seq: i64, dim: i64) -> i64 { return r * (seq + dim) }
called by 1: main
39func main() -> i64