Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
6636e69
cuda: a one-shot RoCE all-gather for two ranks (roce.zig, roce_gather…
BobClawblaw Oct 14, 2026
39de039
lane core and native CUDA host for two-rank families with a vision to…
BobClawblaw Oct 14, 2026
bdc47c8
Merge branch 'pr/roce-gather' into pr/glm-flash-cuda
BobClawblaw Oct 14, 2026
cbe08cf
GLM-5.3-Flash on two CUDA ranks: the native family (zig/src/families/…
BobClawblaw Oct 14, 2026
a76f16a
glm kernels: the tensor-core fragment header beside them (qmm_frag.cu…
BobClawblaw Oct 14, 2026
abb8bbe
glm: the three Flash Next kernels the family loads (experts, experts_…
BobClawblaw Oct 14, 2026
2903dd7
cuda abi: the driver entries the GLM family uses (module function enu…
BobClawblaw Oct 14, 2026
87ef757
tf-cuda-test glm-*: exit right after the pass or summary line (the te…
BobClawblaw Oct 14, 2026
a759ccd
Merge branch 'pr/roce-gather' into pr/glm-flash-cuda
BobClawblaw Oct 15, 2026
db750c4
Merge branch 'pr/lane-host-vision' into pr/glm-flash-cuda
BobClawblaw Oct 15, 2026
a2eefa2
glm cuda: zig fmt
BobClawblaw Oct 15, 2026
22d92e4
lane host: a warm pass that steps aside is not launched after its can…
BobClawblaw Oct 15, 2026
a76651a
glm cuda: comments one line each, files under 600 lines, the long hea…
BobClawblaw Oct 15, 2026
ef73ec3
tf_video: the includes back under its one-line header
BobClawblaw Oct 15, 2026
e0d3baa
Merge branch 'pr/lane-host-vision' into pr/glm-flash-cuda
BobClawblaw Oct 15, 2026
0e50498
cuda: RoCE gather comments on one line each, the protocol notes in do…
BobClawblaw Oct 15, 2026
cc5d9d1
vision inputs: a server without --vision refuses image parts in the f…
BobClawblaw Oct 15, 2026
89c68c8
Merge branch 'pr/lane-host-vision' into pr/glm-flash-cuda
BobClawblaw Oct 15, 2026
aaed024
qwen_image.formatSeconds: t * 10 rounded in integers, not f128, so te…
BobClawblaw Oct 15, 2026
2cc423f
Merge branch 'pr/lane-host-vision' into pr/glm-flash-cuda
BobClawblaw Oct 15, 2026
9e6dfcd
lane host: a set-up job's kept entry stays pinned until its restore r…
BobClawblaw Oct 15, 2026
a8ea350
Merge remote-tracking branch 'fork/pr/lane-host-vision' into pr/glm-f…
BobClawblaw Oct 15, 2026
d069277
cuda: RoCE gather ranks agree one shard cap (each sends its max_bytes…
BobClawblaw Oct 15, 2026
22d2a30
Merge remote-tracking branch 'fork/pr/roce-gather' into pr/glm-flash-…
BobClawblaw Oct 15, 2026
b07b11b
glm cuda: the review's four fixes: a RoCE check after every sync that…
BobClawblaw Oct 15, 2026
52b82fc
prompt cache: an entry removed while pinned is dead to lookups and fr…
BobClawblaw Oct 15, 2026
468fa88
Merge branch 'pr/lane-host-vision' into pr/glm-flash-cuda
BobClawblaw Oct 15, 2026
c525ea9
glm cuda: the gather check and the agreed settings' doc comments on o…
BobClawblaw Oct 15, 2026
7c9d845
Merge remote-tracking branch 'origin/main' into pr/roce-gather
BobClawblaw Oct 16, 2026
b8d45de
cuda: the RoCE gather joins tp_group: its setup crosses the group's N…
BobClawblaw Oct 16, 2026
bb7e2a2
Merge origin/main (1.0.12) into pr/lane-host-vision: main's image pat…
BobClawblaw Oct 16, 2026
b416ec8
lane core: several queued prompts in one pass for a backend with pref…
BobClawblaw Oct 16, 2026
1ac97f6
Merge remote-tracking branch 'fork/pr/roce-gather' into tmp-855-base
BobClawblaw Oct 16, 2026
b982a3b
Merge #853 and #852 (both on main 1.0.12 with #804) into pr/glm-flash…
BobClawblaw Oct 16, 2026
aa9d4a7
glm cuda: the ranks' communicator is a tp_group.Group; on two ranks t…
BobClawblaw Oct 16, 2026
653bd37
glm cuda: EXL3 routed experts (Mia-AiLab's checkpoint: 4-bit mcg trel…
BobClawblaw Oct 16, 2026
8278074
kernel contract: glm_exl3's eight launches with their sm_80/86/89/120…
BobClawblaw Oct 16, 2026
084c253
glm cuda: the ranks watch each other (tp_watch): a rank that fails or…
BobClawblaw Oct 16, 2026
b090a7b
glm cuda: verify windows to the decode buffers' 8 rows, so the lane c…
BobClawblaw Oct 16, 2026
93f5261
glm cuda: the image tower (model.visual.*, rank 0's) on cuBLASLt and …
BobClawblaw Oct 16, 2026
f9d4f9f
glm cuda: images on two ranks (--vision): rank 0's tower encodes a pr…
BobClawblaw Oct 16, 2026
3cc4581
tools/glm_vision_ref.py: the torch reference tf-cuda-test glm-vision …
BobClawblaw Oct 16, 2026
edc2285
glm cuda: the bf16 linears on glm_mm (ours, from the glm_cuda family)…
BobClawblaw Oct 16, 2026
875b695
glm cuda: TF_GLM_PROF=1 also times prompt chunks by section (gate, fo…
BobClawblaw Oct 16, 2026
526ffd4
Merge the glm_cuda family's head (c525ea99): its work now lives in fa…
BobClawblaw Oct 16, 2026
f24a651
glm cuda: DFlash2 drafts on families/glm (--drafter): taps after laye…
BobClawblaw Oct 16, 2026
9f638dc
glm cuda: DFlash2 drafts sized by their chances (the selector's, chai…
BobClawblaw Oct 17, 2026
70faca3
glm cuda: DFlash2's linears at 4 bits by default (--drafter-bits 4|0)…
BobClawblaw Oct 17, 2026
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
Prev Previous commit
Next Next commit
glm cuda: DFlash2 drafts sized by their chances (the selector's, chai…
…ned, cut at glm_cuda's 0.7) against measured window costs; TF_GLM_DFLASH2_LOG and _PROF
  • Loading branch information
BobClawblaw committed Oct 17, 2026
commit 9f638dc4486f4dfda565d52fa98cb7640048db1a
50 changes: 48 additions & 2 deletions zig/src/families/glm/cuda_lanes.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,22 @@ pub const max_rows = fw.window_rows;
const mtp_rows = 1 + engine.max_drafts;
const max_held = dflash.BLOCK - 1; // a DFlash2 block's drafts (the MTP head's chains stop at max_drafts)

/// With DFlash2: a window's ms by rows on two GB10s (EXL3, TF_GLM_PROF: 86 to 107 ms at 5 to 8), shared as glm_cuda's.
const gb10_window_costs = costTable(max_rows, 52.0, 6.8);
const gb10_shared_costs = costTable(engine.shared_rows, 76.0, 4.1);

fn costTable(comptime n: usize, comptime one: f64, comptime row: f64) [n]lanes.config.Cost {
var c: [n]lanes.config.Cost = undefined;
for (&c, 0..) |*x, i| x.* = .{ .width = i + 1, .ms = one + row * @as(f64, @floatFromInt(i)) };
return c;
}

/// A stream's place in the backend: its sequence's slot, the rows its last verify left uncommitted, its held drafts.
const Lane = struct {
slot: u32,
pending_rows: ?usize = null,
held: [max_held]u32 = undefined,
chances: [max_held]f64 = undefined, // DFlash2's: each held draft's chance from the selector
held_n: usize = 0,
fill: ?usize = null, // a prompt pass going a chunk at a time: where its next chunk starts
};
Expand Down Expand Up @@ -51,6 +62,7 @@ pub const Lanes = struct {
.verify = verifyFn,
.keep = keepFn,
.draft = draftFn,
.probabilities = chancesFn,
.release = releaseFn,
};
const steps_vt: be.Backend.VTable = vt: {
Expand All @@ -74,6 +86,9 @@ pub const Lanes = struct {
.drafts = if (block) max_held else engine.max_drafts,
.draft_streams = block, // one block pass drafts every stream of the round
.mtp_step_ms = if (block) 1.6 / @as(f64, max_held) else 0, // a block's 7 drafts in one pass (about 1.6 ms)
.draft_probabilities = block, // the selector's chances size each window against the costs below
.window_costs = if (block) &gb10_window_costs else &.{},
.shared_costs = if (block) &gb10_shared_costs else &.{},
.hidden_rows = sharing,
.batch_rows = if (sharing) engine.shared_rows else 0,
.max_streams = if (sharing) engine.max_shared else 1,
Expand Down Expand Up @@ -316,11 +331,42 @@ pub const Lanes = struct {
n = rows.len;
break :a r.follow[rows.len - 1];
} else self.value(r.first orelse return error.NoFirstToken);
reqs[i] = .{ .slot = l.slot, .pos = 0, .n = n, .anchor = anchor, .out = &l.held };
reqs[i] = .{ .slot = l.slot, .pos = 0, .n = n, .anchor = anchor, .out = &l.held, .probs = &l.chances };
held[i] = l;
}
try self.x.block(reqs[0..requests.len]);
for (requests, held[0..requests.len]) |r, l| l.held_n = @min(r.depth, max_held);
const cut = confidence();
for (requests, held[0..requests.len]) |r, l| {
l.held_n = @min(r.depth, max_held);
var chain: f64 = 1; // glm_cuda's rule: past the first, a chain stops where its product falls under the cut
for (l.chances[0..l.held_n], 0..) |*c, j| {
chain *= c.*;
if (j > 0 and chain < cut) c.* = 0; // held with chance 0: the window sizing leaves it out
if (c.* == 0) chain = 0;
}
}
}

/// TF_GLM_DRAFT_CONFIDENCE: where a DFlash2 chain's chance product stops it (glm_cuda's 0.7).
fn confidence() f64 {
const v = std.c.getenv("TF_GLM_DRAFT_CONFIDENCE") orelse return 0.7;
return std.fmt.parseFloat(f64, std.mem.span(v)) catch 0.7;
}

/// DFlash2's chance for each held draft (the MTP head gives none: the lane core's per-depth rates stand).
fn chancesFn(ptr: *anyopaque, s: *lanes.Stream, out: []f64) anyerror!bool {
const self = of(ptr);
if (self.x.e.drafter == null) return false;
const l = self.lanes.getPtr(s) orelse return false;
if (l.held_n == 0) return false;
const n = @min(out.len, l.held_n);
var chain: f64 = 1; // a draft lands only if every one before it does: the selector's chances chained
for (out[0..n], l.chances[0..n]) |*c, p| {
chain *= p;
c.* = chain;
}
for (out[n..]) |*c| c.* = 0;
return true;
}

/// The stream left the rounds: its sequence is freed on every rank (slot 0 stays for the next stream).
Expand Down
24 changes: 24 additions & 0 deletions zig/src/families/glm/dflash.zig
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ pub const Drafter = struct {
verifies: u64 = 0, // verifies so far: a slot's rows are still in taps_step while its v_step is the latest
lost: u64 = 0, // drafts whose verify rows were gone (their context restarted)
calls: u64 = 0,
log: u64 = 0, // TF_GLM_DFLASH2_LOG=n: the first n rounds' drafts logged (rank 0)
prof: ?std.Io = null, // TF_GLM_DFLASH2_PROF=1: each phase synchronized and timed, logged every 64 rounds
phase_ms: [4]f64 = @splat(0), // ingest, tables, block pass, selector
// device scratch (carved by dflash_load)
x: u64 = 0,
y: u64 = 0,
Expand Down Expand Up @@ -160,6 +163,15 @@ pub const Drafter = struct {
g.destroy(dr);
}

/// TF_GLM_DFLASH2_PROF: the stream idle, the time since `since` added to its phase; the new mark.
fn mark(dr: *Drafter, e: anytype, since: ?struct { i96, usize }) !i96 {
const io = dr.prof orelse return 0;
try e.stream.synchronize();
const now = std.Io.Clock.awake.now(io).toNanoseconds();
if (since) |s| dr.phase_ms[s[1]] += @as(f64, @floatFromInt(now - s[0])) / 1e6;
return now;
}

/// Where a forward's taps go: a prompt chunk's rows or a verify's.
pub fn taps(dr: *const Drafter, chunk: bool) taps_mod.Taps {
return .{ .f = dr.k.tap, .out = if (chunk) dr.taps_prefill else dr.taps_step };
Expand Down Expand Up @@ -220,6 +232,7 @@ pub const Drafter = struct {
pub fn draft(dr: *Drafter, e: anytype, reqs: []const Req) !void {
if (reqs.len == 0) return;
if (reqs.len > MAX_S) return error.TooManyStreams;
var tm = try dr.mark(e, null);
var runs: [MAX_S]Run = undefined;
var nr: usize = 0;
for (reqs) |q| {
Expand All @@ -234,6 +247,7 @@ pub const Drafter = struct {
nr += 1;
}
try dr.ingest(e, runs[0..nr]);
tm = try dr.mark(e, .{ tm, 0 });
const S = reqs.len;
for (reqs, 0..) |q, i| {
const s = &dr.slots.items[q.slot];
Expand All @@ -252,12 +266,22 @@ pub const Drafter = struct {
try block.upload(dr, e, dr.starts, std.mem.sliceAsBytes(dr.h_starts[0..S]));
try block.upload(dr, e, dr.froms, std.mem.sliceAsBytes(dr.h_froms[0..S]));
const rank0 = reqs[0].out != null;
tm = try dr.mark(e, .{ tm, 1 });
try block.pass(dr, e, S, rank0);
tm = try dr.mark(e, .{ tm, 2 });
if (rank0) {
try block.download(dr, e, std.mem.sliceAsBytes(dr.cand[0 .. 2 * M * CW]), dr.gtk);
try block.download(dr, e, std.mem.sliceAsBytes(dr.gh[0 .. M * RANK]), dr.g);
for (reqs, 0..) |q, i| select.select(dr, i, M, q);
if (dr.log > dr.calls) for (reqs) |q| std.log.info("dflash2 round {d}: slot {d} pos {d} kept {d} anchor {d} drafts {any}", .{ dr.calls, q.slot, q.pos, q.n, q.anchor, q.out.?[0 .. BLOCK - 1] });
if (dr.calls % 256 == 255) std.log.info("dflash2: {d} rounds, {d} contexts restarted", .{ dr.calls + 1, dr.lost });
}
_ = try dr.mark(e, .{ tm, 3 });
dr.calls += 1;
if (dr.prof != null and dr.calls % 64 == 0) {
const k: f64 = 64;
std.log.info("dflash2 ms a round: ingest {d:.2} tables {d:.2} block {d:.2} select {d:.2}", .{ dr.phase_ms[0] / k, dr.phase_ms[1] / k, dr.phase_ms[2] / k, dr.phase_ms[3] / k });
dr.phase_ms = @splat(0);
}
}
};
2 changes: 2 additions & 0 deletions zig/src/families/glm/dflash_load.zig
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ pub fn load(gpa: std.mem.Allocator, io: std.Io, e: anytype, dir: []const u8, ran
dr.succ = try gpa.alloc(u16, df.VOCAB * df.RANK);
@memcpy(std.mem.sliceAsBytes(dr.succ), try l.read("candidate_selector.successor_codebook", df.VOCAB * df.RANK * 2));
try carve(dr, d, head.n);
if (std.c.getenv("TF_GLM_DFLASH2_LOG")) |v| dr.log = std.fmt.parseInt(u64, std.mem.span(v), 10) catch 0;
if (std.c.getenv("TF_GLM_DFLASH2_PROF") != null) dr.prof = io;
dr.h_cpos = try gpa.alloc(i64, df.MAX_CTX);
dr.h_crings = try gpa.alloc(u64, df.MAX_CTX);
dr.cand = try gpa.alloc(i32, world * df.MAX_M * df.CW);
Expand Down