Skip to content

inkling2 cuda: Mini streams share one forward, each slot's convs and attention alone - #4786

Open
jschmied wants to merge 2 commits into
ashhart:mainfrom
jschmied:ink2-mini-shared-forward
Open

jschmied wants to merge 2 commits into
ashhart:mainfrom
jschmied:ink2-mini-shared-forward

Conversation

@jschmied

Copy link
Copy Markdown
Contributor

What this changes

Stacked on #4729 (b54506ca73), which is stacked on #4728 (fb55ed477e) and #4640 (321432e4b2). Base lead/inkling2-mini. The diff against #4729 is one commit, fa72a19532. If any of those merge, I'll retarget this PR.

One interaction with #4640's review fix (a28a170bb7, stream_bytes), which is not under this branch: each slot now owns its window backup and history, so slotAllocs has to count them too. In my local merge of the two, slotAllocs returns four sizes (cache, rewind sites, backup, history), newSlot allocates the four, and the stream_bytes test pins 25,087,496 bytes past the cache on Mini (48·4·32 + 48·3·6656·4 + 48·16·6656·4 + 200,058·4 + 32). I'll push that here once #4640 lands.

#4640 gave each served stream its own model slot, but loop_backend still declared .max_streams = 1. Four streams therefore ran four forwards, and each forward read all of the weights (~5.3 GB a token). That is why c=4 aggregate ≈ c=1 on #4640 and on every PR above it: 5.57 vs 5.63 tok/s on #4640, and 27.7 vs 28.1 tok/s on the merged speed stack.

This PR runs every stream's rows in one forward:

  • loop_round.zig (new): forward(chains). Each chain is one stream's {slot, p0, tokens}.
    • The kernels that work row by row run once over all rows: embed, mix, AR, messages, the loop gate, QKV, the row dots, router top-k, the experts, the output mix and the unembed.
    • Each slot's convs and attention (prep, rel table, attend) run as their solo launches over that stream's own rows, on that slot's cache and states. The arguments are the solo ones; only the row offsets into the shared scratch change.
    • Each stream's segment and attention tiles are staged once before the visits. Before, the tiles were uploaded at every visit; the bytes are the same.
  • loop_engine.zig. Model.forward (one slot) is now one chain of it, so prompt chunks and single windows run the same code. Each slot gets its own window backup and history, so every stream rewinds alone. recorded is now per slot.
  • loop_backend.zig. verify and keep take several windows: one forward, then each stream's draws and rewind. The facts declare .plain_share = true, .max_streams = max_slots and .batch_rows = round_rows (128).

The file moves 157 lines out of loop_engine.zig (594 → 437 lines).

Why every stream keeps its solo bits. No kernel changes. Each kernel the shared forward runs over all rows gives a row the same bits whatever other rows run with it:

kernel why row-independent
embed, mix (block a row), AR, messages, gate per row (block or grid row a row)
tf_ink2_mix (rows ≤16) and tf_ink2_mix_rows (>16) same sums in the same order
tf_ink2_loop_project_qkv a thread per (row, output), serial FMA over k
tf_ink2_rowdot and tf_ink2_rowdot_tiles rowdot_tiles is documented as giving rowdot's bits
top-k, softcap, round_bf16, top1 per row or per element
experts rows grouped by expert into 16- or 64-member items; an mma row uses only its own A row; the decode kernel (<32 rows) and the prompt kernel (≥32 rows) are each gated bit-equal to the same baseline (contract gate 3); combine is ascending over a row's picks

The per-slot pieces (convs, attention, rewind history, draws) keep their solo launches. The full per-kernel list is in my notes and can go here if you want it.

  • Inkling-only: three files in families/inkling2/. No kernel, no core file and no Metal file is touched.

Checks on this head (fa72a19532)

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

Speed (served, full speed stack with and without this PR)

A = the merged speed stack (#4640 a28a170bb7 + #4697 ed5da93076 + #4718 e2671d5830 + #4729 e8de695145, which carries #4728), B = the same plus this PR. Served --parallel 8 --context 8192, default copy drafting and prompt cache on, page cache dropped before each server start, a fresh server per run.

  • Protocol: one unscored warm-up per arm, a noise floor from 3 A-vs-A rounds (same harness, model, flags and day), then 5 rounds of A,B,B,A. A round's value for an arm is the mean of its two runs.
  • Cells: cold TTFT of a 7,262-token prompt (1 token out); c=1 decode = 4 topics × 128 greedy tokens, one at a time; c=4 aggregate = 4 topics at once; c=8 aggregate = 8 topics at once; total tokens / wall, counted from usage.
  • SM clock median 2281 MHz in both arms, with the same constant clock-event mask (0x400, the box's boot-time cap). Binaries: A fbd004356ce7, B 325a390a7199 (md5).
cell A, mean of 5 rounds B, mean of 5 rounds verdict
c=1 decode 27.61 tok/s 27.96 tok/s VERDICT c1_tok_s: FASTER (median 1.227%, floor 0.101%, B worse 0 of 5)
c=4 aggregate 27.19 tok/s 64.33 tok/s VERDICT c4_tok_s: FASTER (median 136.216%, floor 0.16%, B worse 0 of 5)
c=8 aggregate 27.08 tok/s 87.77 tok/s VERDICT c8_tok_s: FASTER (median 223.348%, floor 0.149%, B worse 0 of 5)
prompt TTFT (7,262 tokens) 26.391 s 26.390 s VERDICT ttft_s: WITHIN NOISE (median 0.004%, floor 0.14%, B worse 2 of 5)

Reply hashes were equal in every run of both arms: solo, c=4 and c=8.

  • Not measured: a cell at served default sampling (all cells are greedy), and first reasoning token apart from first answer token (the TTFT cell asks for one token).
  • 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: concurrent streams share one forward (each slot's convs and attention alone), so the weights are read once a round instead of once a stream, with each stream's tokens unchanged.

@joshuaswarren

Copy link
Copy Markdown
Contributor

Independent sm_120 cross-check (RTX 5060 Ti, live), head fa72a195, nvcc 13.5:

@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 added a commit to jschmied/TensorFold that referenced this pull request Nov 24, 2026
ashhart#4786 moves each stream's window backup and history from the shared
scratch into its slot. Main's stream budget (ashhart#4640) reports per stream
exactly what newSlot and the lane buffers allocate, so slotAllocs now
sizes all four slot allocations, newSlot and histBytes take their sizes
from it, and streamBytes sums them. Without this, admission would count
each extra stream short by its backup and history.

The stream_bytes test still pins the report to what the allocation hook
sees, and its explicit formula now includes the backup and history.
@ashhart
ashhart force-pushed the ink2-mini-shared-forward branch from fa72a19 to 94fe2f8 Compare November 24, 2026 12:18
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you, @jschmied. We rebased this onto main and ran a serving A/B on a GB10 with Inkling 2 Mini: main against this branch, which also carries #4728 and #4729; builds alternated base, new, new, base.

  • Tokens: identical in all 16 cells (one stream, four streams through the shared forward, prompt-cache resume, and raw prompts of 1 to 33 rows).
  • Four streams, aggregate: 4.67 to 14.92 tok/s (3.2x).
  • One-stream decode: 5.86 to 10.40 tok/s (+77%).
  • Long-prompt time to first token: 14.36 s to 11.52 s.

We'll land #4728 and #4729 first, then this one on top of them.

  • Synthena

jschmied and others added 2 commits November 25, 2026 03:18
…attention alone

loop_backend declared max_streams = 1, so four streams ran four forwards and each read all the weights.
loop_round.zig runs every stream's rows in one pass: the row-wise kernels (mix, AR, gates, QKV, row dots,
router, experts) once over all rows, each slot's convs and attention as its solo launches over its own rows.
Each slot keeps its own window backup and history, so every stream rewinds alone. The backend verifies and
keeps several windows at once and declares plain_share, max_streams and batch_rows (round_rows, 128). Every
kernel gives a row the bits it gives it alone, so each stream's tokens are its solo tokens.
ashhart#4786 moves each stream's window backup and history from the shared
scratch into its slot. Main's stream budget (ashhart#4640) reports per stream
exactly what newSlot and the lane buffers allocate, so slotAllocs now
sizes all four slot allocations, newSlot and histBytes take their sizes
from it, and streamBytes sums them. Without this, admission would count
each extra stream short by its backup and history.

The stream_bytes test still pins the report to what the allocation hook
sees, and its explicit formula now includes the backup and history.
@ashhart
ashhart force-pushed the ink2-mini-shared-forward branch from 94fe2f8 to a8ec28b Compare November 25, 2026 03:21
@AIFlowML

Copy link
Copy Markdown
Contributor

I checked the Inkling host gates on a clean trial merge of a8ec28b078 into 4c79cfe346. The merge commits for both #4728 and #4729 are in that base.

zig build test-inkling2-host test-inkling2-cuda-host check-native-cuda-host -Dfixed-cpu --summary all

On the M5 Max, all 18 build steps succeeded. The host suites passed 88 tests with four skips, and the native CUDA adapter cross-compiled for aarch64-linux-gnu. The GB10 device A/B is still pending.

Igor Lessio - AIFLOW LABS

This branch has not been deployed

No deployments
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.

4 participants