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

## Unreleased

- Nemotron on HIP: a checkpoint whose token table (`backbone.embeddings`) is stored bf16 beside quantized matrices, marked `false` in config.json's quantization block or stored without scales, is admitted and loads; its rows are gathered as stored, the memory plan counts them at their stored bytes, and the startup label adds `+bf16-embed`; a bf16 `lm_head`, projection or other unquantized tensor is still refused by name (#3575, refs #3061). Thanks to @gilby.
- 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.

- GLM-5.3-Flash on Metal: prompt index scores read each row's queries once per tile and routed-expert gathers load the next step's codes ahead, so follow-up turns reach the first token sooner with unchanged outputs (#3458).
- 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.

- Nemotron on HIP: a checkpoint whose token table (`backbone.embeddings`) is stored bf16 beside quantized matrices, marked `false` in config.json's quantization block or stored without scales, is admitted and loads; its rows are gathered as stored, the memory plan counts them at their stored bytes, and the startup label adds `+bf16-embed`; a bf16 `lm_head`, projection or other unquantized tensor is still refused by name (#3575, refs #3061). Thanks to @gilby.

- GLM-5.3-Flash on Metal: prompt index scores read each row's queries once per tile and routed-expert gathers load the next step's codes ahead, so follow-up turns reach the first token sooner with unchanged outputs (#3458).

- Web: an explicit relative `--token-file` path for the service installer is anchored to the directory it is run from, so the file the installer prepares and the file the generated launcher opens are the same; the default path and symlink handling are unchanged (#3838, fixes #3835). Thanks to @AIFlowML.

Expand Down Expand Up @@ -38,8 +40,6 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

- Docs: the Qwen3.8-27B recipe says to serve with `--thinking-budget 4096` when thinking is on, and gives its GPQA Diamond result on TensorFold 1.2.7 and one GB10: replies cut at the limit from 78 of 198 to 0, and correct from 58.1% to 82.8% (#3373, fixes #3323).



- Idol on CUDA: `tf-idol` runs Idol's denoiser on GB10 (sm_121) and on RTX 50-series and RTX PRO Blackwell (sm_120) cards against a reference case, gated step by step against idol-sdk's float32 run as on Metal, and refuses other GPUs by name (#1767, for #1757). Thanks to @jayleaton, with device runs from @GustavBlack and @Nipale-ai.

- Docs: the drafter training recipe gains a section on adapting an already released drafter, budgeted from a few passes over the scarcest class at a low learning rate with early checkpoints, with the Qwen3.8-27B pilot behind it (#3369, refs #2667). Thanks to @Maxrio9.
Expand Down
2 changes: 2 additions & 0 deletions docs/optimization-ledger.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,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
Expand Down Expand Up @@ -675,3 +676,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
56 changes: 55 additions & 1 deletion zig/src/families/flashnext/cuda_rank_wire.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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)));
}
54 changes: 17 additions & 37 deletions zig/src/families/flashnext/host_sample.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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));
}
50 changes: 8 additions & 42 deletions zig/src/families/lfm3/backend.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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" {
Expand Down
2 changes: 1 addition & 1 deletion zig/tests/fixtures/gradient-serving.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading