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

## Unreleased

- Flash Next on CUDA: `TF_FLASHNEXT_SPLIT_DENSE` and `TF_FLASHNEXT_SHARD_HEAD` are checked by name when the engine loads, so a malformed value names the variable, the supplied text and the accepted forms, and an empty or blank value reads as unset; valid values and defaults are unchanged (#3749, refs #2370). Thanks to @devopsfortunato.

- App: Room agents keep their own reasoning effort, and an agent without one inherits the run's default (#3514). Thanks to @AIFlowML.

- Tests: the Zig cache restat tests read `.lib_dir` from `zig env` instead of guessing a `lib` folder beside the executable, so they work with Homebrew Zig (#3786, fixes #3785). Thanks to @AIFlowML.
Expand Down
4 changes: 3 additions & 1 deletion docs/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Direct family readers also refuse malformed values when called without the serve

## Flash Next

Flash Next checks these 31 settings when its engine loads, before any device or checkpoint work: a malformed value
Flash Next checks these 33 settings when its engine loads, before any device or checkpoint work: a malformed value
stops the start with the variable, the supplied text and the accepted forms.

| Variable | Accepted explicit value |
Expand All @@ -129,6 +129,8 @@ stops the start with the variable, the supplied text and the accepted forms.
| `TF_FLASHNEXT_HC_FUSE` | Exactly `0` or `1`; default on |
| `TF_FLASHNEXT_KEEP_LATE` | Exactly `0` or `1`; unset or blank leaves the choice to the loader |
| `TF_FLASHNEXT_DECODE_GRAPH` | Exactly `0` or `1`; default off |
| `TF_FLASHNEXT_SPLIT_DENSE` | Exactly `0` or `1`; default on: two ranks split the BF16 dense projections |
| `TF_FLASHNEXT_SHARD_HEAD` | Exactly `0` or `1`; default off: each rank keeps its half of the output head |
| `TF_FLASHNEXT_ATTN_LANES` | Exactly `0` or `1`; default off |
| `TF_FLASHNEXT_WARM_AHEAD` | Exactly `0` or `1`; default off |
| `TF_FLASHNEXT_TABLE_WARM` | Exactly `0` or `1`; default off |
Expand Down
19 changes: 12 additions & 7 deletions zig/src/families/flashnext/cuda_dense_split.zig
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,13 @@ const deciders = [_][]const u8{
"language_model.model.layers.0.mlp.shared_expert.down_proj.weight",
};

/// TF_FLASHNEXT_SPLIT_DENSE: unset or 1 splits, 0 keeps every dense projection whole.
/// TF_FLASHNEXT_SPLIT_DENSE: unset, blank or 1 splits, 0 keeps every dense projection whole.
pub fn setting(value: ?[]const u8) !bool {
const v = value orelse return true;
if (std.mem.eql(u8, v, "0")) return false;
if (std.mem.eql(u8, v, "1")) return true;
return error.BadDenseSplit;
return @import("sys").environment.value(bool, "TF_FLASHNEXT_SPLIT_DENSE", value, true) catch return error.BadDenseSplit;
}

pub fn enabled() !bool {
return setting(if (std.c.getenv("TF_FLASHNEXT_SPLIT_DENSE")) |v| std.mem.span(v) else null);
return setting(@import("sys").getenv("TF_FLASHNEXT_SPLIT_DENSE"));
}

/// At two ranks with the setting on, a checkpoint whose deciders are BF16 splits; world 1 never reads the setting.
Expand Down Expand Up @@ -115,8 +112,11 @@ test "the dense split setting is on unless 0 and refuses any other value" {
try std.testing.expect(try setting(null));
try std.testing.expect(try setting("1"));
try std.testing.expect(!try setting("0"));
// an empty or whitespace-only value is unset, so it keeps the default on, as every other setting here does
try std.testing.expect(try setting(""));
try std.testing.expect(try setting(" \t"));
try std.testing.expectError(error.BadDenseSplit, setting("2"));
try std.testing.expectError(error.BadDenseSplit, setting(""));
try std.testing.expectError(error.BadDenseSplit, setting("on"));
}

test "the dense split applies at two ranks to BF16 layers only, and world 1 never reads the setting" {
Expand All @@ -134,6 +134,11 @@ test "the dense split applies at two ranks to BF16 layers only, and world 1 neve
try std.testing.expect(!try applies(&bf16, 2));
_ = env.setenv("TF_FLASHNEXT_SPLIT_DENSE", "1", 1);
try std.testing.expect(try applies(&bf16, 2));
// the production reader takes the same blank-as-unset rule, so the split stays on
_ = env.setenv("TF_FLASHNEXT_SPLIT_DENSE", "", 1);
try std.testing.expect(try applies(&bf16, 2));
_ = env.setenv("TF_FLASHNEXT_SPLIT_DENSE", " \t", 1);
try std.testing.expect(try applies(&bf16, 2));
_ = env.setenv("TF_FLASHNEXT_SPLIT_DENSE", "on", 1);
try std.testing.expectError(error.BadDenseSplit, applies(&bf16, 2));
try std.testing.expect(!try applies(&bf16, 1));
Expand Down
29 changes: 24 additions & 5 deletions zig/src/families/flashnext/cuda_head.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
const std = @import("std");
const Tensor = @import("core").safetensors.Tensor;

/// TF_FLASHNEXT_SHARD_HEAD: unset, blank or 0 keeps the whole output head on each rank, 1 keeps only its half.
pub fn setting(value: ?[]const u8) !bool {
const v = value orelse return false;
if (std.mem.eql(u8, v, "0")) return false;
if (std.mem.eql(u8, v, "1")) return true;
return error.BadHeadSharding;
return @import("sys").environment.value(bool, "TF_FLASHNEXT_SHARD_HEAD", value, false) catch return error.BadHeadSharding;
}

pub fn enabled() !bool {
return setting(if (std.c.getenv("TF_FLASHNEXT_SHARD_HEAD")) |v| std.mem.span(v) else null);
return setting(@import("sys").getenv("TF_FLASHNEXT_SHARD_HEAD"));
}

pub fn shard(t: Tensor, world: usize, rank: usize) !Tensor {
Expand Down Expand Up @@ -44,5 +42,26 @@ test "head partitions preserve every BF16 byte in global vocabulary order" {
try std.testing.expect(!try setting(null));
try std.testing.expect(!try setting("0"));
try std.testing.expect(try setting("1"));
// an empty or whitespace-only value is unset, so it keeps the default off, as every other setting here does
try std.testing.expect(!try setting(""));
try std.testing.expect(!try setting(" \t"));
try std.testing.expectError(error.BadHeadSharding, setting("2"));
try std.testing.expectError(error.BadHeadSharding, setting("on"));
}

test "head split: the production reader takes its own environment, blank as unset and junk refused" {
const env = @import("sys").env;
defer _ = env.unsetenv("TF_FLASHNEXT_SHARD_HEAD");
_ = env.unsetenv("TF_FLASHNEXT_SHARD_HEAD");
try std.testing.expect(!try enabled());
_ = env.setenv("TF_FLASHNEXT_SHARD_HEAD", "1", 1);
try std.testing.expect(try enabled());
_ = env.setenv("TF_FLASHNEXT_SHARD_HEAD", "0", 1);
try std.testing.expect(!try enabled());
_ = env.setenv("TF_FLASHNEXT_SHARD_HEAD", "", 1);
try std.testing.expect(!try enabled());
_ = env.setenv("TF_FLASHNEXT_SHARD_HEAD", " \t", 1);
try std.testing.expect(!try enabled());
_ = env.setenv("TF_FLASHNEXT_SHARD_HEAD", "on", 1);
try std.testing.expectError(error.BadHeadSharding, enabled());
}
2 changes: 2 additions & 0 deletions zig/src/platform/environment.zig
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ pub const rules = [_]Rule{
.{ .name = "TF_FLASHNEXT_HC_FUSE", .scope = .flashnext, .kind = .flag, .forms = "0 or 1 (default 1)" },
.{ .name = "TF_FLASHNEXT_KEEP_LATE", .scope = .flashnext, .kind = .flag, .forms = "0 or 1 (unset or blank leaves it unset)" },
.{ .name = "TF_FLASHNEXT_DECODE_GRAPH", .scope = .flashnext, .kind = .flag, .forms = "0 or 1 (default 0)" },
.{ .name = "TF_FLASHNEXT_SPLIT_DENSE", .scope = .flashnext, .kind = .flag, .forms = "0 or 1 (default 1)" },
.{ .name = "TF_FLASHNEXT_SHARD_HEAD", .scope = .flashnext, .kind = .flag, .forms = "0 or 1 (default 0)" },
.{ .name = "TF_FLASHNEXT_ATTN_LANES", .scope = .flashnext, .kind = .flag, .forms = "0 or 1 (default 0)" },
.{ .name = "TF_FLASHNEXT_WARM_AHEAD", .scope = .flashnext, .kind = .flag, .forms = "0 or 1 (default 0)" },
.{ .name = "TF_FLASHNEXT_TABLE_WARM", .scope = .flashnext, .kind = .flag, .forms = "0 or 1 (default 0)" },
Expand Down
33 changes: 26 additions & 7 deletions zig/src/platform/environment_flashnext_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ fn check(name: []const u8, raw: []const u8, valid: bool) !void {
try t.expect(std.mem.endsWith(u8, why.?, e.rule(name).forms));
}

test "Flash Next strict env: the table holds all 31 settings: 20 switches, 9 integers, 1 real, 1 structured" {
test "Flash Next strict env: the table holds all 33 settings: 22 switches, 9 integers, 1 real, 1 structured" {
var counts: [4]usize = @splat(0);
for (e.rules) |r| if (r.scope == .flashnext) {
try t.expect(std.mem.startsWith(u8, r.name, "TF_FLASHNEXT_"));
counts[@backingInt(group(r))] += 1;
};
try t.expectEqual([4]usize{ 20, 9, 1, 1 }, counts);
try t.expectEqual([4]usize{ 22, 9, 1, 1 }, counts);
}

test "Flash Next strict env: unset and blank settings both read as the caller's default" {
Expand All @@ -62,6 +62,23 @@ test "Flash Next strict env: every switch keeps exactly 0 and 1 and refuses the
};
}

test "Flash Next strict env: the dense split and head shard switches keep their own defaults, blank as unset" {
const Switch = struct { name: [:0]const u8, default: bool };
for ([_]Switch{
.{ .name = "TF_FLASHNEXT_SPLIT_DENSE", .default = true },
.{ .name = "TF_FLASHNEXT_SHARD_HEAD", .default = false },
}) |s| {
// unset, empty and whitespace-only all read as unset, so each keeps the default its reader passes
for ([_]?[]const u8{ null, "", " ", "\t", " \t\r\n" }) |raw| {
if (raw) |v| try check(s.name, v, true);
try t.expectEqual(s.default, try e.value(bool, s.name, raw, s.default));
}
try t.expect(!try e.value(bool, s.name, "0", true));
try t.expect(try e.value(bool, s.name, "1", false));
for ([_][]const u8{ "2", "00", "1 ", "-1", "1.0", "yes", "on", "true", "x" }) |raw| try check(s.name, raw, false);
}
}

test "Flash Next strict env: every count keeps its whole numbers and refuses junk, negatives, overflow" {
for (e.rules) |r| if (r.scope == .flashnext and group(r) == .integers) {
try check(r.name, "0", r.min == 0);
Expand Down Expand Up @@ -135,9 +152,11 @@ test "Flash Next strict env: a refusal names the setting, quotes its text, and e
}

test "Flash Next strict env: the scope refuses only its own settings" {
const fx: Fixture = .{ .name = "TF_FLASHNEXT_GPU_TOPK", .raw = "yes" };
const why = try e.refusal(t.allocator, fx, .{ .flashnext = false });
defer if (why) |w| t.allocator.free(w);
try t.expect(why == null);
try t.expectError(error.InvalidEnvironment, e.checkScope(.flashnext, fx));
for ([_][:0]const u8{ "TF_FLASHNEXT_GPU_TOPK", "TF_FLASHNEXT_SPLIT_DENSE", "TF_FLASHNEXT_SHARD_HEAD" }) |name| {
const fx: Fixture = .{ .name = name, .raw = "yes" };
const why = try e.refusal(t.allocator, fx, .{ .flashnext = false });
defer if (why) |w| t.allocator.free(w);
try t.expect(why == null);
try t.expectError(error.InvalidEnvironment, e.checkScope(.flashnext, fx));
}
}
2 changes: 1 addition & 1 deletion zig/tests/fixtures/gradient-serving.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ zig/src/families/flashnext/cuda_embed_main.zig 2b596788cccd420368fe803676e8ad45a
zig/src/families/flashnext/cuda_gdn.zig bc952357f4d6c076542b419b0ee71bbdce89715f0223ab31b4abf821fc2bee62 raw
zig/src/families/flashnext/cuda_glue.zig 0bd837ea17d1bd0a7a0820dc0ee99c4da90113c15d62b3fac31bd7af47a0ecb1 raw
zig/src/families/flashnext/cuda_hc.zig 01f897ac65d6edd2cd6ac76d97cb4d96619c25ffa85bd619d6d76f4f465cda9a raw
zig/src/families/flashnext/cuda_head.zig fc6410e8b17d559a12d81fd4bee9ab4e65f6f8b0999796c68baba58efb8fe818 raw
zig/src/families/flashnext/cuda_head.zig 734cc1ccea8e99ce9a061273a2dd3042f32e4848b622b5de616aa4b6f546bdd4 raw #3749: TF_FLASHNEXT_SHARD_HEAD read through platform/environment.zig, blank as unset
zig/src/families/flashnext/cuda_images.zig 5bd8a6c06cb69440522f4392794d9ef52b3760195b97d96f2316b1acac271bd4 raw
zig/src/families/flashnext/cuda_images_test.zig df984d54d9de1bb732544785cddf82a124de2a7019041ed1f7483b2a4a2d7c99 raw
zig/src/families/flashnext/cuda_lanes.zig 8578e64c69611c219709f48a4ba646bfd01fa02d793d788ea7e577ae03d07808 raw main 4f6017ced (marks inside the pass), fbca90714 (shared solo-chunk rule, #2391), 80e0fd72c (#2753: non-finite draft rows refused by name; finite rows unchanged), dfd9ac5ef4 (#2585: TF_FLASHNEXT_* read through platform/environment.zig, malformed text refused at startup; valid values keep their meaning), #1953: the ladder's values through snap_intermediate, #3308 (loader host test updates the named startup-refusal expectations; no runtime edit to this pinned file); #3135 (kept_disk renamed kept_view for the shared kept image; no served change)
Expand Down