code wiki / _hdl_build / nx_imatrix.nx

nx_imatrix.nx

buildroot/runtime/_hdl_build/nx_imatrix.nx

2968 B57 linesdepth 2pulls 2 transitivereach 5 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_imatrix.nx -- IMPORTANCE-MATRIX quantization = rate-distortion WATER-FILLING (the deepest survived task from the governed loop: VRAM-research actionable A1 ~= historic actionable HA1). Naive quantization minimizes RAW error sum((w-wq)^2) and spends bits uniformly. But not every weight matters equally to the output -- an importance matrix (from calibration activations) says how much each weight's error costs. The right objective is the IMPORTANCE-WEIGHTED error sum(imp_i * (w_i - wq_i)^2), and the right bit allocation is Shannon WATER-FILLING: give the next bit to whichever group reduces the weighted error most. This is rate-distortion optimization (Radio), and it is why imatrix cuts low-bit error ~31% at ~zero size cost: same total bits, but spent where distortion is expensive. Distortion here is the QUALITY-relevant (importance-weighted) distortion, not raw MSE -- closing one notch toward the perceptually-meaningful objective the Critic insisted on. license_tier: ORIGINAL Refs: ggml imatrix PR#4930; Radio (rate-distortion); Shannon water-filling.

dependencies 1 imports · 3 importers

nx_syscalls.nx nx_imatrix.nx nx_builder_synth.nx nx_imatrix_test.nx nx_spec_author.nx

imports: nx_syscalls.nx

imported by: nx_builder_synth.nxnx_imatrix_test.nxnx_spec_author.nx

structs

none

consts

none

functions

16func imat_err2(bits: i64) -> i64
22func imat_weighted_error(n: i64, imp: *i64, bits: *i64) -> i64
28func imat_total_bits(n: i64, bits: *i64) -> i64 { var s: i64 = 0; var i: i64 = 0; while i < n { s = s + bits[i]; i = i + 1 } return s }
called by 2: bsy_verifymain
33func imat_waterfill(n: i64, imp: *i64, total_bits: i64, out_bits: *i64) -> i64
called by 1: main calls 1: imat_err2
52func imat_uniform(n: i64, total_bits: i64, out_bits: *i64) -> i64