Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
1 change: 1 addition & 0 deletions docs/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down
10 changes: 7 additions & 3 deletions docs/recipes/glm-5.3-flash-cuda.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
26 changes: 21 additions & 5 deletions zig/glm_lane_costs_host.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand All @@ -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| {
Expand All @@ -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;
Expand Down Expand Up @@ -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]);
}
14 changes: 13 additions & 1 deletion zig/src/families/glm/cuda_env_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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" {
Expand Down
24 changes: 14 additions & 10 deletions zig/src/families/glm/cuda_lane_cost_measure.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand Down
Loading
Loading