Skip to content

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.

3.5 KB
Raw Blame

Test fixtures

Everything the C test binaries read. All of it is checked in, so make test runs with no network access, no model weights, and no Python, which is the point: if correctness required the 1.56 TB checkpoint, correctness would not get checked.

Total is about 12 MB.

path bytes read by generated by
ops/ ~2 MB test_ops tools/emit_fixtures.py
ops/MANIFEST.json none test_ops same; lists fixtures and tolerances
cache/ ~200 KB test_cache tools/make_cache_fixture.py
st/ ~50 KB test_st tools/make_st_fixture.py
ref_k3.json 6 KB k3_model tools/make_k3_oracle.py
tiny_k3.bin, tiny_k3.json 9 MB k3_model same
mxfp4.json 2.9 MB test_ops, tools/verify_expert.py tools/emit_fixtures.py
golden/ none conformance comparison tools/ref_forward.py, real weights
gates/ none recorded gate output the test binaries
expert_trace.bin 800 KB tools/sim_cache.py a real model run with --dump-cache-trace

Regenerating

Every generator derives its output path from tools/_paths.py, so they all write here and cannot drift apart. Regeneration needs PyTorch and the reference implementation in tools/k3_ref.py:

python tools/emit_fixtures.py        # ops/ and mxfp4.json
python tools/make_k3_oracle.py       # ref_k3.json, tiny_k3.*
python tools/make_cache_fixture.py   # cache/
python tools/make_st_fixture.py      # st/

expert_trace.bin cannot be regenerated without the real checkpoint; capture a new one with ./bin/k3 <model_dir> --dump-cache-trace tests/fixtures ....

Why these fixtures and not simpler ones

Each is adversarial in a specific way, because the cheap version of each would pass against a wrong implementation:

  • ops/situ_glu.json spans |z| from 0.1 to 1000 so both soft caps saturate. In the near-linear regime beta*tanh(z/beta) == z, and an implementation with the caps omitted entirely passes.
  • ops/kda_decay.json exports a spread of A_log, so an implementation indexing it per channel rather than per head fails. With one head, both index the same memory.
  • ops/kda_recur*.json carry the module weights, not just inputs and outputs. A fixture recording only in/out of a randomly-initialised module is unreproducible: no implementation can match it, and it silently provides zero coverage.
  • st/ includes a bf16 1-D tensor, an f16 tensor of non-multiple-of-4 length, a packed U8 2-D tensor, a rank-0 scalar, and a tensor in a second shard, the shapes a reader handles by accident when it only ever sees well-behaved f32 matrices.
  • cache/ uses a deliberately non-conforming expert size. The real checkpoint's 17,547,264 bytes happens to be an exact multiple of 4096, so O_DIRECT alignment holds there by coincidence; these fixtures do not let that coincidence hide a bug.
  • cache/ content is derived from the expert index, so slot aliasing, returning expert a's bytes for expert b, is visible immediately instead of looking like plausible noise.
  • mxfp4.json holds released checkpoint bytes, so the nibble order and the E8M0 scale exponent are checked against the released format rather than against this project's own assumptions about it.
  • ref_k3.json is 13 layers, not 5. The Attention-Residual failure modes cannot appear until two blocks are complete and a third is in progress; a shallower fixture passes a broken implementation.