Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Nemotron CUDA prompts run in passes of up to 4,096 rows between kept …
…points
  • Loading branch information
plotarmordev committed Oct 11, 2026
commit f54f666f89054c9aed2a11fc804a964258a793eb
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 passes of up to 4,096 rows: grid chunks join between the points the prompt cache keeps states at, so a prompt takes fewer passes, each reading the routed experts' weights once. Resume points, kept states and every reply's bits are unchanged; staggered segments, `--dump` and a pass with lessons attached keep the 2,048-row grid. On a GB10, The Grill's natural-prose prefill cells ran 8.1% faster at 4k tokens, 3.9% at 8k, 5.4% at 16k and 5.1% at 32k, and prompts of repository text 6.5 to 16.4% faster; prompts of one chunk and decode are unchanged, and repetitive prompts, which route to few experts, gain little. The prompt workspace takes 0.47 GiB more.

## 1.0.7

- Living Weights learns each fact into about ten new neurons inside the model's own shards, on Macs and on a GB10. Every MoE layer's shared expert gets a pocket of 64 extra neurons; a fact takes one at each of about ten layers, fired at the first row of the reply (a fact about you) or at the subject's last token where a question names it (a fact about someone or something), with outputs fitted through the model so the answers come back, thinking on too, while near misses, free writing about the subject and other answers stay as they were. Nothing the model had is changed, no adapter is loaded, and any MLX loader reads the folder as a slightly wider model. A fact is kept only when held-out wordings bring it back and nothing else moved; otherwise it is taken out and leaves nothing behind. Documents are learned fact by fact: the model finds the facts, names the organisation on each, and keeps only those whose names, numbers and words the text holds (a list holding others is read again), then writes questions that name their subject (rewriting ones that ask for it), and leaves a question another fact answers to that fact. Three personal facts taught one after another each came back on both test questions on an M5 Ultra, an M3 Ultra and a GB10, with no leaks and no drift, live and after a plain restart; a six-fact handbook gave 3 to 6 of 6 answers across six runs, and long documents about one subject are still weak (6 of 16 from a 21-fact handbook). Without learned facts, replies and speed equal 1.0.6's on both backends; a folder with 21 facts decodes about 16% slower on a Mac. `--slide` refuses a folder taught by 1.0.3 to 1.0.6, whose lessons sit in the shared experts the pocket widens; such folders still serve without it. It builds on the CUDA learner and the take-out rule of #591, #599 and #632. Thanks to @ZackSample and @ThinkOffApp.
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.last_row + 1 - rows) * e.c.hidden * 2, rows * e.c.hidden * 2); // the last grid 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_decode.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn generate(gpa: std.mem.Allocator, io: std.Io, e: *Engine, drafter: ?*draft
var st: drafts.Stats = .{};
if (out.items.len < count and !(o.stop_eos and e.c.isEos(out.items[0]))) {
if (drafter) |d| {
const last = (prompt.len - 1) % state.prefill_rows;
const last = e.last_row;
st = try drafts.decode(gpa, e, d.head, &d.rule, prompt, &out, count, o.stop_eos, e.b.p_hidden + last * @as(u64, e.c.hidden) * 2);
} else if (e.serial != null) {
st.rounds = try serialGraphs(gpa, e, &out, count, o.stop_eos);
Expand Down
16 changes: 15 additions & 1 deletion zig/src/families/nemotron/cuda_engine.zig
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const pin_meta = 0;
const pin_ids = 4;
const pin_sampled = 32;
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);

/// One stream's part of a shared window: its sequence, the ids its first rows take from the host, and its rows.
pub const Shared = struct { seq: *state.Seq, ids: []const u32, rows: usize, mask: Mask = .{} };
Expand Down Expand Up @@ -90,6 +90,7 @@ pub const Engine = struct {
copied: cuda.Event = undefined, // the last window's uploads have read the pinned words
sampled_ready: cuda.Event = undefined,
pos: usize = 0,
last_row: usize = 0, // the prompt's last row in p_hidden after a prompt pass
parity: usize = 0,
prev_keep: usize = 0,
rows: usize = 0,
Expand Down Expand Up @@ -350,6 +351,7 @@ pub const Engine = struct {
const waited = e.heat_gate.waited_s;
if (from == 0 and keep == null and e.segments > 1 and dump == null and prompt.len > state.prefill_rows and e.decide == lesson_route.none) {
try segs.prefill(e, try e.segmentSet(), prompt, head, e.segments, cancel);
e.last_row = (prompt.len - 1) % state.prefill_rows;
} else try e.serialChunks(prompt, from, dump, head, cancel, keep);
if (e.heat_gate.waited_s > waited) heat.note(e.heat_gate.waited_s - waited);
const host = e.pinned.slice(u32)[pin_sampled..][0..1];
Expand Down Expand Up @@ -386,9 +388,16 @@ pub const Engine = struct {
if (Cancel.now(cancel)) return error.Cancelled;
try e.beforeChunk(cancel);
var end = grid.end(s, prompt.len, state.prefill_rows);
// grid chunks join up to pass_rows between kept points (rows equal at any cut); not under lessons or dumps
if (dump == null and shared == null and e.decide == lesson_route.none) while (end < prompt.len and !kept(keep, end)) {
const next = grid.end(end, prompt.len, state.prefill_rows);
if (next - s > state.pass_rows) break;
end = next;
};
// 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];
e.last_row = chunk.len - 1;
f.route = .{};
f.route.add(0, chunk.len, e.pos, e.decide, e.slot);
try e.copied.synchronize();
Expand All @@ -406,6 +415,11 @@ pub const Engine = struct {
}
}

fn kept(keep: ?Keep, at: usize) bool {
const k = keep orelse return false;
return at <= std.math.maxInt(u32) and std.mem.indexOfScalar(u32, k.at, @intCast(at)) != null;
}

/// Any block's change, for the buffers every block shares (null: no lesson is attached).
pub fn lessons(e: *const Engine) ?weights.Adapter {
for (e.w.blocks) |blk| switch (blk.kind) {
Expand Down
2 changes: 1 addition & 1 deletion zig/src/families/nemotron/cuda_lanes.zig
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ pub const Cuda = struct {
const keep: ?engine.Keep = if (s.reuse.marks.len == 0) null else .{ .at = s.reuse.marks, .ctx = s, .call = keptAt };
const first = try e.prefillFrom(ids, from, null, self.head, .{ .ptr = s, .check = cancelled }, keep);
// the head's first draft reads the prompt's last row (its hidden row waits where a window's would)
const last = (ids.len - 1) % state.prefill_rows; // a resumed pass ends on the same grid
const last = e.last_row;
try e.ops().copy(e.b.hidden, e.b.p_hidden + last * @as(u64, e.c.hidden) * 2, e.c.hidden * 2);
_ = self.take(first);
if (s.logprobs) |k| {
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
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: the grid passes resume and keep states on
pub const pass_rows = 2 * prefill_rows; // rows one serial prompt pass runs at most: grid chunks between kept points join
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 @@ -72,7 +73,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
2 changes: 1 addition & 1 deletion zig/tests/cuda/tree_accept.zig
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn run(gpu: check.Gpu, model: []const u8, ids_path: []const u8, count_text:
defer drafts.deinit(gpa);
var pending = try e.prefill(prompt.items, null, h);
try truth.append(gpa, pending);
const last = (prompt.items.len - 1) % nemotron.state.prefill_rows;
const last = e.last_row;
try e.ops().copy(e.b.hidden, e.b.p_hidden + last * D * 2, D * 2);
try e.ops().fill32(e.b.sampled, pending, 1);
var vals: [candidates]f32 = undefined;
Expand Down
Loading