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
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

- GLM-5.3-Flash on CUDA: prompts take the TF_GLM_INDEX_CUDA kernels by default (0 keeps tf_glm_scores), with the same tokens; at TP=2 on two GB10s prompts are 44% faster at 2K and 31% at 8K, level at 32K (#3159). Thanks to @Bizuayeu.

- Living Weights (`--slide --slide-drift-gate`): the recall wordings a request supplies are held out of the lesson writer's plan. A planned question that matches one under the gate's own contamination check is dropped and replaced, so the gate no longer refuses a lesson as "supplied recall is missing or trained" for a wording the writer made itself; a lesson that can't reach its three-example floor without them is refused as "the plan could not avoid the supplied recall wordings". With no recall supplied, or the gate off, nothing changes (#2929, for #1389). Thanks to @jimthedj65 for the panel run that found it.

- Tests: two host tests in `test-server-cpu` pin the server's incremental reply text: a character split across tokens streams only once it is whole, and each chunk decodes only the previous chunk and its new tokens, never the whole reply (#3022).
Expand Down
2 changes: 1 addition & 1 deletion zig/src/families/glm/cuda_forward.zig
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub const Modules = struct {
errdefer if (m.index) |*x| x.unload();
const mode = index_mod.Mode.read() catch return error.BadIndexSetting;
if (mode != .off) m.index = index_mod.Kernels.load(d, k.glm_index, mode) catch |err| blk: {
std.log.warn("TF_GLM_INDEX_CUDA: the indexer kernels are not used ({t}); prompt chunks use tf_glm_scores", .{err});
std.log.warn("glm: the indexer kernels are not used ({t}); prompt chunks use tf_glm_scores, as with TF_GLM_INDEX_CUDA=0", .{err});
break :blk null;
};
m.dsel = try @import("sys").environment.read(bool, "TF_GLM_DSEL", true);
Expand Down
68 changes: 59 additions & 9 deletions zig/src/families/glm/cuda_index.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ pub const pool_threads = 256;
pub const rows_from = sparse.score_loop_from;
pub const cap_max = 4096;

/// TF_GLM_INDEX_CUDA: unset or 0 (today's launches), 1 (both kernels), scores (only the scores, to bisect).
/// TF_GLM_INDEX_CUDA: unset, blank or 1 (both kernels), scores (only the scores, to bisect), 0 (neither).
pub const Mode = enum {
off,
both,
scores,

pub fn parse(text: ?[]const u8) !Mode {
const t = text orelse return .off;
if (t.len == 0 or std.mem.eql(u8, t, "0")) return .off;
if (std.mem.eql(u8, t, "1")) return .both;
const t = text orelse return .both;
if (std.mem.trim(u8, t, " \t\r\n").len == 0 or std.mem.eql(u8, t, "1")) return .both;
if (std.mem.eql(u8, t, "0")) return .off;
if (std.mem.eql(u8, t, "scores")) return .scores;
return error.BadIndexMode;
}

pub fn read() !Mode {
const v = std.c.getenv("TF_GLM_INDEX_CUDA") orelse return .off;
const v = std.c.getenv("TF_GLM_INDEX_CUDA") orelse return .both;
return parse(std.mem.span(v));
}
};
Expand Down Expand Up @@ -96,13 +96,15 @@ fn cdiv(a: usize, b: usize) usize {
return (a + b - 1) / b;
}

test "GLM index: TF_GLM_INDEX_CUDA is off unless 1 or scores, and a typo is refused" {
try std.testing.expectEqual(Mode.off, try Mode.parse(null));
try std.testing.expectEqual(Mode.off, try Mode.parse(""));
try std.testing.expectEqual(Mode.off, try Mode.parse("0"));
test "GLM index: TF_GLM_INDEX_CUDA is on unless 0, scores bisects, and a typo is refused" {
try std.testing.expectEqual(Mode.both, try Mode.parse(null));
try std.testing.expectEqual(Mode.both, try Mode.parse(""));
try std.testing.expectEqual(Mode.both, try Mode.parse(" \t"));
try std.testing.expectEqual(Mode.both, try Mode.parse("1"));
try std.testing.expectEqual(Mode.off, try Mode.parse("0"));
try std.testing.expectEqual(Mode.scores, try Mode.parse("scores"));
try std.testing.expectError(error.BadIndexMode, Mode.parse("on"));
try std.testing.expectError(error.BadIndexMode, Mode.parse("off"));
}

test "GLM index: the scores grid covers 8 rows a CTA and 16 pool blocks a CTA" {
Expand All @@ -129,3 +131,51 @@ test "GLM index: only prompt-sized launches on aligned key caches take the kerne
try std.testing.expect(!k.takes(512, 1024, 0x1000, 32760));
try std.testing.expect(!k.takes(512, topk - 1, 0x1000, 32768));
}

/// A driver that records each launched function's handle, in order (selectTokens below, without a device).
const Recorded = struct {
var n: usize = 0;
var ids: [16]usize = undefined;
fn launch(f: cuda.abi.Function, _: c_uint, _: c_uint, _: c_uint, _: c_uint, _: c_uint, _: c_uint, _: c_uint, _: cuda.abi.Stream, _: ?[*]?*anyopaque, _: ?[*]?*anyopaque) callconv(.c) c_int {
if (n < ids.len) ids[n] = @intFromPtr(f);
n += 1;
return 0;
}
fn function(out: *cuda.abi.Function, _: cuda.abi.Module, name: [*:0]const u8) callconv(.c) c_int {
out.* = @ptrFromInt(if (std.mem.eql(u8, std.mem.span(name), "tf_glm_dsa_tokens")) @as(usize, 41) else 40);
return 0;
}
};

test "GLM index: prompt chunks take the kernels; a decode row, an unaligned key cache and a small pool cap keep tf_glm_scores" {
const glue = @import("cuda_glue.zig");
const latent = @import("cuda_latent.zig");
var d: cuda.Driver = undefined;
d.api.cuLaunchKernel = Recorded.launch;
d.api.cuModuleGetFunction = Recorded.function;
var ks: glue.Kernels = undefined; // 20 tf_glm_scores, 21 tf_glm_select_rows, 22 its wide form
ks.scores = .{ .d = &d, .handle = @ptrFromInt(20) };
ks.select_rows = .{ .d = &d, .handle = @ptrFromInt(21) };
ks.select_rows_wide = .{ .d = &d, .handle = @ptrFromInt(22) };
const ops: cuda.Module = .{ .d = &d, .handle = null }; // 40 tf_glm_add_i32, 41 tf_glm_dsa_tokens
const stream: cuda.Stream = .{ .d = &d, .handle = null };
const s: sparse.Scratch = .{ .scores = 0x10000, .ls = 0, .li = 0, .pools = 0x20000, .at = 0x30000 };
const table: latent.Table = .{ .pt = 0x4000, .ps = 32768, .page_rows = 512 };
const Case = struct { rows: usize, pk: u64, cap: usize, want: []const usize };
for ([_]Mode{ .both, .scores }) |mode| {
// 30 tf_glm_index_scores, 31 tf_glm_index_pools
const k: Kernels = .{ .module = undefined, .scores_fn = .{ .d = &d, .handle = @ptrFromInt(30) }, .pools_fn = .{ .d = &d, .handle = @ptrFromInt(31) }, .select = mode == .both };
const set: glue.Set = .{ .glue = &ks, .index = &k };
const prompt: []const usize = if (mode == .both) &.{ 30, 31, 41 } else &.{ 30, 21, 41 };
for ([_]Case{
.{ .rows = 512, .pk = 0x1000, .cap = 1 << 20, .want = prompt }, // a prompt chunk of 512 rows at 65,536
.{ .rows = 1, .pk = 0x1000, .cap = 1 << 20, .want = &.{ 20, 22, 41 } }, // a decode row: the wide select
.{ .rows = 512, .pk = 0x1008, .cap = 1 << 20, .want = &.{ 20, 21, 41 } }, // keys off 16 bytes
.{ .rows = 512, .pk = 0x1000, .cap = 256, .want = &.{ 20, 21, 41 } }, // fewer than 512 pools
}) |c| {
Recorded.n = 0;
try sparse.selectTokens(set, ops, stream, 0x5000, 0x6000, 160, c.pk, table, 0x7000, 65536, c.rows, 32, 128, c.cap, s, 0x8000, 0x9000);
try std.testing.expectEqualSlices(usize, c.want, Recorded.ids[0..Recorded.n]);
}
}
}
Loading