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

- GLM-5.3-Flash on CUDA with a DFlash2 drafter: shared rounds size each stream's drafts by its last grant plus the slack again, trimmed at verify, instead of pricing them first from chances the drafter's chain cut zeroed, so a stream no longer stays at no drafts while its peers decode. On two GB10s at TP=2 with distinct prompts, four-stream decode is 3.7% faster greedy and 3.5% faster at temperature 0.7; one stream, the MTP head and every reply's tokens are unchanged (#2793, fixes #2720). Thanks to @kelchm.

- Tests: three serving pins take their files' new hashes after #2609, #2680 and #2709 changed them, so `zig build test-gradient-serving` passes on main again; test files only (#2798).

- Qwen3.8-27B on Metal: a client that sends earlier replies back without their reasoning now resumes a follow-up turn at the end of its last message instead of far short of it. On an M3 Ultra with `--prompt-cache-gib 5` and a 34K history, such turns resume about 34,100 tokens instead of 7,424, with the first token in about 0.3 s instead of 85 s, while clients that keep the reasoning resume as before; replies are unchanged (#2811, fixes #2791).
Expand Down
2 changes: 1 addition & 1 deletion zig/src/families/glm/cuda_lanes.zig
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub const Lanes = struct {
const costs = if (block) null else if (self.costs) |*c| c else null;
const sharing = drafting and !self.alone;
return .{
.allocate_shared_drafts = drafting,
.allocate_shared_drafts = drafting and !block, // cut chances would price a block's stream at none
.exact_width = if (drafting) max_rows else 1,
.first_copy_rows = 4, // a first copy starts narrow; it grows as its tokens land
.gpu_tokens = false,
Expand Down
99 changes: 90 additions & 9 deletions zig/src/families/glm/cuda_zero_budget_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,99 @@ const engine = @import("cuda_engine.zig");
const dflash = @import("dflash.zig");
const proposals = @import("dflash_proposals.zig");

test "zero grant: GLM CUDA MTP and DFlash2 preserve tokens through a long skip" {
test "zero grant: GLM CUDA MTP preserves tokens through a long skip" {
var e: engine.Engine = undefined;
e.mtp = true;
for ([_]bool{ false, true }) |block| {
e.drafter = if (block) @ptrFromInt(16) else null;
var b: @import("cuda_lanes.zig").Lanes = undefined;
b.x.e = &e;
b.alone = false;
b.mtp_confidence = null;
b.costs = null;
try lanes.shared_draft_check.check(b.facts(), false);
e.drafter = null;
var b: @import("cuda_lanes.zig").Lanes = undefined;
b.x.e = &e;
b.alone = false;
b.mtp_confidence = null;
b.costs = null;
try lanes.shared_draft_check.check(b.facts(), false);
}

/// The fake target with DFlash2's chain cut: one stream's first block held a weak draft and zeros, its later ones sure.
const Cut = struct {
target: lanes.fake.Fake = .{ .gpa = std.testing.allocator },
stream: ?*lanes.Stream = null,
cuts: u32 = 1, // the stream's blocks still to cut
cut: bool = false, // its held block was cut
depths: std.ArrayList(u32) = .empty, // its depth in each shared round from its first grant of none

fn of(ptr: *anyopaque) *Cut {
return @fieldParentPtr("target", @as(*lanes.fake.Fake, @ptrCast(@alignCast(ptr))));
}

fn draft(ptr: *anyopaque, reqs: []const lanes.backend.DraftRequest) !void {
const c = of(ptr);
for (reqs) |r| if (r.stream == c.stream) {
if (reqs.len > 1 and (c.depths.items.len > 0 or r.stream.granted == 0)) try c.depths.append(std.testing.allocator, r.depth);
c.cut = r.depth > 0 and c.cuts > 0;
if (c.cut) c.cuts -= 1;
};
try c.target.backend().vtable.draft(ptr, reqs);
}

fn chances(ptr: *anyopaque, s: *lanes.Stream, out: []f64) !bool {
const c = of(ptr);
var chain: f64 = 1;
for (out, 0..) |*o, j| {
chain *= if (s != c.stream or !c.cut) 0.9 else if (j == 0) 0.05 else 0;
o.* = chain;
}
return true;
}
};

/// Three streams decoded together, the first cut once: its depths from its first grant of none.
fn cutDepths(m: lanes.Model, shared: bool) !std.ArrayList(u32) {
const a = std.testing.allocator;
var c: Cut = .{};
defer c.target.deinit();
errdefer c.depths.deinit(a);
var table = c.target.backend().vtable.*;
table.draft = Cut.draft;
table.probabilities = Cut.chances;
var model = m;
model.allocate_shared_drafts = shared;
var cfg = try lanes.Config.init(a, model, model.exact_width, model.drafts);
defer cfg.deinit(a);
cfg.timed = false;
var clock: lanes.fake.FixedClock = .{};
var e = lanes.Engine.init(a, &cfg, .{ .ptr = &c.target, .vtable = &table }, clock.clock());
defer e.deinit();
var streams: [3]lanes.Stream = undefined;
var made: usize = 0;
defer for (streams[0..made]) |*s| s.deinit(a);
for (&streams, 0..) |*s, i| {
s.* = try lanes.Stream.init(a, .{ .id = "cut", .prompt = &.{ 7, 13, @intCast(i) }, .max_new = 96 });
made += 1;
}
c.stream = &streams[0];
for (&streams) |*s| try e.addStream(s);
for (0..1000) |_| if (e.activeCount() > 0) try e.step();
try std.testing.expectEqual(@as(usize, 0), e.activeCount());
return c.depths;
}

test "zero grant: a GLM DFlash2 stream cut to none drafts again within a few rounds while its peers decode" {
var e: engine.Engine = undefined;
e.mtp = true;
e.drafter = @ptrFromInt(16);
var b: @import("cuda_lanes.zig").Lanes = undefined;
b.x.e = &e;
b.alone = false;
b.mtp_confidence = null;
b.costs = null;
const m = b.facts();
var fixed = try cutDepths(m, m.allocate_shared_drafts);
defer fixed.deinit(std.testing.allocator);
try std.testing.expect(fixed.items.len >= 3 and std.mem.max(u32, fixed.items[0..3]) > 0);
// priced from its cut chances, which only a drafted block refreshes, it stays at none while its peers decode
var priced = try cutDepths(m, true);
defer priced.deinit(std.testing.allocator);
try std.testing.expect(priced.items.len >= 32 and std.mem.allEqual(u32, priced.items[0..32], 0));
}

test "zero grant: GLM DFlash2 skips the actual block pass and transmits a stable proposal mask" {
Expand Down
2 changes: 1 addition & 1 deletion zig/src/native/copy_drafts_cuda_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const families = std.enums.values(Family);
fn mainFacts(family: Family) lanes.Model {
if (family == .glm_mtp or family == .glm_block) {
const block = family == .glm_block;
return .{ .allocate_shared_drafts = true, .exact_width = 32, .first_copy_rows = 4, .gpu_tokens = false, .mtp = true, .speculate = true, .speculate_early = false, .drafts = if (block) 7 else 15, .draft_streams = block, .mtp_step_ms = if (block) 1.6 / @as(f64, 7) else 0, .draft_probabilities = block, .window_costs = if (block) &glm_window_costs else &.{}, .shared_costs = if (block) &glm_shared_costs else &.{}, .shared_drafts = if (block) 0 else 3, .hidden_rows = true, .batch_rows = 32, .max_streams = 16 };
return .{ .allocate_shared_drafts = !block, .exact_width = 32, .first_copy_rows = 4, .gpu_tokens = false, .mtp = true, .speculate = true, .speculate_early = false, .drafts = if (block) 7 else 15, .draft_streams = block, .mtp_step_ms = if (block) 1.6 / @as(f64, 7) else 0, .draft_probabilities = block, .window_costs = if (block) &glm_window_costs else &.{}, .shared_costs = if (block) &glm_shared_costs else &.{}, .shared_drafts = if (block) 0 else 3, .hidden_rows = true, .batch_rows = 32, .max_streams = 16 };
}
if (family == .minimax or family == .minimax_head) {
const head = family == .minimax_head;
Expand Down
Loading