From db4fc4041aedb115d68a186faba48a19603e6eba Mon Sep 17 00:00:00 2001 From: devopsfortunato <57877156+devopsfortunato@users.noreply.github.com> Date: Wed, 18 Nov 2026 02:48:21 +0100 Subject: [PATCH 1/2] flashnext: check TF_FLASHNEXT_SPLIT_DENSE and TF_FLASHNEXT_SHARD_HEAD at load Both switches gain rows in the strict environment table and their readers parse through it: a malformed value is refused by name before device work, blank text reads as unset, and valid values and defaults are unchanged. Part of #2370. --- CHANGELOG.md | 2 ++ docs/environment.md | 4 ++- .../families/flashnext/cuda_dense_split.zig | 19 +++++++---- zig/src/families/flashnext/cuda_head.zig | 29 +++++++++++++--- zig/src/platform/environment.zig | 2 ++ .../platform/environment_flashnext_test.zig | 33 +++++++++++++++---- zig/tests/fixtures/gradient-serving.tsv | 2 +- 7 files changed, 70 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 578ea28b117..5cd9dc8d613 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -363,6 +363,8 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel - Flash Next on Metal: an explicit `--context` smaller than the trained one now sizes the caches and selectors to that context, with the rotary positions unchanged, so a smaller context holds less memory; tokens are unchanged (#3691, part of #3667). +- 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 a value that is empty or only spaces and tabs reads as unset; valid values and defaults are unchanged (#3749, part of #2370). + - Server: text chat requests on engines with a prompt cache or prompt chunking record where each provable message starts in the rendered prompt, at exact token boundaries; nothing uses the starts yet, so replies are unchanged (#3679, step 0 of #3617). - Server: `--cors-origin ORIGIN` (repeatable, exact origins only, no wildcard or credentials mode) lets a browser page on that origin call the API: its preflights are answered and its replies and streams name it, while keys are still required. `/v1/apply-template` returns the prompt text a chat request's `messages` render to, special tokens included, without running the model (#3166, fixes #3111). diff --git a/docs/environment.md b/docs/environment.md index cd6529e1dcd..894b1300ef5 100644 --- a/docs/environment.md +++ b/docs/environment.md @@ -127,7 +127,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 | @@ -147,6 +147,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 | diff --git a/zig/src/families/flashnext/cuda_dense_split.zig b/zig/src/families/flashnext/cuda_dense_split.zig index c08b7a236ce..3c4a2758021 100644 --- a/zig/src/families/flashnext/cuda_dense_split.zig +++ b/zig/src/families/flashnext/cuda_dense_split.zig @@ -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. @@ -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" { @@ -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)); diff --git a/zig/src/families/flashnext/cuda_head.zig b/zig/src/families/flashnext/cuda_head.zig index 4793a99b60b..7529c152e1a 100644 --- a/zig/src/families/flashnext/cuda_head.zig +++ b/zig/src/families/flashnext/cuda_head.zig @@ -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 { @@ -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()); } diff --git a/zig/src/platform/environment.zig b/zig/src/platform/environment.zig index c3c205c632b..973c53e67e1 100644 --- a/zig/src/platform/environment.zig +++ b/zig/src/platform/environment.zig @@ -215,6 +215,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)" }, diff --git a/zig/src/platform/environment_flashnext_test.zig b/zig/src/platform/environment_flashnext_test.zig index 6df4cdca58d..84865f5baa4 100644 --- a/zig/src/platform/environment_flashnext_test.zig +++ b/zig/src/platform/environment_flashnext_test.zig @@ -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" { @@ -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); @@ -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)); + } } diff --git a/zig/tests/fixtures/gradient-serving.tsv b/zig/tests/fixtures/gradient-serving.tsv index fc601611c55..8c49a3d42b3 100644 --- a/zig/tests/fixtures/gradient-serving.tsv +++ b/zig/tests/fixtures/gradient-serving.tsv @@ -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 b72cee919a557e16f001d2c6a7b77602889f6d41a225e0af4736368aff01aee6 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), this change (the page pool opens with the load's device and io, for its arena mapped as pages are used; a new paged stream's first prompt step waits while the arena's thread maps its pieces; paging off: unchanged) From c05cdbec36ffa30d28eb2805450ff6ef14fc9eb2 Mon Sep 17 00:00:00 2001 From: ashhart <71890694+ashhart@users.noreply.github.com> Date: Thu, 19 Nov 2026 20:54:54 +0000 Subject: [PATCH 2/2] changelog: #3749's line from lines/3749.txt in place of its own --- CHANGELOG.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cd9dc8d613..d886df2858c 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 +- 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. + - Tests: the Web loopback startup regression sets its stand-in past the three-second warm-up, so it passes standalone and in the full suite alike (#4086, fixes #3752). - Docs: a one-GB10 recipe serves DeepSeek-V4-Pro-Qwen3.5-9B from a locally converted MLX 4-bit checkpoint, thinking and drafts off, with its health, model-list and chat checks (#4085, fixes #3905). @@ -94,8 +96,6 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel - 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. @@ -363,8 +363,6 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel - Flash Next on Metal: an explicit `--context` smaller than the trained one now sizes the caches and selectors to that context, with the rotary positions unchanged, so a smaller context holds less memory; tokens are unchanged (#3691, part of #3667). -- 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 a value that is empty or only spaces and tabs reads as unset; valid values and defaults are unchanged (#3749, part of #2370). - - Server: text chat requests on engines with a prompt cache or prompt chunking record where each provable message starts in the rendered prompt, at exact token boundaries; nothing uses the starts yet, so replies are unchanged (#3679, step 0 of #3617). - Server: `--cors-origin ORIGIN` (repeatable, exact origins only, no wildcard or credentials mode) lets a browser page on that origin call the API: its preflights are answered and its replies and streams name it, while keys are still required. `/v1/apply-template` returns the prompt text a chat request's `messages` render to, special tokens included, without running the model (#3166, fixes #3111).