Repository navigation
Inkling 2 Mini DSpark on Metal: attention scale 1/sqrt(128), and the recurrent step reads kappa as FP32 - #4447
Conversation
3e0e9bc to
f790014
Compare
…rerun, the device suite at d29431d; changelog credits ashhart#4447 and jschmied
aefb063 to
c41911e
Compare
|
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
|
|
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.
|
e610dc6 to
88e27b4
Compare
|
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.
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.
|
|
@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.
|
|
Marked ready. Thank you for the rebase and the M3 Ultra A/B. |
… step reads kappa as the FP32 it is
… ranks the kernel writes
88e27b4 to
14526f6
Compare
|
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. |
Update: head
e610dc650(one more commit)e610dc650: the recurrent step'szscratch holds the three ranks the kernel writes.tf_ink2_dspark_recurrentwrites3 * rankBF16 values toz, anddspark_state.zigsized that buffer forrank. 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 withDraftNonfiniteuntil this was fixed. One line.Checks on this head:
zig build nativecompiles; 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 --checkandgit diff --checkclean; 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):kappaat the wrong width.tf_ink2_dspark_kappawrites FP32 andtf_ink2_dspark_recurrentdeclared that bufferbfloat. 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 readsfloat.DSP_SCALEwas0x1.6a09e6p-7(0.01105). The head dimension is 128, sohead_dim^-0.5is0x1.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.
3e0e9bcb83, then the serving fixes in Inkling 2 Mini on Metal: #4387's native build compiles, its norms write their output, and concurrent streams equal solo #4446 (992258230,c68340d31, and the shared-forward fix, here as5ea131a37). This pull request's own commit is819edd9bd.atc overlap --json: not run; ATC is not installed on the machine that pushes.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 feedskappaas FP32, as the kappa kernel writes it.dspark_kernels_test.zigpins the new constant.Checks on this head
5ea131a37(the checks below were rerun on it).zig build native -Dcpu=apple_m1: compiles.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 zigandgit diff --check: clean.zig build test test-goldenon 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
inkling2_loopwith--drafteronly. The default path does not load the drafter.thinkingmachines/Inkling-2-Mini@ed40e7da625f594fc9c4990f5f66be24873c22d7with its bundledmtp.safetensors,--parallel 4 --context 8192 --prompt-cache-gib 0, greedy, 300 tokens. The pread cap of checkpoint_metal: clamp pread chunks to INT_MAX #4433 or Metal loader: a checkpoint span of 16 GiB or more loads (each pread capped at 1 GiB) #4435 is applied locally. The rows below were measured with the speed commits of Inkling 2 Mini on Metal: experts, gates, router, depth mix, combine, row batching, attention chunks and a concurrent forward (1,159 to 14 ms a row on M5 Ultra) #4448 underneath, because at Inkling 2 Mini on CUDA and Metal #4387's 0.86 tok/s a 300-token row takes six minutes; those commits do not touch the drafter.token_shaequals the plain reply's.kappa, old scalekappa, old scalekappa, old scalePlain 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.tools/bench_openai.py(256 tokens, 3 reps, greedy), same build: plain 38.3 and 38.0 tok/s on its two prompts, with the drafter 44.2 and 39.1.tools/bench_concurrent.py --levels 1,4 --alone --serial: 38.1 and 30.5 tok/s in total with the drafter against 62.4 and 62.9 plain. The hold's kernels are the cause, and they are the subject of Inkling 2 Mini DSpark on Metal: the hold in one command buffer, and drafts priced by the engine up to the whole block (one stream 44 to 97 tok/s on code, 4 streams 77 to 184-223) #4465.Checklist
"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.)--drafter, no slower than without it. (One stream is faster with it; four streams are slower, as above.)