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

## Unreleased

- CUDA: a request's finished stats list its prompt pass widths for Qwen3.8-27B, GLM-5.3-Flash and Nemotron, appended
only where a pass is already known complete. Telemetry only (#2304).

- Prompt cache: `--learn` opens its kept states in linear time, so a server with 100,000 of them starts about 5 s sooner (8.0x faster open); the same states and files are kept (#2316).

- Fabric: a pipeline stage's boot and round loop is one driver, generic over an engine binding, so a CUDA, Metal or XPU stage writes only its binding; nothing uses it yet. A stop that a middle stage receives now passes on instead of closing the ring (#2241, part of #2005). Thanks to @jschmied.


Expand Down
1 change: 1 addition & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ pub fn build(b: *std.Build) void {
grammar_build.steps(b, target, xgrammar, lanes_cpu);
grammar_build.hostTests(b, test_step);
contract_build.hostTests(b, gemma4_contract_host);
@import("zig/build/startup_states_timing.zig").step(b);
// the CPU-only fake server and engine-less CLI (zig build server-cpu), behind zig/tests/server/build.sh
@import("zig/build/server.zig").cpuArtefacts(b, b.graph.host, optimize, build_options);
@import("zig/build/mcdma_pair.zig").add(b, target);
Expand Down
1 change: 1 addition & 0 deletions zig/build/cuda_family_host.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const std = @import("std");

pub fn steps(b: *std.Build, cuda: *std.Build.Module, mods: anytype, step: *std.Build.Step) void {
const host = b.graph.host;
@import("prefill_widths_cuda.zig").tests(b, cuda, mods, step);
const metal_scope = b.addRunArtifact(b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("zig/src/families/qwen3_5/config.zig"), .target = host }), .filters = &.{ "Metal 2B format scope:", "admit the affine 2B", "admit untied heads" } }));
b.step("test-qwen35-metal-scope-host", "Metal 2B format admission without device or Metal compiler").dependOn(&metal_scope.step);
@import("load_prefetch_host.zig").tests(b, mods.core, step);
Expand Down
16 changes: 16 additions & 0 deletions zig/build/prefill_widths_cuda.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//! Completed prompt observations at the three served CUDA families' existing waits, without devices.
const std = @import("std");
pub fn tests(b: *std.Build, cuda: *std.Build.Module, mods: anytype, all: *std.Build.Step) void {
const host = b.graph.host;
const m = b.createModule(.{ .root_source_file = b.path("zig/cuda_prefill_widths_host.zig"), .target = host, .optimize = .debug, .link_libc = true, .imports = &.{
.{ .name = "qwen35", .module = mods.qwen35 },
.{ .name = "nemotron", .module = mods.nemotron },
.{ .name = "glm", .module = @import("cuda_engines.zig").glmCuda(b, host, .debug, cuda, mods.core, mods.lanes, mods.heat, mods.api) },
.{ .name = "cuda", .module = cuda },
.{ .name = "lanes", .module = mods.lanes },
} });
const run = b.addRunArtifact(b.addTest(.{ .root_module = m, .filters = &.{"CUDA prefill widths:"} }));
run.has_side_effects = true;
b.step("test-cuda-prefill-widths-host", "Three CUDA prompt adapters at existing completion waits without devices").dependOn(&run.step);
all.dependOn(&run.step);
}
39 changes: 39 additions & 0 deletions zig/build/startup_states_timing.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//! test-startup-states-timing: startup's read of 1K, 10K and 100K kept states on disk, ReleaseFast, host only.
const std = @import("std");

const stores = [_][]const u8{ "rows", "imprint" };
const runs = 5;

pub fn step(b: *std.Build) void {
const host = b.graph.host;
if (host.result.os.tag != .macos and host.result.os.tag != .linux) return;
const counts = b.option([]const u8, "startup-states-counts", "Kept-state counts test-startup-states-timing seeds") orelse "1000,10000,100000";
const lanes = b.createModule(.{ .root_source_file = b.path("zig/src/core/lanes/lanes.zig"), .target = host, .optimize = .fast, .link_libc = true });
const root = b.createModule(.{
.root_source_file = b.path("zig/src/core/rows_startup_timing.zig"),
.target = host,
.optimize = .fast,
.link_libc = true,
.imports = &.{.{ .name = "lanes", .module = lanes }},
});
const exe = b.addExecutable(.{ .name = "tf-startup-states", .root_module = root });
const corpus = b.addRunArtifact(b.addTest(.{ .root_module = root, .filters = &.{"conversations keep canonical spans"} }));
const about = "Time startup's read of 1K, 10K and 100K kept states on disk, each store's open in 5 processes (no GPU)";
const top = b.step("test-startup-states-timing", about);
var last: *std.Build.Step = &corpus.step;
var it = std.mem.tokenizeScalar(u8, counts, ',');
while (it.next()) |n| for (stores) |s| {
var modes: [runs + 4][]const u8 = undefined;
modes[0] = "seed";
for (modes[1 .. runs + 1]) |*m| m.* = "open";
modes[runs + 1 ..].* = .{ "phases", "summary", "clean" };
for (modes) |mode| {
const run = b.addRunArtifact(exe);
run.addArgs(&.{ s, mode, n });
run.has_side_effects = true; // timings: run every time, one process after another
run.step.dependOn(last);
last = &run.step;
}
};
top.dependOn(last);
}
6 changes: 6 additions & 0 deletions zig/cuda_prefill_widths_host.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//! Three served CUDA prompt adapters over recording forwards, without a GPU or shader toolchain.
test {
_ = @import("prefill_widths_qwen_host.zig");
_ = @import("prefill_widths_glm_host.zig");
_ = @import("prefill_widths_nemo_host.zig");
}
23 changes: 23 additions & 0 deletions zig/prefill_widths_cuda_fake.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//! Existing CUDA stream waits over an inert driver, with a planted wait failure.
const cuda = @import("cuda");
pub const Driver = struct {
pub var fail = false;
pub var calls: usize = 0;
fn sync(_: cuda.abi.Stream) callconv(.c) c_int {
calls += 1;
return if (fail) cuda.abi.error_not_ready else 0;
}
fn name(_: c_int, out: *?[*:0]const u8) callconv(.c) c_int {
out.* = "fixture";
return 0;
}
pub fn init() cuda.Driver {
var d: cuda.Driver = undefined;
d.api.cuStreamSynchronize = sync;
d.api.cuGetErrorName = name;
d.api.cuGetErrorString = name;
fail = false;
calls = 0;
return d;
}
};
126 changes: 126 additions & 0 deletions zig/prefill_widths_glm_host.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
//! GLM's actual served step and batched-pass bodies over recording leader calls and real CUDA stream waits.
const std = @import("std");
const glm = @import("glm");
const cuda = @import("cuda");
const lanes = @import("lanes");
const Driver = @import("prefill_widths_cuda_fake.zig").Driver;
const t = std.testing;
const Lane = struct { slot: u32 = 0, first: ?u64 = null, fill: ?usize = null };
const Leader = struct {
e: *Engine,
fail: bool = false,
rows: usize = glm.engine.prompt_rows,
pub fn bind(_: @This(), _: u32) !void {}
pub fn chunk(x: @This(), ids: []const u32, at: usize, _: bool, _: anytype, _: anytype, _: anytype) !glm.follow.Chunk {
if (x.fail) return error.PlantedForward;
const rows = @min(x.rows, ids.len - at);
const last = at + rows == ids.len;
if (last) try x.e.stream.synchronize(); // Engine.prefillChunk draws the final row before returning.
return .{ .rows = rows, .first = if (last) 1 else null };
}
pub fn prefillMany(x: @This(), _: []const glm.engine.Prompt, tokens: []u32) !void {
if (x.fail) return error.PlantedForward;
try x.e.stream.synchronize(); // Engine.prefillMany draws each stream before returning.
@memset(tokens, 1);
}
};
const Engine = struct {
gpa: std.mem.Allocator = t.allocator,
stream: cuda.Stream,
prompt_logprobs: ?glm.prompt_logprobs.Want = null,
};
const Backend = struct {
x: Leader,
from: usize = 0,
lanes: std.AutoHashMapUnmanaged(*const lanes.Stream, Lane) = .empty,
pub fn opening(b: *@This(), _: *lanes.Stream) !?glm.engine.Resume {
return if (b.from > 0) .{ .id = 1, .at = b.from } else null;
}
pub fn images(_: *@This(), _: *lanes.Stream, _: anytype) !void {}
pub fn marksOf(_: *@This(), _: *lanes.Stream, _: anytype) ?glm.engine.Marks {
return null;
}
pub fn take(_: *@This(), token: u32) u64 {
return token;
}
};
test "CUDA prefill widths: GLM stepped cold, solo, one-pass and resumed real cuts" {
const cap = glm.engine.prompt_rows;
const ids = try t.allocator.alloc(u32, 2 * cap + 17);
defer t.allocator.free(ids);
@memset(ids, 1);
for ([_]usize{ 0, cap, 0, 0 }, 0..) |from, case| {
var d = Driver.init();
var s = try lanes.Stream.init(t.allocator, .{ .id = "glm", .prompt = if (case == 2) ids[0..7] else ids, .max_new = 1 });
defer s.deinit(t.allocator);
s.settle_step = true;
var e: Engine = .{ .stream = .{ .d = &d, .handle = null } };
var b: Backend = .{ .x = .{ .e = &e, .rows = if (case == 3) glm.engine.solo_rows else cap }, .from = from };
defer b.lanes.deinit(t.allocator);
try b.lanes.put(t.allocator, &s, .{});
while (!try glm.lanes.Lanes.prefillStep(&b, &s)) {}
const expected: []const u32 = if (case == 2) &.{7} else if (case == 3) &.{ glm.engine.solo_rows, 17 } else if (from == 0) &.{ cap, cap, 17 } else &.{ cap, 17 };
try t.expectEqualSlices(u32, expected, s.prefill_widths.items);
try t.expectEqual(expected.len, Driver.calls);
try t.expectEqual(@as(?u64, 1), b.lanes.get(&s).?.first);
}
}
test "CUDA prefill widths: GLM skips unsettled intermediate chunks" {
const ids: [2 * glm.engine.prompt_rows + 17]u32 = @splat(1);
var d = Driver.init();
var s = try lanes.Stream.init(t.allocator, .{ .id = "unsettled", .prompt = &ids, .max_new = 1 });
defer s.deinit(t.allocator);
var e: Engine = .{ .stream = .{ .d = &d, .handle = null } };
var b: Backend = .{ .x = .{ .e = &e } };
defer b.lanes.deinit(t.allocator);
try b.lanes.put(t.allocator, &s, .{});
for (0..2) |_| {
try t.expect(!try glm.lanes.Lanes.prefillStep(&b, &s));
try t.expectEqual(@as(usize, 0), s.prefill_widths.items.len);
try t.expectEqual(@as(usize, 0), Driver.calls);
}
try t.expect(try glm.lanes.Lanes.prefillStep(&b, &s));
try t.expectEqualSlices(u32, &.{17}, s.prefill_widths.items);
try t.expectEqual(@as(usize, 1), Driver.calls);
}
test "CUDA prefill widths: GLM failed launch, final readback and intermediate wait append nothing" {
const ids: [glm.engine.prompt_rows + 1]u32 = @splat(1);
for (0..3) |case| {
var d = Driver.init();
var s = try lanes.Stream.init(t.allocator, .{ .id = "failed", .prompt = if (case == 2) &ids else ids[0..1], .max_new = 1 });
defer s.deinit(t.allocator);
s.settle_step = true;
var e: Engine = .{ .stream = .{ .d = &d, .handle = null } };
var b: Backend = .{ .x = .{ .e = &e, .fail = case == 0 } };
defer b.lanes.deinit(t.allocator);
try b.lanes.put(t.allocator, &s, .{});
Driver.fail = case > 0;
const result = glm.lanes.Lanes.prefillStep(&b, &s);
if (case == 0) try t.expectError(error.PlantedForward, result) else try t.expectError(error.NotReady, result);
try t.expectEqual(@as(usize, 0), s.prefill_widths.items.len);
}
}
test "CUDA prefill widths: GLM batched pass credits each stream's own rows once after readback" {
var d = Driver.init();
var e: Engine = .{ .stream = .{ .d = &d, .handle = null } };
var b: Backend = .{ .x = .{ .e = &e } };
defer b.lanes.deinit(t.allocator);
var left = try lanes.Stream.init(t.allocator, .{ .id = "left", .prompt = &.{ 1, 2 }, .max_new = 1 });
defer left.deinit(t.allocator);
var right = try lanes.Stream.init(t.allocator, .{ .id = "right", .prompt = &.{ 1, 2, 3 }, .max_new = 1 });
defer right.deinit(t.allocator);
try b.lanes.put(t.allocator, &left, .{});
try b.lanes.put(t.allocator, &right, .{});
var tokens: [2]u32 = undefined;
const parts = [_]glm.engine.Prompt{ .{ .slot = 0, .ids = left.prompt() }, .{ .slot = 1, .ids = right.prompt() } };
b.x.fail = true;
try t.expectError(error.PlantedForward, glm.lanes.Lanes.many(&b, &.{ &left, &right }, &parts, &tokens));
b.x.fail = false;
Driver.fail = true;
try t.expectError(error.NotReady, glm.lanes.Lanes.many(&b, &.{ &left, &right }, &parts, &tokens));
try t.expectEqual(@as(usize, 0), left.prefill_widths.items.len + right.prefill_widths.items.len);
Driver.fail = false;
try glm.lanes.Lanes.many(&b, &.{ &left, &right }, &parts, &tokens);
try t.expectEqualSlices(u32, &.{2}, left.prefill_widths.items);
try t.expectEqualSlices(u32, &.{3}, right.prefill_widths.items);
}
59 changes: 59 additions & 0 deletions zig/prefill_widths_nemo_host.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//! Nemotron's served completion call over a recording engine and the existing CUDA stream wait.
const std = @import("std");
const n = @import("nemotron");
const cuda = @import("cuda");
const lanes = @import("lanes");
const Driver = @import("prefill_widths_cuda_fake.zig").Driver;
const t = std.testing;
const Engine = struct {
gpa: std.mem.Allocator = t.allocator,
stream: cuda.Stream,
last_chunk: usize = 0,
pos: usize = 0,
fail: bool = false,
cancel: bool = false,
pub fn prefillFrom(e: *@This(), ids: []const u32, _: usize, _: anytype, _: anytype, _: anytype, _: anytype) !u32 {
if (e.fail) return error.PlantedForward;
if (e.cancel) return error.Cancelled;
try e.stream.synchronize(); // cuda_prompt.prefillFrom downloads the first token, then waits.
e.pos = ids.len;
return 1;
}
};
test "CUDA prefill widths: Nemotron one target pass and resumed pass report only rows run" {
const ids: [n.state.pass_rows + 7]u32 = @splat(1);
for ([_]usize{ 0, n.state.pass_rows, 0 }, 0..) |from, case| {
var d = Driver.init();
var s = try lanes.Stream.init(t.allocator, .{ .id = "nemo", .prompt = if (case == 0) ids[0..7] else if (case == 2) ids[0..n.state.pass_rows] else &ids, .max_new = 1 });
defer s.deinit(t.allocator);
var e: Engine = .{ .stream = .{ .d = &d, .handle = null }, .last_chunk = from, .pos = from };
try t.expectEqual(@as(u32, 1), try n.Lanes.servedPrefill(&e, null, &s, from, null));
try t.expectEqualSlices(u32, &.{if (case == 2) n.state.pass_rows else 7}, s.prefill_widths.items);
try t.expectEqual(@as(usize, 1), Driver.calls);
}
}
test "CUDA prefill widths: Nemotron multi-chunk serial, background and segmented calls stay unrecorded" {
const ids: [2 * n.state.pass_rows + 17]u32 = @splat(1);
for ([_]usize{ 0, n.state.pass_rows, 0 }, 0..) |from, case| {
var d = Driver.init();
var s = try lanes.Stream.init(t.allocator, .{ .id = "skipped", .prompt = &ids, .max_new = 1 });
defer s.deinit(t.allocator);
const last = if (case == 1) ids.len - 1 else ids.len - 17;
var e: Engine = .{ .stream = .{ .d = &d, .handle = null }, .last_chunk = last, .pos = from };
_ = try n.Lanes.servedPrefill(&e, null, &s, from, null);
try t.expectEqual(@as(usize, 0), s.prefill_widths.items.len);
try t.expectEqual(@as(usize, 1), Driver.calls);
}
}
test "CUDA prefill widths: Nemotron failed launch, readback and cancellation append nothing" {
for (0..3) |case| {
var d = Driver.init();
var s = try lanes.Stream.init(t.allocator, .{ .id = "failed", .prompt = &.{1}, .max_new = 1 });
defer s.deinit(t.allocator);
var e: Engine = .{ .stream = .{ .d = &d, .handle = null }, .fail = case == 0, .cancel = case == 2 };
Driver.fail = case == 1;
const result = n.Lanes.servedPrefill(&e, null, &s, 0, null);
if (case == 0) try t.expectError(error.PlantedForward, result) else if (case == 1) try t.expectError(error.NotReady, result) else try t.expectError(error.Cancelled, result);
try t.expectEqual(@as(usize, 0), s.prefill_widths.items.len);
}
}
69 changes: 69 additions & 0 deletions zig/prefill_widths_qwen_host.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//! The real Qwen CUDA prompt loop over a recording engine whose forward finishes before returning.
const std = @import("std");
const q = @import("qwen35");
const lanes = @import("lanes");
const cuda = @import("cuda");
const Driver = @import("prefill_widths_cuda_fake.zig").Driver;
const t = std.testing;
const Cache = struct { delta: i64 = 0 };
const Engine = struct {
fail: bool = false,
stream: ?cuda.Stream = null,
pub fn forward(e: *@This(), _: anytype, _: []const u32, _: q.engine.Keep) !void {
if (e.fail) return error.PlantedForward;
if (e.stream) |stream| try stream.synchronize();
}
};
const Backend = struct {
gpa: std.mem.Allocator = t.allocator,
e: *Engine,
cache: Cache = .{},
prefix: ?struct {
pub fn keep(_: @This(), _: *Cache, _: []const u32, _: usize) !void {}
} = null,
pages: ?struct {
pub fn log(_: @This(), _: usize, _: u32) void {}
} = null,
pub fn cacheOf(b: *@This(), _: *lanes.Stream) !*Cache {
return &b.cache;
}
};
test "CUDA prefill widths: Qwen target cold cuts, one pass, resumed cuts and a failed forward" {
const cap = q.engine.max_rows;
const ids = try t.allocator.alloc(u32, 2 * cap + 17);
defer t.allocator.free(ids);
@memset(ids, 1);
for ([_]usize{ 0, cap, 0 }, 0..) |from, case| {
var d = Driver.init();
var e: Engine = .{ .stream = .{ .d = &d, .handle = null } };
var b: Backend = .{ .e = &e };
const prompt = if (case == 2) ids[0..7] else ids;
var s = try lanes.Stream.init(t.allocator, .{ .id = "qwen", .prompt = prompt, .chunks = &.{13}, .max_new = 1 });
defer s.deinit(t.allocator);
var f: q.prefill.Fill = .{ .at = from, .media = null };
while (!try q.prefill.chunk(&b, &s, &f, 0)) {}
const expected: []const u32 = if (case == 2) &.{7} else if (from == 0) &.{ 13, cap, cap, 4 } else &.{ cap, 17 };
try t.expectEqualSlices(u32, expected, s.prefill_widths.items);
try t.expectEqual(expected.len, Driver.calls);
}
var e: Engine = .{ .fail = true };
var b: Backend = .{ .e = &e };
var s = try lanes.Stream.init(t.allocator, .{ .id = "failed", .prompt = &.{1}, .max_new = 1 });
defer s.deinit(t.allocator);
var f: q.prefill.Fill = .{ .at = 0, .media = null };
try t.expectError(error.PlantedForward, q.prefill.chunk(&b, &s, &f, 0));
try t.expectEqual(@as(usize, 0), s.prefill_widths.items.len);
}

test "CUDA prefill widths: Qwen failed completion wait records no target pass" {
var d = Driver.init();
var e: Engine = .{ .stream = .{ .d = &d, .handle = null } };
var b: Backend = .{ .e = &e };
var s = try lanes.Stream.init(t.allocator, .{ .id = "wait", .prompt = &.{1}, .max_new = 1 });
defer s.deinit(t.allocator);
var f: q.prefill.Fill = .{ .at = 0, .media = null };
Driver.fail = true;
try t.expectError(error.NotReady, q.prefill.chunk(&b, &s, &f, 0));
try t.expectEqual(@as(usize, 0), f.at);
try t.expectEqual(@as(usize, 0), s.prefill_widths.items.len);
}
Loading
Loading