Repository navigation
Conversation
|
Metal is on this now, as a draft: #4749, your head
Two things you may want to know for this pull request. Your host tests pass on macOS beside the Metal stack once the price pin to |
f7e97de to
e078531
Compare
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
|
|
sm_120 contract run on RTX 5060 Ti (independent of GB10), head e078531.
No gate failures on sm_120; limit diffs are record-staleness on this arch, consistent with #4697/#4718/#4728/#4729. |
…cache save and restore kept_state.zig says which rows of which key head of which visit a kept state holds (a global layer all of them, a sliding one its window less one), in packed order, split where a ring wraps. A backend supplies only the copy: CUDA's copyState and snapshotBytes now walk it, issuing the same copies in the same order as before. Host tests restore into caches of other capacities; inkling2-serving restores a device state into a model of another capacity and resumes a turn after a history kept at the chunk grid, after another prompt.
…t, the lanes and the score scratch dspark_lanes.zig holds what Metal's dspark.zig and dspark_state.zig keep beside their kernels today: the rings, each stream's committed rows [from, end), its held drafts, what an absorb commits and when a hold may draft, and the bytes a token of window costs a lane and the shared scores (`tokenBytes`, `fit`, `laneBytes`, `scoreBytes`). Drafter(B) drives the round loop's drafter over a backend B that takes each absorb and each hold in one call for all its streams and returns the drafts, so a backend can keep one command buffer a hold. Nothing calls it yet: host tests pin it to Metal's state functions and to the absorb/hold rules of dspark.zig.
e078531 to
b918bc4
Compare
|
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, builds alternated base, new, new, base.
As a refactor that keeps both, it's now in our landing queue.
|
|
I independently trial-merged I also checked the packed KV walk with different head counts, row widths, and ring sizes within one state. This covers switching between sliding and global visits while keeping both the cache addresses and contiguous packed offsets correct. All 3 tests passed with Reproduce the mixed-visit testAppend this test to test "mixed visit geometries preserve every packed byte across ring wraps" {
const visits = [_]Visit{
.{ .k = 0, .v = 1000, .heads = 2, .ring = 7, .row = 3, .global = false },
.{ .k = 2000, .v = 3000, .heads = 1, .ring = 31, .row = 5, .global = true },
.{ .k = 4000, .v = 5000, .heads = 3, .ring = 9, .row = 2, .global = false },
};
for (1..8) |window| for (0..32) |at| {
const w: u32 = @intCast(window);
var walk = Walk.init(&visits, w, at);
var piece = walk.next();
var within: u64 = 0;
var offset: u64 = 0;
for (visits) |v| for ([_]u64{ v.k, v.v }) |base| for (0..v.heads) |head| {
const first = if (v.global) 0 else at -| (window - 1);
for (first..at) |row| for (0..v.row) |byte| {
const p = piece orelse return error.TestUnexpectedResult;
try testing.expectEqual(base + (head * v.ring + row % v.ring) * v.row + byte, p.cache + within);
try testing.expectEqual(offset, p.offset + within);
within += 1;
offset += 1;
if (within == p.len) {
piece = walk.next();
within = 0;
}
};
};
try testing.expect(piece == null);
try testing.expectEqual(offset, bytes(&visits, w, at));
};
}These were host checks. I did not repeat the checkpoint or GPU A/B runs. Igor Lessio - AIFLOW LABS |
Update for review 7098920791: head
e07853195e, restacked on #4640a28a170bb77901359966(kept-state walk) ande07853195e(DSpark lane host).git diff f7e97de0dc e07853195etouches only 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's four files, so the Metal merge off7e97de0dstill holds. Thedspark_lanes_test.zigpin drop stays with Inkling 2 Mini on Metal: the snapshot and the DSpark drafter move onto #4724's shared kept-state walk and lane host (same replies, kept states 40 % smaller) #4749.Checks on
e07853195e(GB10):pr_check: 0 errors, lean 167 vs 167.inkling2: 53/53, 36 of 36 controls red. No.cufile changed.inkling2-serving: PASS, includingturnAfterHistoryandotherCapacity.f7e97de0dc. Best of 2: 5.622 vs 5.622 tok/s. Paired median 0.9971, 1 of 2 pairs slower, so mixed.What this changes
The shared code agreed on #4387: sethforprivacy's table of his drafts and our reply with the shape. Three pieces in
families/inkling2/, so Metal and CUDA stop keeping two copies of the same host logic. No file underfamilies/inkling2/metal/orkernels/metal/inkling2/is touched, and no core file: sethforprivacy's and gilby's open drafts keep building, and Metal moves onto this when it suits them.321432e4b2), which is onlead/inkling2-mini(3e0e9bcb83). I'll retarget if it merges. Two commits.metal/snapshot.zig,metal/dspark.zig,metal/dspark_state.zig); one host test importsmetal/dspark_state.zigunchanged, to pin the prices to it.The two commits:
One per-head kept-state walk, used by CUDA (
6d22d2472b), newkept_state.zig(154 lines).atrows, a sliding one its window less one, the rows its next token reads), in packed order (visit, K then V, key head, position), split where a ring wraps. Rows are placed by position (pos % ring), so a state restores into a cache whose rings have another size. A backend supplies only the copy.loop_engine.zigcopyStateandsnapshotByteswalk it (keptVisitsdescribes the head-major[kv head][ring][dim]caches). It issues the same copies in the same order as 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's head did, andrestorealso refuses a state whose kept rows don't fit the rings (kept_state.fits).loop_engine.ziggoes from 594 to 580 lines.kept_state.zig: "a state restores each head's kept rows into a cache of another capacity" (sethforprivacy's runtime test, on host buffers: sliding rings 8 and 12, global rings 16 and 40, positions written in order so the sliding rings wrap, seven cut points); "the walk keeps a sliding layer's window less one and splits a head where its ring wraps" (every piece of a wrapped two-head visit).inkling2_serving_tests.zigotherCapacity: the same on the GPU. A's slot gets random bytes, a state saved at 3,300 restores into a secondModelof context 3,500 (sliding rings as A's, wrapped; global rings shorter), and one saved at 1,400 into context 1,500 (all rings shorter). Every kept row of every head and visit must be at its position in B, and the convolution states equal.turnAfterHistory(the second commit of Inkling 2 Mini on Metal: a prompt-cache snapshot copies each key-value head's live rows, and the real-checkpoint serving tests run to it #4607, for CUDA): a history of 2,048 ids (the chunk grid) is kept at its end and decoded on for 24 tokens; another 2,148-id prompt runs on the slot; then the history's next turn (16 more ids) resumed at 2,048 must equal the same turn fresh, logits and tokens, greedy and seeded. Not ported: "draw the first token before its row" is about Metal'sfirstRow; the CUDA backend has none.[ring][kv*dim]copy 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's commit 5 fixed) turns both host tests red, and on the GPUturnAfterHistory,crossPromptandotherCapacityall red (MiniServingTokenMismatch;crossPromptfresh196982, 64, 152304…vs resumed197041, 198, 220…;otherCapacity"other capacity 3500: visit 0 side 0 head 0 position 2277 moved"). Green on this head.snapshot.zig'sencodebecomes a walk overVisit{ key_at, value_at, kv_width / head_dim heads, ring(slot), head_dim * 2, globals[slot] }with one blit copy a piece, and Inkling 2 Mini on Metal: a prompt-cache snapshot copies each key-value head's live rows, and the real-checkpoint serving tests run to it #4607'ssnapshot.zighunk drops; its tests stay. One difference to decide then: Metal keepsmin(len, ring)rows of a sliding visit, in slot order; the walk keeps thewindow - 1its next token reads, by position, sosnapshot.bytesgets smaller.A shared DSpark lane host and one
tokenBytes(f7e97de0dc), newdspark_lanes.zig(240 lines) anddspark_lanes_test.zig(167).dspark.ziganddspark_state.zigkeep beside their kernels today. Each stream'sBook: its rings, committed rows[from, end), held drafts; what an absorb commits (a gap starts the context anew at its start, a step back is refused, the held drafts are cleared) and when a hold may draft (every row before its anchor committed, at most 7 drafts, a draft past the vocabulary is nonfinite).Drafter(B)is the round loop's drafter (lanes.draftervtable) over a backendB.lanes/drafted.zig's: ONEB.hold(items, drafts)call per hold for all of the round's streams, returning their drafts, and oneB.absorb(pieces)per absorb (each stream's rows in pieces of 64). So Metal keeps 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's single command buffer for the blocks, chain steps and picks, and CUDA can put its kernels behind the same call, a step at a time or fused. Every stream's hold is checked before the backend runs.tokenBytes(): what a token of window costs, a lane's global K/V rows (4,096 bytes) and its row of the shared score scratch (768).laneBytes,scoreBytesandfit()(the opener'sfixed,lane,shared, with the global ring's slack of 127 tokens infixed) are all built on it: the disagreement Inkling 2 Mini on Metal: with a drafter, the window fit prices a token at a token's bytes (a 64 GB limit holds the whole window for eight streams) #4622 fixed can't come back.metal/dspark_state.zig's (laneBytes,scoreBytes,globalRing,laneTokenBytes,laneFixedBytes,local_ring) at 8 windows from 1 to 2^20, and the fit never prices a stream under its lane nor over it by more than the slack (Inkling 2 Mini on Metal: with a drafter, the window fit prices a token at a token's bytes (a 64 GB limit holds the whole window for eight streams) #4622's test);metal/dspark.zigover a recording backend: pieces and their feature offsets,from/end, the drafts kept and handed out, and each refusal by name (DraftStreamOpen,DraftContextGap,DraftDepth,DraftStreamUnknown,DraftNonfinite,DraftHeldFewer,DraftFeaturesUnsupported,TreesNotBuilt,DSparkContextActive), with a refused hold reaching no backend call.from: the absorb test goes red.Bis Metal's kernels.openLane(rings)makesstate.Lane's buffers,absorb(pieces)encodesabsorbRowsa piece in one command buffer,hold(items, drafts)is 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'sholdChained(or the per-step path for sampled streams) writingdraftswhere it writeslane.heldnow,setScoresallocates the scores,policygives 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'sstep_ms,plain_guardandbatched. 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 and Inkling 2 Mini DSpark on Metal: the block attends on the M5 tensor units, so a hold costs the same at any context #4660 then rebase theirdspark.zigchanges into thatB, Inkling 2 Mini DSpark on Metal: the block attends on the M5 tensor units, so a hold costs the same at any context #4660's widerscoreBytesgoes intodspark_lanes.scoreBytes, and Inkling 2 Mini on Metal: with a drafter, the window fit prices a token at a token's bytes (a 64 GB limit holds the whole window for eight streams) #4622 callsfit()innative/inkling2.zig(not touched here: it is Metal's opener, and Inkling 2 Mini on Metal: with a drafter, the window fit prices a token at a token's bytes (a 64 GB limit holds the whole window for eight streams) #4622 is open on it). CUDA plugs in when its DSpark kernels land.metal/dspark_fold.zig(the binary64 fold of the hidden head) already depends on nothing of Metal's (stdandbf16_round). It moves with agit mvand one import line when Metal moves; a copy now would be the third copy sethforprivacy asked us to avoid.Checks on this head
f7e97de0dc, on321432e4b2. 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 succeeded, 94/98 tests passed (4 skipped).zig fmt --check build.zig zigandgit diff --check: clean.tools/pr_check.py --base 321432e4b2: 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 (no kernel changes; run for completeness).tf-cuda-test inkling2-serving(9,810-id prompt file): exit 0, all eight cases PASS, the six of 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 and the two new ones (turnAfterHistory,otherCapacity).tensorfold-native serve --parallel 4 --context 8192, page cache dropped, 128 tokens, hashes over reasoning and content, an empty reply fails): every hash equal to 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's head's (SERVED vs #4640 head: ALL EQUAL):9b35cbd7c284, seeded topic 05b886d0faf27);dad96525689aboth;fdb1da1ad592both.lead/inkling2-mini), so every comparison is against this PR's base, 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's head.Proposed CHANGELOG line
tokenBytesfor the window fit, the lanes and the score scratch.