talira

kimi-k3-in-c

An inference engine in portable C99 that runs the 2.78-trillion-parameter Kimi K3 on one CPU with 8 GB of RAM

open sourceApache-2.0free

kimi-k3-in-c is an inference engine for Moonshot AI's Kimi K3 written in portable C99, with no BLAS, no framework and no GPU. Because Kimi K3 is a mixture of experts, the engine streams the experts it needs from disk on each step, so the full 2.78-trillion-parameter model runs on a machine with 8 GB of RAM; more memory only makes it faster (about 26.5 seconds a token at 8 GB and 5.6 seconds at 128 GB or more in the maker's measurements), and the output is the same at every size. It builds with make or CMake into a k3 command that takes the directory of .safetensors shards and a prompt, with presets for different memory sizes and a chat mode. It runs on x86-64 Linux with AVX2 and FMA, and also builds on macOS on arm64 and on Windows; Python scripts download and pack the weights. Its test suite runs without the model.

Problems it solves

  • run a trillion-parameter mixture-of-experts model on a computer without a GPU
  • run Kimi K3 locally on a CPU with little RAM
  • a dependency-free C inference engine I can read and build myself

Features

  • runs Kimi K3 on a CPU by streaming its experts from disk, from 8 GB of RAM up
  • byte-identical output whatever the machine's memory, with presets for each memory size
  • builds with make or CMake from seven C files, with OpenMP
  • a test suite that checks the engine without downloading the model

Limitations

  • The Kimi K3 checkpoint is 1.56 TB, and the engine needs about 1.7 TB of free storage, ideally a fast local disk.1
  • Generation is slow on ordinary machines: about 26.5 seconds per token with 8 GB of RAM in the maker's measurements.1

Alternatives

The same job

These do what kimi-k3-in-c does.

  1. llama.cpp LLM inference in C/C++
  2. colibri Runs huge mixture-of-experts models on ordinary hardware by streaming experts from disk
  3. KTransformers Run and fine-tune huge mixture-of-experts LLMs on limited GPUs by splitting work between CPU and GPU
  4. FreeToken Serving engine that runs frontier-scale open-weight MoE models on consumer GPUs
  5. ExLlamaV3 Quantisation and inference library for running LLMs locally on consumer GPUs
  6. TensorRT-LLM Optimized LLM and visual generation inference on NVIDIA GPUs

Compare kimi-k3-in-c with the top 3