Skip to content

feat(inkling): Inkling 2 Mini runs in basalt — P1 looped text stack, oQ + mlx-lm layouts (#650) - #660

Merged
goodmai merged 2 commits into
mainfrom
feat/650-inkling-p1
Nov 22, 2026
Merged

goodmai merged 2 commits into
mainfrom
feat/650-inkling-p1

Conversation

@goodmai

@goodmai goodmai commented Nov 22, 2026

Copy link
Copy Markdown
Owner

What (#650 P1 — text stack in plain MLX ops, no kernels)

Inkling2Model runs inkling2_loop (Inkling 2 Mini) and inkling2 in basalt, in Sources/BasaltInference/Models/Inkling2/ (7 files, each under the size limits). It was ported from the reference implementation in ml-explore/mlx-lm#2086 and checked against oMLX's oQ layout (omlx/patches/inkling2/oq_layout.py, loader.py); the fork is not touched.

  • Loop: prelude 0..<6, core 6..<18 × 3 passes, coda 18..<24, so 48 layer visits over 24 stored layers. Passes 2 and 3 restart from the prelude output and read a cross-pass message: depth attention over the previous pass's blocks with per-layer queries, mixed into the q, k, v and MoE inputs by rank-64 gates ((1 − tanh f)·x + tanh g·msg).
  • Attention, no RoPE: relative logits (r_proj × rel_logits_proj, distances below 1,024), per-token sinks from sink_proj, a sigmoid output gate, q/k/relative L2 clips, a value norm without gamma, and a log-scaled query temperature on the global layers (5, 11, 17, 23). Static depthwise short convs on local K/V, dynamic ones (static_weight + weight_proj) on global K/V, short convs after attention and after the MLP.
  • Residuals: depth attention over 6-layer blocks for every attention and MoE input; sigmoid + correction-bias router, weights normalized and × route_scale 8; SwiGLU with tanh softcaps over interleaved gate/up expert rows; final logit softcap 30, vocab sliced to 200,058.
  • Caches: a flat [attention, ArraysCache(4)] per visit (96 entries for the real model). Local layers use Inkling2WindowKVCache, which keeps keys in time order, compacts to the window and knows each key's position; relative attention needs exact distances, and the fork's RotatingKVCache keeps its write index private. The window cache counts as a snapshot-only layer, so hybrid prompt-cache reuse works.
  • Weights: the mlx-lm layout (mlx-community/Inkling-2-Mini-4bit naming) loads as is. The oMLX oQ layout (Inkling-2-Mini-oQ3e/oQ4e/oQ2.5e) is mapped to it: fused in_proj (q, k, v, r, gate, sink) and global q_proj / k_proj / v_proj rows are split, quantized matrices included, and loop_down / loop_gain_forget / loop_message.query are unpacked into the message gates and queries. Modules are quantized from the packed weights' shapes (Flint's helper), so oQ's per-path overrides need no renaming.
  • Registration: LLM and VLM registries for inkling2_loop and inkling2; ModelCapabilities row with nothing verified yet.

Not in P1: native NVFP4/MXFP8 experts with global_scale (the 4-bit pack and the original checkpoint), the ModelOpt source layout, kernels (P2), the <|message_model|> frame stream adapter and tool calls (P3), vision and DSpark.

Measured

mlx-community/Inkling-2-Mini-oQ3e-mtp (13.7 GB, 3-bit experts), M4 Pro 24 GB, release build, CI idle:

Check Result
Load + model probe pass, perplexity 1.29, known answers correct
"Capital of France?" (effort low) reasons in `<
"Python function for the n-th Fibonacci" coherent reasoning and code
Decode, short prompt 19.7–20.7 tok/s
Prefill, 4,545-token prompt 263 tok/s
Decode at 4.5K context 18.9 tok/s

Issue targets are ≥ 35 tok/s decode and ≥ 450 tok/s prefill at 4K: P2's kernels (relative attention K1, depth attention K2, fused router K3). Until P3, replies carry the raw frame tokens.

Tests

  • Inkling2ModelTests on TinyModel.inkling2Loop (6 layers, core 2..<4 × 3 passes, window 8, 8 experts):
    • 20-token decode in chunks of 1, 4 and 7 equals the full-sequence logits (≤ 2e-3), past the window;
    • cache layout: 10 visits × 2 slots, window caches on local layers;
    • one pass vs three passes give different logits;
    • the oQ layout built from the fixture's parameters maps back to exactly the same tensors;
    • window cache: keeps window − 1 earlier tokens, reports where its keys start, trims.
  • The new family joins the all-family suites: prompt-cache reuse through the engine answers like a full prefill; Quest and batched decode report off and are excluded, as for other custom-attention families.

Verified

swift build -Xswiftc -warnings-as-errors and -c release clean; no new comments; no size limit exceeded; feature matrix, causality, fixture, hybrid-prefix and prompt-cache suites pass (128 tests) plus the Inkling suites.

🤖 Generated with Claude Code

https://claude.ai/code/session_012cicguZMN3jhNGmf5327oh

goodmai and others added 2 commits November 22, 2026 09:58
…, oQ/mlx-lm weight layouts, TinyModel (#650)

- Inkling2Model (inkling2_loop / inkling2): prelude, core x num_passes and
  coda over 48 layer visits; passes 2-3 restart from the prelude output and
  read cross-pass messages (depth attention over the previous pass's blocks)
  through rank-r gates on q, k, v and the MoE input.
- Attention without RoPE: learned relative logits (r_proj x rel_logits_proj),
  per-token sinks, sigmoid output gate, q/k/rel L2 clips, value norm without
  gamma, log-scaled query temperature on global layers; static short convs on
  local K/V, dynamic ones on global K/V, short convs after attention and MLP.
- Depth-attention residuals over 6-layer blocks; sigmoid + bias router with
  route_scale; softcapped SwiGLU over interleaved gate/up expert rows.
- Caches: a flat [attention, ArraysCache(4)] per visit; local layers use
  Inkling2WindowKVCache (temporal order, compacted to the window, exact key
  positions), treated as snapshot-only so hybrid prompt-cache reuse works.
- Weights: mlx-lm layout as is; oMLX oQ layout (fused in_proj / q_proj /
  k_proj / v_proj rows, packed loop controllers, loop_message queries) mapped
  to it; modules quantized from the packed weights' shapes.
- TinyModel.inkling2Loop (6 layers, core 2..<4 x 3, window 8) with tests:
  decode in chunks of 1/4/7 equals the full forward, loop changes output, oQ
  layout round-trips, window cache positions and trim; joins the all-family
  suites (prompt-cache reuse passes; Quest and batched decode refused).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012cicguZMN3jhNGmf5327oh
…jump-forward for inkling2

Every known family must verify the base capabilities GenerationPlanTests
checks; prompt-cache reuse is covered by the fixture suites, lookup is still
refused at runtime by PromptLookupTokenIterator.supports for these caches,
and KV quantization stays off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012cicguZMN3jhNGmf5327oh
@goodmai
goodmai merged commit 5a465b6 into main Nov 22, 2026
8 checks passed
@goodmai
goodmai deleted the feat/650-inkling-p1 branch November 22, 2026 09:57
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.

1 participant