Repository navigation
Inkling 2 Mini on CUDA and Metal - #4387
Conversation
|
I ran
With only those two load fixes and no numeric change:
The tiny fixture ( For comparison, the same box, prompts and method on my local C1+C3+C4 stack, the slices claimed in #4274 (drafts #4364 and #4365, engine not posted): coherent output, 33.3 tok/s at c=1 and 79.2 at c=4, A-B-B-A with 0 of 4 pairs in #4387's favour. Fresh, resumed and concurrent runs are bit-equal, and the float64 reference agrees on 48 of 48 tokens. The bar from #4274 is 38.7 / 102.3. How would you like to go on: should I send the two load fixes and the layer-0 tap, or does the CUDA side of #4387 build on #4364/#4365 instead? Receipts (logs, diffs, kernel tables) are ready to attach. |
|
Follow-up to my comment above: I found why the output is wrong. With the two load fixes from that comment ( Attention: gate and sink are passed through a sigmoid before
The result is a double sigmoid on the gate and a probability where a logit belongs in the sink. Metal's forward ( Evidence: layer 0, last prompt row, 25-token prompt, compared with an independent CUDA implementation of Mini. That implementation matches a float64 reference on 48/48 greedy tokens and agrees with Metal teacher-forced on the tiny checkpoint.
After fix 3, a smaller drift remains. Residual cosine stays ≥ 0.999 through visit 17. It then drops to 0.981 at visit 18 (the first visit of core pass 2, where cross-pass messages start, All three fixes as one diff (the two load fixes plus this one): --- a/zig/src/families/inkling2/cuda_native.zig
+++ b/zig/src/families/inkling2/cuda_native.zig
- const p = try plan_.build(&c.text, &precisions);
+ const p = try plan_.build(&c.text, precisions[0..c.text.layers]);
--- a/zig/src/families/inkling2/loop_weights.zig
+++ b/zig/src/families/inkling2/loop_weights.zig
- else
- try A.put(&l, ck, "model.llm.layers.{d}.attn_norm.weight", L, &.{h});
+ else if (j == 0)
+ try A.put(&l, ck, "model.llm.layers.{d}.attn_norm.weight", L, &.{h})
+ else
+ layer.attn.norms[1];
--- a/zig/src/families/inkling2/loop_engine.zig
+++ b/zig/src/families/inkling2/loop_engine.zig
- try ops.rowdot(&k.glue, s, u_q, lw.attn.gate, m.s.gate, rows, q_width, h, true, true);
- try ops.rowdot(&k.glue, s, u_q, lw.attn.sink, m.s.sink, rows, layer.heads.q, h, true, true);
+ try ops.rowdot(&k.glue, s, u_q, lw.attn.gate, m.s.gate, rows, q_width, h, true, false);
+ try ops.rowdot(&k.glue, s, u_q, lw.attn.sink, m.s.sink, rows, layer.heads.q, h, true, false); |
|
Speed is a defect too: with the three fixes above, decode is 5.5 tok/s at c=1. Mini reads about 5.5 GB per token, so the bandwidth floor on a GB10 (273 GB/s) is about 49 tok/s. #4387 reaches about 11 % of it; the vLLM bar in #4274 is 38.7. nsys on a short served run (GB10,
There are also no CUDA graphs, at about 1,350 launches per token. That costs little today but becomes visible once the three kernels above are fixed. |
|
Sharing a few real-checkpoint findings from bringing up
|
|
I ran the Metal path of
With those three applied:
I can send 1 and 3 as a pull request onto this branch if that is useful, or you can take them from here. This Mac is free for device runs on later heads. |
|
@sethforprivacy Your For comparison on a much smaller 32 GiB Apple M6 (Mac mini, 12-core GPU, 170 GB/s): 1. Before vs. after fixing that exact MoE + unembed bottleneck
On your M5 Ultra bandwidth, once those strided expert loops are vectorized and 2. The 32 GiB unified-memory situation (why Ring KV matters)
Re: |
|
Follow-up from the M5 Ultra, same head (
Two things not fixed in any of them:
I am continuing on the drafter's hold and the prompt path locally. Tell me if either is already in hand on your side. |
|
The concurrent mismatch I reported above has a cause and a fix, now the third commit of #4446.
The drafts as they stand, all against this branch, M5 Ultra,
With all four, |
|
Two more findings on this head from the M5 Ultra, each with a draft against this branch:
One thing I did not change: |
…in the cache rows test-inkling2-metal-host compiles main's metal module, which reaches Darwin-only std.c (os_unfair_lock, and timespec in metal4.zig on Windows), so registering it on every OS broke `zig build test` on Linux and Windows and put it in Linux's test-host shards. It is now registered, and added to the test step, only when the target is macOS, as main's own Metal host steps are. compile-inkling2-native-host stays on every OS. Inkling 2 Mini's CUDA family has snap_save, so the generic CUDA host builds its prompt cache, and TF_CACHE_EVICT and TENSORFOLD_PROMPT_CACHE_KEEP_OTHERS apply to it. inkling2_loop joins profile.cuda_cache, which cuda_keep_others_test.zig checks against the registry, and the profiles doc's family list.
aefb063 to
c41911e
Compare
|
Thank you @jschmied @sethforprivacy. This is merged into main with your commits under your own name, so you're credited as a TensorFold contributor. |
… of origin/main brought back unreachable ashhart#4441's engine serves inkling2_loop here (as 9f542e6 decided); the merge re-added cuda_native, loop_* and the loop_math image and contract tests without wiring them.
Inkling 2 Mini served natively, on CUDA (one rank) and Metal, from a clean-room implementation of the model's published math.
What it adds:
max_tokensreportsfinish_reason: length.keep_full_lone, default off) for committing fully accepted lone chains. Only Inkling sets it; other families' default call counts are pinned by a test.Checked on the served model (thinkingmachines/Inkling-2-Mini, Apache-2.0, revision ed40e7da62):
tool_choice: auto, a required single tool call, and JSON-schema output, whole and streamed. JSON-schema replies keep exactly the earlier landing tree's token ids.tf-cuda-test kernel-contract inkling2; M3 Ultratf-kernel-contract --only inkling2, every planted control red.Known limitation: with
tool_choice: "required"and parallel calls allowed, a request that needs two calls (for example, the weather in two cities) repeats the calls untilmax_tokensinstead of ending after two. One-call required replies andtool_choice: autoare not affected. This is tracked as a follow-up, and the fix will come in its own PR.