AI/TLDR

kimi-k3-in-c

Run a 2.78-trillion-parameter model on an 8 GB CPU machine, in portable C99

Local RuntimesOpen source
Language
C
License
Apache-2.0
$git clone https://github.com/FareedKhan-dev/kimi-k3-in-c.git

Overview

kimi-k3-in-c is a single-purpose inference engine: it runs Kimi K3 — 2.78 trillion parameters, a 1.56 TB checkpoint — in portable C99, with no BLAS, no framework and no GPU. The measured peak resident set for a generation run is 8.24 GB, which is the point of the project: memory stops being a floor you must clear and becomes a dial that only changes speed. On the author's published ladder the same prompt takes about 26.5 s per token on an 8 GB laptop and about 5.6 s per token on a 128 GB-plus machine, with byte-identical output at every size.

It gets there by streaming. Routed expert weights already ship at half a byte each, the trunk is packed so each of the 93 layers is one read, an LRU cache keeps hot experts in memory, and the KDA and MLA attention paths keep the per-token state from growing. Storage, not RAM, is the real gate: you need roughly 1.7 TB free for the checkpoint plus the 109 GB packed trunk, ideally on a fast local disk. The reference platform is Linux x86-64 with AVX2 and FMA; macOS/arm64 and Windows via MSYS2 MinGW-w64 also build and pass the test gates.

The repository takes correctness seriously enough to be usable as a reference. `make test` runs a weightless gate ladder — teacher forcing, greedy decode, and incremental decode with KV cache and carried KDA state — against a PyTorch reference over a 13-layer model built from the same tensor graph, in under a minute, with no checkpoint, no network and no Python. A `k3-doctor.sh` script checks your toolchain, sizes your RAM to a preset and measures your disk the way the engine reads it, and the download script verifies the checkpoint byte-exactly per shard so a partial download fails loudly instead of producing wrong tokens.

What it does

  • Portable C99 engine — seven C files, a compiler and OpenMP; no BLAS, no framework, no GPU
  • Streams the checkpoint from disk so an 8 GB machine runs the full 2.78T-parameter model; more RAM buys speed, never different output
  • Memory presets (laptop, server, …) sized to the machine by the bundled `k3-doctor.sh`
  • LRU expert cache with a recorded trace you can replay to pick a capacity
  • Weightless test suite: three gates against a PyTorch reference, no checkpoint or network needed
  • Byte-exact per-shard checkpoint verification in the download script
  • Builds with GNU make or CMake/ctest; Linux x86-64 reference, macOS/arm64 and Windows MinGW-w64 also supported
  • Base model — no chat template, so output continues the prompt rather than replying to it

Getting started

You can build and fully test the engine in about a minute without downloading anything. Requirements for a real run: AVX2 + FMA CPU, GCC ≥ 9 or Clang ≥ 10, ~1.7 TB free storage, and Python 3.9+ for the download and packing tools.

Clone, build and verify

No checkpoint, no network, no Python. The run ends with the three gates matching the reference exactly.

bashbash
git clone https://github.com/FareedKhan-dev/kimi-k3-in-c.git
cd kimi-k3-in-c

make -j
make test

Check the machine

The doctor script checks the toolchain, sizes your RAM to a preset, measures your storage the way the engine reads it, and prints the exact next command. It exits non-zero when the machine cannot run the model at all.

bashbash
./scripts/k3-doctor.sh

Fetch and pack the checkpoint

1.56 TB, so hours rather than minutes; the script is resumable and verifies the shard count, the byte total and every individual shard size. Then pack the trunk so each layer is a single read.

bashbash
export HF_TOKEN=hf_your_token_here
./scripts/download-model.sh ~/k3model
./scripts/pack-trunk.sh ~/k3model ~/k3trunk

Generate

Point the binary at the model and packed trunk, choose the preset the doctor suggested, and generate. Peak RSS is reported for the whole run.

bashbash
./bin/k3 ~/k3model --trunk ~/k3trunk --preset laptop \
         --tok ~/k3model --prompt "The capital of France is" --gen 8 --incremental

Commands and code are distilled from the project's own documentation — always check the official repo for the latest.

When to use it

  • Reach for it to run a frontier-scale open model on hardware you already own, when latency does not matter but capability does
  • Reach for it when you need an auditable, dependency-free inference path — seven C files you can read end to end
  • Reach for it as a correctness reference: the weightless gate ladder checks an implementation against PyTorch without a checkpoint
  • Reach for it to study how expert streaming, trunk packing and cache capacity trade memory against tokens per second

How kimi-k3-in-c compares

kimi-k3-in-c alongside other open-source local runtimes tools AI/TLDR tracks, ranked by GitHub stars.

ToolStarsWhat it does
Ollama★ 181kA developer-friendly tool that downloads and runs local LLMs from the terminal with a built-in OpenAI-compatible API.
llama.cpp★ 129kA C/C++ inference engine that runs LLMs in the GGUF format on CPUs, Apple Silicon, and GPUs with low memory use.
GPT4All★ 77.4kGPT4All is a free desktop app and Python client that runs large language models locally on your own computer, with no API calls or GPU required.
LocalAI★ 49.2kA self-hosted server that exposes an OpenAI-compatible API for running text, vision, voice, and image models on local hardware.
Jan★ 44.6kAn open-source desktop app that runs LLMs fully offline as a ChatGPT-style assistant on your own computer.
llmfit★ 36.8kA Rust terminal tool that inspects your CPU, RAM, GPUs and VRAM and scores which open-weight models and quantizations will actually run well on that machine, with a TUI, CLI, REST API and local-runtime integrations.
Colibrì★ 36.5kA pure-C inference engine that keeps a Mixture-of-Experts model's dense trunk resident in RAM and streams its routed experts from disk, so 744B-2.8T models run on consumer hardware.
kimi-k3-in-c★ 8.1kRun a 2.78-trillion-parameter model on an 8 GB CPU machine, in portable C99