Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b923e55
Windows: a platform layer and host builds that pass
BobClawblaw Oct 12, 2026
60c6892
Windows: CUDA kernels, the native server and the GPU suites on sm_89
BobClawblaw Oct 12, 2026
9c36621
Windows: pull into the hub cache, HOME, and the whole test step
BobClawblaw Oct 12, 2026
2f626e1
Windows: build notes, strip before install, formatting
BobClawblaw Oct 12, 2026
ec0ddc5
Default port 8888
BobClawblaw Oct 12, 2026
3c57c14
qwen3_5: serve Qwen3.5-2B on CUDA
BobClawblaw Oct 13, 2026
84c58d3
qwen3_5: serve Qwen3.8-27B on CUDA, one arena for a model's device me…
BobClawblaw Oct 14, 2026
a087521
qwen3_5: replay each decode shape as a CUDA graph
BobClawblaw Oct 14, 2026
c3861d3
qwen3_5: DFlash2 drafts for Qwen3.8-27B on CUDA
BobClawblaw Oct 14, 2026
9b8d4af
qwen3_5: tree drafts on CUDA, the kept path replayed from a log
BobClawblaw Oct 14, 2026
b5b5c4b
docs: the Qwen hybrids on CUDA in the Windows page and the README
BobClawblaw Oct 14, 2026
cf2cdf1
qwen3_5, platform: comments on one line
BobClawblaw Oct 14, 2026
221c2b5
Windows: checkpoint reads skip the page cache
BobClawblaw Oct 14, 2026
522d17d
Windows: the signal handler type allows address 1, for aarch64
BobClawblaw Oct 14, 2026
d1ea47f
docs: Windows as a target in the README and the Windows page
BobClawblaw Oct 14, 2026
95f879e
CI: the host unit tests on Windows
BobClawblaw Oct 14, 2026
7efc823
qwen3_5: the drafter reads TF_TIMING through the platform layer
BobClawblaw Oct 14, 2026
85bb88d
qwen3_5: the drafter takes a prompt longer than its tap ring
BobClawblaw Oct 14, 2026
e01d423
qwen3_5 cuda: prompt chunks past 32 rows see the right keys, and tree…
BobClawblaw Oct 14, 2026
0baccf3
Windows: the server goldens and the Cortheon fuzz step on Windows hosts
BobClawblaw Oct 14, 2026
40159f8
cuda: cuBLASLt opens by its Windows DLL name
BobClawblaw Oct 14, 2026
cdb735b
Windows: writes on an O_APPEND descriptor land at the end whole
BobClawblaw Oct 14, 2026
a63ec9b
golden check: a request-log mismatch names the first differing line
BobClawblaw Oct 14, 2026
d7fb12f
golden check: the request log compares with LF endings on either side
BobClawblaw Oct 14, 2026
02d3e2e
qwen3_5: attention chunks follow each row's own keys, not the forward…
BobClawblaw Oct 15, 2026
e7744bc
qwen3_5: the DFlash2 config's divisors must be positive, and staging …
BobClawblaw Oct 15, 2026
48dcc42
Windows: 1.0.12's new code through the platform layer
BobClawblaw Oct 16, 2026
1d0a11f
docs: 1.0.12's new pages at the default port, 8888
BobClawblaw Oct 16, 2026
26e9b68
lanes recorder: a stream's new file is never made through a link ther…
BobClawblaw Oct 16, 2026
a1f54b4
qwen3_5 cuda: the drafter's top-k over many blocks a row, the same id…
BobClawblaw Oct 16, 2026
b3e306b
qwen3_5 cuda: group sums made once a projection input, the norm writi…
BobClawblaw Oct 16, 2026
cc0fc9e
qwen3_5 cuda: greedy rows' argmax in two stages over many blocks, a r…
BobClawblaw Oct 16, 2026
44005ad
qwen3_5 cuda: a group's sum a thread, in eight 16-byte loads, its ent…
BobClawblaw Oct 16, 2026
48a6622
lanes: a drafter may grow its own trees (Facts.tree_nodes), read back…
BobClawblaw Oct 16, 2026
aa214f9
qwen3_5 cuda: DFlash2 drafts best-first trees of up to 15 nodes, four…
BobClawblaw Oct 16, 2026
c7eea82
qwen3_5 cuda: the delta rule loads a row's inputs while the row befor…
BobClawblaw Oct 16, 2026
a76fd79
qwen3_5 cuda: a hold's chain, lanes and best-first tree in cuda_draft…
BobClawblaw Oct 16, 2026
d15bf69
qwen3_5 cuda: DFlash2 drafts 16-row blocks as the reference does; gro…
BobClawblaw Oct 16, 2026
6f7acde
qwen3_5 cuda: Landing's comment on one line
BobClawblaw Oct 16, 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
qwen3_5 cuda: DFlash2 drafts 16-row blocks as the reference does; gro…
…wn trees' node chances from the nodes that landed (lanes: Absorb.offered)
  • Loading branch information
BobClawblaw committed Oct 16, 2026
commit d15bf69b5dc074a8bf616b7db90aa694b975e61a
17 changes: 14 additions & 3 deletions zig/src/core/lanes/drafted.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const dr = @import("drafter.zig");
const Lane = struct {
rows: bool = false, // the drafter has absorbed the row before the next draft (it can draft)
filler: u32 = 0, // drafts the next verify takes as fillers instead (a prompt restored whole: no row to draft from)
tree_first: ?u32 = null, // the first token of the grown tree read back this round, until a verify carries it
offered: u32 = 0, // the grown tree's nodes the last verify carried, told to the drafter with its kept rows
};

pub const Drafted = struct {
Expand Down Expand Up @@ -122,6 +124,12 @@ pub const Drafted = struct {
const x = self(ptr);
x.windows.clearRetainingCapacity();
try x.windows.appendSlice(x.gpa, windows);
// a window carrying the stream's grown tree (allocation may keep only its first nodes): how many it offers
for (windows) |w| if (x.lanes.getPtr(w.stream)) |lane| {
const head = lane.tree_first orelse continue;
lane.offered = if (w.held == 0 and w.tokens.len > 0 and w.tokens[0] == head) @intCast(w.tokens.len) else 0;
lane.tree_first = null;
};
var total: usize = 0;
for (windows) |w| {
if (w.held > 0 and w.tokens.len != 0) return error.MixedDrafts;
Expand Down Expand Up @@ -176,7 +184,8 @@ pub const Drafted = struct {
for (rows, 0..) |row, i| prefix = prefix and row == i;
const n: u32 = @intCast(if (prefix) rows.len else rows[rows.len - 1] + 1);
const f = try x.target.features(r.stream, x.drafter.taps(), r.start, n);
try x.absorbs.append(x.gpa, .{ .stream = r.stream, .features = f, .start = r.start, .follow = r.follow[0..rows.len], .rows = if (prefix) null else rows });
try x.absorbs.append(x.gpa, .{ .stream = r.stream, .features = f, .start = r.start, .follow = r.follow[0..rows.len], .rows = if (prefix) null else rows, .offered = lane.offered });
lane.offered = 0;
pending = r.follow[rows.len - 1];
lane.rows = true;
} else {
Expand Down Expand Up @@ -214,9 +223,11 @@ pub const Drafted = struct {
/// A drafter-grown tree as host tokens and parents; null: the drafter holds a chain or nothing grown.
fn tree(ptr: *anyopaque, s: *Stream, gpa: Allocator) anyerror!?Held {
const x = self(ptr);
const lane = x.lanes.get(s) orelse return null;
const lane = x.lanes.getPtr(s) orelse return null;
if (lane.filler > 0) return null;
return x.drafter.tree(s, gpa);
const held = try x.drafter.tree(s, gpa) orelse return null;
lane.tree_first = if (held.tokens) |t| (if (t.len > 0) t[0] else null) else null;
return held;
}

fn dropStream(x: *Drafted, s: *Stream) void {
Expand Down
9 changes: 8 additions & 1 deletion zig/src/core/lanes/drafter.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ pub const Facts = struct {
};

/// Target rows [start, start + features.rows) and the token after each; `rows`, when given, picks which to absorb.
pub const Absorb = struct { stream: *Stream, features: Features, start: u64, follow: []const u32, rows: ?[]const u32 = null };
pub const Absorb = struct {
stream: *Stream,
features: Features,
start: u64,
follow: []const u32,
rows: ?[]const u32 = null,
offered: u32 = 0, // the drafter's grown tree's first nodes the verified window carried (0: none of its own)
};

/// `depth` drafts after `pending` at `position`; with `lanes` a tree, lane i the rank-r choice after its parent.
pub const Hold = struct { stream: *Stream, pending: u32, position: u64, depth: u32, lanes: ?*const Shape = null };
Expand Down
21 changes: 17 additions & 4 deletions zig/src/families/qwen3_5/cuda_draft.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const Stream = lanes.Stream;
const max_rows = engine.max_rows;
/// The logprob row's words (sample.cu's LP_WORDS) and its best-token capacity.
const lp_words = 3 + 2 * 20;
/// A hold's rows: the reference's 16-row blocks (dflash2.block), past the 8 the checkpoint was trained with.
const draft_block = 16;
const lp_top = 20;

pub const Config = struct {
Expand Down Expand Up @@ -98,7 +100,8 @@ pub const Config = struct {
// what the kernels fix: the head width, two-tap convolutions, a block of 8, the selector's top-k within a row
if (c.head_dim != 128 or try int(d.object, "conv_kernel_size") != 2 or c.block != 8 or c.topk > lp_top or c.mask >= c.vocab) return error.UnsupportedDraftConfig;
if (c.hidden != target.hidden or c.vocab != target.vocab or c.hidden % 256 != 0 or c.hidden % c.group != 0 or c.heads % c.kv_heads != 0 or c.layers > 8) return error.UnsupportedDraftConfig;
if (c.window < c.block or c.window > engine.tap_rows - max_rows) return error.UnsupportedDraftConfig;
if (c.window < draft_block or c.window > engine.tap_rows - max_rows) return error.UnsupportedDraftConfig;
c.block = draft_block;
return c;
}
};
Expand Down Expand Up @@ -185,6 +188,8 @@ pub const Draft = struct {
streams: std.AutoHashMapUnmanaged(*Stream, *Ctx) = .empty,
/// Contexts between streams, allocated and run once (`reserve`), as the driver stalls a buffer's first kernel.
pool: std.ArrayList(*Ctx) = .empty,
/// Grown trees' nodes offered and landed, by own chance: the nodes' chances the round loop prices.
landing: tree.Landing = .{},
/// One level of a hold (a hold drafts every level at once; timed at load, over the block's levels).
step_ms: f64 = 1.0,
/// The target's window ms by rows (cuda_native.zig times them), for the round loop's prices.
Expand Down Expand Up @@ -483,6 +488,13 @@ pub const Draft = struct {
for (items) |it| {
const ctx = d.streams.get(it.stream) orelse return error.UnknownStream;
if (it.features.space != .device or it.features.dtype != .bf16) return error.UnsupportedFeatures;
if (it.offered > 0 and ctx.grown > 0) {
var prefix: [engine.most_window]u32 = undefined;
for (prefix[0..@min(it.follow.len, prefix.len)], 0..) |*x, i| x.* = @intCast(i);
const kept = it.rows orelse prefix[0..@min(it.follow.len, prefix.len)];
d.landing.observeTree(it.stream.sampling != null, ctx.parents[0..ctx.grown], ctx.own[0..ctx.grown], it.offered, kept);
}
ctx.grown = 0;
// the target's features: its ring, `offset` the first row's position (cuda_native.zig's featuresFn)
if (it.rows) |rs| {
try d.absorb(ctx, it.features.buffer, it.features.offset, rs.len, rs);
Expand Down Expand Up @@ -518,12 +530,13 @@ pub const Draft = struct {
return .{ .count = @intCast(ctx.grown), .tokens = tokens, .parents = try gpa.dupe(i32, ctx.parents[0..ctx.grown]) };
}

/// A grown tree's nodes' chances: each its own chance under its parent times its parent's.
/// A grown tree's nodes' chances: each its landing chance under its parent times its parent's.
fn chancesFn(p: *anyopaque, s: *Stream, out: []f64) anyerror!bool {
const d = cast(p);
const ctx = d.streams.get(s) orelse return error.UnknownStream;
if (ctx.grown == 0 or out.len > ctx.grown) return false;
for (out, ctx.parents[0..out.len], ctx.own[0..out.len]) |*o, parent, own| o.* = @exp(own) * (if (parent >= 0) out[@intCast(parent)] else 1);
const sampled = s.sampling != null;
for (out, ctx.parents[0..out.len], ctx.own[0..out.len]) |*o, parent, own| o.* = d.landing.chance(sampled, own) * (if (parent >= 0) out[@intCast(parent)] else 1);
return true;
}

Expand All @@ -534,7 +547,7 @@ pub const Draft = struct {
};

/// Acceptance by depth until a stream has its own (the reference's chat text: measured, see the commit).
const prior = [_]f64{ 0.75, 0.65, 0.58, 0.52, 0.47, 0.43, 0.4 };
const prior = [_]f64{ 0.75, 0.65, 0.58, 0.52, 0.47, 0.43, 0.4, 0.37, 0.35, 0.33, 0.31, 0.29, 0.28, 0.27, 0.26 };

/// TF_TIMING=1: each call's wall time on stderr.
pub fn timing(what: []const u8, io: std.Io, t0: std.Io.Timestamp) void {
Expand Down
46 changes: 46 additions & 0 deletions zig/src/families/qwen3_5/cuda_draft_tree.zig
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,38 @@ pub fn nodes() usize {
return @min(n, engine.most_window - 1);
}

/// Offered tree nodes (their parent's row kept) and those that landed, by own log-chance in half-nat bins: greedy
/// rounds', then every round's (as the 27B engine keeps them). A node's chance is its bin's, its own chance the prior.
pub const Landing = struct {
counts: [2][16][2]f64 = @splat(@splat(.{ 0, 0 })),

fn bin(own: f64) usize {
return @min(15, @as(usize, @intFromFloat(@max(0, @floor(-own / 0.5)))));
}

pub fn observe(l: *Landing, sampled: bool, own: f64, landed: bool) void {
for (l.counts[@intFromBool(sampled)..]) |*table| {
const x = &table[bin(own)];
x[0] += 1;
if (landed) x[1] += 1;
}
}

pub fn chance(l: *const Landing, sampled: bool, own: f64) f64 {
const x = l.counts[@intFromBool(sampled)][bin(own)];
return (x[1] + 2 * @exp(own)) / (x[0] + 2);
}

/// A verified window's offered nodes (the first `offered`, node i at row i + 1) against the rows it kept.
pub fn observeTree(l: *Landing, sampled: bool, parents: []const i32, own: []const f64, offered: usize, kept: []const u32) void {
for (parents[0..@min(offered, parents.len)], own[0..@min(offered, own.len)], 0..) |p, o, i| {
const parent_row: u32 = if (p < 0) 0 else @intCast(p + 1);
if (std.mem.indexOfScalar(u32, kept, parent_row) == null) continue;
l.observe(sampled, o, std.mem.indexOfScalar(u32, kept, @intCast(i + 1)) != null);
}
}
};

fn bf16(h: u16) f64 {
return @as(f32, @bitCast(@as(u32, h) << 16));
}
Expand Down Expand Up @@ -149,6 +181,20 @@ pub fn grow(c: Candidates, pending: u32, rows: usize, most: usize, tokens: []u32
return count;
}

test "landing: a node is offered when its parent's row is kept, and landed when its own is" {
var l: Landing = .{};
// nodes 0 and 1 under the pending row, node 2 under node 0; the window kept rows 0, 1 (node 0) and 3 (node 2)
l.observeTree(false, &.{ -1, -1, 0 }, &.{ -0.1, -1.2, -0.3 }, 3, &.{ 0, 1, 3 });
try std.testing.expectEqual(@as(f64, 2), l.counts[0][0][0]); // nodes 0 and 2, both landed
try std.testing.expectEqual(@as(f64, 2), l.counts[0][0][1]);
try std.testing.expectEqual(@as(f64, 1), l.counts[0][2][0]); // node 1 offered, not landed
try std.testing.expectEqual(@as(f64, 0), l.counts[0][2][1]);
try std.testing.expectEqual(l.counts[0], l.counts[1]); // greedy rounds count for sampled streams too
l.observeTree(true, &.{-1}, &.{-0.1}, 1, &.{0});
try std.testing.expect(l.chance(true, -0.1) < l.chance(false, -0.1));
try std.testing.expectApproxEqAbs((2 + 2 * @exp(@as(f64, -0.1))) / 4, l.chance(false, -0.1), 1e-12);
}

test "best first: a node's children follow it, the cheapest open node first, chances that sum to one a row" {
// two rows, four candidates each, no selector (rank 1, zero codebooks): unary logits alone order the tree
const rank = 1;
Expand Down