nx_lowrank_rank_plan.nx
buildroot/runtime/nx_lowrank_rank_plan.nx
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
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
structs
| none |
consts
| none |
functions
| 18 | func 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 } |
| 23 | func rp_putn(v: i64) -> i64 { nxi_out(v); return 0 } |
| 27 | func rp_min_rank(cum: *i64, n: i64, thresh: i64) -> i64 called by 1: main |
| 37 | func rp_cells(r: i64, seq: i64, dim: i64) -> i64 { return r * (seq + dim) } called by 1: main |
| 39 | func main() -> i64 |