Skip to content

Inkling 2 Mini: one shared per-head kept-state walk (CUDA uses it) and a shared DSpark lane host with one tokenBytes - #4724

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

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

Conversation

@jschmied

@jschmied jschmied commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Update for review 7098920791: head e07853195e, restacked on #4640 a28a170bb7

Checks on e07853195e (GB10):


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 under families/inkling2/metal/ or kernels/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.

The two commits:

  1. One per-head kept-state walk, used by CUDA (6d22d2472b), new kept_state.zig (154 lines).

  2. A shared DSpark lane host and one tokenBytes (f7e97de0dc), new dspark_lanes.zig (240 lines) and dspark_lanes_test.zig (167).

Checks on this head

Proposed CHANGELOG line

  • Inkling 2 Mini: one shared per-head kept-state walk (CUDA's prompt-cache save and restore use it; Metal can move onto it) and a shared, host-tested DSpark lane host with one tokenBytes for the window fit, the lanes and the score scratch.

@sethforprivacy

Copy link
Copy Markdown
Contributor

Metal is on this now, as a draft: #4749, your head f7e97de0d merged into the Metal stack.

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 metal/dspark_state.zig is dropped, which #4749 does in dspark_lanes_test.zig (those functions are gone there). And I left scoreBytes alone: #4660's partials fit under it from 1,024 tokens up, and Metal's setScores takes its own floor below that, so no Metal constant went into shared code.

@jschmied
jschmied force-pushed the ink2-mini-shared-state branch from f7e97de to e078531 Compare November 23, 2026 14:49
@ashhart
ashhart force-pushed the lead/inkling2-mini branch 4 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:48
@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 base branch was removed. It is reopened and now targets main. We will follow up here on what it needs next; nothing is needed from you yet.

  • Synthena

@joshuaswarren

Copy link
Copy Markdown
Contributor

sm_120 contract run on RTX 5060 Ti (independent of GB10), head e078531.

tf-cuda-test kernel-contract inkling2:

  • 53/53 kernels pass gates 1-4, 0 gate failures
  • 36/36 planted controls red as designed, 0 missed
  • 20 limit problems: the new experts/vision/modelopt/loop_math kernels launch with real register+shared usage while the sm_120 records read 0,0 placeholders; small drifts on older kernels (tf_ink2_attn 194 vs 202 recorded, tf_ink2_mix 72 vs 74, tf_ink2_rowdot 35 vs 34).
  • nvcc 13.5 images against the nvcc 13.3 record set.

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.
@ashhart
ashhart force-pushed the ink2-mini-shared-state branch from e078531 to b918bc4 Compare November 24, 2026 11:06
@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, builds alternated base, new, new, base.

  • Tokens: identical in all 16 cells (one stream, four streams, prompt-cache resume through the shared kept-state walk, and raw prompts of 1 to 33 rows).
  • Speed: unchanged within run-to-run spread (one-stream decode 5.85 to 5.84 tok/s, four streams 4.670 to 4.676 tok/s, long-prompt time to first token 14.37 s to 14.44 s).

As a refactor that keeps both, it's now in our landing queue.

  • Synthena

@AIFlowML

Copy link
Copy Markdown
Contributor

I independently trial-merged b918bc4b61 into d1ff890729 on an M5 Max. The merge was clean. zig build test-inkling2-host test-inkling2-cuda-host check-native-cuda-host -Dfixed-cpu -j2 --summary all passed 96 tests with 4 skips.

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 zig test zig/src/families/inkling2/kept_state.zig. As a negative control, changing the head-boundary check from the current visit's v.heads to w.visits[0].heads left the two existing tests green and failed the new case at expected cache byte 3000 versus observed 2155.

Reproduce the mixed-visit test

Append this test to zig/src/families/inkling2/kept_state.zig and run the command above.

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

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.

5 participants