diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b404955e53..d44c1ca53c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,14 +4,16 @@ 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. + +- LFM3 and Flash Next: LFM3's sampled and grammar-masked row draws and Flash Next's host reference draw call core's one row sampler with the same errors and messages, and an empty Flash Next reference row is refused by name instead of panicking (#2679, refs #2460). Thanks to @jschmied. + - Qwen on CUDA: a development build for sm_110 (`-Dsm=110`, NVIDIA Thor) refuses by name, before paging or weight loading, the modes not qualified there: `--slide`, a DSpine `--drafter`, `TF_DSPINE_WINDOW`, `--kv-cache fp8`, `--prompt-precision int8`, `--rope-yarn`, `TF_QWEN_KV_PAGES`, `TF_QWEN_KV_PAGES_ALL=1`, `TF_QWEN_KV_SHARE`, `TF_QWEN_REQUEST_STARTS=1`, `TF_QWEN_KV_PAGE_TEST`, `TF_QWEN_KEEP_LATE=1`, `TF_NO_TREES` and `TF_DRAFT_NODES`; the default path and the DFlash2 drafter are still served, and other GPUs are unchanged (#3057, refs #2319). Thanks to @yguanrong. - CUDA: a Flash Next prompt pass holds 3,072 rows while other streams decode (it held 1,536), so a long prompt beside running streams takes half as many passes (#3726). Thanks to @BadAd84. - GLM-5.3-Flash on CUDA: the sampled draw takes its rule from the shared `cuda.sample.rule`, as MiniMax M3 does, instead of building its own copy with a fixed `near` value (#3705, part of #2680). Thanks to @jschmied. - - - Server: `GET /v1/models/{id}` (and `/models/{id}`) returns the entry `/v1/models` lists for the served name or an alias, the id sent as written or percent-escaped (`org%2Fname`); any other id is a 404 `model_not_found`, and API keys and key scopes treat the route as they treat `/v1/models` (#3535). - Server: the next turn's background prefill puts the reply's reasoning into its guess when the client sends reasoning back, so thinking requests resume from the real next prompt instead of redoing the pass from before the reply; clients whose history drops reasoning keep the old guess (#3264). @@ -24,8 +26,6 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel - GLM-5.3-Flash on CUDA: GLM's kernels and qmmf's decode linears launch as programmatic dependent launches, so a decode token's kernels lose most of their launch gaps; experts, the router plan and the RoCE exchange stay plain launches, a prompt chunk's KDA chain launches plain from 64 rows, and `TF_GLM_PDL=0` launches everything plain (#3776, refs #3652). Thanks to @ultradaoto. - - - dots.mocr on CUDA: `--vision` now serves images through the image tower instead of refusing them, within the request's `--vision-image-tokens` budget; text-only replies keep their pinned hashes, and the GB10 runner gains `tf-cuda-test dots-text` (three prompts of our own, served with and without `--vision`, against pinned reply hashes) and `dots-invariants` (image prompts cut into chunks against the uncut run) (#2771, refs #1927). Thanks to @laudney. - Qwen3.8-27B on Metal before M5: decode rounds read their cached keys through the prefix kernels, as on an M5, and prompt passes size their memory the same way; `TF_QWEN27_SHARED_PREFIX=0` keeps cached keys on the tail kernel (#3677, refs #3604). Thanks to @hobbesd. @@ -38,14 +38,10 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel - Desktop: an MCP server's startup diagnostics reach the Plugins preview as whole lines, masked as a whole and capped at 64 KiB, instead of one row per stderr write (#3759). Thanks to @AIFlowML. - - - Flash Next on HIP: the prompt chunk fallback counts the window plan's slot bytes as used before deciding whether a smaller chunk admits more streams, where it counted them as free and could keep the larger chunk (#3419). Thanks to @gilby. - DeepSeek-V4.1 on Metal: its GPU work goes through a Metal 4 command queue by default where the Mac has one (macOS 26 and later), with the same kernels in the same order and bit-identical outputs; `TF_METAL4=0` keeps Metal 3, `TF_METAL4_TIMELINE=n` logs per-stage GPU times for n rounds of each kind, and `TF_DSV41_ROUND_PROF=1` logs decode rounds' host and GPU milliseconds (#3374). - - - Flash Next on HIP: the verify window holds eight rows instead of four, so a stream alone in a round can land copy drafts of up to seven tokens a round; rounds shared by several streams keep three-token copies, MTP still drafts at most three, and each stream's window snapshots take more device memory, which admission counts (#2730). Thanks to @gilby. - OCR: the native HIP engine reads documents through `POST /v1/ocr` in Mistral's OCR contract (its Python and TypeScript SDKs), with dots.mocr's reader (a box for each layout block). Images and PDFs (`--vision-pdf`) share one page budget per request (`TENSORFOLD_MAX_PDF_PAGES`, default 16), each PDF measured before any inference and each page rendered just before it is read, and Mistral crops share one image budget (256 images, 4 times the page pixels, 16 MiB plus 2 MiB a page). An option that changes content and that TensorFold cannot apply, such as annotations, is refused. A page cut at the context limit or out of its model's format fails the whole request with HTTP 422; `docs/api.md` lists the contract's fields, statuses and limits (#2570, #2571, #2440). Thanks to @laudney. diff --git a/docs/optimization-ledger.md b/docs/optimization-ledger.md index 128c354befc..3da57e90b56 100644 --- a/docs/optimization-ledger.md +++ b/docs/optimization-ledger.md @@ -483,6 +483,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 @@ -691,3 +692,4 @@ below; these are estimates for planning a port, not results. [#1603]: https://github.com/ashhart/TensorFold/issues/1603 [#2977]: https://github.com/ashhart/TensorFold/pull/2977 [#2805]: https://github.com/ashhart/TensorFold/pull/2805 +[#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/src/families/flashnext/host_sample.zig b/zig/src/families/flashnext/host_sample.zig index 28144fed8ca..dceba076fe9 100644 --- a/zig/src/families/flashnext/host_sample.zig +++ b/zig/src/families/flashnext/host_sample.zig @@ -20,45 +20,15 @@ fn key(word: u16) u16 { return if (w & 0x8000 != 0) ~w else w | 0x8000; } -fn value(word: u16) f64 { - return @as(f32, @bitCast(@as(u32, word) << 16)); -} +const value = lanes.sampling_row.value; -/// qwen3_5/backend.zig's draw without a mask: the unchanged top-k candidates for the keyed sampler. +/// The unmasked row draw the one-pass `draw` must equal: core's (lanes.sampling_row) under the Qwen error names. pub fn reference(gpa: std.mem.Allocator, logits: []const u16, p: lanes.Sampling, position: u64) !u32 { - var best: ?usize = null; - for (logits, 0..) |word, id| { - const x = value(word); - if (!std.math.isFinite(x)) return error.NonfiniteQwenLogits; - if (best == null or x > value(logits[best.?])) best = id; - } - if (p.temperature <= 0) return @intCast(best.?); - const allowed = logits.len; - const k = if (p.top_k == 0) allowed else @min(allowed, p.top_k); - const values = try gpa.alloc(f64, k); - defer gpa.free(values); - const ids = try gpa.alloc(u64, k); - defer gpa.free(ids); - var filled: usize = 0; - for (logits, 0..) |word, id| { - const x = value(word); - if (k == allowed) { - values[filled] = x; - ids[filled] = id; - filled += 1; - continue; - } - if (filled == k and x <= values[k - 1]) continue; - var at = @min(filled, k - 1); - while (at > 0 and x > values[at - 1]) : (at -= 1) { - values[at] = values[at - 1]; - ids[at] = ids[at - 1]; - } - values[at] = x; - ids[at] = id; - filled = @min(filled + 1, k); - } - return @intCast(try lanes.sampling.choose(gpa, values, ids, position, p)); + return lanes.sampling_row.draw(gpa, logits, p, position, &.{}) catch |e| switch (e) { + error.NonfiniteLogits => error.NonfiniteQwenLogits, + error.NoAllowedToken => error.NoAllowedQwenToken, + else => e, + }; } /// Row `row` of a [rows, vocab] bf16 logits buffer whose bytes start at `base`. @@ -214,3 +184,13 @@ test "wide draw preserves reference when uniform rounds to one" { words[2] = 0x4280; try std.testing.expectEqual(try reference(gpa, &words, p, 0), try draw(gpa, &words, p, 0)); } + +test "the reference refuses an empty or nonfinite row under the Qwen error names" { + const gpa = std.testing.allocator; + var words: [300]u16 = @splat(0x3f80); + const p: lanes.Sampling = .{ .seed = 7, .temperature = 0.7, .top_k = 20 }; + try std.testing.expectError(error.NoAllowedQwenToken, reference(gpa, &.{}, p, 0)); + words[5] = 0xff80; + try std.testing.expectError(error.NonfiniteQwenLogits, reference(gpa, &words, p, 0)); + try std.testing.expectError(error.NonfiniteQwenLogits, reference(gpa, &words, .{ .seed = 7, .temperature = 0 }, 0)); +} diff --git a/zig/src/families/lfm3/backend.zig b/zig/src/families/lfm3/backend.zig index dc608b14a7c..c200e43082f 100644 --- a/zig/src/families/lfm3/backend.zig +++ b/zig/src/families/lfm3/backend.zig @@ -265,51 +265,16 @@ pub const Snaps = struct { /// A row's allowed-token bits (structured output): one bit a logit. const mask_words = (c.vocab + 31) / 32; -pub fn value(word: u16) f64 { - return @as(f32, @bitCast(@as(u32, word) << 16)); -} +pub const value = lanes.sampling_row.value; -/// The unchanged top-k candidates for the shared fp64 keyed sampler; a `mask` keeps its allowed ones (-inf's draw). +/// Greedy unmasked rows take greedy.select; the rest core's row draw (lanes.sampling_row) under the LFM error names. pub fn draw(gpa: std.mem.Allocator, logits: []const u16, settings: ?lanes.Sampling, position: u64, mask: []const u32) !u32 { if (mask.len == 0 and (settings == null or settings.?.temperature <= 0)) return greedy.select(logits); - var best: ?usize = null; - var allowed: usize = 0; - for (logits, 0..) |word, id| { - const x = value(word); - if (!std.math.isFinite(x)) return error.NonfiniteLfmLogits; - if (mask.len > 0 and !lanes.grammar.allows(mask, id)) continue; - allowed += 1; - if (best == null or x > value(logits[best.?])) best = id; - } - if (best == null) return error.NoAllowedLfmToken; - const sampling = settings orelse return @intCast(best.?); - if (sampling.temperature <= 0) return @intCast(best.?); - const k = if (sampling.top_k == 0) allowed else @min(allowed, sampling.top_k); - const values = try gpa.alloc(f64, k); - defer gpa.free(values); - const ids = try gpa.alloc(u64, k); - defer gpa.free(ids); - var filled: usize = 0; - for (logits, 0..) |word, id| { - if (mask.len > 0 and !lanes.grammar.allows(mask, id)) continue; - const x = value(word); - if (k == allowed) { - values[filled] = x; - ids[filled] = id; - filled += 1; - continue; - } - if (filled == k and x <= values[k - 1]) continue; - var at = @min(filled, k - 1); - while (at > 0 and x > values[at - 1]) : (at -= 1) { - values[at] = values[at - 1]; - ids[at] = ids[at - 1]; - } - values[at] = x; - ids[at] = id; - filled = @min(filled + 1, k); - } - return @intCast(try lanes.sampling.choose(gpa, values, ids, position, sampling)); + return lanes.sampling_row.draw(gpa, logits, settings, position, mask) catch |e| switch (e) { + error.NonfiniteLogits => error.NonfiniteLfmLogits, + error.NoAllowedToken => error.NoAllowedLfmToken, + else => e, + }; } /// The shared lane facts after the load-time exactness gate succeeds. @@ -356,6 +321,7 @@ test "candidate selection preserves full-vocabulary keyed draws and tie order" { try std.testing.expectEqual(try draw(gpa, words, null, 0, &.{}), try draw(gpa, words, .{ .seed = 7, .temperature = 0 }, 99, &.{})); words[0] = 0x7fc0; try std.testing.expectError(error.NonfiniteLfmLogits, draw(gpa, words, null, 0, &.{})); + try std.testing.expectError(error.NonfiniteLfmLogits, draw(gpa, words, .{ .seed = 7, .temperature = 0.7 }, 0, &.{})); } test "a masked draw is the full-vocabulary draw with the other tokens at -inf" { diff --git a/zig/tests/fixtures/gradient-serving.tsv b/zig/tests/fixtures/gradient-serving.tsv index 2fa4cd4c142..c36f462b1fd 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