diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f3bd9fe8bd..13b2a762913 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel ## Unreleased +- CUDA: at `--tp 2` a Flash Next rank's control-link wait polls with a 50 µs timeout for its first 50 ms and then blocks as before, so drafted rounds pick up the next header sooner; replies are unchanged (#2971). Thanks to @swbiggart. + - CUDA: `capabilities --json` now advertises `modelopt-mixed` and `modelopt-nvfp4` for the dense Qwen3.5 family, matching the ModelOpt exports its loader serves (#4192). Thanks to @javierbits. - CUDA capabilities: the dense Qwen3.8-27B row now advertises the ModelOpt exports its loader reads, `modelopt-mixed` (`nvidia/Qwen3.8-27B-NVFP4`) and `modelopt-nvfp4`, beside `mlx-q4g64` and `exl3`; a client that filters on `capabilities --json` no longer hides a checkpoint the engine serves (#4150). Thanks to @Flyinpiz-dev. - HIP: the gfx12 WMMA step pieces move from `tiles/wmma12_gemm.hpp` into a shared header, `tiles/wmma12_step.hpp`, for the coming gfx12 affine tile; it is only a move, so the kernels' bytes do not change (#3862, refs #2401). Thanks to @millaguie. diff --git a/docs/optimization-ledger.md b/docs/optimization-ledger.md index 33812aa14ed..8909cb53019 100644 --- a/docs/optimization-ledger.md +++ b/docs/optimization-ledger.md @@ -489,6 +489,7 @@ below; these are estimates for planning a port, not results. | Family | Gain (measured) | Where | | --- | --- | --- | | flashnext (C), TP=2 | prompt passes reduce-scatter the experts' slots by rows: rank 0 sends 5.81 → 3.43 MiB a prompt token, cold prefill +26.5..+26.8 % on two GB10s, +30.9..+33.9 % on two RTX PRO 6000s, same replies | [#2977] | + | flashnext (C), TP=2 | control-link waits poll 50 µs for 50 ms before they block: drafted decode +1.4..+1.5 % at one stream, +3.7..+4.7 % at four on two GB10s, same replies | [#2971] | 26. **Pipeline stages.** Layer ranges on different nodes, one hidden row a token over Ethernet, so a GB10 and a Mac can serve one model ([#2005]). The stage link and its protocol are [#2012] and [#2060]; the 27B as a stage is @@ -708,3 +709,4 @@ below; these are estimates for planning a port, not results. [#2805]: https://github.com/ashhart/TensorFold/pull/2805 [#3305]: https://github.com/ashhart/TensorFold/issues/3305 [#2941]: https://github.com/ashhart/TensorFold/issues/2941 +[#2971]: https://github.com/ashhart/TensorFold/pull/2971 diff --git a/zig/src/families/flashnext/cuda_rank_wire.zig b/zig/src/families/flashnext/cuda_rank_wire.zig index 23fc60e5485..017b58aea5b 100644 --- a/zig/src/families/flashnext/cuda_rank_wire.zig +++ b/zig/src/families/flashnext/cuda_rank_wire.zig @@ -58,19 +58,33 @@ pub fn pause() void { _ = platform.c.nanosleep(&ts, null); } +/// How long a wait polls with a short timeout before it blocks: a core idle through a whole round wakes late. +pub const warm_ns = 50 * std.time.ns_per_ms; + fn wait(fd: p.socket_t, events: i16, until: ?u64) !void { + const start = now(); while (true) { const current = now(); if (until) |end| if (current >= end) return error.RankTimeout; const ms: i32 = if (until) |end| @intCast(@min(1000, (end - current + std.time.ns_per_ms - 1) / std.time.ns_per_ms)) else 1000; var fds = [_]p.pollfd{.{ .fd = fd, .events = events, .revents = 0 }}; - const count = try p.poll(&fds, ms); + const count = if (current - start < warm_ns) try shortPoll(&fds) else try p.poll(&fds, ms); if (count == 0) continue; if (fds[0].revents & events != 0) return; if (fds[0].revents & (p.POLL.ERR | p.POLL.HUP | p.POLL.NVAL) != 0) return error.RankDisconnected; } } +/// One poll ending within about 50 us: the core stays in a shallow idle state, and data wakes it at once. +fn shortPoll(fds: []p.pollfd) !usize { + if (builtin.os.tag != .linux) return p.poll(fds, 1); + const short: p.timespec = .{ .sec = 0, .nsec = 50_000 }; + return p.ppoll(fds, &short, null) catch |err| switch (err) { + error.SignalInterrupt => 0, + else => err, + }; +} + pub const Link = struct { fd: p.socket_t, @@ -220,3 +234,43 @@ test "rank frames are versioned, bounded and exact" { try std.testing.expectError(error.BadRankFrame, Header.decode(&raw)); try std.testing.expectError(error.BadRankFrame, (Header{ .kind = .forward, .bytes = max_payload + 1 }).encode()); } + +fn sendLater(fd: c_int, ms: u64, close: bool) void { + const ts: platform.c.timespec = .{ .sec = @intCast(ms / 1000), .nsec = @intCast((ms % 1000) * std.time.ns_per_ms) }; + _ = platform.c.nanosleep(&ts, null); + const byte: u8 = 7; + if (close) _ = std.c.close(fd) else _ = std.c.send(fd, &byte, 1, 0); +} + +fn sleeps() isize { + return if (builtin.os.tag == .linux) p.getrusage(p.rusage.THREAD).nvcsw else 0; +} + +test "a link wait polls briefly, then blocks, and still ends at its data, its deadline or its peer's exit" { + if (builtin.os.tag == .windows) return error.SkipZigTest; + var pair: [2]c_int = undefined; + if (std.c.socketpair(p.AF.UNIX, p.SOCK.STREAM, 0, &pair) != 0) return error.SocketPair; + defer _ = std.c.close(pair[0]); + const flags = std.c.fcntl(pair[0], p.F.GETFL); + _ = std.c.fcntl(pair[0], p.F.SETFL, flags | @as(c_int, @bitCast(@as(u32, @bitCast(p.O{ .NONBLOCK = true }))))); + const l: Link = .{ .fd = pair[0] }; + var byte: [1]u8 = .{0}; + var start = now(); + try std.testing.expectError(error.RankTimeout, l.receive(&byte, deadline(20))); + try std.testing.expect(now() - start >= 20 * std.time.ns_per_ms and now() - start < std.time.ns_per_s); + // a byte inside the short polls, then one after them: the short polls stop at warm_ns, then one poll blocks + for ([_]u64{ 5, 600 }) |late| { + start = now(); + const t = try std.Thread.spawn(.{}, sendLater, .{ pair[1], late, false }); + const before = sleeps(); + try l.receive(&byte, null); + const polls = sleeps() - before; + t.join(); + try std.testing.expect(byte[0] == 7 and now() - start >= late * std.time.ns_per_ms); + if (builtin.os.tag == .linux and late > 50) try std.testing.expect(polls > 20 and polls < 2000); + byte[0] = 0; + } + const t = try std.Thread.spawn(.{}, sendLater, .{ pair[1], 5, true }); + defer t.join(); + try std.testing.expectError(error.RankDisconnected, l.receive(&byte, deadline(1000))); +} diff --git a/zig/tests/fixtures/gradient-serving.tsv b/zig/tests/fixtures/gradient-serving.tsv index 806c4a58db3..bf2851a3e69 100644 --- a/zig/tests/fixtures/gradient-serving.tsv +++ b/zig/tests/fixtures/gradient-serving.tsv @@ -162,7 +162,7 @@ zig/src/families/flashnext/cuda_qmm.zig 6d035feb053691cc9750a369c86a5463d41ed942 zig/src/families/flashnext/cuda_rank_engine.zig df6a83bcf80edfd94ac4474dbbc2e73818d40b7532430399af73f2eb95ccfa33 raw zig/src/families/flashnext/cuda_rank_media.zig e5c268c8cf257934bb49fe401ba6213ea8b108258bbfd4d06edb990d568c3c2b raw zig/src/families/flashnext/cuda_rank_memory.zig 072954f4e2e9d6ea66124a209d20a1fa1c7ed391e501310d41880f11ce61ada8 raw -zig/src/families/flashnext/cuda_rank_wire.zig ee1ea4202cb6b383e03a3c909d002fbdefb8fee469cae1440714e51291aa30a4 raw +zig/src/families/flashnext/cuda_rank_wire.zig 79e0af71e788100719baeaedd7bb0c3ce278f542eb4723c4f098a838f931f77f raw a control-link wait polls with a 50 us timeout for its first 50 ms, then blocks; how the host waits only, replies unchanged zig/src/families/flashnext/cuda_round_graph.zig 7fa3a54e93c81de36cf3962d0a68eb72a7dd81b8869f47b6d9ed8b9a6cc325cd raw main dfd9ac5ef4 (#2585: TF_FLASHNEXT_* read through platform/environment.zig, malformed text refused at startup; valid values keep their meaning) zig/src/families/flashnext/cuda_rows.zig 735fc8915036e47d09f533f4e5948e5fc4b61556172ebe2c6bfdaad3e0373216 raw main dfd9ac5ef4 (#2585: TF_FLASHNEXT_* read through platform/environment.zig, malformed text refused at startup; valid values keep their meaning) zig/src/families/flashnext/cuda_select_main.zig 5c012c2d59fa6dd573424fce7b6d8b162a06cb9f6103530a0fc0b03dbdb17bd3 raw