Skip to content

inkling2 cuda: split Mini's loop gate into a down half and an up half (decode 5.6 to 7.2 tok/s, same bits) - #4697

Merged
ashhart merged 3 commits into
ashhart:mainfrom
jschmied:ink2-mini-speed-gate
Nov 24, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
jschmied:ink2-mini-speed-gate

Conversation

@jschmied

@jschmied jschmied commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Update for review 7098920791: head ed5da93076

Point 2, the kernel records. The two new launches admit sm_80 onward, and now carry compiled usage for every pinned SM.

  • Measured with nvcc 13.0, -cubin -O3 --resource-usage per SM, the image's flags. There are no stack frames or spills; static shared bytes and launch bounds are as on sm_121.
launch sm_80 sm_86 sm_89 sm_120 sm_121
tf_ink2_loop_gate_down regs 22 24 24 32 31
tf_ink2_loop_gate_up regs 38 70 46 46 46
  • Registry check (checkCuda over all_cuda): the test-kernel-contract registry test finds 40 on this head, the base's 40. Before this commit it was 48.

Checks on ed5da93076 (on 05a5ed3ffd, GB10):

#4718 now stacks on this head, because the two conflicted in contract_inkling2_loop_math_extra.zig.


What this changes

Mini's loop gate (tf_ink2_loop_gate, 96 calls a token) ran one block per gate row. At decode that is one block on one SM for each gate. That block reads the 590 KB down matrix and the 590 KB forget/gain pair, so the gates took 41.2 ms of the 181.8 ms a token on #4640's head (nsys, c=1, 60 decode forwards).

This PR splits the gate into two kernels:

  • tf_ink2_loop_gate_down: one block per row and rank pair (grid rows × 32). Each block runs the same code path as the one-block kernel for its two ranks: the same norms, the same 256-thread chains and the same two-level reduction tree. It writes the BF16 zeta to a [rows][64] scratch (Scratch.zeta, loop_engine.zig).
  • tf_ink2_loop_gate_up: one thread per output column (64 per block). It runs the same ascending rank chains for forget and gain, the same tanhf and the same four FP32 rounding steps.

Every value is computed by the same operations in the same order, so the outputs are bit-equal. The gates go from 41.2 ms to 1.65 ms a token (down 1.23, up 0.42).

tf_ink2_loop_gate stays in the image, unchanged and not served. It is the contract's baseline: the split is registered as its replacement, so gate 3 requires its bytes.

Checks on this head (05a5ed3ffd)

GB10 (sm_121, CUDA 13.0), Zig 0.17.0, thinkingmachines/Inkling-2-Mini@ed40e7da.

Speed (A-B-B-A against #4640's head, this head's binary)

Served, tensorfold-native serve --parallel 4 --context 8192, default copy drafting and prompt cache on, page cache dropped before each server start. Each arm is a fresh server. Order A B B A, two rounds. A = #4640's head (321432e4b2), B = this head.

  • Cells: cold TTFT of a 7,262-token prompt (1 token out); c=1 decode = 4 topics × 128 greedy tokens, (tokens − 1) / (wall − 1-token wall); c=4 aggregate = the 4 topics at once, total tokens / wall. Tokens are counted from usage.
  • SM clock was logged at 1 Hz: median 2288 MHz in both arms, with the same constant clock-event mask (0x400, the box's boot-time clock cap). No round was dropped.
cell A (#4640), best of 4 B (this PR), best of 4 paired median B/A pairs where B is slower
c=1 decode 5.62 tok/s 7.22 tok/s 1.283 0 of 4
c=4 aggregate 5.56 tok/s 7.12 tok/s 1.279 0 of 4
prompt TTFT (7,262 tokens) 33.93 s 33.18 s 0.978 0 of 4

The reply hashes were equal in every arm, solo and c=4. nsys on the same kernels (c=1, 60 decode forwards): 181.8 → 141.0 ms a token, and the gates 41.2 → 1.65 ms (down 1.23, up 0.42).

  • Binaries: A 019c09e6 (built from 321432e4b2), B a8088b93 (built from 05a5ed3ffd, the commit itself). The gates above ran on the same B build.
  • Why not against main: this PR targets lead/inkling2-mini, whose Mini engine main does not have.

Proposed CHANGELOG line

  • Inkling 2 Mini on CUDA: the loop gate runs as a down half (a block per rank pair) and an up half (a thread per column), so a decode token spends ~1.5 ms in gates instead of 41 ms, with the same bits.

@ashhart

ashhart commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Thanks @jschmied for the Mini backend work. We found a Metal prompt-cache snapshot bug while reviewing this branch, but it is in the base branch, not your commits. #4542 fixes it, so nothing is needed from you for that.

  • Synthena

@joshuaswarren

Copy link
Copy Markdown
Contributor

Independent sm_120 check on ed5da930 (RTX 5060 Ti eGPU, aarch64 Linux, driver 615.78.08, zig 0.17.0, /opt/cuda/bin/nvcc, -Dsm=120):

./zig-out/bin/tf-cuda-test kernel-contract inkling2 → (filtered) SUMMARY 53 kernels: 53 pass gates 1-4, 0 fail, 0 known findings; 37 controls: 37 red as planted, 0 missed; 22 limit problems — exits TestFailed on the limit problems.

The correctness side matches your GB10 numbers: every gate-1..4 cell passes, including the QKV/down/up shapes and the planted controls. The 22 limits live problems are all the same shape: kernels launch with real register/shared usage while their sm_120 records read 0,0 — e.g. tf_ink2_loop_gate_down launches 256 threads, 32 regs, 264 shared bytes vs recorded 0,0; tf_ink2x_rows 145 regs, 32832+0 vs 0,0. Looks like the sm_120 rows of the launch table still carry placeholders for the new kernels rather than measured values.

@jschmied

Copy link
Copy Markdown
Contributor Author

Thanks for the sm_120 run, @joshuaswarren. The 0,0 is not a missing record. It is what the registry returns for nvcc 13.2 and later. Your box builds with nvcc 13.4.92. The Inkling launches carry later_pending, so for any compiler from 13.2 on they read "no receipt yet". This PR's nvcc 13.0 rows are filled. kernel-contract-limits over fatbins built here with -Dsm=80,86,89,120,121 (nvcc 13.0) prints PASS ... (record current) for both new launches. For example: PASS limits sm_120 inkling2_loop_math tf_ink2_loop_gate_down: 32 registers, 264 static shared bytes, bound 256 (record current).

How your live values compare with nvcc 13.0 on sm_120:

  • tf_ink2_loop_gate_down: 32 regs, 264 bytes. This is the same under both compilers.
  • tf_ink2x_rows: 145 regs under 13.4 against 144 under 13.0 (lead's record), with 32832 bytes under both. They differ by one register.

The base launches' 13.0 rows are on lead/inkling2-mini in 383c65d. Nothing changes on this PR (head ed5da93076).

To clear the run on 13.4, the registry needs a 13.4 receipt set. Could you post the full limits live lines from your run? Each line names registers and shared bytes for one launch. We would record them as nvcc 13.4's.

@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:46
@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 branch was removed. It is reopened and now targets main. We will rebase it onto main for you; nothing is needed from you.

  • Synthena

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @jschmied. The split preserves the reduction tree, BF16 rounding and output steps in source, and the contract compares its bytes with the original gate. Scratch ownership and stream ordering also look sound. The five target records are filled for compiler 13.0; later compiler receipts remain separate.

This looks ready for a serving comparison against current main on the pinned Mini checkpoint: matching token IDs and logits, plus decode and prompt timings. Please keep the existing speed figures labelled with the revisions they were measured on, and refresh the old base and commit wording in the description.

  • Synthena

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Results on our side, @jschmied: we compared this head (dea5ed208e) with main on a GB10 serving the Inkling 2 Mini checkpoint, with builds alternated base, new, new, base.

  • Tokens: every generated token matched across all four runs and the one-stream reference: one stream 5/5, four streams 8/8, prompt-cache resume 3/3, and raw prompts of 1, 15, 16, 17, 18, 32 and 33 rows 7/7.
  • Speed: one-stream decode 5.96 to 7.61 tok/s (+27.8%), four streams 4.74 to 5.79 tok/s aggregate (+22%), long-prompt (2,114 tokens) time to first token 14.09 to 13.84 s.

No cell was slower. Thank you for this one; it goes into our landing queue now.

  • Synthena

jschmied and others added 3 commits November 24, 2026 17:00
…block and an up half a column a thread

tf_ink2_loop_gate ran one block a gate row: one block read the 590 KB down matrix and the 590 KB
forget/gain pair for each of the 96 gates a token. tf_ink2_loop_gate_down runs a block a row and rank
pair, each with the one-block kernel's norms, 256-thread chains and reduction tree, and writes the BF16
zeta to a [rows][64] scratch; tf_ink2_loop_gate_up runs a thread a column with the same ascending rank
chains, tanh and four rounding steps. tf_ink2_loop_gate stays in the image, unserved, as the contract's
baseline: the halves are gated bit-equal to it.
…20 too

nvcc 13.0 -cubin -O3 --resource-usage per SM, as the image builds them: tf_ink2_loop_gate_down 22/24/24/32
registers, tf_ink2_loop_gate_up 38/70/46/46, static shared bytes and launch bounds as on sm_121, no stack or
spills. The two launches admit sm_80 onward, so the registry check now has their numbers on every pinned SM.
@ashhart
ashhart force-pushed the ink2-mini-speed-gate branch from dea5ed2 to 60f2cce Compare November 24, 2026 17:00
@ashhart
ashhart merged commit eeeee24 into ashhart:main Nov 24, 2026
10 checks passed
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you @jschmied. 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 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.

3 participants