FareedKhan-dev/kimi-k3-in-c

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.

What is kimi-k3-in-c?

kimi-k3-in-c is a small C program that runs a gigantic AI model — the Kimi K3 model with 2.78 trillion parameters — on an ordinary computer with just 8 GB of RAM, no GPU, and no special math libraries. It does this by streaming the model from disk instead of loading it all into memory, and it produces byte-identical output no matter how much RAM you have — only the speed changes.

The entire engine is just 176 KB of C99 code, and it works on Linux, macOS, and Windows (with some porting).

Why is this impressive?

Normally, a model this large would need a cluster of servers with terabytes of RAM and many GPUs. This project shows that you can run the same model on a laptop, just much slower. The trick is that the model is stored on disk (1.56 TB checkpoint) and read piece by piece as needed, with a smart caching system that keeps the most-used parts in memory.

How does it work?

The README explains four key “reductions” that make this possible:

  1. The experts are already packed at half a byte – the model’s “expert” components are stored in a compressed 4-bit format, so they take less space.
  2. KDA attention – a special attention mechanism that uses a fixed amount of memory regardless of how long the input is.
  3. MLA (Multi-head Latent Attention) – instead of using 96 separate attention heads, it uses one latent representation, saving memory.
  4. Streaming the trunk – the dense layers (the “trunk” of the model) are read from disk on demand, so you can choose how much of them to keep in RAM.

There’s also an LRU cache for the expert components, so frequently used ones stay in memory.

What do you need to run it?

  • Storage: about 1.7 TB free (1.56 TB for the checkpoint + 109 GB for a packed trunk file).
  • CPU: any x86-64 with AVX2+FMA, or ARM64 with NEON.
  • RAM: 8 GB minimum; more RAM only makes it faster, never changes the output.
  • Toolchain: GCC ≥9 or Clang ≥10, plus GNU make or CMake.
  • Python 3.9+ (only for downloading and packing the model, not for running the tests).

How do you use it?

  1. Clone the repository.
  2. Build with make -j (takes seconds).
  3. Test with make test (verifies the engine works without needing the huge model).
  4. Download the 1.56 TB checkpoint from Hugging Face (requires a token).
  5. Pack the trunk with ./scripts/pack-trunk.sh (creates a 109 GB file for faster streaming).
  6. Run with a command like:
    ./bin/k3 ~/k3model --trunk ~/k3trunk --preset laptop --tok ~/k3model --prompt "The capital of France is" --gen 8 --incremental
    

You can choose a preset (laptop, desktop, workstation, server, max) that sets how much RAM to use. The output is always the same, but the speed varies.

Performance

From the README’s measurements (on a specific machine):

Machine RAM Time per token
Ordinary laptop 8 GB 26.5 s
High-end laptop 32 GB 24.2 s
Desktop 64 GB 19.8 s
Heavy workstation 128 GB+ 5.6 s

So more RAM means faster generation, but the answer is always identical.

Key features

  • Portable C99 – no external dependencies beyond the standard library and OpenMP.
  • Exact reproducibility – the same prompt always gives the same output, regardless of hardware.
  • No GPU required – runs on any modern CPU.
  • Comprehensive test suite – verifies the engine matches a reference implementation exactly.
  • Open source – licensed under Apache-2.0.

Where to learn more

The README includes detailed documentation on the architecture, validation, measurements, and usage. It also has a docs/ folder with data and diagrams.


This explainer is based solely on the project’s README. No extra features or facts were added.

Related

  • Dispatch
  • Project
  • Dispatch
  • Dispatch
  • Project