Deltafin: Running Kimi K3 on a Single M1 Max

Moonshot AI's Kimi K3 is a 1.56 trillion parameter Mixture-of-Experts model. Its sheer size (1.56 TB of MXFP4 weights) would normally require a datacenter. Deltafin, an open-source inference engine, makes it possible to run this model on a single workstation — even an aging M1 Max Mac.

The Key Insight: MoE Sparsity

K3 has 82,432 routed experts across 92 layers. Per token, the router selects only 16 experts per layer (top-16 of 896). That's roughly 1.8% of expert weights touched per token. The resident spine (attention, shared experts, embeddings) is ~114 GB (quantized to int8 ~60 GB) and is read sequentially from disk. This design makes local inference feasible despite the massive total size.

Installation and Setup

Deltafin requires Python 3.12+, a C/C++ compiler, and PyTorch. The setup is straightforward:

git clone https://github.com/gavamedia/deltafin.git
cd deltafin
python3 -m venv venv
./venv/bin/pip install torch numpy safetensors tiktoken ml_dtypes blobfile "transformers==4.56.2" einops tokenizers
python3 tools/build_native.py
./venv/bin/python tools/setup_k3.py --full

The build_native.py script compiles native libraries (.dylib or .so) with host-specific ISA flags (e.g., AVX2/FMA3 on x86-64-v3, NEON on aarch64). It validates symbols and ABI before installing.

Two Operating Modes

ModeDisk NeededDownload TimeSpeed (M1 Max)
--full~1.7 TB5–10 hours14.6 s/token decode
--stream~215 GB~30 minutes~3+ min/token (network bound)

The critical difference: every token reads 16 experts × 92 layers = 25.8 GB of expert data. From local NVMe that's ~4 seconds; over the network it's minutes. Streaming is a good trial mode; you can upgrade later with fetch_experts_all.py without reinstalling.

Performance Benchmarks

On a single M1 Max (10-core CPU, 32-core GPU, 64 GB RAM, internal NVMe) with full install, int8 spine, Metal MoE, fp32 numerics, greedy decoding, and tracing off:

MetricValue
Prefill (5-token prompt)28.0 s median (range 24.9–37.9 s)
Steady decode0.0687 token/s (14.6 s/token)
3-token generation (model time)56.5 s median
Fresh-process wall time64.1 s median
Streaming decode~3 min/token (network bound)

This is an early Apple Silicon machine — newer hardware with higher memory bandwidth should perform better. The maintainer notes this is a "conservative reference point."

Usage

Deltafin provides a CLI and an OpenAI-compatible API server.

CLI example:

./venv/bin/python tools/kimi_run.py --chat --prompt "What are the three largest moons of Saturn?"

API server:

./venv/bin/python tools/serve_openai.py --port 8000

Then use any OpenAI client:

from openai import OpenAI
client = OpenAI(base_url="http://127.0.0.1:8000/v1", api_key="none")
r = client.chat.completions.create(
    model="deltafin-kimi-k3",
    messages=[{"role": "user", "content": "Hello!"}])
print(r.choices[0].message.content)

Caveats: answers take minutes; set client timeouts to hours. Streaming installs are much slower for chat (prefill touches many experts). Only greedy decoding is supported (temperature/top_p ignored). One request at a time.

Configuration

Deltafin auto-detects the best device (MPS, CUDA, CPU) and uses int8 spine if built. Override via environment variables:

  • K3_DEV: set device (mps, cuda, cpu)
  • K3_MOE: MoE backend (metal, cpu)
  • K3_SPINE: weight type (int8, bf16)
  • K3_MOE_TOP_K: number of routed experts (default 16)
  • K3_CPU_MOE_BATCH: CPU worker ring size

Why This Matters

Running a 1.56T parameter model on a single consumer machine is a milestone. The Mixture-of-Experts architecture, combined with aggressive quantization (MXFP4) and sparse activation, enables local inference that was previously impossible. For developers, this means experimenting with state-of-the-art LLMs without cloud costs, though patience is required: 0.07 tokens/second is not interactive.

Next Steps

If you have 1.7 TB free disk space and a recent Mac or Linux machine, try the full install. For a quick test, use streaming mode. Monitor the GitHub repo for updates — the M1 Max benchmark already shows 87× improvement in prefill since the first version.