code wiki / (root) / nx_lowrank_kv_real.nx

nx_lowrank_kv_real.nx

buildroot/runtime/nx_lowrank_kv_real.nx

18036 B366 linesdepth 13pulls 55 transitivereach 0 importersview sourcekind tooltopic lowrank
docsdependenciesstructsconstsfunctions

about

nx_lowrank_kv_real.nx -- M4c-1: is REAL Qwen2.5-0.5B KV actually low-rank? (the empirical foundation of the low-rank-KV competition). Loads the sovereign-downloaded model, runs a real forward, then measures the SINGULAR SPECTRUM of the real cached K: cumulative energy in the top-r directions vs total. If the top few directions hold most of the energy, real KV IS low-rank -> our per-token compression (M3) helps real models. Reuses: the proven real-LM load+forward (nx_f32_llm_forward_v4, identical to nx_f32_llm_live_load_test) + the M1 reorthogonalization lesson for the eigen-extraction. Arithmetic = nx_f32 (software, matches the LM stack) + nx_f32_hw f32_of/f32_int for int<->f32. Sovereign: nx_cc->nxasm, no gcc. license_tier: ORIGINAL

dependencies 17 imports · 0 importers

nx_syscalls.nx nx_itoa_lib.nx nx_tier.nx nx_gguf.nx nx_gguf_load.nx nx_gguf_meta.nx nx_f32.nx nx_f32_hw.nx nx_f32_kv_cache.nx nx_f32_lazy_weight.nx nx_lowrank_kv_real.nx

diagram shows first 10 each side; +7 more imports, +0 more importers in the complete lists below.

imports: nx_syscalls.nxnx_itoa_lib.nxnx_tier.nxnx_gguf.nxnx_gguf_load.nxnx_gguf_meta.nxnx_f32.nxnx_f32_hw.nxnx_f32_kv_cache.nxnx_f32_lazy_weight.nxnx_f32_llama_block.nxnx_f32_llama_block_v4.nxnx_f32_llama_stack_v4.nxnx_f32_llama_layer_lazy_load.nxnx_f32_llm.nxnx_f32_llm_v4.nxnx_f32_llm_read_dims.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 r_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 ↻ nx_f32_llama_model_alloc sys_mmap ↻ nx_f32_llm_read_dims_from_ sys_mmap ↻ nx_gguf_meta_find nx_le_read_u64 ↻ nx_le_read_u32 ↻ _gmeta_bytes_equal nx_gguf_skip_value _gguf_skip_value ↻ nx_gguf_meta_read_string_l nx_le_read_u64 ↻ nx_gguf_meta_read_string_p _fld_read_arch_u32 sys_mmap ↻ _fld_concat_key nx_gguf_meta_find ↻ nx_gguf_meta_read_u32 nx_le_read_u32 ↻ _fld_read_vocab_size_from_ sys_mmap ↻

structs

none

consts

none

functions

27func r_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 2: r_spectrummain calls 1: sys_write
32func r_putn(v: i64) -> i64 { nxi_out(v); return 0 }
called by 2: r_spectrummain calls 1: nxi_out
33func r_is_zero(x: i64) -> i64 { if (x & 0x7fffffff) == 0 { return 1 } return 0 }
36func r_dot(a: *i64, b: *i64, n: i64) -> i64
42func r_normalize(v: *i64, n: i64) -> i64
52func r_gmatvec(G: *i64, v: *i64, d: i64, out: *i64) -> i64
called by 1: r_power_one calls 2: nx_f32_addnx_f32_mul
63func r_deflate1(v: *i64, basis: *i64, found: i64, d: i64) -> i64
75func r_reorth(v: *i64, basis: *i64, found: i64, d: i64) -> i64
called by 1: r_power_one calls 1: r_deflate1
79func r_power_one(G: *i64, d: i64, basis: *i64, found: i64, v: *i64, w: *i64) -> i64
104func r_gram(K: *i64, seq: i64, d: i64, G: *i64) -> i64
119func r_trace(G: *i64, d: i64) -> i64
127func r_spectrum(K: *i64, seq: i64, d: i64, label: *u8) -> i64
153func r_rank_for_threshold(K: *i64, seq: i64, d: i64, thresh: i64) -> i64
173func r_argmax(a: *i64, n: i64) -> i64
calls 1: nx_f32_gt
185func r_compress_layer(K: *i64, seq: i64, d: i64, rank: i64) -> i64
217func r_copy(dst: *i64, src: *i64, n: i64) -> i64 { var i: i64 = 0; while i < n { dst[i] = src[i]; i = i + 1 } return 0 }
called by 1: main
220func r_logit_rel(la: *i64, lb: *i64, n: i64) -> i64
234func main() -> i64