code wiki / (root) / nx_lowrank_weight_spectrum.nx

nx_lowrank_weight_spectrum.nx

buildroot/runtime/nx_lowrank_weight_spectrum.nx

8419 B185 linesdepth 8pulls 19 transitivereach 0 importersview sourcekind tooltopic lowrank
docsdependenciesstructsconstsfunctions

about

nx_lowrank_weight_spectrum.nx -- the FORWARD-FREE VRAM lever: are the real model's WEIGHT matrices low-rank? (FlashSVD / over-parameterization: arXiv 2508.01506). Unlike the KV-cache lever, this needs NO forward -- just load a weight tensor + measure its singular spectrum -- so it iterates without the slow software-f32 forward. Measures attn_q (square 896x896) AND ffn_gate (4864x896, the big MLP weight where most params live) for Qwen2.5-0.5B: cumulative covariance energy in the top-r of the smaller (cols) dimension. High energy at small r => low-rank => SVD-compressible. Sovereign (nx_cc->nxasm, no gcc). NOTE: SVD funcs copied from nx_lowrank_kv_real (proven f32+reorth) -- TODO extract both to nx_lowrank_svd.nx (DRY #15). license_tier: ORIGINAL

dependencies 8 imports · 0 importers

nx_syscalls.nx nx_gguf.nx nx_gguf_load.nx nx_gguf_meta.nx nx_gguf_load_f32.nx nx_f32.nx nx_f32_div.nx nx_f32_hw.nx nx_lowrank_weight_spectrum.nx

imports: nx_syscalls.nxnx_gguf.nxnx_gguf_load.nxnx_gguf_meta.nxnx_gguf_load_f32.nxnx_f32.nxnx_f32_div.nxnx_f32_hw.nx

imported by: nobody (leaf or entry point)

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

main sys_mmap sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_close w_puts sys_write nx_gguf_parse nx_le_read_u32 nx_le_read_u64 nx_le_read_u32 ↻ _gguf_skip_value nx_le_read_u64 ↻ nx_le_read_u32 ↻ _gguf_skip_value ↻ sys_mmap ↻ w_measure nx_gguf_find_tensor nx_gguf_tensor_at nx_gguf_name_equals w_puts ↻ nx_gguf_tensor_at ↻ sys_mmap ↻ nx_gguf_load_tensor_to_f32 nx_gguf_find_tensor ↻ nx_gguf_tensor_at ↻ nx_gguf_tensor_n_values sys_mmap ↻ nx_le_read_u32 ↻ nx_le_read_u16 nx_f16_to_f32 nx_q4k_to_f32 nx_q4k_block_to_f32 nx_le_read_u16 ↻ nx_f16_to_f32 ↻ nx_le_read_u8 nx_i32_to_f32

structs

none

consts

none

functions

17func w_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 3: w_spectrumw_measuremain calls 1: sys_write
18func w_putn(v: i64) -> i64
30func r_is_zero(x: i64) -> i64 { if (x & 0x7fffffff) == 0 { return 1 } return 0 }
31func r_dot(a: *i64, b: *i64, n: i64) -> i64
37func r_normalize(v: *i64, n: i64) -> i64
47func r_gmatvec(G: *i64, v: *i64, d: i64, out: *i64) -> i64
called by 1: r_power_one calls 2: nx_f32_addnx_f32_mul
58func r_deflate1(v: *i64, basis: *i64, found: i64, d: i64) -> i64
70func r_reorth(v: *i64, basis: *i64, found: i64, d: i64) -> i64
called by 1: r_power_one calls 1: r_deflate1
73func r_power_one(G: *i64, d: i64, basis: *i64, found: i64, v: *i64, w: *i64) -> i64
98func r_gram(W: *i64, rows: i64, cols: i64, G: *i64) -> i64
called by 1: w_spectrum calls 2: nx_f32_addnx_f32_mul
113func r_trace(G: *i64, d: i64) -> i64
called by 1: w_spectrum calls 1: nx_f32_add
121func w_spectrum(W: *i64, rows: i64, cols: i64, label: *u8) -> i64
147func w_measure(buf: *u8, hdr: *NxGgufHeader, name: *u8, name_len: nx_int, label: *u8) -> i64
166func main() -> i64