Repository navigation
Inkling 2 Mini on CUDA: #4387's engine loads the checkpoint, answers correctly (64/64 teacher-forced), serves --parallel streams, and resumes prompt-cache states exactly - #4640
Conversation
Derive per-visit cache access and exact arithmetic for the 48 visits so CUDA admission and kernels have a reference before serving is enabled.
Decode stored NVFP4 and MXFP8 expert weights to BF16 and launch them beside the grouped expert/vision kernels, with exact tensor baselines and planted faults.
Launch cross-pass messages, rank-64 gates, residual steps and split QKV with FP32 reductions, BF16 rounding controls and per-launch resource records.
Run all 48 visits with per-visit cache state, prompt snapshots and exact rollback. Refuse TP, vision and DSpark loading until those engines exist.
…ttn_norm upload a sliding layer)
The merge kernel takes the sink as a logit and applies the gate's sigmoid itself; the engine applied a sigmoid to both first, so every layer's attention output was wrong from layer 0.
…ad them tf_ink2_loop_messages wrote [row][core][role][c]; the engine reads each role's rows as one plane at messages + role * rows * c. The two agree for one row, so decode was right and every multi-row prompt chunk from the first visit of pass 2 on was not. The kernel now writes [core][role][rows][c] and the contract reference indexes the same way.
The backend held one stream, so with --parallel N every request past the first failed with NoFreeSlot. The model now keeps a slot per stream (K/V rows, conv states, rewind sites), the loaded engine takes the server's stream count through reserve, and forwards still run one stream at a time on shared scratch. inkling2-serving adds four concurrent streams, greedy and seeded, equal to solo, and a fifth refused.
The CUDA caches are head-major ([kv head][ring][dim]); copyState copied rows as [ring][kv*dim], so a state held part of head 0's ring and none of the others. A resumed prompt looked right only because the slot still held its own keys: after another prompt resumed the shared prefix, it answered that prompt. inkling2-serving adds that order (A keeps 14 and 39, B resumes A's 14 and decodes, A resumes 39 == fresh).
|
Thanks @jschmied. We've reviewed all six against
#4724's own walker and host changes are ready for device checks once #4640's accounting is in, and #4729 waits on #4728's bounds. Once these are in, we'll run the device cells.
|
…ts row and sampling rule Admission read only the cache layout's bytes a stream, but each extra stream also allocates its rewind-site table (four sites a visit) and, in the backend, a vocabulary row of last logits and a sampling rule: 806,408 bytes more on Mini (48 x 4 x 32 + 200,058 x 4 + 32). engine.slotAllocs and backend.laneAllocs now size those allocations, and backend.streamBytes, which cuda_native reports, is their sum. A host test installs a DeviceBuffer hook that sums what Model.newSlot and Backend.slotBuffers ask for and pins stream_bytes to it, and the 806,408 bytes past the cache to the formula. The layout test that needed no CUDA moved from loop_engine.zig to loop.zig.
|
Thanks. All four points are in. Each PR body opens with an update section that has the details; the summary is below. Everything ran on GB10 (sm_121, CUDA 13.0, Zig 0.17.0) on the head named.
On every head:
Speed: one A-B-B-A per PR against its previous head, c=1, plus c=4 and TTFT where a kernel changed.
These are paired losses of 0.01 to 0.08 %, but they are losses, so please don't land #4728 or #4729 yet. A three-round A-B-B-A is running on both, and I'll post it on each PR. No CHANGELOG change. |
3e0e9bc to
f790014
Compare
|
An sm_120 data point, since the plan lists "any CUDA chip other than sm_121" as a gap. All three heads below built with Setup
Heads
Decode, tok/s (median of 3; spread at most 1.1%)
Cold prefill, tok/s (time to first token)
Same bits. In every cell the reply text has one sha256 across all three heads, with copy drafts on or off, over 4 requests each: Memory. 20,864 MiB after load at Three things I noticed
Not run: the kernel contract on sm_120, more than one stream, images, requests above 40,960 context, #4718 alone. I can rerun any head on this card if that helps. |
|
sm_120 gate run (RTX 5060 Ti, live):
No gate failures and no missed controls on this head - the contract exit (rc=1) is the limits problem count, not a gate miss. Independent sm_120 confirmation that the inkling2 contract cells run clean on the 5060 Ti. |
aefb063 to
c41911e
Compare
|
Sorry for the noise: this was closed automatically when #4387 landed on main and its branch was removed. It is reopened and now targets
|
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#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.
Update for review 7098920791: head
a28a170bb7Point 1, the stream budget.
stream_bytesreported onlylayout.bytes, but each extra stream also allocates its rewind-site table and, in the backend, a vocabulary row of last logits and a sampling rule.loop_engine.slotAllocsandloop_backend.laneAllocsnow size those four allocations.Model.newSlotandBackend.slotBuffersallocate through them.loop_backend.streamBytes, whichcuda_native.zigreports, is their sum. On Mini that islayout.bytes + 806,408: 48 × 4 × 32 for the sites, 200,058 × 4 for the row, 32 for the rule.cuda_native.zig, intest-inkling2-cuda-host): aDeviceBufferhook sums whatnewSlotandslotBuffersactually ask for. It pinsstream_bytesto that sum, and pins the 806,408 bytes past the cache to the formula.streamBytesplanted back tolayout.bytes(the old report), the test failsexpected 776392200, found 775585792, exactly 806,408 short.loop_engine.zigthat needs no CUDA moved toloop.zig, so the engine file stays under 600 lines.Checks on
a28a170bb7(GB10, sm_121, CUDA 13.0, Zig 0.17.0):test-inkling2-host,test-inkling2-cuda-host,compile-cuda-tests,check-native-cuda-host: green.test-kernel-contracthas one failure. It is the registry test, finding the branch's existing 40 missing-resource diagnostics, the same 40 as on3e0e9bcb83.zig fmtandgit diff --check: clean.pr_check --base 321432e4b2: 0 errors, lean 167 vs 167.inkling2: 53/53 pass gates 1-4, 36 of 36 controls red, 0 limit problems. No.cufile changed.inkling2-serving: all cases PASS.--parallel 4 --context 8192, page cache dropped, hashes cover reasoning and content):321432e4b2's (9b35cbd7c284 …,5b886d0faf27 …);dad96525689a;fdb1da1ad592.321432e4b2(binary019c09e6), B = this head (9fed8620). Best of 2: 5.624 vs 5.616 tok/s. Paired median B/A 0.9997, 1 of 2 pairs slower, so mixed, with no consistent change. SM clock median 2288 MHz in both arms.#4724 is restacked on this head (
e07853195e).What this changes
Before: on
lead/inkling2-mini(3e0e9bcb83) the CUDA engine does not load the released Mini checkpoint (PrecisionCount, thenLoopWeightsOverflow). With those two load errors fixed, every reply is" \n\n\n…": teacher-forced on our float64-checked token stream, the top-1 matches 0 of 64. With--parallel 4, 3 of 4 concurrent requests fail withNoFreeSlot. After: it loads, the 64 teacher-forced steps match 64 of 64,inkling2-serving(your own test, which failed withMiniServingLogitMismatch) passes, and four streams serve at once, each equal to its solo run.This is a proposal on top of #4387, like gilby's and sethforprivacy's Metal PRs on this branch. It is CUDA only. Take the commits in whatever form suits you. The defects were reported on #4387 in comment 1, comment 2 and comment 3. Fix 3 below is new: it is the residual drift those comments left open.
lead/inkling2-miniat3e0e9bcb83. Five commits.lead/inkling2-miniitself conflicts with main (registry_union.zig,lanes/drafted.zig,native/metal.zig, …). None of those files are in this PR's four commits, so a rebase of the lead branch should carry them unchanged.atc overlap: none of the open PRs on this branch touch these files. They are all Metal (families/inkling2/metal/,kernels/metal/).The five commits:
Load (
c0f151cb96).cuda_native.zig:111:plan_.buildgetsprecisions[0..c.text.layers]. It used to get the whole 128-entry array, so it failed withPrecisionCounton every checkpoint.loop_weights.zig:203-208: a sliding layer's k and v inputs share oneattn_norm.weightupload. The arena is sized to the checkpoint, so the second upload overflowed withLoopWeightsOverflow.Gate and sink raw (
4c9b2738da),loop_engine.zig:395-396. Bothops.rowdotcalls passedsigmoid = true.tf_ink2_merge(attention.cu:340-382) takes the sink as a logit and applies the gate's sigmoid itself. So the gate was squashed twice and a probability was used as the sink logit. That broke layer 0's attention output (cos 0.35 against our engine) and every layer after it. Metal (dense) and the CUDA attention contract both pass raw values already. Both calls now passfalse.Cross-pass messages (
e2b3acdc94),loop_math.cu:157.tf_ink2_loop_messageswrote[row][core][role][c]. The engine (loop_engine.zig:365,core_layers = 1) and the gates read roleratmessages + r * rows * c, which is plane-major. The two layouts agree for one row, so decode was right. Every multi-row prompt chunk went wrong from visit 18 on (the first visit of pass 2, the first visit with messages). That was the residual drift: cos 0.981 at visit 18, 0.72 by visit 47, top-1 58 of 64.[core][role][rows][c]. It already receivedrowsand ignored it.contract_inkling2_loop_math.zig:267,304) now indexes the same way. Its one-row 12-layer shape is byte-for-byte the old layout.inkling2_experts_records.zig:19: the kernel's registers are 36 now, recorded 40 before.A cache slot per served stream (
7f4bc4c92c).facts.max_streams = 1is correct, because it means one stream per shared forward. Butopeningrefused every second stream, while the host had counted and budgeted--parallelstreams.Model(loop_engine.zig:100-146) keeps up to 16 slots, each with its own K/V and conv state and its own rewind-site table.m.slotselects the slot.rewindrefuses a slot other than the one the last recorded window used (loop_engine.zig:289).Backend(loop_backend.zig) keeps a lane, a last-logits buffer and a rule buffer per slot.laneOfselects the stream's slot before every call.Loaded.reserve(cuda_native.zig:55,76) takes the host's stream count. The host already pricesstream_bytes * (streams - free_streams)and callsreserve. More than 16 is refused by name (Inkling2TooManyStreams).Prompt-cache states copied per key head (
321432e4b2),loop_engine.zig:523-553.copyStatesaved and restored K/V as[ring][kv_heads * dim]rows. The CUDA caches are head-major,[kv head][ring][dim](attention.cu:87,197), so a state held part of head 0's ring and none of the others. gilby found the same class of bug on Metal in inkling2 metal: snapshot DSpark lane state for prompt cache #4542.fresh and resumedtest passes that way.3e0e9bcb83+ the load and gate fixes with one slot, so it predates this PR.copyStatenow walks each key head's ring.snapshotBytesis unchanged.crossPrompt(inkling2_serving_tests.zig): A keeps states at 14 and 39; B, sharing A's first 14 ids, resumes A's 14, keeps its own 39 and decodes; then A resumed at 39 must equal fresh A, logits and tokens. It is red on commit 4 (MiniServingTokenMismatch, fresh196982, 64, 152304…vs resumed197041, 198, 220…) and green on this head.Checks on this head
321432e4b2, on3e0e9bcb83. GB10 (sm_121, CUDA 13), Zig 0.17.0,thinkingmachines/Inkling-2-Mini@ed40e7da.zig build test-inkling2-host test-inkling2-cuda-host compile-cuda-tests check-native-cuda-host: 24/24 steps, 86/90 tests passed (4 skipped).zig fmt --check build.zig zigandgit diff --check: clean.tools/pr_check.py --base 3e0e9bcb83: 0 errors. Lean 167 vs 167, 0 new.zig build install native -Dnvcc=/usr/local/cuda/bin/nvcc -Dsm=121: OK.tf-cuda-test kernel-contract inkling2:SUMMARY 53 kernels: 53 pass gates 1-4, 0 fail, 0 known findings; 36 controls: 36 red as planted, 0 missed; 0 limit problems, exit 0.tf_ink2_loop_messagespasses nonfinite, repeat, sums and shapes (1×12 layers, 16 and 2048 rows) on the new layout.tf-cuda-test inkling2-serving(your test, 9,810-id prompt file): exit 0, all six cases PASS:3e0e9bcb83+ the two load fixes withMiniServingLogitMismatch);reserve);inkling2_serving_tests.zig:157). Four prompts of 8 to 2,100 ids (one spans two 2,048-row chunks) run interleaved through the lane engine, greedy and seeded (seed 37, T 0.8). Each equals its solo trace token for token.fitsis false and a fifthprefillreturnsNoFreeSlotwithfill_atstill 0, so nothing of it ran.3e0e9bcb83this is theNoFreeSlotthat 3 of 4 served requests hit.tensorfold-native serve --parallel 4 --context 8192, page cache dropped, 128 tokens; hashes cover reasoning and content, and an empty reply fails):--no-draftsthe hashes were the same, and with--prompt-cache-gib 0everything was equal.--no-drafts. For example topic 0 is82c2ff38ac0bboth ways.5b57c420ae9c.6fceca4629ec.3e0e9bcb83+ load and gate fixes, and on commit 4, the last two answered about the violin.Correctness against our engine
Same 25 prompt ids, per-visit hidden state of the last prompt row. The other side is our C4 Mini engine (
dc2ca8a178), which matches a float64 reference 48 of 48. Teacher-forced on its 64 greedy tokens:3e0e9bcb83+ load fixes" \n\n\n…"How the table was taken:
Still open
TENSORFOLD_CUDA_KERNELSstay refused as on3e0e9bcb83.Receipt
3e0e9bcb83: it does not load (PrecisionCount). With the load fixes only, see the table above.inkling2_looponly. Metal untouched.--parallelnow works up to 16.- Inkling 2 Mini on CUDA: loads the released checkpoint, passes the attention gate and sink raw, fixes the cross-pass message layout for prompt chunks, serves --parallel streams on their own cache slots, and copies prompt-cache states per key head.Checklist
NoFreeSloton the base; the cross-prompt case is red on commit 4; the serving test failedMiniServingLogitMismatchon the base + load fixes.