Project notes · 10

Running Inkling 2 Mini on a Mac behind a local OpenAI API

To use Inkling 2 Mini on my 32 GB Mac mini for long-form Chinese writing and document summaries, I wrote a custom MLX runtime and wrapped it in a Rust OpenAI-compatible server.

Local Inkling 2 Mini inference · Inference runtime · Apple Silicon GitHub

When Thinking Machines dropped Inkling 2 Mini, I immediately wanted it running locally on my Mac mini (M6, 32 GB) for everyday long-form Chinese drafting and long-document summaries. Problem was, mlx-vlm 0.8 only supported Inkling 2 Small at the time; it had no support for Mini’s three-pass looped layer architecture. Rather than wait around, I wrote a dedicated MLX runtime myself.

Once outputs matched reference, I spent the next stretch squeezing speed out of it: plain decoding runs at about 34 tok/s, structured text like code reaches 36–40 tok/s with DSpark speculative decoding, and an 8k prefill runs at roughly 900 tok/s. A small Rust launcher wraps the worker process and exposes a local OpenAI-compatible server that existing desktop and CLI clients can talk to out of the box.

Source code: github.com/Quorafind/inkling2-mlx

Quick start

You’ll need an Apple silicon Mac with at least 32 GB of unified memory (resident footprint is ~18.9 GB), Python 3.12, and Rust:

git clone https://github.com/Quorafind/inkling2-mlx && cd inkling2-mlx
uv venv -p 3.12 .venv && uv pip install -p .venv/bin/python -r requirements.txt

# ~20 GB of weights, available on Hugging Face or ModelScope
hf download thinkingmachines/Inkling-2-Mini --local-dir models/Inkling-2-Mini

./inkling2

The first ./inkling2 invocation compiles the Rust launcher, loads the weights, and starts serving http://127.0.0.1:8000/v1 in under ten seconds. If you just want a quick terminal REPL, run ./inkling2 chat.

Connecting clients & multi-turn KV reuse

Point any OpenAI client at http://127.0.0.1:8000/v1 with an arbitrary API key and model inkling-2-mini. Both Chat Completions and Responses endpoints are supported, complete with streaming, tool calling, and vision inputs. Chain-of-thought comes back in reasoning_content, controlled via reasoning_effort.

Most of my engineering time went into multi-turn KV cache reuse, because when you’re chatting over a long document, prefill latency hurts far more than token generation:

  • Chat Completions clients resend the entire message array every turn; the server matches the longest cached prefix so it only prefills newly appended messages.
  • Responses requests carrying previous_response_id pick up directly from the prior turn’s state in memory.
  • Heavy system prompts and tool schemas get snapshotted separately, so brand-new threads reuse them for free.

In practice, turn 2 of an 8,000-token document chat drops from a 9.3-second cold prefill to 0.3 seconds to first token.

How it stacks up against Strata

Strata is another popular option for running Inkling 2 Mini locally. It’s a broad C++ engine built for NVIDIA, AMD, Intel, and Apple GPUs that tiers MoE experts across VRAM, system RAM, and SSD so low-VRAM PCs can run big models, bundled with a desktop app and deep Codex hooks. My project has a much narrower scope: run this single model as well as possible on Apple silicon.

I benchmarked both on the exact same Mac mini against the official safetensors weights and identical token sequences:

Metric Strata (patched) This repo, BF16 This repo, 6-bit
Plain decode (tok/s) 21.7 23.6 34.7
DSpark on code (tok/s) 22–26 27–33 36–40
Prefill 8k / 32k (tok/s) 718 / 627 967 / 867 879 / 805
Mean KL vs. FP32 reference 9.3e-4 4.3e-3 8.2e-3

Strata numbers are on v0.1.66 with my local bugfix applied; 6-bit is this repo’s default config. This repo’s decode numbers were re-measured with the same script after the work in the next section; Strata’s column, prefill and KL are from the original run.

One debugging rabbit hole worth noting: out of the box, Strata v0.1.66 spat out pure gibberish on my Mac when loading official safetensors. Diffing intermediate activations layer by layer turned up the culprit: its Metal kernels were reading several small BF16 tensors (norm weights, short-conv taps, scale factors) as FP32, corrupting activations right at layer 0’s RMSNorm. (Strata’s custom .strata container takes a different code path that I didn’t test.) I wrote a local patch to fix the tensor reads before running the benchmarks above, and included the patch in my repo.

Patched Strata edges out my runtime on numerical precision because it keeps activations in FP32 throughout. Even so, test-set perplexity lands between 5.08 and 5.13 on both engines (against 5.110 in FP32 reference), which is indistinguishable in real writing.

How it compares with mlx-swift-lm

Later, a pull request to mlx-swift-lm (#821) added Inkling 2 and reported 43.7 tok/s at 4-bit on an M6 Mac mini, close to 30% faster than my 4-bit at the time. I built its branch and ran it on the same machine with the same weights and the same input tokens:

Decode (tok/s) BF16 dense 4-bit dense
mlx-swift-lm PR #821 22.8–24.1 39.5–40.3
This repo, after the work below 23.5–23.6 about 39

On my machine its 4-bit runs at about 40 tok/s, against about 35 for mine before this round, so the real gap was about 8%, and only at 4-bit. In BF16 each token reads over 6 GB, the time goes almost entirely to memory reads, and the two run level. With half the bytes, the cost of the small kernels around each layer starts to show.

I suspected the experts first, but its expert kernels, run as-is in my harness, were only 2% faster. Timing every kernel separately with Metal System Trace found the real cost: the block attention residual that runs before and after every layer took over 20 µs per call, about 100 calls per token, and renormalized every earlier block each time. Now each block is normalized once, and the post-attention short convolution runs in the same kernel. Routing, experts and the convolution after them take three kernels, and the relative-position bias and output gate moved into the attention kernels. 4-bit went from 36.4 to 39.1 tok/s and the 6-bit default from 31.9 to 34.5 tok/s, with the same precision.

This round also fixed a reproducibility problem. DSpark used to pick how many tokens to verify per round from measured timings, which jitter, so two identical requests could take different paths and greedy output could split where the top candidates were nearly tied. The costs are now a fixed table adjusted for context length, so the same request always gives the same output, at the same speed.

Design trade-offs

  • Leave routed experts in their native training formats. On unified memory, every expert already sits resident in RAM, so there’s no PCIe tiering bottleneck to fight. Keeping the trained NVFP4 / MXFP8 weights avoids unnecessary quantization loss.
  • Quantize only the dense layers, defaulting to 6-bit. Autoregressive decode is almost purely memory-bandwidth bound: reading ~3.8 GB per token at 6-bit vs. ~6.4 GB in BF16 buys a big jump in tok/s, while 8-bit and 16-bit flags remain one switch away when precision matters most.
  • Lean on MLX for matmuls, write custom Metal kernels for the small stuff. Apple’s tuned matrix kernels already deliver top-tier prefill throughput on M-series chips, which matters most for long prompts, while fused Metal kernels clean up launch overhead across the small ops in the decode loop.
  • Throttle speculative decoding dynamically. Because Inkling 2 Mini is a three-pass looped MoE, each extra draft token verified costs ~30% of a full step. Rather than forcing a fixed lookahead, the runtime scales verification length per step from the draft head’s own confidence and drops back to plain decode when confidence dips, so prose never slows down and code gets a further boost (3% and 15% on the two code prompts I measured).
  • Keep conversation state server-side. Stateful Responses sessions and automatic prefix matching on Chat Completions eliminate redundant prefills across multi-turn chats.
  • Rust on the outside, Python + MLX on the inside. Rust handles HTTP routing, SSE streaming, request cancellation, and worker supervision cleanly, leaving the model math in Python and MLX where kernel and architecture experiments stay fast to iterate on.