Inkling-2-Mini-MLX / README.md
balllvin's picture
Standardize model card with Batch 4 template
8c7021a verified
|
Raw History Blame Contribute Delete
9.52 kB
metadata
library_name: mlx
license: mit
pipeline_tag: text-generation
base_model: thinkingmachines/Inkling-2-Mini
base_model_relation: finetune
language:
  - en
tags:
  - mlx
  - apple-silicon
  - metal-4
  - m5
  - moe
  - nvfp4
  - mxfp8
  - speculative-decoding
  - inkling-2-mini

Inkling-2-Mini-MLX (Apple Silicon Metal 4 Runtime)

This repository provides the Apple Silicon (MLX + Metal 4) inference engine for thinkingmachines/Inkling-2-Mini (26.4B total / 3.4B active per pass / 5.4B effective active MoE with 3 loop passes = 48 layer visits per token and 256K context). It mirrors github.com/Balllvin/inkling-mlx and is the MLX base runtime that pairs with balllvin/BS-0.5-Mini.

What This Build Is & Why Use It

Standard MLX runners lose throughput on Inkling-2-Mini from command-buffer flushes (max_ops_per_cb = 50), MoE sorting bottlenecks, redundant lm_head reads, dense prefill masks, and leaving the built-in mtp.safetensors drafter unused. inkling-mlx replaces the hot path with custom Metal 4 NAX and SIMT kernels while matching PyTorch Transformers bit-tight (KL = 2.48e-10).

  • Runtime format (inkling-mlx, code-only repo): Contains no duplicated weight binaries (36 files). At launch, inkling-mlx serve downloads or loads thinkingmachines/Inkling-2-Mini (~20.2 GB) directly and runs the exact mixed NVFP4/MXFP8/BF16 weights, unquantized 256K BF16 KV cache, and built-in mtp.safetensors speculative drafter over an OpenAI-compatible HTTP/SSE API (/v1/chat/completions, /v1/models, /health).
  • Adapter pairing (balllvin/BS-0.5-Mini): Pass --adapter balllvin/BS-0.5-Mini to inkling-mlx serve to merge our rank-16 BS Code / DeepSeek Harness LoRA+ adapter (312 text attention & cross-pass controller modules) into BF16 weights at load time (~2.8 s) with zero decode speed penalty.
  • Hardware support: Native Metal 4.0 NAX .dylibs target Apple M5 + macOS 26+ (applegpu_g17s); M1–M4 Macs or < macOS 26 fall back to pure MLX + Metal 3.1 SIMT kernels with --skip-build (untested on M1–M4).

Variant & Companion Guide

Role / Hardware Format / Engine Repository
Upstream base weights (CUDA / PEFT / source) Mixed NVFP4 / MXFP8 / BF16 thinkingmachines/Inkling-2-Mini
Apple Silicon MLX + Metal 4 runtime (inkling-mlx) Code-only engine (no duplicated weights) balllvin/Inkling-2-Mini-MLX (this repo)
GitHub source mirror inkling-mlx source Balllvin/inkling-mlx
BS Code / DeepSeek Harness LoRA+ adapter Rank-16 PEFT adapter (~50 MB) balllvin/BS-0.5-Mini
Agent harness & CLI bscode Balllvin/BS

Evaluation & Parity Results

Because inkling-mlx executes the exact untouched thinkingmachines/Inkling-2-Mini weights with no re-quantization or KV compression, downstream quality matches the official checkpoint:

  • Numerical & downstream parity: 16 / 16 chat top-1 agreement (KL = 2.48e-10 vs PyTorch Transformers MPS); 100% byte-identical single-stream greedy MTP parity; B=4 batched prefill 4 / 4 top-1 (KL <= 2.88e-10); GSM8K-50 48–49 / 50 (96%–98%); 131,014-tok and 249,926-tok needle retrieval 2 / 2 pass; 20 / 20 (100%) on a 20-task multi-turn agentic coding suite at c=4.
  • Official Inkling-2-Mini reference scores: AA Index v5.0 20.1, Vals Index v2.2 46.5%, SWEBench Verified 79.2%, SWEBench Pro v2 77.9%, Vibe Code Bench v1.1 77.9%, Terminal Bench v2.1 71.6%, DeepSearchQA 85.3%, MCP Atlas 82.7%, BrowseComp 79.0%, ARC-AGI v1 / v2 84.5% / 49.3%.

Speed & Weight Size (Apple M5 Pro 64 GB)

Measured on MacBook Pro (Mac17,9, Apple M5 Pro 20-core GPU, 64 GB RAM, macOS 26.5.1, MLX 0.32.4):

Workload Stock mlx-vlm / Initial MLX inkling-mlx Speedup
Single User Plain (B=1, ctx=512, T=0.0) 25.98 tok/s 48.97 tok/s 1.88x
Single Agent w/ Tools (B=1 MTP, T=0.0) 25.98 tok/s 120.19 tok/s 4.63x
4 Concurrent Agents (B=4 MTP, ctx=512) 39.31 tok/s 117.68 tok/s 2.99x
32 Concurrent Streams (B=32, ctx=512) 36.10 tok/s 277.11 tok/s 7.68x
Max Clean Batch (B=64, ctx=512) β€” 335.48 tok/s β€”
Cold 16K Prompt TTFT (B=1) 20.58–21.4 s 11.14 s 1.85x–1.92x
Cold 16K 4-Stream Decode (B=4) 1.87 tok/s 93.12 tok/s 49.8x
250K Context Decode (250,102 tok, B=1) β€” 19.79 tok/s β€”

Memory & Context Budget

  • Checkpoint resident footprint: 17.59 GiB text LLM (model-00001-of-00001.safetensors: 10.68 GiB NVFP4 experts L0–19, 3.92 GiB MXFP8 experts L20–23, 1.22 GiB BF16 attention, 1.73 GiB BF16 embed/head) + 0.59 GiB mtp.safetensors = 18.18 GiB (~20.4 GB active after warmup, excluding eager vision).
  • Native context & KV cache: 262,144 (256K) across 48 layer visits (3 passes): 40 sliding-window visits (w=1024, capped at 160 MiB per stream) + 8 global-attention visits (32 KiB/tok, 1 GiB per 32K tokens) + ~3.8 MiB ShortConv state.
Unified Memory Status Recommended Setup / Limits
16–24 GB Unsupported Resident weights + MTP exceed 20 GB before KV cache
32 GB Minimum B=1 up to 16K–32K with --no-mtp --cache-limit-gb 2.0
48 GB Supported B=1..4 w/ MTP (64K–128K), or B=1 at 256K with --no-mtp
64 GB Recommended Full 256K w/ MTP (~29.6 GiB active, ~38.6 GB peak), B=1..4 MTP, or B=64 at ctx=512
96–128 GB+ Supported Multiple concurrent 128K–256K streams and larger prefix caches

Agent Setup & Hosting

Authenticate with Hugging Face (hf auth login or HF_TOKEN) so inkling-mlx can download thinkingmachines/Inkling-2-Mini (and optionally balllvin/BS-0.5-Mini).

1. Install inkling-mlx (Apple Silicon / MLX)

git clone https://huggingface.co/balllvin/Inkling-2-Mini-MLX inkling-mlx
cd inkling-mlx
bash scripts/setup.sh   # installs Python venv + builds Metal 4 .dylibs (M5 + macOS 26+)

# Pre-download base weights (or let `inkling-mlx serve` resolve automatically)
.venv/bin/inkling-mlx download --repo thinkingmachines/Inkling-2-Mini --local-dir ~/models/Inkling-2-Mini

2. Serve Base Model or Pair with balllvin/BS-0.5-Mini

# Base Inkling-2-Mini on OpenAI-compatible HTTP/SSE server:
.venv/bin/inkling-mlx serve \
  --model thinkingmachines/Inkling-2-Mini \
  --host 127.0.0.1 --port 8095

# Or serve with the BS-0.5-Mini coding/agent adapter merged at load time:
.venv/bin/inkling-mlx serve \
  --model thinkingmachines/Inkling-2-Mini \
  --adapter balllvin/BS-0.5-Mini \
  --host 127.0.0.1 --port 8095

(Pass --skip-build on Apple M1–M4 or < macOS 26 to use the pure MLX + Metal 3.1 fallback; add --no-mtp --cache-limit-gb 2.0 on 32 GB Macs. Wire into BS Code with bscode providers add inkling-bs --base-url http://127.0.0.1:8095/v1 --models inkling-2-mini+balllvin/BS-0.5-Mini --no-key.)

3. Verify Running Server

curl -sS http://127.0.0.1:8095/health | python3 -m json.tool
curl -sS http://127.0.0.1:8095/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "inkling-2-mini",
    "messages": [{"role": "user", "content": "What is 17 * 23? Show brief reasoning then the answer."}],
    "max_tokens": 512,
    "temperature": 0.0
  }' | python3 -m json.tool

How It Was Built

  1. Single-command-buffer decode (src/inkling_mlx/native/decode_runner.mm): Executes all 48 layer visits inside 1 MTLCommandBuffer via 16 KB page-aligned zero-copy MTLBuffer wrappers, eliminating MLX flush overhead.
  2. Unified B=1..4 GPU-accept MTP (mtp_draft_runner.mm): Runs the 3-layer DSpark + folded FP64 MarkovHead drafter and Leviathan rejection sampling on GPU without CPU round-trips.
  3. Regime-matched MoE & Zero-Mask FlashAttention (moe_kernels.py, prefill_moe_nax.mm, flash_attn_nax.mm): Dispatches direct dot8_nvfp4 (M=1..2), zero-spill grouped tiles (M=3..112), and Metal 4.0 NAX matmul2d (M >= 128) plus arithmetic causal/sliding-window attention.
  4. Included skill & tests: See skills/mlx-apple-silicon-inference/SKILL.md and verification tests under tests/.

Limits & License

  • Hardware & modality scope: Requires Apple Silicon (32 GB+ unified RAM; 64 GB recommended). Native Metal 4.0 NAX kernels require Apple M5 + macOS 26+; M1–M4 fallback (--skip-build) is untested. Text generation and OpenAI tool calling are supported; vision inputs are not wired into this server.
  • License: Engine code is MIT (LICENSE); underlying thinkingmachines/Inkling-2-Mini weights remain Apache-2.0 by Thinking Machines Lab, Inc. Independent community build.