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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel
- CUDA: refresh 13 nvcc 13.0 register-count slots from the five-SM 13.0.88 audit; other compiler records and launch geometry stay unchanged (#2515, refs #2395).

- 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 known complete. Telemetry only (#2304).
- GLM CUDA: bound the peer warm-up after NCCL init to 300 seconds, aborting its communicator and stopping every rank with the missing peers and observed transport named on timeout (#2512, part of #2347).

- 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).

Expand Down
8 changes: 5 additions & 3 deletions zig/src/cuda/tp_watch.zig
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ pub fn fatal(name: []const u8) void {
}

/// Ends this process at once: a stream may hold kernels that wait on the gone rank, which a normal exit would join.
fn stop() noreturn {
pub fn stop() noreturn {
platform.c._exit(1);
}

Expand Down Expand Up @@ -491,9 +491,10 @@ const ProcessTest = struct {
}
}
if (mode == 3) return error.InjectedParentFailure;
if (mode == 1) {
if (mode == 1 or mode == 4) {
var record: Record = .{ .kind = error_kind, .rank = 1 };
@memcpy(record.text[0..8], "peer OOM");
const name = if (mode == 4) "PeerWarmupTimedOut" else "peer OOM";
@memcpy(record.text[0..name.len], name);
const data = std.mem.asBytes(&record);
try std.testing.expectEqual(@as(isize, data.len), posix.system.write(pair[1], data.ptr, data.len));
}
Expand Down Expand Up @@ -522,6 +523,7 @@ test "the real peer watcher exits on a closed line and on an error record, and r
try ProcessTest.check(0);
try ProcessTest.check(1);
try ProcessTest.check(2);
try ProcessTest.check(4);
}

test "a failing parent check still closes the line, kills and reaps the watcher's child" {
Expand Down
1 change: 1 addition & 0 deletions zig/src/cuda/tp_watch_child.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub fn said(mode: u8) []const u8 {
0 => "[default] (err): rank 0: another rank's process ended (its line closed); " ++
"this rank stops instead of waiting on it\n",
1 => "[default] (err): rank 0: rank 1 stopped (peer OOM); this rank stops too\n",
4 => "[default] (err): rank 0: rank 1 stopped (PeerWarmupTimedOut); this rank stops too\n",
else => "",
};
}
2 changes: 1 addition & 1 deletion zig/src/families/glm/cuda_native.zig
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ fn openRank(a: StartArgs, set: ranks.Settings) !Loaded {
errdefer _ = own.group.lib.api.ncclCommDestroy(own.group.comm);
cuda.p2p_report.beforePeers(&diag, .{ .lib = &own.group.lib, .comm = comm, .later = true });
own.progress.enter(.peer_warmup);
if (p.world > 1) try @import("cuda_warm_peers.zig").warm(ctx.d, &own.group, set.ring);
if (p.world > 1) try @import("cuda_warm_peers.zig").warm(io, ctx.d, &own.group, set.ring, &diag);
cuda.p2p_report.afterInit(&diag, .{ .lib = &own.group.lib, .comm = comm, .d = ctx.d, .later = true });
const cap = capacity(o.context);
own.progress.enter(.weights);
Expand Down
40 changes: 40 additions & 0 deletions zig/src/families/glm/cuda_warm_deadline.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//! One deadline for the peer exchange, including blocking NCCL calls and stream cleanup.
const std = @import("std");

pub const timeout_ms: u64 = 300_000;

/// The test supplies a short limit and a fake clock through the same boundary as the production warm-up.
pub fn run(clock: anytype, limit_ms: u64, action: anytype, args: anytype, comptime work: anytype) anyerror!void {
const Guard = struct {
const State = enum(u8) { waiting, finished, expired };
state: std.atomic.Value(State) = .init(.waiting),
clock: @TypeOf(clock),
action: @TypeOf(action),
since: u64,
limit: u64,

fn expire(g: *@This()) void {
if (g.state.cmpxchgStrong(.waiting, .expired, .acq_rel, .acquire) == null) g.action.expired();
}
fn watch(g: *@This()) void {
while (g.state.load(.acquire) == .waiting) {
if (g.clock.now() -| g.since >= g.limit) {
g.expire();
return;
}
g.clock.pause();
}
}
fn finish(g: *@This()) bool {
if (g.clock.now() -| g.since >= g.limit) g.expire();
return g.state.cmpxchgStrong(.waiting, .finished, .acq_rel, .acquire) != null;
}
};
var guard: Guard = .{ .clock = clock, .action = action, .since = clock.now(), .limit = limit_ms };
const watcher = try std.Thread.spawn(.{}, Guard.watch, .{&guard});
const result = work(args);
const expired = guard.finish();
watcher.join();
if (expired) return error.PeerWarmupTimedOut;
return result;
}
81 changes: 74 additions & 7 deletions zig/src/families/glm/cuda_warm_peers.zig
Original file line number Diff line number Diff line change
@@ -1,16 +1,83 @@
//! Connect GLM's explicit prompt-exchange peers before weights consume the registration budget.
const std = @import("std");
const cuda = @import("cuda");
const deadline = @import("cuda_warm_deadline.zig");

pub const bytes = 4 << 20;

pub fn warm(d: *const cuda.Driver, g: *const cuda.tp_group.Group, ring: bool) !void {
pub fn warm(io: std.Io, d: *const cuda.Driver, g: *cuda.tp_group.Group, ring: bool, diag: *const cuda.p2p_report.Session) !void {
return warmWith(d, g, ring, Clock{ .io = io }, deadline.timeout_ms, Action{ .g = g, .ring = ring, .diag = diag });
}

/// Production uses 300 s; host fixtures shorten only this injected clock/deadline and termination action.
pub fn warmWith(d: *const cuda.Driver, g: *cuda.tp_group.Group, ring: bool, clock: anytype, limit_ms: u64, action: anytype) !void {
if (g.world <= 1) return;
var buf = try cuda.DeviceBuffer.alloc(d, 2 * bytes * g.world);
defer buf.free();
var stream = try cuda.Stream.init(d, false);
defer stream.deinit();
try post(g, stream, buf.ptr, ring);
try stream.synchronize();
try deadline.run(clock, limit_ms, action, Work{ .d = d, .g = g, .ring = ring }, Work.run);
}

const Work = struct {
d: *const cuda.Driver,
g: *cuda.tp_group.Group,
ring: bool,
fn run(a: Work) !void {
const d = a.d;
const g = a.g;
const ring = a.ring;
var buf = try cuda.DeviceBuffer.alloc(d, 2 * bytes * g.world);
defer buf.free();
var stream = try cuda.Stream.init(d, false);
defer stream.deinit();
try post(g, stream, buf.ptr, ring);
try stream.synchronize();
}
};

const Clock = struct {
io: std.Io,
pub fn now(c: Clock) u64 {
return @intCast(@divTrunc(std.Io.Clock.awake.now(c.io).toNanoseconds(), std.time.ns_per_ms));
}
pub fn pause(c: Clock) void {
std.Io.sleep(c.io, .fromMilliseconds(10), .awake) catch {};
}
};

const Action = struct {
g: *cuda.tp_group.Group,
ring: bool,
diag: *const cuda.p2p_report.Session,
pub fn expired(a: Action) void {
timeoutWith(a.g, a.ring, a.diag, cuda.tp_watch, log);
}
};

fn log(text: []const u8) void {
std.log.err("{s}", .{text});
}

/// Publish the named cause before abort can release a blocked NCCL call with a less specific error.
pub fn timeoutWith(g: *cuda.tp_group.Group, ring: bool, diag: *const cuda.p2p_report.Session, watch: anytype, sink: cuda.startup_log.Sink) void {
var raw: [64 << 10]u8 = undefined;
const how = cuda.startup_watch.transport(diag.capture.read(&raw), @intCast(g.rank));
var buf: [2048]u8 = undefined;
var w = std.Io.Writer.fixed(&buf);
timeoutLine(&w, g.rank, g.world, ring, how) catch {};
sink(w.buffered());
watch.fail("PeerWarmupTimedOut");
g.abort();
watch.stop();
}

pub fn timeoutLine(w: *std.Io.Writer, rank: usize, world: usize, ring: bool, how: u3) !void {
try w.print("rank {d}: peer warm-up: 4 MiB send/recv with rank(s) ", .{rank});
const plan: cuda.relay_plan.Relay = .{ .rank = rank, .world = world, .n = 0 };
var first = true;
for (0..world) |peer| {
if (peer == rank or (ring and peer != plan.next() and peer != plan.prev())) continue;
try w.print("{s}{d}", .{ if (first) "" else ",", peer });
first = false;
}
try w.print(" not finished after {d} s (NCCL transport {s}); PeerWarmupTimedOut; stopping every rank", .{ deadline.timeout_ms / 1000, cuda.startup_watch.transportName(how) });
}

/// The existing 4 MiB send/receive, restricted to neighbours only when ring exchange was selected.
Expand Down
4 changes: 4 additions & 0 deletions zig/src/families/glm/cuda_warm_peers_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,7 @@ test "GLM warm peers: existing ring selector alone restricts warm-up, gather and
}
Fake.mode = null;
}

test {
_ = @import("cuda_warm_timeout_test.zig");
}
Loading
Loading