Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Each release's page on GitHub has its notes and measurements. See [the 1.0.0 release notes](RELEASE-NOTES-1.0.0.md) for the native binary's supported models and migration details.

## Unreleased

- Nemotron on CUDA runs a prompt in chunks of up to 4,096 rows instead of 2,048, so a prompt takes fewer passes, each reading the routed experts' weights once. Kept states, resume points and every reply's bits are unchanged, since a prompt row's bits do not depend on where its chunk is cut; staggered segments, `--dump`, a pass with lessons attached, and a chunk that would hold more keep marks than a chunk takes keep 2,048-row chunks. On a GB10, The Grill's natural-prose prefill cells ran 7.7% faster at 4k tokens, 7.9% at 8k, 5.2% at 16k and 6.1% at 32k, and 14k- to 56k-token prompts reached their first token 3.4 to 4.5% sooner; decode is unchanged. The prompt workspace takes 0.47 GiB more.

## 1.0.8

- Nemotron on CUDA keeps and resumes prompt states at any row instead of only on the 2,048-row grid, so a conversation resumes from where its last turn's history ended, and chats of 2,048 tokens or fewer resume too. Every kernel a prompt chunk runs gives a prompt row the same bits wherever the prompt is cut into chunks: dumps of every layer's rows, the final states, the MTP head's caches and the first token were byte-equal at 17 cut patterns on a GB10 and an RTX PRO 6000, with the built-in kernels and with the captured GB10 set. A state kept inside a chunk costs no extra prompt call: as the chunk's scan passes that row it stores the Mamba state there, into a buffer the cache keeps free, and the key and value rows are copied once the chunk is queued. Those states were byte-equal to the ones a chunk ending at the same rows leaves, at the same 17 patterns on both GPUs. On a GB10, turns 2 to 5 of chats from 350 to 16,000 tokens started 1.7 to 2.8 times sooner (medians 0.09 to 0.11 s, against 0.15 to 0.30 s). Cold first turns took as long as before from 10,000 tokens, and 1 to 3 ms longer (1 to 2%) under 1,400 tokens, which now keep two or three states where they kept none; on an RTX PRO 6000 they were within 1.1% at every length (A B B A, eight rounds of prompts from 330 to 27,600 tokens). A first turn keeps more states than on the grid: where the user's message starts, and 512 and 2,048 tokens before the end of a long system prompt. Conversations that share a system prompt share those states; with a different system prompt in every chat, the 16 GiB default kept about the last 100 of 300 two-turn chats ready to resume, where whole-window states left room for about 25, and a second turn resumed 2,607 of its 2,647 tokens instead of 2,048 (medians). Replies equal the cache-off server's token for token, drafted and with `"draft": false`, greedy and seeded sampled, alone and four chats at once (#670). Thanks to @jschmied.
Expand Down
2 changes: 1 addition & 1 deletion zig/src/cli/cuda_segments.zig
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ fn digest(gpa: std.mem.Allocator, e: *nemotron.Engine, head: ?*nemotron.Head, to
var lg = Sha.init(.{});
try hashDevice(&lg, gpa, e, e.b.p_logits, e.c.vocab * 2);
var hi = Sha.init(.{});
try hashDevice(&hi, gpa, e, e.b.p_hidden, rows * e.c.hidden * 2);
try hashDevice(&hi, gpa, e, e.b.p_hidden + (e.pos - e.last_chunk - rows) * e.c.hidden * 2, rows * e.c.hidden * 2); // the last 2,048-row chunk's rows
return .{ .state = hex(&st), .head = hex(&hd), .logits = hex(&lg), .hidden = hex(&hi), .token = token };
}

Expand Down
2 changes: 1 addition & 1 deletion zig/src/families/nemotron/cuda_engine.zig
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const pin_meta = 0;
const pin_ids = 4;
pub const pin_sampled = 32;
pub const pin_prompt = 64;
const pin_shared = pin_prompt + segs.MAX * state.prefill_rows;
const pin_shared = pin_prompt + @max(segs.MAX * state.prefill_rows, state.pass_rows);
/// Graph ids of masked verify windows (launchGraph's ids: windows from 1, head levels from 1000).
const masked_ids = 4000;

Expand Down
4 changes: 2 additions & 2 deletions zig/src/families/nemotron/cuda_mtp.zig
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub const Head = struct {
if (e.w.mtp == null) return error.NoMtpHead;
const c = e.c;
const D: usize = c.hidden;
const R: usize = state.prefill_rows;
const R: usize = state.pass_rows;
const kv: usize = @as(usize, e.max_len) * c.kv_heads * c.head_dim * 2;
const n = e.w.draft_count;
const sizes = [_]usize{ kv, kv, 17 * 4, state.max_rows * D * 2, state.max_rows * 4, max_chain * 4, D * 2, R * D * 2, R * 2 * D * 2, R * 2 * D / 64 * 4, R * D * 2, D * 2, D * 2, D * 2, D / 64 * 4, n * 2, n * 4, sampler.max_candidates * 4, sampler.max_candidates * 8, sampler.max_candidates * 8, 32, R * 4, torch_ops.topkScratchBytes(1, n), 4 };
Expand All @@ -74,7 +74,7 @@ pub const Head = struct {
try h.buf.fill8(0, e.stream.handle); // on the engine's stream: the legacy one would race its first uploads
e.head = h;
inline for (seq_fields, &e.own.head) |name, *ptr| ptr.* = @field(h, name);
h.pinned = try cuda.HostBuffer.alloc(e.ctx.d, (128 + state.prefill_rows) * 4);
h.pinned = try cuda.HostBuffer.alloc(e.ctx.d, (128 + state.pass_rows) * 4);
h.copied = try cuda.Event.init(e.ctx.d, false);
try h.copied.record(e.stream);
for (&h.ready) |*r| r.* = try cuda.Event.init(e.ctx.d, false);
Expand Down
13 changes: 12 additions & 1 deletion zig/src/families/nemotron/cuda_prompt.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const segs = @import("cuda_segments.zig");
const cuts = @import("cuda_prompt_cuts.zig");
const prompt_rows = @import("cuda_prompt_rows.zig");
const reuse = @import("cuda_reuse.zig");
const marks = @import("cuda_marks.zig");
const lesson_route = @import("lesson_route.zig");
const heat = @import("heat");
const pin_sampled = engine.pin_sampled;
Expand Down Expand Up @@ -75,7 +76,9 @@ pub fn serialChunks(e: *Engine, prompt: []const u32, from: usize, dump: ?*Dump,
while (s < prompt.len) {
if (Cancel.now(cancel)) return error.Cancelled;
try e.beforeChunk(cancel);
var end = cuts.end(s, prompt.len, state.prefill_rows, if (keep) |k| (if (k.cut) k.at else &.{}) else &.{});
// a chunk runs up to pass_rows (rows equal at any cut), 2,048 under lessons or dumps or when its marks crowd
const wide = dump == null and shared == null and e.decide == lesson_route.none and inside(keep, s, s + state.pass_rows) < marks.max;
var end = cuts.end(s, prompt.len, if (wide) state.pass_rows else state.prefill_rows, if (keep) |k| (if (k.cut) k.at else &.{}) else &.{});
// the decision row ends its chunk: the rows after it read the lessons it latched
if (e.decide != lesson_route.none and e.decide >= s and e.decide + 1 < end) end = @intCast(e.decide + 1);
const chunk = prompt[s..end];
Expand All @@ -102,6 +105,14 @@ pub fn serialChunks(e: *Engine, prompt: []const u32, from: usize, dump: ?*Dump,
}
}

/// The keep marks strictly inside rows [s, end).
fn inside(keep: ?Keep, s: usize, end: usize) usize {
const k = keep orelse return 0;
var n: usize = 0;
for (k.at) |m| n += @intFromBool(m > s and m < end);
return n;
}

/// The keeps of rows strictly inside the chunk [s, end), made before it runs: the chunk writes their Mamba states.
fn arm(e: *Engine, k: Keep, s: usize, end: usize) void {
e.armed.open = .{ s, end };
Expand Down
5 changes: 3 additions & 2 deletions zig/src/families/nemotron/cuda_state.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const sampler = @import("cuda_sampler.zig");
const seq_graphs = @import("cuda_seq_graphs.zig");

pub const max_rows = 16; // a verify window's rows (the row tile of the row-parallel kernels)
pub const prefill_rows = 2048; // rows of a prompt chunk
pub const prefill_rows = 2048; // rows of a prompt chunk under lessons and dumps, and of a staggered segment
pub const pass_rows = 2 * prefill_rows; // rows a serial prompt chunk runs at most otherwise
pub const chunk_keys = 512; // keys an attention chunk holds, at fixed absolute positions
const shared_words = 2 * max_rows + 8 * max_rows; // the shared expert's members, then (items, counts) a row count

Expand Down Expand Up @@ -83,7 +84,7 @@ const scratch_count = 35;

/// Scratch windows and chunks share on one stream: window logits, chunk io, activations, the expert plan.
fn scratchSizes(c: Config, nch: usize) [scratch_count]usize {
const R: usize = prefill_rows;
const R: usize = pass_rows;
const W: usize = max_rows;
const D: usize = c.hidden;
const ns: usize = c.slots();
Expand Down
Loading