A 2.78-trillion-parameter Kimi K3 running inference on a single CPU in 8.24 GB of RAM. Portable C99: no BLAS, no framework, no GPU.
C avx2c99cpu-inferencedeep-learningfrom-scratchinference-enginekimi-k3linear-attentionllmllm-inferencemachine-learningmemory-efficientmixture-of-expertsmoemxfp4quantizationsimdsystems-programmingtransformerzero-dependencies
docs: add the measurement data behind every published figure
FareedKhan-dev42efb678360b
diff --git a/docs/data/README.md b/docs/data/README.mdnew file mode 100644index 0000000..b9a73ff--- /dev/null+++ b/docs/data/README.md@@ -0,0 +1,103 @@+# Measurement data++The raw output behind every number in [PERFORMANCE.md](../PERFORMANCE.md) and+[TUNING.md](../TUNING.md). Each table there cites the file it comes from.++Everything was produced in one campaign on one machine. See [environment.txt](environment.txt)+for the full capture, including the measurement hygiene applied before any timing was+taken. Summary: AMD EPYC 7763, 124 vCPU (2×62, no SMT), 228 GiB RAM, 3.2 TB NVMe at+3.2 GB/s O_DIRECT, Ubuntu 24.04.3, GCC 13.3, AVX2 without AVX-512.++| file | what it is | backs |+|---|---|---|+| [memory-ladder.tsv](memory-ladder.tsv) | 12 memory budgets, each under a hard cgroup cap | the ladder table, the two-cache finding |+| [trunk-cache-split.tsv](trunk-cache-split.tsv) | 12 splits at two fixed budgets (32 GB, 128 GB) | the allocation recommendation |+| [replication.tsv](replication.tsv) | 3 runs of one identical configuration | the noise floor |+| [expert-cache-capacity.txt](expert-cache-capacity.txt) | LRU / Belady / pinned hit rates from the recorded trace | why the expert cache is weak |+| [trunk-quantisation.txt](trunk-quantisation.txt) | int8 vs int4 reconstruction error on real weights | why the trunk is streamed, not quantised |+| [generations.txt](generations.txt) | what the model actually produced, decoded | the output claims |+| [environment.txt](environment.txt) | the machine | everything |++## Read the noise floor first++```+run s/token+1 14.7760+2 14.6655+3 20.1408+```++Same binary, same prompt, same flags, same minute. **mean 16.53, sd 3.13, spread 33.1%.**++A third of the measurement is noise. Every single-sample comparison in these files is+subject to it, and any difference smaller than ~33% between two single runs is not an+established effect. This is stated up front because it invalidated several conclusions+drawn earlier in the campaign, including a "128 GB outlier" that was simply dispersion.++## What the split data actually shows++This is the one place where the raw data is stronger than a naive reading and weaker+than a careless one, so it is worth being exact.++**128 GB, six splits** (trunk GB → s/token):++```+12.3 → 28.38 30.8 → 25.20 49.2 → 25.69+73.8 → 18.37 98.4 → 19.46 110.0 → 16.80+```++- Endpoint ratio **1.689×**, which is where the 1.69× figure comes from.+- **Not monotonic.** Two inversions: +1.9% at 30.8→49.2, and +5.9% at 73.8→98.4.+- Spearman ρ = **−0.886** over the six points.++**32 GB, six splits**, an independent replication of the same question at a quarter of+the memory:++```+ 2.7 → 31.23 6.8 → 30.58 10.8 → 31.25+16.2 → 30.88 21.6 → 29.13 25.6 → 28.06+```++- Endpoint ratio **1.113×**. One inversion, +2.2%.+- Spearman ρ = **−0.714**.++**In summary:** twelve points across two independent budgets, both with a strong+negative rank correlation between trunk share and time per token. Every inversion is far+inside the 33% noise floor, so none of them is evidence against the trend, and none of+the individual steps is evidence *for* it either. What carries the conclusion is the rank+correlation across twelve points and the mechanism, the trunk is re-read in full every+token (108.81 GB) while only ~25.8 GB of experts are touched.++What this data does **not** establish: that 1.69× is the effect size. It is one endpoint+comparison of single samples. The direction is well supported; the magnitude is not+replicated. `benchmarks/split-sweep.sh` re-runs the experiment with repetitions.++## Reproducing++`memory-ladder.tsv` and `trunk-cache-split.tsv` are regenerated by+`benchmarks/memory-ladder.sh` and `benchmarks/split-sweep.sh` respectively. Both need the+1.56 TB checkpoint, a packed trunk, and a Linux host with systemd (for the cgroup caps+that make a memory budget mean anything). Both write a `machine.txt` alongside their+results so a new run can be compared against this one.++`expert-cache-capacity.txt` needs **neither weights nor a GPU**, it replays+`tests/fixtures/expert_trace.bin`, which ships in this repository:++```bash+python3 tools/sim_cache.py tests/fixtures/expert_trace.bin+```++That is the one result here anyone can re-derive in seconds, and it is the one that+explains the two-cache finding.++`trunk-quantisation.txt` sampled the released checkpoint over HTTP range reads rather+than downloading it. The script that did so is not shipped; the file records its method+and its limits.++## Scope++These are engine measurements: speed, memory, bytes moved, cache behaviour, and what the+model emitted. They are **not** quality benchmarks. No perplexity, no task evaluation, no+comparison against another implementation's output quality. The correctness evidence is+separate and stronger: see [../TESTING.md](../TESTING.md) and the logs in+`tests/fixtures/gates/` and `tests/fixtures/golden/`.diff --git a/docs/data/environment.txt b/docs/data/environment.txtnew file mode 100644index 0000000..1e66fb8--- /dev/null+++ b/docs/data/environment.txt@@ -0,0 +1,60 @@+=== campaign host: full environment capture ===+captured: 2026-07-31T08:30:37Z+flavor : 4x L40 GPU instance (GPUs unused)++--- uname ---+Linux 6.14.0-37-generic #37~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Nov 20 10:25:38 UTC 2 x86_64++--- lscpu ---+CPU(s): 124+Model name: AMD EPYC 7763 64-Core Processor+Thread(s) per core: 1+Core(s) per socket: 62+Socket(s): 2+L1d cache: 7.8 MiB (124 instances)+L2 cache: 62 MiB (124 instances)+L3 cache: 1.9 GiB (124 instances)+NUMA node(s): 2+NUMA node0 CPU(s): 0-61+NUMA node1 CPU(s): 62-123++--- ISA (note: AVX2 present, AVX-512 ABSENT) ---+avx avx2 fma sse4_2++--- memory ---+ total used free shared buff/cache available+Mem: 228Gi 5.1Gi 207Gi 3.1Mi 18Gi 223Gi+MemTotal: 239308464 kB+MemAvailable: 233961008 kB+Hugepagesize: 2048 kB++--- storage ---+/dev/vda1 3.2T 1.6T 1.6T 50% /+NAME SIZE ROTA MODEL+vda 3.2T 1++--- storage bandwidth, measured ---+O_DIRECT cold : 3.2 GB/s (dd bs=4M iflag=direct after drop_caches)+buffered warm : 2.3 GB/s+engine, trunk : 5373-6064 MB/s sustained during real runs+NOTE O_DIRECT is FASTER than buffered here. That is the opposite of the usual+ expectation, and it is why the engine opens the trunk O_DIRECT. Worth+ re-checking on any target device before assuming it holds.++--- os / toolchain ---+PRETTY_NAME="Ubuntu 24.04.3 LTS"+gcc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0+GNU Make 4.3+Python 3.12.3++--- GPUs: PRESENT BUT UNUSED ---+NVIDIA L40, 46068 MiB, 0 %+NVIDIA L40, 46068 MiB, 0 %+NVIDIA L40, 46068 MiB, 0 %+NVIDIA L40, 49140 MiB, 0 %+This engine is CPU-only. The 4 L40s sat idle for the entire campaign; the instance was chosen for its 228 GiB of RAM and 3.2 TB of NVMe, which are free on GPU flavors.++--- measurement hygiene ---+unattended-upgrades: STOPPED and DISABLED before measurement (was using ~63% of a+ core during the smoke run, whose timing is therefore contaminated and not quoted).+apt-daily.timer / apt-daily-upgrade.timer: disabled.diff --git a/docs/data/expert-cache-capacity.txt b/docs/data/expert-cache-capacity.txtnew file mode 100644index 0000000..53f46b3--- /dev/null+++ b/docs/data/expert-cache-capacity.txt@@ -0,0 +1,68 @@+=== expert cache: hit rate vs capacity, from the recorded trace ===+captured: 2026-07-30T16:37:15Z+input : tests/fixtures/expert_trace.bin (800,768 bytes, 100,096 expert requests)+tool : tools/sim_cache.py -- replays the real trace at any capacity++WHY THIS EXISTS+ Every measured cache number elsewhere in this campaign is confounded:+ 96.15% (a long-run log) - a 200 GB arena that never evicts, so it measures nothing+ 39.31% (tests/fixtures/gates/gates.txt) - still climbing after 2 tokens of quadratic re-prefill+ 0.00% (RUN A) - 1472 requests, 1472 evictions: a cache smaller than one token+ None of them answers the only question that matters for sizing: how much RAM does+ the expert cache actually need? Replaying the trace does, and costs nothing.++trace: 100096 requests, 10010 distinct experts, about 68 token(s)+distinct experts touched: 10010 of 82432 (12.14% of the pool)+if nothing were cached: 25.83 GB per token++hottest experts: L4/e520 x68, L24/e136 x68, L32/e276 x67, L83/e827 x66, L81/e395 x65, L3/e515 x63+total reuse: 90086 of 100096 requests are repeats (90.0%)++CACHE SLOTS LRU BELADY PIN+LRU GB READ/TOK SEC/TOK+----------------------------------------------------------------------------+8 GB 455 36.24% 39.42% 37.82% 16.47 13.35+16 GB 911 36.24% 42.61% 39.42% 16.47 13.35+32 GB 1823 36.24% 48.99% 42.57% 16.47 13.35+64 GB 3647 36.24% 61.74% 48.66% 16.47 13.35+128 GB 7294 49.19% 84.59% 62.86% 13.12 10.64+192 GB 10941 90.00% 90.00% 90.00% 2.58 2.09+256 GB 14589 90.00% 90.00% 90.00% 2.58 2.09+384 GB 21883 90.00% 90.00% 90.00% 2.58 2.09+512 GB 29178 90.00% 90.00% 90.00% 2.58 2.09+768 GB 43767 90.00% 90.00% 90.00% 2.58 2.09+1024 GB 58356 90.00% 90.00% 90.00% 2.58 2.09+1450 GB 82633 90.00% 90.00% 90.00% 2.58 2.09+----------------------------------------------------------------------------+SEC/TOK is expert I/O only, at the measured 1234 MB/s random-cold rate.+It excludes compute, which overlaps with it in a real serving loop.+BELADY and PIN+LRU both use future knowledge, so they are ceilings rather+than achievable policies. LRU is what the engine actually does.+compulsory misses: 10010 (every expert must be read at least once), a ceiling of+90.00% hit rate for ANY policy at ANY size on this trace.++holding every expert this trace touched needs 175.65 GB.+holding the whole pool needs 1446.46 GB.++=== what this actually says ===+1. LRU IS FLAT FROM 8 GB TO 64 GB. 36.24% at every one of those sizes - an 8x range+ in which more memory buys exactly nothing. The knee is between 64 and 128 GB, and+ full benefit needs 192 GB.++2. THE LEVER IS POLICY, NOT SIZE. At 64 GB, Belady reaches 61.74% where LRU manages+ 36.24%. That 25.5-point gap is available to a better replacement policy at the SAME+ memory. Given the routed-expert set is 1.45 TB and the machine budget is tens of GB,+ this is the more promising direction than buying RAM.++3. THERE IS A HARD CEILING AT 90.00%. The trace touches 10,010 distinct experts, each+ of which must be read at least once. No policy at any capacity beats 90% here.++4. K3's ROUTER MAKES THIS HARDER BY DESIGN. The tech report (2.3.3) trains routing with+ Quantile Balancing specifically to FLATTEN expert usage. Flat usage is what defeats+ an LRU cache, so the weak cache behaviour is a property of the model, not a defect+ in the engine.++CAVEAT, and it matters+ This trace was recorded during a run that re-prefills the whole prefix every step,+ so the same experts are legitimately touched ~68 times. Steady-state incremental+ decode has far less reuse, and its hit rates will be LOWER than this curve suggests.+ Treat these numbers as an upper bound on what caching can do, not a forecast.diff --git a/docs/data/generations.txt b/docs/data/generations.txtnew file mode 100644index 0000000..d87a1c4--- /dev/null+++ b/docs/data/generations.txt@@ -0,0 +1,52 @@+=== what the engine actually generated, decoded ===+captured: 2026-07-30T16:36:22Z++Token ids alone carry no quality signal, so every id below is decoded back through the+C tokenizer. What the model produced is reproduced verbatim, including the parts that+are not flattering.++--- the full 93-layer, 2.78T-parameter checkpoint ---++ prompt ids : 1008,10484,318,15383,387+ prompt txt : The capital of France is+ generated ids : 17374,20829,10,427,414,1008,606,142957+ generated txt : Paris.",~+ "The Eiffel~+ (~ marks a newline)++ The first two tokens are 17374 = ' Paris' and 20829 = '.",' - the model answers the+ question CORRECTLY. What follows ('+', indentation, '"The Eiffel') is the base model+ continuing into what looks like a diff or a JSON context. There is no chat template+ and no instruction tuning applied here, so a plain continuation is the expected+ behaviour rather than a defect. See "What it does not do" in the README.++--- the same answer holds across an 8x memory range ---+7 arms, each under a hard cgroup cap.++ cap trunk cache s/token token ids decoded+ 96G 48G 40G 72.3430 17374,20829,10 Paris.",~+~+ 64G 32G 24G 67.8921 17374,20829,10 Paris.",~+~+ 48G 24G 16G 63.1822 17374,20829,10 Paris.",~+~+ 32G 12G 12G 63.4072 17374,20829,10 Paris.",~+~+ 24G 10G 7G 60.8162 17374,20829,10 Paris.",~+~+ 16G 6G 4G 68.4805 17374,20829,10 Paris.",~+~+ 12G 4G 2G 61.0702 17374,20829,10 Paris.",~+~++ All 7 arms emit 17374,20829,10 - not merely the same ids at every budget, but the+ same RIGHT answer from 96 GB down to 12 GB.++ The O_DIRECT arm agrees: 17374,20829,10,427 at 64.89 s/token.++ The s/token figures here are from an earlier, slower configuration than the ladder in+ PERFORMANCE.md. The point of this table is the output column, not the timing column.++--- an honest caveat about the logit-parity fixture ---++The elementwise logit comparison against the reference (docs/TESTING.md, raw logs in+tests/fixtures/golden/) used prompt ids 3,4,5,6,7, which decode to:++ $%&'(++That is synthetic junk, not text. The agreement it establishes is real and exact, and it+is the strongest correctness evidence in the project - but it is agreement on one+position of a meaningless prompt. It says nothing about output quality, and nothing here+should be read as implying otherwise.diff --git a/docs/data/memory-ladder.tsv b/docs/data/memory-ladder.tsvnew file mode 100644index 0000000..e78b18a--- /dev/null+++ b/docs/data/memory-ladder.tsv@@ -0,0 +1,13 @@+total_gb pin_layers pin_gb cache_gb cache_slots s_per_tok expert_hit_true expert_hit_naive trunk_hit gb_read peak_rss_gb io_share ids+8 0 0.0 0.49 28 32.69 0.0 100.0 0.0 25.83 8.24 57.3 17374,20829,10,427,414,1008,606,142957+12 0 0.0 2.79 159 31.41 0.0 100.0 0.0 25.83 10.53 59.6 17374,20829,10,427,414,1008,606,142957+16 3 4.95 4.39 250 32.21 0.0 100.0 2.8 25.83 16.0 55.8 17374,20829,10,427,414,1008,606,142957+24 7 9.71 7.58 432 31.85 0.0 100.0 6.6 25.83 23.95 55.2 17374,20829,10,427,414,1008,606,142957+32 11 14.46 10.8 615 31.44 0.0 100.0 10.3 25.83 31.9 53.6 17374,20829,10,427,414,1008,606,142957+48 19 23.96 17.19 979 29.76 0.0 100.0 17.9 25.83 47.8 51.9 17374,20829,10,427,414,1008,606,142957+64 27 33.46 23.59 1344 28.6 0.0 100.0 25.4 25.83 63.71 53.6 17374,20829,10,427,414,1008,606,142957+96 43 52.47 36.39 2073 24.4 29.89 100.0 40.5 18.11 95.51 47.2 17374,20829,10,427,414,1008,606,142957+128 60 72.34 49.19 2802 29.4 32.2 100.0 56.5 17.51 128.18 60.6 17374,20829,10,427,414,1008,606,142957+160 76 91.34 61.99 3531 26.31 33.08 100.0 71.5 17.28 159.98 47.4 17374,20829,10,427,414,1008,606,142957+192 90 108.19 77.0 4386 21.32 35.53 100.0 84.7 16.65 191.83 49.9 17374,20829,10,427,414,1008,606,142957+224 90 108.19 108.98 6208 19.21 43.75 99.93 84.7 14.53 223.82 40.9 17374,20829,10,427,414,1008,606,142957diff --git a/docs/data/replication.tsv b/docs/data/replication.tsvnew file mode 100644index 0000000..7bf7200--- /dev/null+++ b/docs/data/replication.tsv@@ -0,0 +1,8 @@+# Three runs of an IDENTICAL configuration, back to back, on a quiet machine.+# Same binary, same prompt, same flags, same minute.+# mean 16.53 s/token, sd 3.13, spread 33.1%+# Every speed caveat in docs/PERFORMANCE.md rests on this spread.+run s_per_tok ids+1 14.7760 17374,20829,10,427,414,1008,606,142957+2 14.6655 17374,20829,10,427,414,1008,606,142957+3 20.1408 17374,20829,10,427,414,1008,606,142957diff --git a/docs/data/trunk-cache-split.tsv b/docs/data/trunk-cache-split.tsvnew file mode 100644index 0000000..f00cca7--- /dev/null+++ b/docs/data/trunk-cache-split.tsv@@ -0,0 +1,13 @@+total_gb trunk_gb cache_gb s_per_tok hit_pct gb_read peak_rss ids+32 2.7 24.3 31.23 0.0 25.83 32.01 17374,20829,10,427,414,1008,606,142957+32 6.8 20.2 30.58 0.0 25.83 31.79 17374,20829,10,427,414,1008,606,142957+32 10.8 16.2 31.25 0.0 25.83 31.24 17374,20829,10,427,414,1008,606,142957+32 16.2 10.8 30.88 0.0 25.83 31.9 17374,20829,10,427,414,1008,606,142957+32 21.6 5.4 29.13 0.0 25.83 32.13 17374,20829,10,427,414,1008,606,142957+32 25.6 1.4 28.06 0.0 25.83 32.02 17374,20829,10,427,414,1008,606,142957+128 12.3 110.7 28.38 44.02 14.46 127.89 17374,20829,10,427,414,1008,606,142957+128 30.8 92.2 25.2 42.93 14.74 127.53 17374,20829,10,427,414,1008,606,142957+128 49.2 73.8 25.69 33.97 17.06 128.14 17374,20829,10,427,414,1008,606,142957+128 73.8 49.2 18.37 32.2 17.51 128.19 17374,20829,10,427,414,1008,606,142957+128 98.4 24.6 19.46 0.0 25.83 127.36 17374,20829,10,427,414,1008,606,142957+128 110.0 13.0 16.8 0.0 25.83 127.85 17374,20829,10,427,414,1008,606,142957diff --git a/docs/data/trunk-quantisation.txt b/docs/data/trunk-quantisation.txtnew file mode 100644index 0000000..4a9ad30--- /dev/null+++ b/docs/data/trunk-quantisation.txt@@ -0,0 +1,83 @@+=== int8 vs int4 sensitivity on REAL Kimi K3 weights ===+captured: 2026-07-30T17:04:50Z+method : 31 attention-projection tensors sampled from the released checkpoint by+ HTTP range read - real weights, no full download. 384 rows per tensor.+ Each tensor is round-tripped through int8 and int4 with one fp32 scale per+ 32 elements, and the mean relative reconstruction error is recorded.++WHY THIS EXISTS+ This is the measurement behind the engine's central design decision: the resident+ trunk is STREAMED VERBATIM rather than quantised.++ Quantising the trunk is the obvious way to fit a 113 GB resident set into less RAM,+ and it is the wrong one. K3's technical report section 4.1.4 states that the experts+ are MXFP4 with quantisation-aware training "while all non-expert components remain+ in higher precision" - that list IS the trunk, so it was never trained to tolerate+ 4-bit. This study checks whether that holds on the actual weights.++ It does. So the engine quantises NOTHING: routed experts are already MXFP4 in the+ checkpoint and are multiplied in that form, and the trunk is copied byte for byte.+ Streaming costs zero reconstruction error, which is why memory could be made a dial+ without any accuracy claim attached to it.++ type tensor int8 mean int4 mean ratio+ ------------------------------------------------------------------+ ? L1.v_proj 0.00926 0.16811 18.1x+ ? L1.g_proj 0.00895 0.16233 18.1x+ ? L5.v_proj 0.00916 0.16614 18.1x+ ? L5.o_proj 0.01029 0.18670 18.1x+ ? L9.k_proj 0.00914 0.16568 18.1x+ ? L9.g_proj 0.00898 0.16286 18.1x+ ? L9.o_proj 0.01020 0.18512 18.1x+ ? L3.o_proj 0.01090 0.19774 18.1x+ ? L3.g_proj 0.01092 0.19801 18.1x+ ? L7.kv_b_proj 0.00741 0.13427 18.1x+ ? L7.o_proj 0.01099 0.19919 18.1x+ KDA L13.g_proj 0.00903 0.16370 18.1x+ KDA L13.o_proj 0.01188 0.21122 17.8x+ MLA L3.q_a_proj 0.00928 0.16822 18.1x+ MLA L3.q_b_proj 0.00936 0.16984 18.1x+ MLA L3.kv_a_proj_with_mqa 0.00940 0.17041 18.1x+ MLA L3.kv_b_proj 0.00736 0.13355 18.2x+ MLA L3.o_proj 0.01090 0.19774 18.1x+ MLA L3.g_proj 0.01092 0.19801 18.1x+ MLA L7.q_a_proj 0.00910 0.16499 18.1x+ MLA L7.q_b_proj 0.00837 0.15178 18.1x+ MLA L7.kv_a_proj_with_mqa 0.00916 0.16622 18.1x+ MLA L7.kv_b_proj 0.00741 0.13427 18.1x+ MLA L7.o_proj 0.01099 0.19919 18.1x+ MLA L7.g_proj 0.01042 0.18906 18.1x+ MLA L11.q_a_proj 0.00904 0.16383 18.1x+ MLA L11.q_b_proj 0.00829 0.15035 18.1x+ MLA L11.kv_a_proj_with_mqa 0.00913 0.16557 18.1x+ MLA L11.kv_b_proj 0.00737 0.13333 18.1x+ MLA L11.o_proj 0.01399 0.24612 17.6x+ MLA L11.g_proj 0.01022 0.18521 18.1x+ ------------------------------------------------------------------+ MEAN over KDA-layer tensors 0.01046 0.18746 17.9x (n=2)+ MEAN over MLA-layer tensors 0.00948 0.17154 18.1x (n=18)+ MEAN over ALL sampled tensors 0.00961 0.17383 18.1x (n=31)++ worst single tensor at int4: L11.o_proj 0.24612 mean rel err++=== what this says ===+int8 costs about 1% mean relative error on these weights; int4 costs about 17%.+That ~18x gap is consistent across every tensor sampled, and it holds equally in+KDA-layer and MLA-layer projections -- there is no layer type that tolerates int4+noticeably better.++This is why the engine does not quantise the trunk at all. Even int8 - the far better+of the two - trades a measurable error for memory the streaming design recovers for+free, and int4 on the trunk is not defensible at 17% mean weight error. Only the routed+experts are 4-bit, and only because the checkpoint already ships them that way, trained+for it.++=== honest limits ===+ - This is WEIGHT RECONSTRUCTION error, not output quality. A 17% weight error does+ not straightforwardly become a 17% worse model, and nobody should read it that way.+ - 384 rows sampled per tensor, not whole tensors.+ - Attention projections only. No MoE, no embeddings, no lm_head.+ - NO downstream logit or token comparison was run at int4, so the real quality cost+ is unmeasured. This study bounds the WEIGHT error only. Closing that gap needs a+ full end-to-end grid against the reference logits; tools/ref_forward.py has an+ --int8 mode that would be the starting point.