diff --git a/CHANGELOG.md b/CHANGELOG.md index faa5b46820a..3aac163cff8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel ## Unreleased +- GLM-5.3-Flash on CUDA: `TF_GLM_EXPERT_FORM=classic` or `factored` names the expert form and skips the load's race between the two, so launches and builds compare at one form; a load that times nothing still takes the named form, and unset keeps the race (#3151). Thanks to @Bizuayeu. - Security: on macOS and Windows, a library named without a folder is never loaded from the directory the server was started in; on macOS, name its folder in DYLD_FALLBACK_LIBRARY_PATH if it was only found there (#3100). - Prompt cache: with `--learn-conversations`, an image conversation's kept states stay in RAM as before, and the log now says so once per conversation ("kept RAM-only (ImageConversation)") instead of leaving disk silently unused; no prompt text or image content is logged, and replies are unchanged (#3008). diff --git a/docs/environment.md b/docs/environment.md index ec9622d3cad..55707374235 100644 --- a/docs/environment.md +++ b/docs/environment.md @@ -48,6 +48,7 @@ Diagnostics quote and escape the supplied text so it cannot create another termi | `TF_GLM_DFLASH2_LOG` | Whole unsigned 64-bit count of DFlash2 rounds whose drafts are logged; default 0 | | `TF_GLM_DRAFT_CONFIDENCE` | Finite number 0 through 1 where a DFlash2 chain's chance product stops it; default 0.7 | | `TF_GLM_CONTEXT_CEILING` | GLM-5.3-Flash on CUDA: whole token count 1 through 2147483616, the window `--context` may ask for and `--context 0` serves, in place of config.json's 1048576; read at GLM's open. Past that length the model's quality is the operator's to check. Unset keeps config.json's window | +| `TF_GLM_EXPERT_FORM` | `classic` or `factored`: the expert form GLM's CUDA decode windows use (the same bits either way), also at a load that times nothing; unset or blank races the two when a build first loads with drafts and scratch context and keeps the winner, else classic; read on rank 0, which chooses every rank's form | | `TF_PROMPT_ROWS` | Native serving: a multiple of 16 from 128 through 2048; unset keeps the chip/family default | | `TF_ANE_COLUMNS` | Whole u32 count; zero disables the experimental share; default zero | | `TF_FLASHNEXT_SCALE_INDEX` | Flash Next on Metal before tensor units: exactly `0` or `1`; default 1, where the 4-bit expert kernels (decode, grouped and prompt gathers) read each group's scale and bias through a 16-bit index into its tensor's table of pairs, the same values from fewer weight bytes, and the routed experts' stored scales and biases are not kept in memory; `0` keeps and reads the stored arrays; ignored with `--ssd-experts` | diff --git a/docs/recipes/glm-5.3-flash-cuda.md b/docs/recipes/glm-5.3-flash-cuda.md index 76bb177a8df..b882983940f 100644 --- a/docs/recipes/glm-5.3-flash-cuda.md +++ b/docs/recipes/glm-5.3-flash-cuda.md @@ -134,12 +134,16 @@ bits. MTP also times windows of 1, 2, 3, 4, 6, 8, 12, 16, 24 and 32 rows, with s chained draft step. Its startup line reports `glm: windows (timed)` and the expert form. DFlash2 keeps the existing seed forward and step prices in lone and shared rounds; it times only the target expert-form race and reports `glm: expert form (timed)`. No unused DFlash2 window or draft-step table is measured or published to the lane core. +`TF_GLM_EXPERT_FORM=classic` or `factored` names the form instead and skips the race, so launches compare at one +form, and a load that times nothing still runs it (`glm: expert form (untimed)`); a named form's startup line puts +`(TF_GLM_EXPERT_FORM)` after the form's word. The measurements stay in `~/.cache/tensorfold/window-costs`, keyed by the build, GPU/driver, full checkpoint and drafter identity, drafter precision, rank count, layer limit, L2-prefetch options, loaded NVFP4 decode warps, KDA and matmul -modes, dense/head bits, KV placement and the recorded NCCL channel/P2P settings. The DFlash2 form-only records have -separate keys from window tables. An identity too long for its buffer skips both price caches with a log line and -still measures the required work; it never truncates an identity or refuses the model for that reason. +modes, dense/head bits, KV placement, the recorded NCCL channel/P2P settings and a form `TF_GLM_EXPERT_FORM` names, so +a named form never reads the race's record. The DFlash2 form-only records have separate keys from window tables. An +identity too long for its buffer skips both price caches with a log line and still measures the required work; it +never truncates an identity or refuses the model for that reason. An older TP=2 GB10 receipt, before the unused DFlash2 timing was removed, had one empty-price-cache load of 85.2 s and other loads of 70-75 s. Its drafter mode is not recorded. That single sample does not estimate this startup path. diff --git a/zig/glm_lane_costs_host.zig b/zig/glm_lane_costs_host.zig index 4216a8f5b22..9a626876b0a 100644 --- a/zig/glm_lane_costs_host.zig +++ b/zig/glm_lane_costs_host.zig @@ -27,7 +27,7 @@ const Recording = struct { test "GLM load prices: DFlash2 races expert forms without timing unused windows or head steps" { var r: Recording = .{}; - const kept = try costs.measurements.measure(&r, true); + const kept = try costs.measurements.measure(&r, true, null); try t.expectEqual([3]bool{ false, true, true }, r.forms); try t.expectEqual(@as(usize, 0), r.drafts); for (r.windows, 0..) |count, i| { @@ -41,7 +41,7 @@ test "GLM load prices: DFlash2 races expert forms without timing unused windows test "GLM load prices: MTP retains every timed width and the two-level head slope" { var r: Recording = .{}; - const kept = try costs.measurements.measure(&r, false); + const kept = try costs.measurements.measure(&r, false, null); try t.expectEqual([3]bool{ false, true, true }, r.forms); try t.expectEqual(@as(usize, 32), r.drafts); for (r.windows, 0..) |count, i| { @@ -55,6 +55,22 @@ test "GLM load prices: MTP retains every timed width and the two-level head slop try t.expect(costs.tableFor(kept, true) == null); } +test "GLM load prices: a named expert form is set once, before the warm-up, and no forms race" { + for ([_]bool{ false, true }) |pin| for ([_]bool{ false, true }) |block| { + var r: Recording = .{}; + const kept = try costs.measurements.measure(&r, block, pin); + try t.expectEqual(@as(usize, 1), r.changes); + try t.expectEqual(pin, r.forms[0]); + try t.expectEqual(@as(u64, @intFromBool(pin)), kept.fact); + try t.expectEqual(@as(usize, if (block) 0 else 16), r.drafts); + for (r.windows, 0..) |count, i| { + const warm: usize = if (i == costs.widths.len - 1) 8 else 0; + try t.expectEqual(warm + @as(usize, if (block) 0 else 8), count); + } + try t.expect(costs.measurements.reusable(kept, block)); + }; +} + const Device = struct { fn attribute(out: *c_int, attr: cuda.abi.DeviceAttribute, _: cuda.abi.Device) callconv(.c) cuda.abi.Result { out.* = if (attr == .compute_capability_major) 12 else 1; @@ -99,14 +115,14 @@ test "GLM load prices: an oversized NCCL setting disables the cache without reje defer a.free(long); @memset(long, 'x'); try t.expectEqual(@as(c_int, 0), env.setenv(variable, long, 1)); - try t.expect((try costs.keyParts(&e, &ctx, &name, &shape)) == null); + try t.expect((try costs.keyParts(&e, &ctx, &name, &shape, null)) == null); try t.expectEqual(@as(c_int, 0), env.setenv(variable, "SYS", 1)); - const parts = (try costs.keyParts(&e, &ctx, &name, &shape)) orelse return error.ExpectedShortIdentity; + const parts = (try costs.keyParts(&e, &ctx, &name, &shape, null)) orelse return error.ExpectedShortIdentity; try t.expectEqualStrings("glm-cuda", parts[0]); var dr: @TypeOf(e.drafter.?.*) = undefined; dr.bits = 4; dr.checkpoint_digest = @splat(2); e.drafter = &dr; - const form = (try costs.keyParts(&e, &ctx, &name, &shape)) orelse return error.ExpectedFormIdentity; + const form = (try costs.keyParts(&e, &ctx, &name, &shape, null)) orelse return error.ExpectedFormIdentity; try t.expectEqualStrings("glm-cuda-form", form[0]); } diff --git a/zig/src/families/glm/cuda_env_test.zig b/zig/src/families/glm/cuda_env_test.zig index cb457eda5a4..a74685852f0 100644 --- a/zig/src/families/glm/cuda_env_test.zig +++ b/zig/src/families/glm/cuda_env_test.zig @@ -21,6 +21,7 @@ const counts = [_][:0]const u8{"TF_GLM_DFLASH2_LOG"}; const reals = [_][:0]const u8{"TF_GLM_DRAFT_CONFIDENCE"}; /// The window GLM may serve past config.json's: GLM's raisedCeiling reads it at the open, after these rows' check. const windows = [_][:0]const u8{"TF_GLM_CONTEXT_CEILING"}; +const words = [_][:0]const u8{"TF_GLM_EXPERT_FORM"}; /// The row by name without `rule`, so a missing row fails an assertion instead of panicking. fn row(name: []const u8) !e.Rule { @@ -58,12 +59,23 @@ test "GLM strict env: every GLM reader's name is a glm row, and the glm scope ho for (counts) |name| try t.expectEqual(e.Kind.u64, (try row(name)).kind); for (reals) |name| try t.expectEqual(e.Kind.real, (try row(name)).kind); for (windows) |name| try t.expectEqual(e.Kind.u64, (try row(name)).kind); + for (words) |name| try t.expectEqual(e.Kind.word, (try row(name)).kind); var n: usize = 0; for (e.rules) |r| if (r.scope == .glm) { try t.expect(std.mem.startsWith(u8, r.name, "TF_GLM_")); n += 1; }; - try t.expectEqual(switches.len + counts.len + reals.len + windows.len, n); + try t.expectEqual(switches.len + counts.len + reals.len + windows.len + words.len, n); +} + +test "GLM strict env: the expert form takes classic or factored, leaves blank to the race, and refuses the rest by name" { + for ([_]?[]const u8{ null, "", " ", " \t\r\n" }) |raw| { + try t.expectEqual(@as(?u64, null), try e.value(?u64, words[0], raw, null)); + if (raw) |v| try check(words[0], v, true); + } + try t.expectEqual(@as(?u64, 0), try e.value(?u64, words[0], "classic", null)); + try t.expectEqual(@as(?u64, 1), try e.value(?u64, words[0], "factored", null)); + for ([_][]const u8{ "Classic", "FACTORED", "0", "1", "race", "auto", " classic", "factored " }) |raw| try check(words[0], raw, false); } test "GLM strict env: switches keep unset, blank, 0 and 1, and refuse words and padded digits by name" { diff --git a/zig/src/families/glm/cuda_lane_cost_measure.zig b/zig/src/families/glm/cuda_lane_cost_measure.zig index 7487bc8a972..f4d00545c80 100644 --- a/zig/src/families/glm/cuda_lane_cost_measure.zig +++ b/zig/src/families/glm/cuda_lane_cost_measure.zig @@ -8,8 +8,8 @@ const warm = 8; const levels = [2]usize{ 1, 8 }; pub const Kept = extern struct { ms: [widths.len]f64, step_ms: f64, fact: u64 }; -/// Warm the target, race its expert forms, then measure only the prices that this drafter consumes. -pub fn measure(timer: anytype, block: bool) !Kept { +/// Warm the target, race its expert forms unless `pin` names one, then measure only the prices this drafter consumes. +pub fn measure(timer: anytype, block: bool, pin: ?bool) !Kept { const Window = struct { timer: @TypeOf(timer), pub fn time(w: @This(), i: usize) !f64 { @@ -24,15 +24,19 @@ pub fn measure(timer: anytype, block: bool) !Kept { }; const w: Window = .{ .timer = timer }; const d: Draft = .{ .timer = timer }; + if (pin) |f| try timer.form(f); for (0..warm) |_| _ = try w.time(widths.len - 1); - var forms: [2]f64 = .{ 0, 0 }; - for (&forms, [_]bool{ false, true }) |*sum, fact| { - try timer.form(fact); - for (race) |i| sum.* += try rule.fastest(w, i); - if (!block) sum.* += try rule.fastest(d, levels[0]); - } - const fact = forms[1] < forms[0] * (1 - margin); - try timer.form(fact); + const fact = pin orelse race: { + var forms: [2]f64 = .{ 0, 0 }; + for (&forms, [_]bool{ false, true }) |*sum, f| { + try timer.form(f); + for (race) |i| sum.* += try rule.fastest(w, i); + if (!block) sum.* += try rule.fastest(d, levels[0]); + } + const won = forms[1] < forms[0] * (1 - margin); + try timer.form(won); + break :race won; + }; var k: Kept = .{ .ms = @splat(0), .step_ms = 0, .fact = @intFromBool(fact) }; if (block) return k; for (&k.ms, 0..) |*m, i| m.* = try rule.fastest(w, i); diff --git a/zig/src/families/glm/cuda_lane_costs.zig b/zig/src/families/glm/cuda_lane_costs.zig index 1e707010470..da1233ad728 100644 --- a/zig/src/families/glm/cuda_lane_costs.zig +++ b/zig/src/families/glm/cuda_lane_costs.zig @@ -59,16 +59,17 @@ pub fn tableFor(k: Kept, block: bool) ?Table { /// Rank 0 chooses expert forms; prices are null for DFlash2, no drafts, or too little scratch context. pub fn price(gpa: std.mem.Allocator, io: std.Io, ctx: *const cuda.Context, dir: []const u8, x: follow.Leader) !?Table { const e = x.e; - if (!e.mtp or e.capacity < prefix + 2 * fw.window_rows + 2) return null; + const pin = try pinnedForm(); + if (!e.mtp or e.capacity < prefix + 2 * fw.window_rows + 2) return untimed(x, pin); var name: [256]u8 = undefined; var shape: [512]u8 = undefined; const block = e.drafter != null; - const parts = try keyParts(e, ctx, &name, &shape); + const parts = try keyParts(e, ctx, &name, &shape, pin); const key = if (parts) |v| cache.key(gpa, io, &v) catch null else null; - if (key) |k| if (cache.load(Kept, gpa, io, k)) |kept| if (measurements.reusable(kept, block)) { + if (key) |k| if (cache.load(Kept, gpa, io, k)) |kept| if (reuses(kept, block, pin)) { try x.expertForm(kept.fact != 0); try x.idle(); - report(kept, "kept", block); + report(kept, "kept", block, pin != null); return tableFor(kept, block); }; const path = try std.fs.path.join(gpa, &.{ dir, "tokenizer.json" }); @@ -80,49 +81,82 @@ pub fn price(gpa: std.mem.Allocator, io: std.Io, ctx: *const cuda.Context, dir: if (ids.len < prefix + fw.window_rows + 1) return error.CostTextTooShort; var s: Scratch = .{ .x = x, .io = io, .ids = ids, .most = @min(room, e.capacity - fw.window_rows - prefix - 2), .drafting = !block }; try s.begin(); - var kept = try measurements.measure(&s, block); + var kept = try measurements.measure(&s, block, pin); const reference = if (!block and parts != null) cache.referenceKey(&parts.?) else null; if (reference) |key_ref| if (cache.load(Kept, gpa, io, key_ref)) |r| if (rule.drifted(&kept.ms, &r.ms)) try rule.again(Windows{ .s = &s }, &kept.ms); try x.release(0); try x.idle(); if (key) |k| cache.save(Kept, gpa, io, k, kept); if (reference) |key_ref| cache.save(Kept, gpa, io, key_ref, kept); - report(kept, "timed", block); + report(kept, "timed", block, pin != null); return tableFor(kept, block); } -fn report(k: Kept, how: []const u8, block: bool) void { +/// A kept record stands for this load when it holds prices and, under a named form, was kept at that form. +fn reuses(kept: Kept, block: bool, pin: ?bool) bool { + return measurements.reusable(kept, block) and (pin == null or pin.? == (kept.fact != 0)); +} + +/// TF_GLM_EXPERT_FORM on rank 0, which chooses every rank's form: null races classic and factored, else the one named. +fn pinnedForm() !?bool { + const i = (try sys.environment.read(?u64, "TF_GLM_EXPERT_FORM", null)) orelse return null; + return i == 1; +} + +/// A load that times nothing still sends a named form to every rank; unnamed, the forms stay classic. +fn untimed(x: anytype, pin: ?bool) !?Table { + const f = pin orelse return null; + try x.expertForm(f); + try x.idle(); + std.log.info(untimed_line, .{if (f) "factored" else "classic"}); + return null; +} + +/// The startup lines; a named form puts ` (TF_GLM_EXPERT_FORM)` right after the form's word. +const window_line = "glm: windows ({s}): {d:.2} ms at 1 row, {d:.2} at 4, {d:.2} at 32, a draft {d:.2} ms; experts {s}{s}"; +const form_line = "glm: expert form ({s}): {s}{s}; DFlash2 keeps its seed window and step prices"; +const untimed_line = "glm: expert form (untimed): {s} (TF_GLM_EXPERT_FORM)"; + +fn report(k: Kept, how: []const u8, block: bool, pinned: bool) void { + const form = if (k.fact != 0) "factored" else "classic"; if (block) { - std.log.info("glm: expert form ({s}): {s}; DFlash2 keeps its seed window and step prices", .{ how, if (k.fact != 0) "factored" else "classic" }); + std.log.info(form_line, .{ how, form, named(pinned) }); return; } - std.log.info("glm: windows ({s}): {d:.2} ms at 1 row, {d:.2} at 4, {d:.2} at 32, a draft {d:.2} ms; experts {s}", .{ how, k.ms[0], k.ms[3], k.ms[widths.len - 1], k.step_ms, if (k.fact != 0) "factored" else "classic" }); + std.log.info(window_line, .{ how, k.ms[0], k.ms[3], k.ms[widths.len - 1], k.step_ms, form, named(pinned) }); +} + +fn named(pinned: bool) []const u8 { + return if (pinned) " (TF_GLM_EXPERT_FORM)" else ""; } -/// Cache identity: the GPU and driver, this checkpoint and drafter, and the settings a window's time follows. -pub fn keyParts(e: *const engine.Engine, ctx: *const cuda.Context, name: []u8, shape: []u8) !?[3][]const u8 { - const at = cacheShape(e, try ctx.capability(), try ctx.d.version(), shape) orelse return null; +/// Cache identity: the GPU and driver, this checkpoint and drafter, the settings a window's time follows, a named form. +pub fn keyParts(e: *const engine.Engine, ctx: *const cuda.Context, name: []u8, shape: []u8, pin: ?bool) !?[3][]const u8 { + const at = cacheShape(e, try ctx.capability(), try ctx.d.version(), shape, pin) orelse return null; return .{ if (e.drafter != null) "glm-cuda-form" else "glm-cuda", ctx.name(name) catch "gpu", at }; } /// An oversized identity disables caching; it does not reject a valid model or truncate a key. -fn cacheShape(e: *const engine.Engine, sm: usize, driver: c_int, shape: []u8) ?[]const u8 { - return keyShape(e, sm, driver, shape) catch { +fn cacheShape(e: *const engine.Engine, sm: usize, driver: c_int, shape: []u8, pin: ?bool) ?[]const u8 { + return keyShape(e, sm, driver, shape, pin) catch { std.log.warn("glm: lane cost identity exceeds its buffer; skipping the lane cost cache", .{}); return null; }; } -fn keyShape(e: *const engine.Engine, sm: usize, driver: c_int, shape: []u8) ![]const u8 { +/// A named form ends the identity, so a race's kept prices and a named form's never stand in for each other. +fn keyShape(e: *const engine.Engine, sm: usize, driver: c_int, shape: []u8, pin: ?bool) ![]const u8 { const set = e.settings; const hex = std.fmt.bytesToHex(e.checkpoint_digest, .lower); const draft_hex = std.fmt.bytesToHex(if (e.drafter) |dr| dr.checkpoint_digest else @as([32]u8, @splat(0)), .lower); - return std.fmt.bufPrint(shape, "sm{d} cuda{d} ranks{d} {s} drafter{d}/{d}/{s} layers{d} l2{d}/{d}/{d}/{d}/{d} warps{d} kda{d} mm{d} bits{d}/{d} kv8{d} pages{d} host{d} roce{d} p2p{s}/{s}/{s}", .{ + const tail: []const u8 = if (pin) |f| (if (f) " form factored" else " form classic") else ""; + return std.fmt.bufPrint(shape, "sm{d} cuda{d} ranks{d} {s} drafter{d}/{d}/{s} layers{d} l2{d}/{d}/{d}/{d}/{d} warps{d} kda{d} mm{d} bits{d}/{d} kv8{d} pages{d} host{d} roce{d} p2p{s}/{s}/{s}{s}", .{ sm, driver, e.share.world, hex[0..], @intFromBool(e.drafter != null), if (e.drafter) |dr| dr.bits else @as(u8, 0), draft_hex[0..], set.layers, @intFromBool(set.l2pf.on), @intFromBool(set.l2pf.named), set.l2pf.mb, set.l2pf.ctas, set.l2pf.pace_gbps, e.m.experts.nvfp4.warps, @intFromBool(set.kda_wide), @intFromBool(set.tiled), set.dense_bits, set.head_bits, @intFromBool(set.kv8), @intFromBool(set.pages), set.kv_host, @intFromBool(set.roce_multi), sys.getenv("NCCL_P2P_LEVEL") orelse "", sys.getenv("NCCL_MIN_NCHANNELS") orelse "", sys.getenv("NCCL_MAX_NCHANNELS") orelse "", + tail, }); } @@ -214,7 +248,7 @@ test "GLM cost identity: the consumed key includes drafter precision and all tim dr.checkpoint_digest = @splat(2); e.drafter = &dr; var base: [512]u8 = undefined; - const before = try keyShape(&e, 121, 13000, &base); + const before = try keyShape(&e, 121, 13000, &base, null); for (0..11) |which| { const original = e.settings; switch (which) { @@ -232,7 +266,7 @@ test "GLM cost identity: the consumed key includes drafter precision and all tim else => unreachable, } var changed: [512]u8 = undefined; - try std.testing.expect(!std.mem.eql(u8, before, try keyShape(&e, 121, 13000, &changed))); + try std.testing.expect(!std.mem.eql(u8, before, try keyShape(&e, 121, 13000, &changed, null))); e.settings = original; e.drafter = &dr; dr.bits = 4; @@ -240,4 +274,76 @@ test "GLM cost identity: the consumed key includes drafter precision and all tim e.checkpoint_digest = @splat(1); e.m.experts.nvfp4.warps = 4; } + // a named form only ends the identity, so the race's key stays as it was + var classic: [512]u8 = undefined; + var factored: [512]u8 = undefined; + const pinned = try keyShape(&e, 121, 13000, &classic, false); + try std.testing.expect(std.mem.startsWith(u8, pinned, before) and pinned.len > before.len); + try std.testing.expect(!std.mem.eql(u8, pinned, try keyShape(&e, 121, 13000, &factored, true))); +} + +test "GLM cost identity: a named form's startup line ends at (TF_GLM_EXPERT_FORM), and a raced one as it did" { + var buf: [256]u8 = undefined; + const raced = try std.fmt.bufPrint(&buf, window_line, .{ "timed", 29.73, 44.02, 130.65, 1.53, "classic", named(false) }); + try std.testing.expect(std.mem.endsWith(u8, raced, "130.65 at 32, a draft 1.53 ms; experts classic")); + const kept = try std.fmt.bufPrint(&buf, window_line, .{ "kept", 29.73, 44.02, 130.65, 1.53, "factored", named(true) }); + try std.testing.expect(std.mem.endsWith(u8, kept, "a draft 1.53 ms; experts factored (TF_GLM_EXPERT_FORM)")); + const form = try std.fmt.bufPrint(&buf, form_line, .{ "timed", "classic", named(true) }); + try std.testing.expect(std.mem.startsWith(u8, form, "glm: expert form (timed): classic (TF_GLM_EXPERT_FORM); DFlash2")); + try std.testing.expectEqualStrings("glm: expert form (untimed): factored (TF_GLM_EXPERT_FORM)", try std.fmt.bufPrint(&buf, untimed_line, .{"factored"})); +} + +test "GLM cost identity: a load that times nothing sends a named form to every rank once, and nothing unnamed" { + const Leader = struct { + form: ?bool = null, + sent: usize = 0, + idles: usize = 0, + pub fn expertForm(l: *@This(), fact: bool) !void { + l.form = fact; + l.sent += 1; + } + pub fn idle(l: *@This()) !void { + l.idles += 1; + } + }; + for ([_]?bool{ null, false, true }) |pin| { + var l: Leader = .{}; + try std.testing.expect((try untimed(&l, pin)) == null); + try std.testing.expectEqual(pin, l.form); + try std.testing.expectEqual(@as(usize, @intFromBool(pin != null)), l.sent); + try std.testing.expectEqual(l.sent, l.idles); + } +} + +test "GLM cost identity: a record kept at one named form is not reused at the other" { + const a = std.testing.allocator; + const io = std.testing.io; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const root = try tmp.dir.realPathFileAlloc(io, ".", a); + defer a.free(root); + var e: engine.Engine = undefined; + e.settings = .{}; + e.checkpoint_digest = @splat(1); + e.share.world = 2; + e.m.experts.nvfp4.warps = 4; + e.drafter = null; + var shapes: [2][512]u8 = undefined; + var keys: [2][32]u8 = undefined; + for ([_]bool{ false, true }, 0..) |fact, i| { + const parts = [_][]const u8{ "glm-cuda", "gpu", try keyShape(&e, 121, 13000, &shapes[i], fact) }; + keys[i] = cache.buildKey("engine", &parts); + } + var ms: [widths.len]f64 = undefined; + for (&ms, widths) |*m, w| m.* = 20 + @as(f64, @floatFromInt(w)); + cache.saveAt(Kept, a, io, keys[0], .{ .ms = ms, .step_ms = 1.5, .fact = 0 }, root); + // a load that names factored looks under its own key and finds nothing to reuse + try std.testing.expect(cache.loadAt(Kept, a, io, keys[1], root) == null); + // the classic load reads the record back and reuses it, as the race does; factored would refuse even this record + const classic = cache.loadAt(Kept, a, io, keys[0], root).?; + try std.testing.expect(reuses(classic, false, false) and reuses(classic, false, null)); + try std.testing.expect(!reuses(classic, false, true)); + var factored = classic; + factored.fact = 1; + try std.testing.expect(reuses(factored, false, true) and !reuses(factored, false, false)); } diff --git a/zig/src/platform/environment.zig b/zig/src/platform/environment.zig index 2cf75312aeb..d4c7094238a 100644 --- a/zig/src/platform/environment.zig +++ b/zig/src/platform/environment.zig @@ -96,6 +96,7 @@ pub const rules = [_]Rule{ .{ .name = "TF_GLM_DRAFT_CONFIDENCE", .scope = .glm, .kind = .real, .max = 1, .forms = "a finite chain-chance cut from 0 to 1 (default 0.7)" }, // 2^31 - 32: GLM's slots, the window and its 32 verify rows (glm/cuda_native.zig's capacity), keep i32 positions .{ .name = "TF_GLM_CONTEXT_CEILING", .scope = .glm, .kind = .u64, .first_digit = true, .min = 1, .max = 2147483616, .forms = "a whole token count from 1 to 2147483616 (the window GLM-5.3-Flash may serve in place of config.json's)" }, + .{ .name = "TF_GLM_EXPERT_FORM", .scope = .glm, .kind = .word, .words = &.{ "classic", "factored" }, .forms = "classic or factored (unset races the two when a build first loads)" }, .{ .name = "TF_DSV41_MHC_DEFER", .scope = .dsv41, .kind = .toggle, .trim = " \t", .no_word = false, .forms = "0, 1, true, false, on, off or yes (any case)" }, .{ .name = "TF_DSV41_COEF_LATE", .scope = .dsv41, .kind = .toggle, .trim = " \t", .no_word = false, .forms = "0, 1, true, false, on, off or yes (any case)" }, .{ .name = "TF_DSV41_LOOKUP", .scope = .dsv41, .kind = .toggle, .trim = " \t", .forms = "0, 1, true, false, on, off, yes or no (any case); blank turns lookup drafts off" },