Skip to content

inkling2: serve Thinking Machines Inkling 2 Mini (inkling2_loop) - #1260

Closed
botbocks wants to merge 3 commits into
ddalcu:mainfrom
botbocks:inkling2
Closed

botbocks wants to merge 3 commits into
ddalcu:mainfrom
botbocks:inkling2

Conversation

@botbocks

Copy link
Copy Markdown

Closes #1253. Reference: the mlx-lm Inkling 2 PR (ml-explore/mlx-lm#2086).

A new plugin, src/plugins/inkling2/, serves inkling2_loop (Inkling 2 Mini) text generation from mlx-lm-layout
packs: mlx-community/Inkling-2-Mini-4bit (affine 4-bit trunk) and mlx-lm-converted 8-bit / bf16 trunks, all with the
release's NVFP4 / MXFP8 experts. The v1 inkling plugin is unchanged. Images are refused by name, inkling2
(Small, no loop) and the ModelOpt release (model.llm.*) are not claimed, decode is serial, and spec decode is not
wired.

Three commits:

  1. computeQuantParams fix (shared SDK). Under an affine model, a bias-less uint8-scale bank was always read as
    mxfp8 with a group size derived from mxfp8's ratio, so an NVFP4 g16 bank loaded as mxfp8 g8 and an MXFP4 g32 bank as
    mxfp8 g16. The fp format is now solved from the packed ratio (the rule the non-affine arm already used), and the
    old rule remains the fallback for any other ratio. The test was red on the unpatched tree (expected .nvfp4, found .mxfp8). Every computeQuantParams / quant caller filter gives the same per-test results before and after.
  2. The plugin on composed MLX ops. Config parse with by-name refusals, a 48-entry visit schedule (prelude, a
    3-pass looped core, tail), short convs, relative-logit attention with sinks, depth (block) attention residuals,
    message gates, and routed experts with the NVFP4 per-expert scale. Also the tiny fixtures and their mlx-lm dump
    script, the proof tests, the live script tests/test_inkling2.sh, and the docs rows.
  3. Kernels. mlx-lm's relative_attention (prefill) and depth_attention Metal kernels, with their bodies
    unchanged. Each is registered with the kernel contract and listed in digests and NOTICE. The composed path stays
    the fallback and the reference, and MLX_SERVE_INKLING2_KERNELS=0 turns both kernels off.
prefill attention, one global visit, L rows over S keys
  composed (=0):  bias gather [H,L,S] f32 -> mask [H,L,S] -> logits [H,L,S] f32 -> concat sinks -> softmax -> @V
  kernel:         relative_attention: one dispatch, blocks of 16 keys, sinks and the band inside the kernel
depth read, every visit (decode and prefill)
  composed (=0):  stack blocks -> norm -> dot -> softmax -> weighted sum (about 8 ops)
  kernel:         depth_attention: one dispatch

Parity

The fixtures and references come from tests/dump_inkling2_fixtures.py run on the mlx-lm PR. Every bf16 reference
uses transformers' declared rounding (static convs and weighted norms in f32), which the script patches into mlx-lm.

Check Bar Result
Tiny CPU f32 pack: prefill (32 rows), whole and in chunks of 5/7/9/11 rows, then 4 decode steps min cos > 0.999, 0 decided misses pass
Tiny quantized pack on the GPU, rel-RMS to the f32 truth no worse than mlx-lm's GPU run x 1.25 prefill 1.51e-2 vs mlx-lm 1.64e-2, decode 1.74e-2 vs 2.33e-2
Real pack, teacher-forced (prefill's last row + 16 steps) against mlx-lm under the same rounding min cos > 0.99, 0 decided misses 4-bit 0.998265, 8-bit 0.999401, 0 misses

Spread against stock mlx-lm, 3 chat prompts x 33 rows (prefill's last row + 32 teacher-forced steps), kernels on:

Pack Pair Top-1 agree Min cos (worst of 3 prompts)
4-bit ours vs mlx-lm 98/99 0.997711
4-bit mlx-lm vs mlx-lm (transformers rounding) 97/99 0.998374
8-bit ours vs mlx-lm 98/99 0.998230
8-bit mlx-lm vs mlx-lm (transformers rounding) 98/99 0.983022

Each top-1 miss falls on a row where mlx-lm's two roundings also disagree, with margins of 0.04-0.10 logits.

Speed

The kernels against their own kill switch, from one binary:

Pack Cell Kernels on (tok/s) MLX_SERVE_INKLING2_KERNELS=0 (tok/s) On / off
4-bit prefill 512 1588 1339 1.19
4-bit prefill 2048 1759 1050 1.68
4-bit prefill 8192 1688 226 7.47
4-bit decode 256 40.0 35.1 1.14
8-bit prefill 512 1582 1355 1.17
8-bit prefill 2048 1791 1060 1.69
8-bit prefill 8192 1687 224 7.52
8-bit decode 256 40.1 35.5 1.13

Method: M5 Max 128 GB, macOS 27.0, ReleaseFast. --warmup-full --prefix-cache-entries 0 --no-pld, boots A B B A
(one arm per boot, because the switch is read per process). Raw /v1/completions prompts of exactly 512 / 2048 / 8192
tokens with max_tokens 1, then 256 greedy chat tokens with ignore_eos. Each cell is the median of 6 samples
(2 boots x 3 reps) of the server's own rate line. Both [inkling2] ... engaged lines appear in every on-arm boot and
none in the off-arm boots.

Against mlx-lm (the PR branch, stream_generate in process) on the same packs, mlx-serve is slower:

Pack Cell mlx-serve (tok/s) mlx-lm (tok/s) mlx-serve / mlx-lm
4-bit prefill 512 1540.8 1632.5 0.94
4-bit prefill 2048 1797.2 2078.2 0.86
4-bit prefill 8192 1704.8 2036.0 0.84
4-bit decode 300 39.5 41.0 0.96
8-bit prefill 512 1562.3 1608.3 0.97
8-bit prefill 2048 1809.9 2071.2 0.87
8-bit prefill 8192 1687.1 2022.8 0.83
8-bit decode 300 39.8 41.2 0.96

Method: same machine and session, one model at a time, boots S L L S per pack, and the same prompt texts (equal token
counts on both sides). mlx-serve runs over HTTP with the flags above. mlx-lm runs stream_generate after one untimed
warm-up, with its default prefill_step_size 2048 and the rates mlx-lm reports. Each cell is the median of 6 samples.
The MLX allocator peak for a one-shot 300-token CLI run is 15.66 GB for mlx-serve and 17.47 GB for mlx-lm (4-bit).

The cost: decode is 4% behind mlx-lm and prefill is 3-17% behind. Most of the remaining decode time is kernel encode:
about 9,200 small kernels per 48-visit forward. mlx-lm compiles its clip and softcapped SwiGLU chains, and this PR
runs them eagerly. Compiling those chains and fusing the decode-attention prep are follow-up PRs, each to be measured
against this head.

Known limits

  • Sliding visits keep a full KV buffer, so at the default context the hot prefix cache gets a 0 MB budget. With
    --ctx-size 32768, prefix restore works and matches a cold server, as the live script checks.
  • Without the kernels (=0, or a non-bf16 pack), the composed prefill holds [H, L, S] f32 logits per global visit,
    and the chunk auto-cap does not account for them.

Verified

On an M5 Max with 128 GB, macOS 27.0.1, ReleaseFast:

  • Targeted filters all pass: inkling2 (76 pass, 1 skip: the real-pack test without its env), computeQuantParams,
    mlx-lm configs, plugin registry, inkling plugin, inkling config (v1 unchanged), and kernel contract
    (636/636 kernels pass gates 1-4, 64 known findings, 10/10 controls red).
  • The real-pack teacher-forced test passes on the 4-bit and 8-bit packs.
  • python3 scripts/lint.py --strict exits 0, and zig build unit-closure passes. zig build units-check -Dunits=true
    fails with the same 19 duplicated globals on main (none from this plugin).
  • tests/test_inkling2.sh passes 10/10 on the 4-bit pack: model listing, greedy Berlin, prefix reuse and restore
    matching a cold server, image 400, reasoning_effort, and both kernels engaged. It also passes 10/10 on the 8-bit
    pack. The script fails at step 1 on a main binary.
  • cd app && swift build && bash test.sh: 4406 tests, 0 failures.
  • Full suite, run once (zig build test -Dslow-tests -Doptimize=ReleaseFast): 5518/5925 passed, 402 skipped, 5
    failed. One failure was this branch's: the new 4-bit fixture config was missing from the quant-block claimant table.
    It is fixed in commit 2, and -Dtest-filter="quant block" now passes. The other 4 are
    verify_projection_test, which runs out of GPU memory. They fail the same way when run alone on this branch and on
    main (c60de41).

🤖 Generated with Claude Code

Under an affine model, bias-less uint8-scale banks always resolved as
mxfp8 with a group size from mxfp8's ratio: an nvfp4 g16 bank loaded as
mxfp8 g8, an mxfp4 g32 bank as mxfp8 g16. The fp format now comes from
the packed ratio (the non-affine arm's rule); other ratios keep the old
fallback. Inkling 2 Mini's 4-bit pack carries such banks.
A new plugin for mlx-lm-layout Inkling 2 Mini packs: config parse with
by-name refusals, the 48-visit schedule (prelude, 3-pass looped core,
tail), short convs, relative-logit attention with sinks, depth attention
residuals, message gates, NVFP4/MXFP8 routed experts with the per-expert
scale. Text only; images, Inkling 2 Small and the ModelOpt release are
refused. Kernel wrappers are stubs that decline.

Tests against mlx-lm's Inkling 2 (tests/dump_inkling2_fixtures.py): tiny
CPU f32 and quantized GPU fixtures, chunked prefill, verify rollback, the
served driver, a real pack teacher-forced; tests/test_inkling2.sh live.
Ports of mlx-lm's relative_attention (prefill) and depth_attention
kernels, bodies unchanged, launched through mlx-c. Registered with the
kernel contract (gates 1-5, drift guard, planted controls), digests and
NOTICE. The composed path stays the fallback and the reference;
MLX_SERVE_INKLING2_KERNELS=0 turns both off. On an M5 Max 4-bit pack:
prefill 8192 1688 vs 226 tok/s, decode 40.0 vs 35.1 tok/s (on vs =0).
@botbocks

Copy link
Copy Markdown
Author

Superseded by #1261 (same commits, opened from the author's account).

@botbocks botbocks closed this Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Thinking Machines Inkling 2 Mini (inkling2_loop, 26B-A5.4B looped multimodal MoE)

2 participants