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 Metal without an MTP head: concurrent streams now share one exact round instead of taking turns. Replies are unchanged. On an M5 Ultra, two streams decode about 20% faster, four streams about 75%, eight streams 2.3 to 2.5 times as fast and 24 streams 3.2 to 3.5 times; one stream is unchanged (#3005, for #2968).

- HIP: the TCP fabric Kind gains its device side for two hosts over a network link: staged copies through mapped host memory, a stream that waits on a peer's counter, a 30 s limit on each proxy copy, and every rank refusing a bad part size together. Nothing selects the Kind yet (#2961). Thanks to @Shoestring-dev.

- GLM-5.3-Flash on CUDA: a decode window's DSA select spreads each row over many blocks (`TF_GLM_DSEL`, default on; `TF_GLM_DSEL=0` keeps one block a row) and picks `tf_glm_select_rows`' pools. At TP=4 on four GB10s, the decode round after a 1,040,384-token prompt is 5.05%, 9.36% and 11.36% shorter at 1, 4 and 8 streams, with every reply unchanged (#2722). Ported from patch 0067 of Mia's AI Lab's GLM-5.3-Flash stack. Thanks to Mia's AI Lab (@MiaAI-Lab).
Expand Down
3 changes: 2 additions & 1 deletion zig/src/core/lanes/config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub const Model = struct {
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)
streams_exact: bool = true, // shared forwards keep each stream's bits
plain_share: bool = false, // width-one streams may share a forward without a wider per-stream window
hidden_rows: bool = false, // the backend runs several streams' windows in one forward
batch_rows: u32 = 0, // a shared forward's rows at most (0: 32)
max_streams: u32 = 0, // a shared forward's streams at most (0: 32)
Expand Down Expand Up @@ -122,7 +123,7 @@ pub const Config = struct {
const first_rows: i64 = if (m.first_copy_rows != 0) m.first_copy_rows else width;
const first_copy: u32 = @intCast(@max(1, @min(@as(i64, max_copy), first_rows - 1)));
const prior = if (m.draft_prior.len > 0) m.draft_prior else &default_prior;
const streams = width >= 2 and m.streams_exact and m.hidden_rows;
const streams = (width >= 2 or m.plain_share) and m.streams_exact and m.hidden_rows;
const batch_rows: u32 = if (m.batch_rows != 0) m.batch_rows else 32;
var family_costs: Table = .{};
errdefer family_costs.deinit(gpa);
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 @@ -62,6 +62,7 @@ pub const Trim = trim.Trim;
test {
std.testing.refAllDecls(@This());
_ = @import("engine_test.zig");
_ = @import("plain_streams_test.zig");
_ = @import("late_draft_test.zig");
_ = @import("long_loop.zig");
_ = @import("long_loop_test.zig");
Expand Down
100 changes: 100 additions & 0 deletions zig/src/core/lanes/plain_streams_test.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//! Plain cross-stream sharing has its own capability, without widening a stream's verification window.
const std = @import("std");
const setup = @import("config.zig");
const Engine = @import("engine.zig").Engine;
const be = @import("backend.zig");
const sm = @import("stream.zig");
const fake = @import("fake.zig");
const a = std.testing.allocator;

const Watch = struct {
var inner_verify: *const fn (*anyopaque, []const be.Window, []be.Verified) anyerror!void = undefined;
var inner_queue: *const fn (*anyopaque, *sm.Stream, be.Feed, u64) anyerror!u64 = undefined;
var widest: usize = 0;
var queues: usize = 0;
fn verify(ptr: *anyopaque, windows: []const be.Window, out: []be.Verified) !void {
widest = @max(widest, windows.len);
for (windows) |w| try std.testing.expectEqual(@as(usize, 1), w.rows());
try inner_verify(ptr, windows, out);
}
fn queue(ptr: *anyopaque, s: *sm.Stream, feed: be.Feed, position: u64) !u64 {
queues += 1;
return inner_queue(ptr, s, feed, position);
}
};
const Result = struct { tokens: [4][32]u32 = undefined, widest: usize, queues: usize };
fn run(n: usize, sharing: bool, sampled: bool, drafts: bool, staggered: bool) !Result {
var target: fake.Fake = .{ .gpa = a };
defer target.deinit();
var backend = target.backend();
var hooks = backend.vtable.*;
Watch.inner_verify = hooks.verify;
Watch.inner_queue = hooks.queue;
Watch.widest = 0;
Watch.queues = 0;
hooks.verify = Watch.verify;
hooks.queue = Watch.queue;
backend.vtable = &hooks;
var cfg = try setup.Config.init(a, .{ .plain_share = sharing, .gpu_tokens = true, .hidden_rows = true, .batch_rows = 4, .max_streams = 4 }, 16, 15);
defer cfg.deinit(a);
var clock: fake.FixedClock = .{};
var engine = Engine.init(a, &cfg, backend, clock.clock());
defer engine.deinit();
var streams: [4]sm.Stream = undefined;
const prompt = [_]u32{ 1, 5, 9, 2, 8, 3, 7 };
for (streams[0..n], 0..) |*s, i| s.* = try sm.Stream.init(a, .{ .id = "plain", .prompt = prompt[0 .. 3 + i], .max_new = 32, .drafts = drafts, .sampling = if (sampled) .{ .seed = 7 + i, .temperature = 0.7, .top_k = 20, .top_p = 0.95 } else null });
defer for (streams[0..n]) |*s| s.deinit(a);
for (streams[0..n], 0..) |*s, i| {
try engine.addStream(s);
if (staggered and i == 0) for (0..4) |_| try engine.step();
}
var steps: usize = 0;
while (engine.activeCount() > 0) : (steps += 1) {
if (steps > 256) return error.RoundLoopDidNotFinish;
try engine.step();
}
var result: Result = .{ .widest = Watch.widest, .queues = Watch.queues };
for (streams[0..n], 0..) |*s, i| {
try std.testing.expectEqual(@as(usize, 32), s.emitted().len);
@memcpy(&result.tokens[i], s.emitted());
}
try std.testing.expectEqual(@as(usize, 0), target.drafts_calls);
try std.testing.expectEqual(@as(u64, 0), engine.drafted);
return result;
}

test "plain sharing: width one may share streams without increasing drafts or copies" {
var c = try setup.Config.init(a, .{ .plain_share = true, .gpu_tokens = true, .hidden_rows = true, .batch_rows = 4, .max_streams = 4 }, 16, 15);
defer c.deinit(a);
try std.testing.expect(c.family_streams and c.pipelined);
try std.testing.expectEqual(@as(u32, 4), c.batch_streams);
try std.testing.expectEqual(@as(u32, 1), c.family_width);
try std.testing.expectEqual(@as(u32, 1), c.base_width);
try std.testing.expectEqual(@as(u32, 0), c.max_copy);
try std.testing.expectEqual(@as(u32, 0), c.most_drafts);
try std.testing.expect(!c.family_mtp);
for ([_]setup.Model{
.{ .hidden_rows = true },
.{ .plain_share = true },
.{ .plain_share = true, .hidden_rows = true, .streams_exact = false },
}) |m| {
var off = try setup.Config.init(a, m, 16, 15);
defer off.deinit(a);
try std.testing.expect(!off.family_streams);
try std.testing.expectEqual(@as(u32, 1), off.batch_streams);
}
}

test "plain sharing: synchronous streams equal pipelined solo and keep the lone path" {
for ([_]bool{ false, true }) |sampled| for ([_]bool{ false, true }) |drafts| {
for ([_]usize{ 1, 2, 3, 4 }) |n| for ([_]bool{ false, true }) |staggered| {
const before = try run(n, false, sampled, drafts, staggered);
const after = try run(n, true, sampled, drafts, staggered);
for (0..n) |i| try std.testing.expectEqualSlices(u32, &before.tokens[i], &after.tokens[i]);
if (n > 1) try std.testing.expectEqual(n, after.widest) else {
try std.testing.expectEqual(@as(usize, 0), after.widest);
try std.testing.expectEqual(before.queues, after.queues);
}
};
};
}
1 change: 1 addition & 0 deletions zig/src/families/nemotron/backend.zig
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ pub const Metal = struct {
.window_costs = self.costs.window[0..@min(self.costs.windows, max_window)],
.mtp_step_ms = self.costs.head_ms,
.hidden_rows = true,
.plain_share = true,
.batch_rows = @intCast(self.o.batch_rows),
.max_streams = @intCast(self.o.streams),
.shared_costs = self.costs.shared[0..self.costs.shareds],
Expand Down
19 changes: 19 additions & 0 deletions zig/src/native/metal.zig
Original file line number Diff line number Diff line change
Expand Up @@ -546,3 +546,22 @@ test "Metal capabilities: fish_omni retains FP8 and includes its native NVFP4 ex
};
try std.testing.expect(fp8 and nvfp4);
}

test "plain sharing: Nemotron without a head shares streams without widening its window" {
var b: nemotron.backend.Metal = undefined;
b.o = .{ .capacity = 4096, .streams = 4, .batch_rows = 32, .drafts = false };
b.head = null;
b.costs = .{};
const facts = b.facts();
try std.testing.expect(facts.plain_share and facts.hidden_rows);
try std.testing.expectEqual(@as(u32, 1), facts.exact_width);
try std.testing.expect(!facts.mtp and !facts.speculate and !facts.allocate_shared_drafts);
var config = try lanes.Config.init(std.testing.allocator, facts, nemotron.backend.max_window, nemotron.backend.max_window - 1);
defer config.deinit(std.testing.allocator);
try std.testing.expect(config.family_streams and config.pipelined);
try std.testing.expectEqual(@as(u32, 4), config.batch_streams);
try std.testing.expectEqual(@as(u32, 1), config.family_width);
try std.testing.expectEqual(@as(u32, 0), config.max_copy);
try std.testing.expectEqual(@as(u32, 0), config.most_drafts);
try std.testing.expect(!config.family_mtp);
}
Loading