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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

## Unreleased

- Nemotron on HIP: at `--tp 1`, `--mtp-drafts` takes up to 15, widening a lone stream's verify window up to 16 rows; unset or at 3 or fewer the window stays at four rows, rounds shared by several streams chain at most three drafts a stream, and above `--tp 1` more than three is refused by name (#3613, refs #3394). Thanks to @gilby.

- Server: opt-in --tool-think-close bounds thinking for required or named tool calls so the call has room in max_tokens; the flag defaults off and keeps smaller thinking budgets (#4157). Thanks to @jayleaton.

- CUDA: Drama 3 loads compact NVFP4 checkpoints as stored, stages held experts in slot order, and masks routing to their original ids (#4144). Thanks to @plotarmordev.
Expand Down
19 changes: 19 additions & 0 deletions docs/recipes/nemotron-3.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,22 @@ servers plus one `--no-drafts` server):
| `bench_openai` code / chat (`--no-drafts`) | median tok/s | 86.2 / 86.1 | 87.9 / 87.9 | 1.00 token/round (1.828 GB read/token, ~160.7 GB/s greedy) |
| `bench_concurrent` 1 / 2 / 4 streams | aggregate tok/s | 124.4 / 136.0-137.0 / 168.4-168.9 | 131.5-132.4 / 146.5 / 175.5-176.4 | 84/84 concurrent=alone; 48/48 alone=`"draft": false` |
| `bench_cache` 2,048 / 7,099 / 28,333 tokens | cold TTFT (s) | — | 0.731-0.732 / 2.672-2.676 / 13.130-13.205 | 2,797-2,800 / 2,653-2,657 / 2,146-2,158 tok/s (repeated cold) |

## Deep MTP drafts on HIP (opt-in)

On one HIP rank (`--tp 1`), Nemotron 3.5 Lightning keeps its four-row verify window and three MTP drafts by default so latency, GTT memory and shared-round throughput stay as before. Passing `--mtp-drafts N` from `4` to `15` widens each stream's verify window to `N + 1` rows (up to sixteen) for a lone decoding stream, while shared multi-stream rounds stay capped at three head drafts per stream and 32 rows in the round plan (or `4 * streams` above eight streams; above `--tp 1`, `--mtp-drafts` remains capped at `3` and `--mtp-drafts 16` is refused by name).

Measured on a Strix Halo (`gfx1151`, `TENSORFOLD_MEMORY_RESERVE_GIB=4 --context 131072 --parallel 4 --prompt-cache-gib 0`, greedy and sampled 256-token replies):

| Checkpoint | Prompt suite (`L=1` unless noted) | `d=3` (default) | `d=5` | `d=7` | `d=11` | `d=15` |
|---|---|---|---|---|---|---|
| `Lightning-30B-A3B-MLX-4bit` | Edit copy (`T=1.0 / T=0.0`, tok/s) | `149.0 / 149.6` | `165.5 / 164.8` | `184.3 / 179.4` | `212.6 / 207.8` | `229.1 / 214.0` |
| `Lightning-30B-A3B-MLX-4bit` | Edit copy `L=2` agg (`T=1.0 / T=0.0`) | `151.6 / 156.6` | `178.3 / 170.4` | `187.0 / 182.8` | `172.8 / 175.2` | `188.7 / 187.1` |
| `Lightning-30B-A3B-MLX-4bit` | General `bench_prompts` (`T=1.0 / T=0.0`) | `125.5 / 131.4` | `125.9 / 131.3` | `125.5 / 133.0` | `124.9 / 134.4` | `124.6 / 135.2` |
| `Lightning-30B-A3B-MLX-4bit` | `fibonacci-raw` / `gpu-chat` (`T=0.0`) | `122.6 / 98.8` | `125.3 / 94.5` | `132.0 / 94.5` | `135.2 / 94.5` | `136.6 / 94.5` |
| `NVIDIA-Nemotron-3.5-Lightning-30B-A3B-oQ4e-HIP` | Edit copy (`T=1.0 / T=0.0`, tok/s) | `132.9 / 134.3` | `151.9 / 153.3` | `165.1 / 167.9` | `186.3 / 198.0` | `194.0 / 204.7` |
| `NVIDIA-Nemotron-3.5-Lightning-30B-A3B-oQ4e-HIP` | Edit copy `L=2` agg (`T=1.0 / T=0.0`) | `144.0 / 145.1` | `163.2 / 170.5` | `179.0 / 178.4` | `163.0 / 163.5` | `175.3 / 184.0` |
| `NVIDIA-Nemotron-3.5-Lightning-30B-A3B-oQ4e-HIP` | General `bench_prompts` (`T=1.0 / T=0.0`) | `104.8 / 124.1` | `110.7 / 125.0` | `110.5 / 123.8` | `110.0 / 122.6` | `109.6 / 120.9` |
| `NVIDIA-Nemotron-3.5-Lightning-30B-A3B-oQ4e-HIP` | `fibonacci-raw` / `gpu-chat` (`T=0.0`) | `122.8 / 91.8` | `123.3 / 95.8` | `122.5 / 96.4` | `123.9 / 94.7` | `122.7 / 96.8` |

General prose and plain prompts are mixed or slightly slower at higher depth (`gpu-chat` at `T=0` drops from `98.8` to `94.5` tok/s on `Lightning-30B-A3B-MLX-4bit`, and `bench_prompts` at `T=0` drops from `124.1` to `120.9` tok/s on `NVIDIA-Nemotron-3.5-Lightning-30B-A3B-oQ4e-HIP`), whereas copy-heavy edits gain `43–54%` at one stream (`229.1` vs `149.0` tok/s on `MLX-4bit`; `204.7` vs `134.3` on `oQ4e`) and `20–27%` at two. Idle GTT across four `--parallel 4` streams grows by `+2,243.3 MiB` from `--mtp-drafts 3` (`1.15 GiB` per stream) to `--mtp-drafts 15` (`1.70 GiB` per stream). Every checked reply kept identical tokens across depths `3..15`, solo runs, concurrent runs, and `"draft": false` baselines (`100%` across `84` OpenAI, `588` concurrent/alone, and `336` serial checks per checkpoint) as well as across `12` prompt-cache reuse runs (`42/42` reused rows at `--mtp-drafts 7, 11, 15` with `--prompt-cache-gib 8`).
2 changes: 2 additions & 0 deletions docs/recipes/qwen3.8-flash-next.md
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ zig build native-hip -Dhip=true -Dhip-arch=gfx1151 -Dhipcc=/usr/bin/hipcc -Dopti
--parallel 1 --context 131072
```

The MTP head chains three drafts a stream by default. `--mtp-drafts N`, up to seven (the verify window's eight rows less the pending one), lets a stream that is alone in a round chain up to N; rounds shared by several streams keep at most three a stream, and `--tp` above 1 refuses more than three. Seven helps where a lone stream's drafts land often (greedy code and chat); on copy-heavy edit text, where copied drafts already fill most of the window, seven ran 0.8% slower than three on one Strix Halo iGPU (gfx1151), and on a sampled chat reply it ran 1% to 3% slower, so pick a lower N for that kind of work. `--mtp-drafts 0` stops the head's drafts.

## Draft vocabulary provenance

The Flash Next dump tool accepts `--draft-vocab default` for the shipped list,
Expand Down
42 changes: 42 additions & 0 deletions tools/bench_edit_prompts.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions zig/src/core/lanes/config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub const Model = struct {
window_costs: []const Cost = &.{}, // forward ms by exact window width (timed at load)
window_costs_lone: bool = false, // window_costs price a lone stream only; shared forwards use shared_costs
shared_drafts: u32 = 0, // allocate_shared_drafts: a shared round's most head drafts a stream (0: drafts)
shared_mtp_cap: u32 = 0, // most head drafts a stream chains in a shared round; a lone one chains `drafts` (0: off)
mtp_step_ms: f64 = 0.0, // one chained head step (timed at load)
shared_step_ms: ?f64 = null, // a separate shared head step; null keeps mtp_step_ms
draft_step_ms: f64 = 0.0, // a shared round's draft past a stream's first, as the backend's head runs it (0: priced free)
Expand Down Expand Up @@ -110,6 +111,7 @@ pub const Config = struct {
mtp_step_ms: f64,
draft_step_ms: f64 = 0, // Model.draft_step_ms
shared_drafts: u32 = 0, // Model.shared_drafts
shared_mtp_cap: u32 = 0, // Model.shared_mtp_cap
lone_cost_tile: u32 = 0, // Model.lone_cost_tile
context_copies: bool = false, // Model.context_copies, within the existing verification width
enter_match: i64 = 8, // matching tokens a copy needs (rejects coincidental indentation)
Expand Down Expand Up @@ -200,6 +202,7 @@ pub const Config = struct {
},
.draft_step_ms = m.draft_step_ms,
.shared_drafts = m.shared_drafts,
.shared_mtp_cap = m.shared_mtp_cap,
};
}

Expand Down
156 changes: 156 additions & 0 deletions zig/src/core/lanes/deep_chain_test.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
//! A lone stream chains up to a model's most drafts while shared rounds keep the model's shared cap.
const std = @import("std");
const depth = @import("depth.zig");

const empty: @import("table.zig").Table = .{};
const high: [7]f64 = @splat(0.95);
const low: [7]f64 = @splat(0.5);

const NoCopy = struct {
fn copy(_: *anyopaque, _: *const depth.Who) bool {
return false;
}
};

fn rule(prior: []const f64, shared_cap: u32) depth.Rule {
return .{
.gpa = std.testing.allocator,
.prior = prior,
.most_drafts = 7,
.shared_cap = shared_cap,
.family_costs = &empty,
.shared_costs = &empty,
.mtp_step_ms = 0,
.plain_guard = false,
.node_probabilities = false,
.batch_rows = 16,
};
}

fn who(state: *?depth.State) depth.Who {
return .{ .state = state, .draft_room = 100, .finished = false, .forced = false };
}

test "a lone stream asks for most_drafts on a high first-draft acceptance and stays low on a low one" {
var unused: u8 = 0;
const probe: depth.Probe = .{ .ptr = &unused, .copy = NoCopy.copy };
var r = rule(&high, 3);
defer r.deinit();
var s: ?depth.State = null;
defer if (s) |*x| x.deinit(std.testing.allocator);
try std.testing.expectEqual(@as(i64, 7), try r.headDepth(&who(&s), null, probe));
r.prior = &low;
var t: ?depth.State = null;
defer if (t) |*x| x.deinit(std.testing.allocator);
try std.testing.expectEqual(@as(i64, 1), try r.headDepth(&who(&t), null, probe));
}

test "streams that share a round chain at most the shared cap each" {
var unused: u8 = 0;
const probe: depth.Probe = .{ .ptr = &unused, .copy = NoCopy.copy };
var r = rule(&high, 3);
defer r.deinit();
var a: ?depth.State = null;
var b: ?depth.State = null;
defer if (a) |*x| x.deinit(std.testing.allocator);
defer if (b) |*x| x.deinit(std.testing.allocator);
var whos = [_]depth.Who{ who(&a), who(&b) };
var out: [2]i64 = undefined;
try r.budgets(&whos, probe, false, &out);
try std.testing.expect(out[0] > 0 and out[1] > 0);
try std.testing.expect(out[0] <= 3 and out[1] <= 3);
}

test "a zero shared cap keeps the ladder's top of three for a lone stream and most_drafts for shared budgets" {
var unused: u8 = 0;
const probe: depth.Probe = .{ .ptr = &unused, .copy = NoCopy.copy };
var r = rule(&high, 0);
defer r.deinit();
var a: ?depth.State = null;
var b: ?depth.State = null;
defer if (a) |*x| x.deinit(std.testing.allocator);
defer if (b) |*x| x.deinit(std.testing.allocator);
try std.testing.expectEqual(@as(i64, 3), try r.headDepth(&who(&a), null, probe));
var whos = [_]depth.Who{ who(&a), who(&b) };
var out: [2]i64 = undefined;
try r.budgets(&whos, probe, false, &out);
try std.testing.expect(out[0] > 3 or out[1] > 3);
}

test "under a confidence floor or node probabilities a shared round chains at most the cap; a lone stream chains seven" {
var unused: u8 = 0;
const probe: depth.Probe = .{ .ptr = &unused, .copy = NoCopy.copy };
inline for (.{ .{ 0.5, false }, .{ null, false }, .{ null, true } }) |c| {
for ([_]u32{ 3, 0 }) |cap| {
var r = rule(&high, cap);
defer r.deinit();
r.node_probabilities = true;
r.confidence_floor = c[0];
r.granted_depth = c[1];
var a: ?depth.State = null;
var b: ?depth.State = null;
defer if (a) |*x| x.deinit(std.testing.allocator);
defer if (b) |*x| x.deinit(std.testing.allocator);
try std.testing.expectEqual(@as(i64, 7), try r.headDepth(&who(&a), null, probe));
var whos = [_]depth.Who{ who(&a), who(&b) };
var out: [2]i64 = undefined;
try r.budgets(&whos, probe, false, &out);
const want: i64 = if (cap == 0) 7 else 3;
try std.testing.expectEqualSlices(i64, &.{ want, want }, &out);
}
}
}

test "allocated shared rows, granted or not, reserve at most the shared cap a stream" {
const a = std.testing.allocator;
const Cfg = @import("config.zig");
const fake = @import("fake.zig");
const S = @import("stream.zig").Stream;
const win = @import("windows.zig");
for ([_]bool{ false, true }) |granted| {
for ([_]u32{ 3, 0 }) |cap| {
var cfg = try Cfg.Config.init(a, .{ .exact_width = 8, .drafts = 7, .shared_mtp_cap = cap, .allocate_shared_drafts = true, .draft_probabilities = granted, .granted_depth = granted, .batch_rows = 16 }, 8, 7);
defer cfg.deinit(a);
var back: fake.Fake = .{ .gpa = a };
defer back.deinit();
var clock: fake.FixedClock = .{};
var e = @import("engine.zig").Engine.init(a, &cfg, back.backend(), clock.clock());
defer e.deinit();
var one = try S.init(a, .{ .id = "one", .prompt = &.{ 7, 13, 29 }, .max_new = 64 });
defer one.deinit(a);
var two = try S.init(a, .{ .id = "two", .prompt = &.{ 7, 13, 29 }, .max_new = 64 });
defer two.deinit(a);
try one.draft_chances.appendNTimes(a, 1, 7);
try two.draft_chances.appendNTimes(a, 1, 7);
const plans = [_]win.Plan{ .{ .stream = &one, .position = 0, .kind = .none }, .{ .stream = &two, .position = 0, .kind = .none } };
var out: [2]i64 = undefined;
try @import("shared_drafts.zig").budgets(&e, &plans, &.{ 0, 1 }, &out);
const want: i64 = if (cap == 0) 7 else 3;
try std.testing.expectEqualSlices(i64, &.{ want, want }, &out);
}
}
}

test "a stream that opens beside a live one takes at most the shared cap as its first drafts" {
const a = std.testing.allocator;
const Cfg = @import("config.zig");
const fake = @import("fake.zig");
const S = @import("stream.zig").Stream;
for ([_]u32{ 3, 0 }) |cap| {
var cfg = try Cfg.Config.init(a, .{ .exact_width = 8, .drafts = 7, .shared_mtp_cap = cap, .draft_probabilities = true, .batch_rows = 16 }, 8, 7);
defer cfg.deinit(a);
var back: fake.Fake = .{ .gpa = a };
defer back.deinit();
var clock: fake.FixedClock = .{};
var e = @import("engine.zig").Engine.init(a, &cfg, back.backend(), clock.clock());
defer e.deinit();
var live = try S.init(a, .{ .id = "live", .prompt = &.{ 7, 13, 29 }, .max_new = 64 });
defer live.deinit(a);
var s = try S.init(a, .{ .id = "new", .prompt = &.{ 7, 13, 29 }, .max_new = 64 });
defer s.deinit(a);
try std.testing.expectEqual(@as(u32, 7), try @import("open.zig").firstDepth(&e, &s, .head));
try e.live.append(a, &live);
defer e.live.clearRetainingCapacity();
try std.testing.expectEqual(@as(u32, if (cap == 0) 7 else 3), try @import("open.zig").firstDepth(&e, &s, .head));
}
}
13 changes: 7 additions & 6 deletions zig/src/core/lanes/depth.zig
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub const Rule = struct {
k: Constants = .{},
prior: []const f64,
most_drafts: u32,
shared_cap: u32 = 0, // Model.shared_mtp_cap: most a shared round chains a stream; a lone one chains most_drafts (0: off)
family_costs: *const Table,
shared_costs: *const Table,
mtp_step_ms: f64,
Expand Down Expand Up @@ -172,7 +173,7 @@ pub const Rule = struct {
if (r.confidence_floor != null and !who.sampled and !r.k.floor_rates) return most;
const p = try r.rates(who);
if (r.family_costs.empty()) {
const want: i64 = if (p[0] < 0.8) 1 else if (p[0] < 0.9) 2 else 3;
const want: i64 = if (p[0] < 0.8) 1 else if (p[0] < 0.9) 2 else if (r.shared_cap != 0) r.most_drafts else 3;
return @max(1, @min(most, want));
}
const st = try r.state(who);
Expand Down Expand Up @@ -390,15 +391,15 @@ pub const Rule = struct {
const streams = if (paired != null) total_streams else whos.len;
// drafts lose here: none asked, no head pass
if (r.plain_streams > 0 and whos.len >= r.plain_streams) return @memset(out, 0);
const top: i64 = if (r.shared_cap != 0) @min(r.most_drafts, r.shared_cap) else r.most_drafts;
if (r.confidence_floor != null) {
for (whos, out) |*w, *o| o.* = try r.headDepth(w, null, probe);
for (whos, out) |*w, *o| o.* = @min(try r.headDepth(w, null, probe), top);
return;
}
if (r.node_probabilities) {
for (whos, out) |*w, *o| {
const inner = try r.headDepth(w, null, probe);
const granted: i64 = if (w.granted) |g| g else r.most_drafts;
o.* = if (r.granted_depth) inner else try r.headDepth(w, @min(inner, granted + r.k.draft_slack), probe);
const inner = @min(try r.headDepth(w, null, probe), top);
o.* = if (r.granted_depth) inner else try r.headDepth(w, @min(inner, @as(i64, w.granted orelse r.most_drafts) + r.k.draft_slack), probe);
}
if (r.granted_depth) capPass(out, r.batch_rows);
if (r.granted_depth and r.k.hold_costs.len > 0) try r.payHoldsFor(whos, sampled, out, total_streams);
Expand All @@ -412,7 +413,7 @@ pub const Rule = struct {
var made: usize = 0;
defer for (probs[0..made]) |p| r.gpa.free(p);
for (whos, most, probs[0..whos.len]) |w, *m, *p| {
m.* = @min(@as(i64, r.most_drafts), @max(1, w.draft_room - 1));
m.* = @min(top, @max(1, w.draft_room - 1));
p.* = try alloc.chainProbabilities(r.gpa, try r.rates(w), @intCast(m.*));
made += 1;
}
Expand Down
5 changes: 2 additions & 3 deletions zig/src/core/lanes/engine.zig
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub const Engine = struct {
.k = cfg.k,
.prior = cfg.depth_prior,
.most_drafts = cfg.most_drafts,
.shared_cap = cfg.shared_mtp_cap,
.family_costs = &cfg.family_costs,
.shared_costs = &cfg.shared_costs,
.mtp_step_ms = cfg.mtp_step_ms,
Expand Down Expand Up @@ -128,9 +129,7 @@ pub const Engine = struct {
}
if (live.items.len > 1 and e.cfg.family_streams) {
// a shared round is synchronous: a stream that ran a step ahead lands its queued token first
for (live.items) |s| {
if (s.inflight != null) try e.landInflight(s);
}
for (live.items) |s| if (s.inflight != null) try e.landInflight(s);
var kept: usize = 0;
for (live.items) |s| {
if (s.finished) continue;
Expand Down
1 change: 1 addition & 0 deletions zig/src/core/lanes/lanes.zig
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ test {
std.testing.refAllDecls(@This());
_ = @import("engine_test.zig");
_ = @import("plain_streams_test.zig");
_ = @import("deep_chain_test.zig");
_ = @import("late_draft_test.zig");
_ = @import("long_loop.zig");
_ = @import("long_loop_test.zig");
Expand Down
4 changes: 2 additions & 2 deletions zig/src/core/lanes/open.zig
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ fn openedCommitted(e: *Engine, s: *Stream, reach: Reach, hook: ?be.Committed) !v
/// The first drafts' depth for `reach`.
pub fn firstDepth(e: *Engine, s: *Stream, reach: Reach) !u32 {
var who = win.who(s);
if (reach == .head and e.cfg.node_probabilities) return @intCast(try e.rule.headDepth(&who, null, win.probe(e)));
return @intCast(try e.rule.depth(who));
const d = if (reach == .head and e.cfg.node_probabilities) try e.rule.headDepth(&who, null, win.probe(e)) else try e.rule.depth(who);
return @intCast(if (e.cfg.shared_mtp_cap > 0 and e.live.items.len > 0) @min(d, e.cfg.shared_mtp_cap) else d); // joins a shared round
}

/// Whether the backend can run a prompt pass a chunk at a time between rounds (`fillStream`).
Expand Down
3 changes: 2 additions & 1 deletion zig/src/core/lanes/shared_drafts.zig
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ pub fn budgets(e: *Engine, plans: []const win.Plan, heads: []const usize, out: [
if (!s.drafts) continue;
const cap = if (e.backend.vtable.draft_capacity) |f| f(e.backend.ptr, s) else e.cfg.most_drafts;
const shared = if (e.cfg.shared_drafts > 0) e.cfg.shared_drafts else e.cfg.most_drafts; // Model.shared_drafts
const most = @min(cap, shared, e.cfg.most_drafts, if (limits) |l| l.depths[i] else e.cfg.most_drafts, @as(u32, @intCast(@max(0, s.draftRoom() - 1))));
const chain = if (e.cfg.shared_mtp_cap > 0) e.cfg.shared_mtp_cap else e.cfg.most_drafts; // Model.shared_mtp_cap
const most = @min(cap, shared, chain, e.cfg.most_drafts, if (limits) |l| l.depths[i] else e.cfg.most_drafts, @as(u32, @intCast(@max(0, s.draftRoom() - 1))));
if (most == 0) continue;
head.* = true;
const cached = s.draft_chances.items;
Expand Down
1 change: 1 addition & 0 deletions zig/src/families/flashnext/hip.zig
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ test {
_ = native;
_ = @import("hip/state_test.zig");
_ = @import("hip/fused_prep_test.zig");
_ = @import("hip/mtp_drafts_test.zig");
}
Loading
Loading