Skip to content

Inkling 2 Mini DSpark on Metal: attention scale 1/sqrt(128), and the recurrent step reads kappa as FP32 - #4447

Merged
ashhart merged 3 commits into
ashhart:mainfrom
sethforprivacy:inkling2-mini-metal-dspark
Nov 24, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
sethforprivacy:inkling2-mini-metal-dspark

Conversation

@sethforprivacy

@sethforprivacy sethforprivacy commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Update: head e610dc650 (one more commit)

e610dc650: the recurrent step's z scratch holds the three ranks the kernel writes. tf_ink2_dspark_recurrent writes 3 * rank BF16 values to z, and dspark_state.zig sized that buffer for rank. The writes past its end went to memory outside the buffer. I saw no symptom of it on this branch; with #4465's chained hold a hold failed with DraftNonfinite until this was fixed. One line.

Checks on this head: zig build native compiles; the six Inkling host steps exit 0; tf-kernel-contract --only inkling2: SUMMARY 41 kernels: 41 pass gates 1-4, 0 fail, 0 known findings; 41 controls: 41 red as planted, 0 missed; 0 limit problems, exit 0; zig fmt --check and git diff --check clean; lean 167 on the base and 167 here, 0 new.


What this changes

Before: with --drafter, #4387's DSpark head proposes token 0 at every step, so no DSpark draft is ever accepted. After: its drafts are accepted at 54 to 76 % on three prompts, 1.65 to 3.45 tokens a round, and drafted output still equals plain.

Two defects, one commit (819edd9bd):

  1. The recurrent step read kappa at the wrong width. tf_ink2_dspark_kappa writes FP32 and tf_ink2_dspark_recurrent declared that buffer bfloat. Read as BF16 the values reach 2.7e38, the state and the latent go NaN, every final logit is NaN, and the argmax is token 0. The kernel now reads float.
  2. The attention scale was 8 times too small. DSP_SCALE was 0x1.6a09e6p-7 (0.01105). The head dimension is 128, so head_dim^-0.5 is 0x1.6a09e6p-4 (0.08839), which is what oMLX's implementation and Metal: experimental Inkling 2 Mini text, vision and bundled DSpark #4337's use for this drafter. With the first defect fixed and the old scale, acceptance is 18 to 28 %; with the scale corrected it is 54 to 76 %.

This is a proposal on top of #4387, opened as a draft.

The scale is an arithmetic constant under the contract, so the contract's reference changes with it (metal_inkling2_dspark.zig, one line), and the recurrent probe now feeds kappa as FP32, as the kappa kernel writes it. dspark_kernels_test.zig pins the new constant.

Checks on this head

  • Head commit: 5ea131a37 (the checks below were rerun on it).
  • Lean checker, on the base and on this head: 167 and 167, 0 new.
  • Tests run:
    • zig build native -Dcpu=apple_m1: compiles.
    • The six Inkling host steps (test-inkling2-metal-host, test-inkling2-host, test-inkling2-controls-host, test-inkling2-launch-map-host, test-inkling2-metal-capabilities, compile-inkling2-native-host): exit 0.
    • tf-kernel-contract --only inkling2 (-Doptimize=safe): SUMMARY 41 kernels: 41 pass gates 1-4, 0 fail, 0 known findings; 41 controls: 41 red as planted, 0 missed; 0 limit problems, exit 0. With the kernel reading FP32 and the probe still feeding BF16, the recurrent kernel fails its shapes gate, as it should.
    • zig fmt --check build.zig zig and git diff --check: clean.
  • CI: not yet reported when this was written.
  • Not run, and why: the whole zig build test test-golden on this exact head (the stack's inherited failures are listed in Inkling 2 Mini on Metal: #4387's native build compiles, its norms write their output, and concurrent streams equal solo #4446). CUDA's DSpark, which Inkling 2 Mini on CUDA and Metal #4387 refuses by name.

Receipt

Prompt Build Rounds Drafted Accepted Tokens a round Decode
Fibonacci function #4387's drafter 279 350 20 (6 %, all from copies) 1.08 22.3 tok/s
Fibonacci function FP32 kappa, old scale 218 290 81 (28 %) 1.38 28.2
Fibonacci function both fixes 87 278 212 (76 %) 3.45 53.0
Why the sky is blue FP32 kappa, old scale 251 267 48 (18 %) 1.20 25.7
Why the sky is blue both fixes 182 217 118 (54 %) 1.65 34.6
Ten primes FP32 kappa, old scale 235 252 65 (26 %) 1.28 27.4
Ten primes both fixes 146 244 154 (63 %) 2.05 39.3

Plain decode on the same build is 37.4 tok/s on the first prompt. In #4387's row the drafter proposed token 0 at every step (traced: held = { 0, 0 } on every hold), and the 20 accepted tokens came from the copy drafts.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. (The recurrent contract probe fails on the old kernel's width once it feeds what the kappa kernel writes.)
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Drafted equals plain. Concurrent equals solo with Inkling 2 Mini on Metal: #4387's native build compiles, its norms write their output, and concurrent streams equal solo #4446's third commit, which this branch carries. Resumed not run.)
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it. (One stream is faster with it; four streams are slower, as above.)

This was referenced Nov 22, 2026
plotarmordev added a commit to plotarmordev/TensorFold that referenced this pull request Nov 23, 2026
…rerun, the device suite at d29431d; changelog credits ashhart#4447 and jschmied
@ashhart
ashhart force-pushed the lead/inkling2-mini branch 3 times, most recently from aefb063 to c41911e Compare November 24, 2026 09:43
@ashhart
ashhart deleted the branch ashhart:lead/inkling2-mini November 24, 2026 09:43
@ashhart ashhart closed this Nov 24, 2026
@ashhart ashhart reopened this Nov 24, 2026
@ashhart
ashhart changed the base branch from lead/inkling2-mini to main November 24, 2026 09:49
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Sorry for the noise: this was closed automatically when #4387 landed on main and its base branch was removed. It is reopened and now targets main. We will follow up here on what it needs next; nothing is needed from you yet.

  • Synthena

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you @sethforprivacy. The FP32 kappa read, corrected attention scale and larger z scratch are all present. They affect the drafter, while the target still verifies its proposals. Both fixes are also included in #4465, which supersedes this PR once qualified. The remaining comparison on current main is a maintainer qualification step; no further source change was identified in these two fixes.

  • Synthena

@ashhart
ashhart force-pushed the inkling2-mini-metal-dspark branch from e610dc6 to 88e27b4 Compare November 24, 2026 12:20
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you, @sethforprivacy. We rebased this onto main and ran a DSpark A/B on an M3 Ultra with Inkling 2 Mini (greedy, 64 tokens, math, code, prose and a ~2,100-token code prompt; builds alternated base, new, new, base). The base also carried a separate Inkling Metal speed change of ours that is not yet on main.

  • Tokens: drafted replies equal plain replies on every run, at one stream and at four (16 of 16 cells), and plain replies are identical across the two builds.
  • Draft acceptance: 3.0% to 54.9% at one stream, 0.6% to 25.3% at four.
  • Drafted decode, one stream: 7.68 to 12.01 tok/s (+56%). Four streams, aggregate with prompt time: 1.08 to 1.40 tok/s (+29%).
  • Plain decode is unchanged (12.54 to 12.56 tok/s at one stream).

On this M3, drafted one-stream decode is now close to plain but not yet above it, so there is room for more. This fix is now in our landing queue.

  • Synthena

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

@sethforprivacy, this is still marked as a draft, so our landing queue skips it. From our side it's ready: the review asks are closed and the M3 Ultra A/B above is exact. If you're happy with it, please mark it ready for review, or say so here and we'll do it for you.

  • Synthena

@sethforprivacy
sethforprivacy marked this pull request as ready for review November 24, 2026 16:55
@sethforprivacy

Copy link
Copy Markdown
Contributor Author

Marked ready. Thank you for the rebase and the M3 Ultra A/B.

@ashhart
ashhart force-pushed the inkling2-mini-metal-dspark branch from 88e27b4 to 14526f6 Compare November 24, 2026 19:22
@ashhart
ashhart merged commit 191b7e8 into ashhart:main Nov 24, 2026
10 of 11 checks passed
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you @sethforprivacy. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

ashhart added a commit to BlivionIaG/TensorFold that referenced this pull request Nov 24, 2026
ashhart added a commit that referenced this pull request Nov 24, 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.

2 participants