Tiny engine, immense model. A readable, single-file C++17 inference
experiment targeting consumer-memory machines. It opens Moonshot AI's
official Kimi-K3 safetensors directly, keeps a bounded expert cache, and
streams native MXFP4 routed experts from disk with io_uring + O_DIRECT.
The engine needs no PyTorch, CUDA, GGUF conversion, or liburing. It uses the
Linux system-call ABI directly and keeps the model equations in one source
file that can be read from top to bottom. The optional official-reference
oracle recorder does use PyTorch on a separate, suitably large validation
host.
[!IMPORTANT] This is an engineering preview, not a production inference server. Checkpoint-independent kernels and all 497,220 official tensor schemas are tested. Full 93-layer logits have not yet been compared with the official Python implementation because this development host has only one 800 GB local SSD and therefore cannot store the 1.42 TiB checkpoint. This is a storage-capacity limit, not a claim that the model needs 1.42 TiB of RAM. The only generation command is deliberately named
--generate-unverified.
Kimi-K3 has about 2.8 trillion total parameters but activates only 16 of 896 routed experts per MoE layer. That sparsity makes a disk-backed CPU engine possible:
The bounded mutable state and minimum 16-slot expert cache are well below 25 GB. On a 25 GB machine, however, Linux must also demand-page roughly 106.5 GiB of always-active file-backed weights. It should be possible to run without loading the 1.42 TiB model into RAM, but it will be extremely storage-bound and has not yet been benchmarked on such a machine. This repository does not pretend otherwise.
You still need at least 1,638,903,341,107 free bytes for the official checkpoint plus a 5% working margin.
Requirements:
make
./kimik3 --self-test
./kimik3 --architecture
./kimik3 --check-runtime-state
./kimik3 --check-numa
The executable links only the ordinary C/C++ runtime, libm, and OpenMP.
The range downloader fetches only each safetensors header plus the tokenizer:
./setup_kimik3.sh --headers /ssd/kimik3-headers
That downloads about 72 MiB of headers and then checks:
./kimik3 --benchmark-storage 8
The benchmark creates one temporary 17,547,264-byte expert fixture under
/ssd, opens it with O_DIRECT, submits the exact six operand reads through
raw io_uring, validates every byte, reports the backend actually used, and
removes the fixture.
The development host reports eight io_uring batches and zero fallback
batches. Throughput varies with the SSD and cache state, so the command prints
its own measurement instead of baking a headline number into the project.
./setup_kimik3.sh --model /ssd/Kimi-K3
Or explicitly download it after the free-space guard passes:
./setup_kimik3.sh --download /ssd/Kimi-K3
The unvalidated generation diagnostic is:
KIMIK3_EXPERT_CACHE_SLOTS=64 \
./kimik3 --generate-unverified \
/ssd/Kimi-K3 /ssd/kimik3-headers/tiktoken.model \
"Explain why sparse MoE models can stream experts from SSD." 32
Sixteen slots are the correctness minimum and consume about 268.5 MiB. Each additional aligned slot costs about 16.78 MiB.
io_uring reads with O_DIRECT and exact pread fallback.MPOL_INTERLEAVE resident tensor placement.The point is auditability. kimik3.cpp is ordered as a story:
architecture and resource accounting
→ number formats and kernels
→ KDA / MLA / Attention Residuals / MoE
→ checkpoint mapping
→ tokenizer and XTML
→ expert cache and asynchronous storage
→ 93-layer decoder
→ tests and CLI
There is no graph compiler or tensor framework between the model equations and the code executing them.
The local tests prove the components and metadata contract. They do not prove
that complete checkpoint-backed generation matches Moonshot's implementation.
The oracle machinery for the remaining acceptance test is included and
documented in KIMIK3_ORACLE.md. It compares:
The normal generation command will stay gated until that oracle passes on a host capable of loading the complete checkpoint.
kimik3.cpp — the engine and deterministic self-tests.Makefile — release build and focused test targets.setup_kimik3.sh — build, metadata validation, and guarded download.fetch_kimik3_headers.py — pinned parallel range downloader.test_kimik3_tokenizer.py — checkpoint-independent tokenizer vectors.test_kimik3_xtml.py — exact multi-turn/tools/schema/image prompt vectors.kimik3_oracle.py — official-reference recorder and dependency-free
comparator.KIMIK3_ORACLE.md — byte format, commands, tolerances, and acceptance plan.scripts/check_public_tree.py — fail-closed public-tree policy audit.References:
4 commits
C++
83.8%
Python
15.3%
Tiny engine, immense model. A readable, single-file C++17 inference
experiment targeting consumer-memory machines. It opens Moonshot AI's
official Kimi-K3 safetensors directly, keeps a bounded expert cache, and
streams native MXFP4 routed experts from disk with io_uring + O_DIRECT.
The engine needs no PyTorch, CUDA, GGUF conversion, or liburing. It uses the
Linux system-call ABI directly and keeps the model equations in one source
file that can be read from top to bottom. The optional official-reference
oracle recorder does use PyTorch on a separate, suitably large validation
host.
[!IMPORTANT] This is an engineering preview, not a production inference server. Checkpoint-independent kernels and all 497,220 official tensor schemas are tested. Full 93-layer logits have not yet been compared with the official Python implementation because this development host has only one 800 GB local SSD and therefore cannot store the 1.42 TiB checkpoint. This is a storage-capacity limit, not a claim that the model needs 1.42 TiB of RAM. The only generation command is deliberately named
--generate-unverified.
Kimi-K3 has about 2.8 trillion total parameters but activates only 16 of 896 routed experts per MoE layer. That sparsity makes a disk-backed CPU engine possible:
The bounded mutable state and minimum 16-slot expert cache are well below 25 GB. On a 25 GB machine, however, Linux must also demand-page roughly 106.5 GiB of always-active file-backed weights. It should be possible to run without loading the 1.42 TiB model into RAM, but it will be extremely storage-bound and has not yet been benchmarked on such a machine. This repository does not pretend otherwise.
You still need at least 1,638,903,341,107 free bytes for the official checkpoint plus a 5% working margin.
Requirements:
make
./kimik3 --self-test
./kimik3 --architecture
./kimik3 --check-runtime-state
./kimik3 --check-numa
The executable links only the ordinary C/C++ runtime, libm, and OpenMP.
The range downloader fetches only each safetensors header plus the tokenizer:
./setup_kimik3.sh --headers /ssd/kimik3-headers
That downloads about 72 MiB of headers and then checks:
./kimik3 --benchmark-storage 8
The benchmark creates one temporary 17,547,264-byte expert fixture under
/ssd, opens it with O_DIRECT, submits the exact six operand reads through
raw io_uring, validates every byte, reports the backend actually used, and
removes the fixture.
The development host reports eight io_uring batches and zero fallback
batches. Throughput varies with the SSD and cache state, so the command prints
its own measurement instead of baking a headline number into the project.
./setup_kimik3.sh --model /ssd/Kimi-K3
Or explicitly download it after the free-space guard passes:
./setup_kimik3.sh --download /ssd/Kimi-K3
The unvalidated generation diagnostic is:
KIMIK3_EXPERT_CACHE_SLOTS=64 \
./kimik3 --generate-unverified \
/ssd/Kimi-K3 /ssd/kimik3-headers/tiktoken.model \
"Explain why sparse MoE models can stream experts from SSD." 32
Sixteen slots are the correctness minimum and consume about 268.5 MiB. Each additional aligned slot costs about 16.78 MiB.
io_uring reads with O_DIRECT and exact pread fallback.MPOL_INTERLEAVE resident tensor placement.The point is auditability. kimik3.cpp is ordered as a story:
architecture and resource accounting
→ number formats and kernels
→ KDA / MLA / Attention Residuals / MoE
→ checkpoint mapping
→ tokenizer and XTML
→ expert cache and asynchronous storage
→ 93-layer decoder
→ tests and CLI
There is no graph compiler or tensor framework between the model equations and the code executing them.
The local tests prove the components and metadata contract. They do not prove
that complete checkpoint-backed generation matches Moonshot's implementation.
The oracle machinery for the remaining acceptance test is included and
documented in KIMIK3_ORACLE.md. It compares:
The normal generation command will stay gated until that oracle passes on a host capable of loading the complete checkpoint.
kimik3.cpp — the engine and deterministic self-tests.Makefile — release build and focused test targets.setup_kimik3.sh — build, metadata validation, and guarded download.fetch_kimik3_headers.py — pinned parallel range downloader.test_kimik3_tokenizer.py — checkpoint-independent tokenizer vectors.test_kimik3_xtml.py — exact multi-turn/tools/schema/image prompt vectors.kimik3_oracle.py — official-reference recorder and dependency-free
comparator.KIMIK3_ORACLE.md — byte format, commands, tolerances, and acceptance plan.scripts/check_public_tree.py — fail-closed public-tree policy audit.References:
4 commits
C++
83.8%
Python
15.3%