Skip to content

feat(inkling): DSpark speculative decoding with a cost-aware draft depth (#650 P2a) - #728

Merged
goodmai merged 5 commits into
mainfrom
feat/inkling-dspark
Nov 23, 2026
Merged

goodmai merged 5 commits into
mainfrom
feat/inkling-dspark

Conversation

@goodmai

@goodmai goodmai commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Summary

#650 P2a: speculative decoding for Inkling 2 with the DSpark drafter that ships in the checkpoint's mtp.safetensors (0.32B, block of 8). --mtp now drafts on Inkling 2 Mini.

Fork (goodmai/mlx-swift-lm, branch basalt-650-dspark, pin 70d0190 → see Package.swift):

  • ConvolutionStatesCache, ported from upstream Add Inkling 2 Mini and Small ml-explore/mlx-swift-lm#821: short-conv states that rewind inside their last write. It stays snapshot-only for prompt caches (isTrimmable is false); only a speculative round, which asks isTrimmable(after:), rewinds it.
  • A recurrent leaf that can undo a round's write exactly now writes through a staged round (AppendOnlyRoundStrategy) instead of refusing it.
  • MTPDraftDepthPolicy: a drafter that proposes its whole block in one call sets draftWidthCost, and each round verifies the depth with the most expected tokens per unit of verify cost. It keeps a decaying acceptance estimate per draft position, so it drafts deep on code and shallow on prose. nil keeps the chained rule Qwen and Nemotron use.

basalt:

  • Inkling2DSparkDraftModel: the upstream DSpark port, against our StatefulMTPDrafterModel API. Its Markov head is folded into the target's lm_head at load, dequantizing a quantized head.
  • Inkling2Model emits the drafter's features under the MTP flag: the residual entering visits 5/23/41 and the final hidden state (mtp_config.target_layer_ids). Long prompts are prefilled in 512-token chunks, and only the last row's logits are computed.
  • Inkling2WindowKVCache keeps the round's rows past its window, so a rejected suffix trims back exactly. Conv states use ConvolutionStatesCache.
  • .mtp added to the Inkling 2 capability row. Without it, the plan dropped --mtp for Inkling 2 even with the drafter loaded.
  • --mtp-block defaults to a block drafter's own block (8 for DSpark). Qwen and Nemotron keep 4.

Measured

Inkling-2-Mini-oQ3e-mtp on an Apple M4 Pro with 24 GB, release build, GPU lock, CI idle. Commit f8b07b9 (identical code to this head for these runs; the head only changes the --mtp-block default). 256 tokens, decode tok/s. Log: logs/dspark_bench-2026-11-23T071050Z.log.

Prompt Temperature Plain --mtp-block 4 --mtp-block 8 (new default)
Swift merge function (code) 0 28.0 43.0 (α 0.76) 49.8 (α 0.78)
Hash-map collisions (explanation) 0 27.9 32.1 (α 0.57) 31.9 (α 0.56)
Train timetable (arithmetic) 0 27.9 38.9 (α 0.70) 37.7 (α 0.62)
French Revolution list (prose) 0 28.0 29.2 (α 0.50) 28.8 (α 0.50)
Formal rewrite (short) 0 26.7 33.8 (α 0.56) 31.5 (α 0.55)
Swift merge function (code), 3 runs 0.7, seed 11 26.8 36.3 (α 0.73) 38.4 (α 0.68)
French Revolution list (prose), 3 runs 0.7, seed 11 27.0 25.9 (α 0.42) 26.8 (α 0.44)
gemma-4-26B-A4B-it-qat-4bit (no MTP head), code 0 74.3 – 74.5: --mtp falls back, same output

Parity (#228)

  • Tiny fixture, exact. InklingDSparkTests runs on inkling2Loop, with a window of 8, 10 visits and conv states:
    • drafts that are partly accepted (SuccessorDrafter) and random-init DSpark drafts both give the plain decoder's tokens, greedy and seeded at T = 0.7;
    • the same holds through the engine, and on a second identical request that reuses the prompt cache and the DSpark prefix;
    • a rejected 3-position write trims back to the conv states of a 1-token decode.
  • oQ3e, real model. Greedy text is identical on 2 of 5 prompts at block 8, and diverges later on the rest.
    • A teacher-forced check takes the plain greedy sequence and feeds it in verify-shaped chunks.
    • Chunks of 4 with no rollback disagree with one-token decoding only where the top-2 margin is ≤ 0.054.
    • Chunks of 2 with no rollback disagree at margins up to 0.24. Chunks of 4 that keep 2 and trim 2 show the same class.
    • So the divergence comes from width-dependent numerics of the 3-bit MoE: an L > 1 eager pass against the compiled L = 1 step. The rewind adds no error of its own.
    • The scratch test is not part of this PR; it is in the session's scratchpad.

Tests

  • New: InklingDSparkTests (9 tests). It covers the rewind parity above, conv-state trimming, tap features and chunked prefill, the sidecar load and head fold, DSpark parity, engine parity, cached second-turn parity, and the depth policy.
  • InklingDSparkTests|MTP|ServeConfigFile|Nemotron: 76 tests in 18 suites pass. Inkling|PromptCache|Hybrid|Batched|KVCache: pass.
  • Full swift test --parallel on this Mac: another session's CI run started mid-run. That gave time-limit failures in the compose/on-demand suites and a NIO writer crash. FeatureMatrixTests and PreemptibleTrainingTests pass alone. CI on this PR is the full run.
  • check_no_new_comments and check_size_limits --impact: clean.

Part of #650.

🤖 Generated with Claude Code

https://claude.ai/code/session_012cicguZMN3jhNGmf5327oh

goodmai and others added 5 commits November 23, 2026 10:24
… conv states, tap features, folded Markov head (#650 P2a)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012cicguZMN3jhNGmf5327oh
…t drafts through DSpark (#650 P2a)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012cicguZMN3jhNGmf5327oh
…s per verify cost; cached second turn drafts too (#650 P2a)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012cicguZMN3jhNGmf5327oh
…he depth policy picks within it (#650 P2a)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012cicguZMN3jhNGmf5327oh
@goodmai
goodmai force-pushed the feat/inkling-dspark branch from 6a942bc to 5eb43ad Compare November 23, 2026 09:24
@goodmai
goodmai merged commit 80992fc into main Nov 23, 2026
8 checks passed
@goodmai
goodmai deleted the feat/inkling-dspark branch November 23, 2026 09:43
goodmai added a commit that referenced this pull request Nov 23, 2026
…g safety, DSpark config guards, compiled 1-row rewind, HF-aligned YaRN factor (#750)

* fix(rope,inkling): staging follows its source's file set and sweeps abandoned temporaries; MTP drafter from the staged config; DSpark block_size within the conv rewind, strictly increasing taps, null mtp_config; compiled 1-row steps keep conv windows; chunked drafter prefill (review)

* chore(fork): pin e9feb1e — HF-aligned YaRN attention factor, exact-trim precondition; test the attention-factor rules (review)
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