diff --git a/CHANGELOG.md b/CHANGELOG.md index 72471ab285e..56e532f361f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 takes `--mtp-confidence F` (off by default), as Nemotron does: each MTP draft carries its chance, read from the ranks' greedy pick with their softmax sums, and a chain stops where that chance falls under F. On GB10 at TP=3 with 0.5, decode went from 51.6 to 54.1 tok/s (+4.9%), greedy chat at one stream from 45.0 to 47.9 tok/s, and four distinct prompts at once from 70.6 to 75.0 tok/s, with the same tokens. At TP=2 four greedy code streams were 3.7% slower with it, so a code-heavy TP=2 server is better off without it. Under any `--mtp-confidence` floor, Nemotron's included, a sampled stream now drafts its rates' depth instead of the deepest window. Without the flag every path is unchanged, and `tf_glm_top1` compiles to the same code (#1585). Thanks to @Bizuayeu. + - LFM2.5-24B-A2B on Metal can hand an external drafter the rows of the layers it reads (its taps), copied on the GPU by a new kernel, `lfm2_tap`, that the kernel contract checks bit for bit with two planted controls (#1390, part of #1374). A drafting stream resumes a kept prompt state only when it also holds the drafter's context. Nothing uses the taps yet: without a drafter none are kept and every forward runs as before. Thanks to @BlivionIaG. - Nemotron on CUDA: the MoE residual's norm, Mamba's group norm, the MTP input norms and the bf16 token rows run on the shared norm and embedding kernels instead of Nemotron's own copies, which are removed. The shared kernels keep Nemotron's summation order, so replies are the same tokens as before, and one fewer CUDA image loads (#1353, step 1 of #548). Thanks to @jschmied. diff --git a/zig/kernels/cuda/glm_glue_rows.cuh b/zig/kernels/cuda/glm_glue_rows.cuh index 5928630754c..f708771a766 100644 --- a/zig/kernels/cuda/glm_glue_rows.cuh +++ b/zig/kernels/cuda/glm_glue_rows.cuh @@ -192,8 +192,8 @@ extern "C" __global__ void tf_glm_conv_shift(__nv_bfloat16* conv, const __nv_bfl } // decode.sample_rows' greedy pick, as the host scan: first max of n bf16 logits, NaN never wins; out fp32 bits, lo+id. -extern "C" __global__ void __launch_bounds__(1024) tf_glm_top1(const unsigned short* logits, int64_t n, unsigned lo, - unsigned* out) { +template +__device__ __forceinline__ void glm_top1(const unsigned short* logits, int64_t n, unsigned lo, unsigned* out) { __shared__ float sv[1024]; __shared__ unsigned si[1024]; const int t = threadIdx.x; @@ -217,6 +217,30 @@ extern "C" __global__ void __launch_bounds__(1024) tf_glm_top1(const unsigned sh out[0] = __float_as_uint(sv[0]); out[1] = lo + (si[0] == 0xffffffffu ? 0u : si[0]); } + if constexpr (sums) { + // out[2]: the slice's sum of exp(logit - its max), fp32 bits, from which rank 0 reads the pick's chance + const float m = sv[0]; + float s = 0.0f; + for (int64_t i = t; i < n; i += 1024) + s += __expf(__int_as_float(static_cast(static_cast(logits[i]) << 16)) - m); + __syncthreads(); + sv[t] = s; + __syncthreads(); + for (int h = 512; h > 0; h >>= 1) { + if (t < h) sv[t] += sv[t + h]; + __syncthreads(); + } + if (t == 0) out[2] = __float_as_uint(sv[0]); + } +} +extern "C" __global__ void __launch_bounds__(1024) tf_glm_top1(const unsigned short* logits, int64_t n, unsigned lo, + unsigned* out) { + glm_top1(logits, n, lo, out); +} +// The pick with its slice's softmax sum in out[2]: an MTP draft's chance (--mtp-confidence) across the ranks. +extern "C" __global__ void __launch_bounds__(1024) tf_glm_top1_sums(const unsigned short* logits, int64_t n, + unsigned lo, unsigned* out) { + glm_top1(logits, n, lo, out); } // The leader's step for the other ranks, written to the link's buffer from launch arguments (cuda_follow's Link.send). diff --git a/zig/src/core/contract/glm_sampling_pending.zig b/zig/src/core/contract/glm_sampling_pending.zig index 1d93333cdf7..c16af9f4e96 100644 --- a/zig/src/core/contract/glm_sampling_pending.zig +++ b/zig/src/core/contract/glm_sampling_pending.zig @@ -2,12 +2,13 @@ const std = @import("std"); const R = @import("registry.zig").CudaRecord; -/// Shared sampling and GLM greedy launches used for prompt scoring and grammar-constrained draws. +/// Shared sampling and GLM greedy launches: prompt scoring, grammar-constrained draws and MTP drafts' chances. pub const sampling = [_]R{ .{ .launch = .{ .name = "sample tf_draw", .symbol = "tf_draw", .image = "sample", .threads = 1024 }, .usage = .{ .{ .regs = 52, .static = 9752, .bound = 1024 }, .{ .regs = 64, .static = 9752, .bound = 1024 }, .{ .regs = 64, .static = 9752, .bound = 1024 }, .{ .regs = 64, .static = 9752, .bound = 1024 }, .{ .regs = 64, .static = 9752, .bound = 1024 } }, .later_pending = true }, .{ .launch = .{ .name = "sample tf_logprob_rows", .symbol = "tf_logprob_rows", .image = "sample", .threads = 1024 }, .usage = .{ .{ .regs = 27, .static = 520, .bound = 1024 }, .{ .regs = 28, .static = 520, .bound = 1024 }, .{ .regs = 28, .static = 520, .bound = 1024 }, .{ .regs = 40, .static = 520, .bound = 1024 }, .{ .regs = 40, .static = 520, .bound = 1024 } }, .later_pending = true }, .{ .launch = .{ .name = "sample tf_grammar_mask", .symbol = "tf_grammar_mask", .image = "sample", .threads = 256 }, .usage = .{ .{ .regs = 28, .static = 0, .bound = 256 }, .{ .regs = 26, .static = 0, .bound = 256 }, .{ .regs = 26, .static = 0, .bound = 256 }, .{ .regs = 16, .static = 0, .bound = 256 }, .{ .regs = 16, .static = 0, .bound = 256 } }, .later_pending = true }, .{ .launch = .{ .name = "glm_glue tf_glm_top1", .symbol = "tf_glm_top1", .image = "glm_glue", .threads = 1024 }, .usage = .{ .{ .regs = 29, .static = 8192, .bound = 1024 }, .{ .regs = 30, .static = 8192, .bound = 1024 }, .{ .regs = 30, .static = 8192, .bound = 1024 }, .{ .regs = 36, .static = 8192, .bound = 1024 }, .{ .regs = 36, .static = 8192, .bound = 1024 } }, .later_pending = true }, + .{ .launch = .{ .name = "glm_glue tf_glm_top1_sums", .symbol = "tf_glm_top1_sums", .image = "glm_glue", .threads = 1024 }, .usage = .{ .{ .regs = 32, .static = 8192, .bound = 1024 }, .{ .regs = 31, .static = 8192, .bound = 1024 }, .{ .regs = 31, .static = 8192, .bound = 1024 }, .{ .regs = 39, .static = 8192, .bound = 1024 }, .{ .regs = 39, .static = 8192, .bound = 1024 } }, .later_pending = true }, }; test "GLM sampling has measured 13.0 resources on every target" { diff --git a/zig/src/core/lanes/depth.zig b/zig/src/core/lanes/depth.zig index 8595a67aab4..06a0c71c1e1 100644 --- a/zig/src/core/lanes/depth.zig +++ b/zig/src/core/lanes/depth.zig @@ -144,7 +144,7 @@ pub const Rule = struct { pub fn depth(r: *Rule, who: Who) !i64 { const most = @min(@as(i64, r.most_drafts), @max(1, who.draft_room - 1)); if (most <= 0) return 0; - if (r.confidence_floor != null) return most; + if (r.confidence_floor != null and !who.sampled) return most; const p = try r.rates(who); if (r.family_costs.empty()) { const want: i64 = if (p[0] < 0.8) 1 else if (p[0] < 0.9) 2 else 3; @@ -192,9 +192,9 @@ pub const Rule = struct { return true; } - /// Python `_head_depth`: the next round's head drafts for a stream (0 when forced, 1 with a copy ahead). + /// Python `_head_depth`: next head drafts (0 forced, 1 with a copy); a floor leaves a sampled stream its rates'. pub fn headDepth(r: *Rule, who: *const Who, budget: ?i64, probe: Probe) !i64 { - const d: i64 = if (who.finished) 0 else if (budget) |b| b else if (r.node_probabilities) + const d: i64 = if (who.finished) 0 else if (budget) |b| b else if (r.node_probabilities and !(who.sampled and r.confidence_floor != null)) @min(@as(i64, r.most_drafts), @max(1, who.draft_room - 1)) else try r.depth(who.*); @@ -353,6 +353,26 @@ test "depth picks the most tokens a ms and probes deeper" { try std.testing.expectEqual(@as(i64, 3), try rule.depth(who)); } +test "under a confidence floor a greedy stream drafts the most, and a sampled one keeps its rates' depth" { + const gpa = std.testing.allocator; + const empty: Table = .{}; + const No = struct { + fn copy(_: *anyopaque, _: *const Who) bool { + return false; + } + }; + var unused: u8 = 0; + const probe: Probe = .{ .ptr = &unused, .copy = No.copy }; + var rule: Rule = .{ .gpa = gpa, .prior = &.{ 0.5, 0.5, 0.5 }, .most_drafts = 3, .family_costs = &empty, .shared_costs = &empty, .mtp_step_ms = 0.5, .plain_guard = false, .node_probabilities = true, .confidence_floor = 0.5, .batch_rows = 8 }; + defer rule.deinit(); + var states: [2]?State = .{ null, null }; + defer for (&states) |*s| if (s.*) |*x| x.deinit(gpa); + const greedy: Who = .{ .state = &states[0], .draft_room = 100, .finished = false, .forced = false }; + const sampled: Who = .{ .state = &states[1], .draft_room = 100, .finished = false, .forced = false, .sampled = true }; + try std.testing.expectEqual(@as(i64, 3), try rule.headDepth(&greedy, null, probe)); + try std.testing.expectEqual(@as(i64, 1), try rule.headDepth(&sampled, null, probe)); // a first rate under 0.8: one draft +} + test "a shared round's drafts come out the same whichever depths its overhead was measured at" { const gpa = std.testing.allocator; var shared: Table = .{}; diff --git a/zig/src/families/glm/cuda.zig b/zig/src/families/glm/cuda.zig index bf1f50e8c8f..3ff6fcc164f 100644 --- a/zig/src/families/glm/cuda.zig +++ b/zig/src/families/glm/cuda.zig @@ -77,6 +77,7 @@ test { _ = lanes; _ = native; _ = @import("cuda_qpack.zig"); + _ = @import("cuda_mtp_chance.zig"); _ = @import("cuda_tile.zig"); _ = @import("heat"); // upstream's heat bands, run where the GLM ranks use them } diff --git a/zig/src/families/glm/cuda_engine.zig b/zig/src/families/glm/cuda_engine.zig index 69c309e40be..9716f9f7900 100644 --- a/zig/src/families/glm/cuda_engine.zig +++ b/zig/src/families/glm/cuda_engine.zig @@ -528,7 +528,7 @@ pub const Engine = struct { } /// decode.draft: the MTP head absorbs the kept rows (committed first) with `follow`, then chains `depth` drafts. - pub fn draft(e: *Engine, from_prompt: bool, follow: []const u32, depth: usize, out: []u32) !void { + pub fn draft(e: *Engine, from_prompt: bool, follow: []const u32, depth: usize, out: []u32, chances: ?[]f64) !void { if (!e.mtp) return error.NoDraftHead; if (depth > max_drafts) return error.TooDeep; var one: [1]fw.Rank = undefined; @@ -545,7 +545,14 @@ pub const Engine = struct { try e.cur.st.setMtpLen(e.stream, e.cur.st.mtp_len + part.len); } for (0..depth) |j| { - try e.draw(e.bm.logits, 1, e.cur.st.pos + 1 + j, 0, out[j..][0..1]); + if (chances != null and !e.structured and e.cur.sampling == null) { + const p = try e.greedyChance(e.bm.logits); + out[j] = p.token; + chances.?[j] = p.chance; + } else { + try e.draw(e.bm.logits, 1, e.cur.st.pos + 1 + j, 0, out[j..][0..1]); + if (chances) |c| c[j] = 1; // a sampled or structured draft keeps chance 1: its window runs whole + } if (j + 1 < depth) { try f.mtp(@ptrCast(out[j..][0..1]), &.{e.bm.fnormed}); try e.cur.st.setMtpLen(e.stream, e.cur.st.mtp_len + 1); @@ -569,6 +576,7 @@ pub const Engine = struct { pub const redrawFirst = @import("cuda_structured.zig").redrawFirst; /// decode.sample_rows' greedy pick: per-rank top-1 (tf_glm_top1), all-gathered, largest value then lowest id. const greedy = @import("cuda_engine_pick.zig").greedy; + const greedyChance = @import("cuda_engine_pick.zig").greedyChance; /// A failed RoCE gather's error, after a synchronize whose result read gathered rows (they hold nothing then). pub fn checkGathers(e: *const Engine) !void { diff --git a/zig/src/families/glm/cuda_engine_pick.zig b/zig/src/families/glm/cuda_engine_pick.zig index 648cb1f0319..e489d13422b 100644 --- a/zig/src/families/glm/cuda_engine_pick.zig +++ b/zig/src/families/glm/cuda_engine_pick.zig @@ -1,16 +1,26 @@ //! The existing rank-gathered greedy pick, kept separate from engine lifetime and prompt diagnostics. const cuda = @import("cuda"); const ranks = @import("cuda_ranks.zig"); +const chance = @import("cuda_mtp_chance.zig"); const Engine = @import("cuda_engine.zig").Engine; const pair_bytes = 16; pub fn greedy(e: *Engine, logits: u64) !u32 { + return (try pick(e, logits, false)).token; +} + +/// greedy with the pick's chance from every rank's softmax sum (tf_glm_top1_sums), for --mtp-confidence's drafts. +pub fn greedyChance(e: *Engine, logits: u64) !chance.Pick { + return pick(e, logits, true); +} + +fn pick(e: *Engine, logits: u64, sums: bool) !chance.Pick { const world = e.share.world; var a: cuda.Args = .{}; a.add(logits); a.add(@as(i64, @intCast(e.share.vocab.len()))); a.add(@as(u32, @intCast(e.share.vocab.lo))); a.add(e.pairs.ptr + e.share.rank * pair_bytes); - try cuda.launch.launch(e.m.glue.top1, .{ .grid = .{ .x = 1 }, .block = .{ .x = 1024 } }, e.stream, &a); + try cuda.launch.launch(if (sums) e.m.glue.top1_sums else e.m.glue.top1, .{ .grid = .{ .x = 1 }, .block = .{ .x = 1024 } }, e.stream, &a); const mine = e.pairs.ptr + e.share.rank * pair_bytes; const stamp = @import("cuda_prof.zig").span(e.profiling_prompt, e.stream, .token_gather); if (e.group) |g| try g.allGather(e.stream, mine, e.pairs.ptr, pair_bytes) else try e.lib.check(e.lib.api.ncclAllGather(mine, e.pairs.ptr, pair_bytes, .u8, e.comm, e.stream.handle), "ncclAllGather"); @@ -19,11 +29,5 @@ pub fn greedy(e: *Engine, logits: u64) !u32 { try e.checkGathers(); var all: [ranks.max_world][4]u32 = undefined; // Engine.init refuses a larger world try e.d.check(e.d.api.cuMemcpyDtoH_v2(&all, e.pairs.ptr, world * pair_bytes), "cuMemcpyDtoH"); - var pick = all[0]; - for (all[1..world]) |p| { - const v: f32 = @bitCast(p[0]); - const b: f32 = @bitCast(pick[0]); - if (v > b or (v == b and p[1] < pick[1])) pick = p; - } - return pick[1]; + return chance.pick(all[0..world], sums); } diff --git a/zig/src/families/glm/cuda_follow.zig b/zig/src/families/glm/cuda_follow.zig index 6e5436dfb1a..cdf90bbfb5f 100644 --- a/zig/src/families/glm/cuda_follow.zig +++ b/zig/src/families/glm/cuda_follow.zig @@ -19,7 +19,7 @@ pub const Header = extern struct { kind: u32, n: u32 = 0, // ids that follow depth: u32 = 0, // draft: drafts to chain; chunk: where it starts; shared: its parts - flags: u32 = 0, // begin: sampled; draft: from the prompt; prefill, chunk: prompt_logprobs (1); chunk: indexer rows split (2); verify, shared: whole rows + flags: u32 = 0, // begin: sampled; draft: from the prompt (1), chances (2); prefill, chunk: prompt_logprobs (1); chunk: indexer rows split (2); verify, shared: whole rows a: u64 = 0, // keep: rows; prefill, chunk: the kept state it resumes (0: none); redraw: the prompt's length seed: u64 = 0, // begin: the sampling seed; prefill, chunk: the kept state's position temperature: f64 = 0, @@ -275,10 +275,11 @@ pub const Leader = struct { return x.e.redrawFirst(len, bits); } - pub fn draft(x: Leader, from_prompt: bool, follow_ids: []const u32, depth: usize, out: []u32) !void { + /// With `chances` every rank picks with its softmax sum, so rank 0 reads each draft's chance (--mtp-confidence). + pub fn draft(x: Leader, from_prompt: bool, follow_ids: []const u32, depth: usize, out: []u32, chances: ?[]f64) !void { try x.flush(); - try x.send(.{ .kind = @backingInt(Kind.draft), .depth = @intCast(depth), .flags = @intFromBool(from_prompt) }, follow_ids); - try x.e.draft(from_prompt, follow_ids, depth, out); + try x.send(.{ .kind = @backingInt(Kind.draft), .depth = @intCast(depth), .flags = @intFromBool(from_prompt) | @as(u32, @intFromBool(chances != null)) << 1 }, follow_ids); + try x.e.draft(from_prompt, follow_ids, depth, out, chances); } /// DFlash2's round on every rank (Engine.draftBlock): each stream's slot, kept rows and anchor. @@ -318,6 +319,7 @@ fn structuredStep(h: Header) bool { /// A rank other than 0 runs rank 0's steps until it ends; a cancelled prefill is error.Cancelled and the loop goes on. pub fn follow(e: *Engine, link: *Link) !void { var drafts: [engine.max_drafts]u32 = undefined; + var chances: [engine.max_drafts]f64 = undefined; var sampled: [16]u32 = undefined; cuda.tp_watch.sleep(e.io); // rank 0 starts with no stream: its first step wakes this rank while (true) { @@ -383,7 +385,7 @@ pub fn follow(e: *Engine, link: *Link) !void { .draft => { const ids = try e.gpa.dupe(u32, step.ids); defer e.gpa.free(ids); - try e.draft(h.flags & 1 != 0, ids, h.depth, &drafts); + try e.draft(h.flags & 1 != 0, ids, h.depth, &drafts, if (h.flags & 2 != 0) &chances else null); }, .block => { const k = h.depth; diff --git a/zig/src/families/glm/cuda_glue.zig b/zig/src/families/glm/cuda_glue.zig index 520fb1525f6..4250f64f1b2 100644 --- a/zig/src/families/glm/cuda_glue.zig +++ b/zig/src/families/glm/cuda_glue.zig @@ -24,6 +24,7 @@ pub const Kernels = struct { combine: cuda.Function, slice_sum: cuda.Function, top1: cuda.Function, + top1_sums: cuda.Function, put_words: cuda.Function, embed_b16: cuda.Function, conv_shift: cuda.Function, diff --git a/zig/src/families/glm/cuda_lanes.zig b/zig/src/families/glm/cuda_lanes.zig index c6aa3a91791..13ba93e11d3 100644 --- a/zig/src/families/glm/cuda_lanes.zig +++ b/zig/src/families/glm/cuda_lanes.zig @@ -34,7 +34,7 @@ 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 + chances: [max_held]f64 = undefined, // each held draft's chance: DFlash2's selector's, or the MTP head's (--mtp-confidence) held_n: usize = 0, first: ?u64 = null, fill: ?usize = null, // a prompt pass going a chunk at a time: where its next chunk starts @@ -44,6 +44,7 @@ pub const Lanes = struct { x: follow.Leader, whole: bool = false, // prompt passes run whole (TF_GLM_PROMPT_STEPS=0): no other stream's round between chunks alone: bool = false, // each window in its own forward (TF_GLM_SHARED=0) + mtp_confidence: ?f64 = null, // --mtp-confidence: the MTP head's chains stop where their chance falls under it shared: u64 = 0, // forwards that held several streams' windows (checks read it) lanes: std.AutoHashMapUnmanaged(*const lanes.Stream, Lane) = .empty, drawn: [ring]u32 = undefined, @@ -114,7 +115,8 @@ 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 + .draft_probabilities = block or self.mtp_confidence != null, // chances size each window (DFlash2's by the costs) + .draft_confidence = if (block) null else self.mtp_confidence, .window_costs = if (block) &gb10_window_costs else &.{}, .shared_costs = if (block) &gb10_shared_costs else &.{}, .hidden_rows = sharing, @@ -473,12 +475,13 @@ pub const Lanes = struct { if (r.position != self.x.e.pos() + 1) return error.PositionMismatch; if (r.lanes != null) return error.TreesNotBuilt; const depth = @min(r.depth, engine.max_drafts); + const chances: ?[]f64 = if (self.mtp_confidence != null) l.chances[0..depth] else null; if (r.rows) |rows| { for (rows, 0..) |row, i| if (row != i) return error.TreesNotBuilt; - try self.x.draft(false, r.follow[0..rows.len], depth, &l.held); + try self.x.draft(false, r.follow[0..rows.len], depth, &l.held, chances); } else { const first = self.value(r.first orelse return error.NoFirstToken); - try self.x.draft(true, &.{first}, depth, &l.held); + try self.x.draft(true, &.{first}, depth, &l.held, chances); } l.held_n = depth; } @@ -521,10 +524,10 @@ pub const Lanes = struct { 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). + /// Each held draft's chance, DFlash2's or the MTP head's under --mtp-confidence (else the 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; + if (self.x.e.drafter == null and self.mtp_confidence == 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); diff --git a/zig/src/families/glm/cuda_mtp_chance.zig b/zig/src/families/glm/cuda_mtp_chance.zig new file mode 100644 index 00000000000..7a177df96da --- /dev/null +++ b/zig/src/families/glm/cuda_mtp_chance.zig @@ -0,0 +1,46 @@ +//! An MTP draft's chance under --mtp-confidence: the ranks' top-1 words with their softmax sums, read on rank 0. +const std = @import("std"); + +pub const Pick = struct { token: u32, chance: f64 = 1 }; + +/// Each rank's (value, id, sum, _) -> the largest value, lowest id on a tie; with sums, its whole-vocabulary softmax. +pub fn pick(words: []const [4]u32, sums: bool) Pick { + var best = words[0]; + for (words[1..]) |p| { + const v: f32 = @bitCast(p[0]); + const b: f32 = @bitCast(best[0]); + if (v > b or (v == b and p[1] < best[1])) best = p; + } + if (!sums) return .{ .token = best[1] }; + const top: f64 = @as(f32, @bitCast(best[0])); + var z: f64 = 0; + for (words) |p| z += @as(f64, @as(f32, @bitCast(p[2]))) * @exp(@as(f64, @as(f32, @bitCast(p[0]))) - top); + return .{ .token = best[1], .chance = 1 / z }; +} + +fn word(v: f32, id: u32, sum: f32) [4]u32 { + return .{ @bitCast(v), id, @bitCast(sum), 0 }; +} + +test "mtp chance: the ranks' pick keeps greedy's order, and its chance is the softmax over every rank's slice" { + const t = std.testing; + // three slices of logits {2, 0}, {3, 1}, {3, 0}: the max ties at 3, the lower id (rank 1's 10) wins + const one = [_]f32{ 2, 0 }; + const two = [_]f32{ 3, 1 }; + const three = [_]f32{ 3, 0 }; + var words: [3][4]u32 = undefined; + var whole: f64 = 0; + for ([_][]const f32{ &one, &two, &three }, [_]u32{ 0, 10, 20 }, &words) |slice, lo, *w| { + const m = @max(slice[0], slice[1]); + var s: f32 = 0; + for (slice) |x| s += @exp(x - m); + w.* = word(m, lo + @as(u32, if (slice[0] >= slice[1]) 0 else 1), s); + for (slice) |x| whole += @exp(@as(f64, x)); + } + const p = pick(&words, true); + try t.expectEqual(@as(u32, 10), p.token); + try t.expectApproxEqRel(@exp(3.0) / whole, p.chance, 1e-6); + try t.expectEqual(Pick{ .token = 10 }, pick(&words, false)); + // one rank: its slice's sum alone + try t.expectApproxEqRel(1.0 / 1.5, pick(&.{word(4, 7, 1.5)}, true).chance, 1e-12); +} diff --git a/zig/src/families/glm/cuda_native.zig b/zig/src/families/glm/cuda_native.zig index 620f2c01e98..8193fae5de2 100644 --- a/zig/src/families/glm/cuda_native.zig +++ b/zig/src/families/glm/cuda_native.zig @@ -40,6 +40,7 @@ pub const Options = struct { vision: ?images_mod.Limits = null, // --vision: rank 0's tower, every rank's image rows drafter: ?[]const u8 = null, // --drafter: DFlash2's folder (the same on every rank; needs drafts on) drafter_bits: u8 = 4, // --drafter-bits: 4 (default) or 0 (bf16) + mtp_confidence: ?f64 = null, // --mtp-confidence: rank 0's lanes stop an MTP chain where its chance falls under it }; /// --drafter: DFlash2 (incoai/GLM-5.3-Flash-DFlash2, non-commercial weights) drafts instead of the MTP head. pub const takes_drafter = true; @@ -302,7 +303,7 @@ fn finishRank(a: OpenArgs) !Loaded { } }.get; own.link.asleep = cuda.tp_watch.open(); // the other ranks begin asleep (follow): the first step wakes them - own.lanes = .{ .x = .{ .e = own.e, .link = &own.link }, .whole = off("TF_GLM_PROMPT_STEPS"), .alone = off("TF_GLM_SHARED") }; + own.lanes = .{ .x = .{ .e = own.e, .link = &own.link }, .whole = off("TF_GLM_PROMPT_STEPS"), .alone = off("TF_GLM_SHARED"), .mtp_confidence = o.mtp_confidence }; const extra: u64 = (if (o.drafter != null) dflash.ring_bytes else 0) + if (own.e.images) |v| v.streamBytes() else @as(usize, 0); own.layout = if (set.pages) try pages_mod.layout(gpa, own.e, extra) else null; return .{ diff --git a/zig/src/native/cuda_refusal.zig b/zig/src/native/cuda_refusal.zig index 70c23420654..62956678dbf 100644 --- a/zig/src/native/cuda_refusal.zig +++ b/zig/src/native/cuda_refusal.zig @@ -3,6 +3,7 @@ const std = @import("std"); const api = @import("engine_api"); const nemotron = @import("nemotron"); pub const deepseek_release_message = "DeepSeek-V4.1 is not served by this release's CUDA server; its whole-model gate is #827"; +const glm_model_type = "glm5_next"; // GLM-5.3-Flash's (glm.cuda_native.model_type): its Options take mtp_confidence /// Flags refused whatever the family; null when `o` may open. pub fn backend(o: api.Open) ?[]const u8 { @@ -10,7 +11,10 @@ pub fn backend(o: api.Open) ?[]const u8 { return deepseek_release_message; if (o.mtp_drafts) |n| if (n > nemotron.native.max_drafts) return std.fmt.comptimePrint("--mtp-drafts: the CUDA engine drafts at most {d}", .{nemotron.native.max_drafts}); if (o.mtp_confidence) |c| if (!(c >= 0 and c <= 1)) return "--mtp-confidence must be from 0 to 1"; - if (o.mtp_drafts != null or o.mtp_confidence != null) { + if (std.mem.eql(u8, o.model_type, glm_model_type)) { + if (o.mtp_drafts != null) return "--mtp-drafts: GLM-5.3-Flash's MTP head drafts at the lanes' depth; serve it without --mtp-drafts (--mtp-confidence stops its chains)"; + if (o.mtp_confidence != null and o.drafter != null) return "--mtp-confidence stops the MTP head's chains, and with --drafter DFlash2 drafts instead: serve without one of them"; + } else if (o.mtp_drafts != null or o.mtp_confidence != null) { if (!std.mem.eql(u8, o.model_type, nemotron.native.model_type) and !std.mem.eql(u8, o.model_type, nemotron.omni.model_type)) return "--mtp-drafts: this CUDA family's drafts are not tunable; serve it without --mtp-drafts or --mtp-confidence"; @@ -72,6 +76,12 @@ test "--learn is refused whatever the family, and --slide or a learned-disk size try std.testing.expect(backend(.{ .dir = "d", .model_type = "nemotron_h", .slide = true, .learn_gib = 8, .learn_min_free_gib = 2 }) == null); } +test "GLM-5.3-Flash takes --mtp-confidence alone: --mtp-drafts, or a drafter beside it, is refused by name" { + try std.testing.expect(backend(.{ .dir = "d", .model_type = "glm5_next", .mtp_confidence = 0.3 }) == null); + try std.testing.expectStringStartsWith(backend(.{ .dir = "d", .model_type = "glm5_next", .mtp_drafts = 2 }) orelse "", "--mtp-drafts: GLM-5.3-Flash's"); + try std.testing.expectStringStartsWith(backend(.{ .dir = "d", .model_type = "glm5_next", .mtp_confidence = 0.3, .drafter = "x" }) orelse "", "--mtp-confidence stops"); +} + test "flags with nothing to do on CUDA are refused, not ignored" { try std.testing.expectStringStartsWith(backend(.{ .dir = "d", .model_type = "nemotron_h", .speed_up = "rank0.json" }) orelse "", "--speed-up links two Macs"); try std.testing.expectStringStartsWith(backend(.{ .dir = "d", .model_type = "nemotron_h", .prompt_cache_over_cap = true }) orelse "", "--prompt-cache-over-cap"); @@ -179,8 +189,8 @@ test "CUDA MTP controls refuse unsupported families before device work" { for ([_][]const u8{ "glm5_next", "lfm2_vl" }) |model_type| { try std.testing.expect(backend(.{ .dir = "d", .model_type = model_type }) == null); try std.testing.expectStringStartsWith(backend(.{ .dir = "d", .model_type = model_type, .mtp_drafts = 0 }) orelse "", "--mtp-drafts"); - try std.testing.expectStringStartsWith(backend(.{ .dir = "d", .model_type = model_type, .mtp_confidence = 0 }) orelse "", "--mtp-drafts"); } + try std.testing.expectStringStartsWith(backend(.{ .dir = "d", .model_type = "lfm2_vl", .mtp_confidence = 0 }) orelse "", "--mtp-drafts"); } test "policy options are refused by families that do not implement them" { diff --git a/zig/src/native/draft_sources_cuda_test.zig b/zig/src/native/draft_sources_cuda_test.zig index 6f15bad03a8..e1595d47b3a 100644 --- a/zig/src/native/draft_sources_cuda_test.zig +++ b/zig/src/native/draft_sources_cuda_test.zig @@ -33,11 +33,15 @@ test "draft sources: CUDA GLM distinguishes its checkpoint head from loaded DFla var b: g.lanes.Lanes = undefined; b.x.e = &e; b.alone = false; + b.mtp_confidence = null; e.mtp = false; e.drafter = null; try check(b.facts(), null, false, false); e.mtp = true; try check(b.facts(), null, true, true); + b.mtp_confidence = 0.3; // --mtp-confidence: the head's chances size its windows, still a checkpoint head + try check(b.facts(), null, true, true); + b.mtp_confidence = null; e.drafter = present(@TypeOf(e.drafter.?)); try check(b.facts(), .{ .kind = "DFlash2", .name = "example/draft" }, true, false); } diff --git a/zig/tests/cuda/contract_glm_top1.zig b/zig/tests/cuda/contract_glm_top1.zig new file mode 100644 index 00000000000..494d73573fd --- /dev/null +++ b/zig/tests/cuda/contract_glm_top1.zig @@ -0,0 +1,293 @@ +//! GLM's greedy pick under the contract on CUDA: tf_glm_top1_sums, its pick as tf_glm_top1's, its sum against float64. +const std = @import("std"); +const cuda = @import("cuda"); +const core = @import("core"); +const glm = @import("glm_cuda"); +const rig_ = @import("contract_rig.zig"); + +const contract = core.contract; +const c = contract.spec; +const g = contract.gates; +const rows = contract.rows; + +/// A rank's vocabulary slice: TP=2, 3 (both sizes) and 4 cut 154,880 rows in 64-row units; one launch a row. +const served = [_]c.Shape{ .{ .rows = 1, .n = 1, .k = 77440 }, .{ .rows = 1, .n = 1, .k = 51648 }, .{ .rows = 1, .n = 1, .k = 51584 }, .{ .rows = 1, .n = 1, .k = 38720 } }; +const tiles = [3]c.Tile{ .{}, .{}, .{ .size = 1024 } }; +const lo = 77440; // the slice's first row, as rank 1 of two passes it + +const rule = "tf_glm_top1's words, and the host's scan: the first bf16 logit above every earlier one from -inf (a NaN " ++ + "never wins), its fp32 bits and lo plus its row; none above -inf gives -inf and lo"; + +fn noSums(_: c.Shape) usize { + return 0; +} + +/// Each thread's strided adds, then ten halvings over the block's 1,024 threads. +fn depth(s: c.Shape) usize { + return (s.k + 1023) / 1024 + 10; +} + +pub fn pickSpec() c.Spec { + return .{ .name = "cuda glm tf_glm_top1_sums pick (tf_glm_top1's words)", .accum = .none, .depth = noSums, .out = .raw, .nan = .{ .stated = rule }, .tiles = tiles, .served = &served }; +} + +pub fn sumSpec() c.Spec { + return .{ .name = "cuda glm tf_glm_top1_sums softmax sum", .accum = .f32, .depth = depth, .out = .f32, .tiles = tiles, .served = &served }; +} + +const Top = struct { v: f32, i: ?usize }; + +/// Each launch's bf16 logits: quarter steps in [-16, 16) with -0 among the zeros, or gate 4's 0s (7 in 8) and -infs. +const Logits = struct { + host: []u16 = &.{}, + shape: c.Shape = undefined, + + fn deinit(self: *Logits, a: std.mem.Allocator) void { + a.free(self.host); + self.host = &.{}; + } + + /// Non-finite: rows 0-3 hold NaN, +inf, -inf and +inf with -inf at four places each, row 4 is all -inf. + fn fill(self: *Logits, a: std.mem.Allocator, shape: c.Shape, how: g.Fill, seed: u64) !void { + self.deinit(a); + self.shape = shape; + self.host = try a.alloc(u16, shape.rows * shape.k); + var prng = std.Random.DefaultPrng.init(seed); + const rng = prng.random(); + for (self.host) |*v| v.* = switch (how) { + .stress => c.toBf16(if (rng.uintLessThan(u32, 8) != 0) 0 else -std.math.inf(f32)), + else => blk: { + const level: i32 = @as(i32, @intCast(rng.uintLessThan(u32, 128))) - 64; + break :blk c.toBf16(if (level == 0 and rng.boolean()) -0.0 else @as(f32, @floatFromInt(level)) * 0.25); + }, + }; + if (how != .nonfinite) return; + const k = shape.k; + const put = [_]f32{ std.math.nan(f32), std.math.inf(f32), -std.math.inf(f32), std.math.inf(f32) }; + for (put, 0..) |v, r| if (r < shape.rows) { + for (0..4) |e| self.host[r * k + e * (k / 4)] = c.toBf16(v); + }; + if (shape.rows > 3) self.host[3 * k + k - 1] = c.toBf16(-std.math.inf(f32)); + if (shape.rows > 4) @memset(self.host[4 * k ..][0..k], c.toBf16(-std.math.inf(f32))); + } + + fn at(self: *const Logits, r: usize, i: usize) f32 { + return c.fromBf16(self.host[r * self.shape.k + i]); + } + + /// The host's scan of row `r`: from -inf, each value above the best so far becomes it, so a NaN never wins. + fn top(self: *const Logits, r: usize) Top { + var t: Top = .{ .v = -std.math.inf(f32), .i = null }; + for (0..self.shape.k) |i| { + const x = self.at(r, i); + if (x > t.v) t = .{ .v = x, .i = i }; + } + return t; + } + + /// Row `r`'s terms exp(x - max) in float64, the max as the pick finds it. + fn terms(self: *const Logits, r: usize, t: []f64) void { + const m: f64 = self.top(r).v; + for (t, 0..) |*o, i| o.* = @exp(@as(f64, self.at(r, i)) - m); + } +}; + +/// One launch a row as cuda_engine_pick makes it (a 1,024-thread block), at row `r`'s logits and four words. +fn launch(rig: *rig_.Rig, f: cuda.Function, in: u64, out: u64, shape: c.Shape) !void { + for (0..shape.rows) |r| { + var a: cuda.Args = .{}; + inline for (.{ in + @as(u64, r * shape.k * 2), @as(i64, @intCast(shape.k)), @as(u32, lo), out + @as(u64, r * 16) }) |v| a.add(v); + try cuda.launch.launch(f, .{ .grid = .{ .x = 1 }, .block = .{ .x = 1024 } }, rig.s, &a); + } + try rig.s.synchronize(); +} + +/// Bytes `from` to `from + len` of each launch's 16, gathered into `list`. +fn words(list: *std.ArrayList(u8), a: std.mem.Allocator, all: []const u8, from: usize, len: usize) ![]const u8 { + list.clearRetainingCapacity(); + var i: usize = 0; + while (i < all.len) : (i += 16) try list.appendSlice(a, all[i + from ..][0..len]); + return list.items; +} + +/// The words the gates read in place of the rig's whole output. +fn withOutput(comptime T: type) g.VTable { + var v = g.hooks(T); + v.output = struct { + fn f(ctx: *anyopaque) anyerror![]const u8 { + return @as(*T, @ptrCast(@alignCast(ctx))).view(); + } + }.f; + return v; +} + +/// tf_glm_top1_sums' first two words a launch, the pick; tf_glm_top1's on the same logits must equal them. +pub const Pick = struct { + rig: rig_.Rig, + sums: cuda.Function, + plain: cuda.Function, + logits: Logits = .{}, + in: u64 = 0, + out: u64 = 0, + base: u64 = 0, + got: std.ArrayList(u8) = .empty, + want: std.ArrayList(u8) = .empty, + msg: [160]u8 = undefined, + + const vt = withOutput(Pick); + + pub fn deinit(self: *Pick) void { + const a = self.rig.gpu.gpa; + self.logits.deinit(a); + self.got.deinit(a); + self.want.deinit(a); + self.rig.deinit(); + } + + pub fn kernel(self: *Pick) g.Kernel { + return .{ .spec = pickSpec(), .ctx = self, .vt = &vt }; + } + + pub fn prepare(self: *Pick, shape: c.Shape, fill: g.Fill, seed: u64) !bool { + if (shape.k == 0 or shape.rows == 0) return false; + self.rig.reset(); + try self.logits.fill(self.rig.gpu.gpa, shape, fill, seed); + self.in = try self.rig.input(std.mem.sliceAsBytes(self.logits.host)); + self.out = try self.rig.output(shape.rows * 16); + self.base = try self.rig.scratch(shape.rows * 16); + return true; + } + + pub fn run(self: *Pick) !void { + try launch(&self.rig, self.sums, self.in, self.out, self.logits.shape); + } + + pub fn view(self: *Pick) ![]const u8 { + return words(&self.got, self.rig.gpu.gpa, try self.rig.outputBytes(), 0, 8); + } + + pub fn count(self: *Pick) usize { + return self.logits.shape.rows * 8; + } + + pub fn reference(_: *Pick, want: []f64, mag: []f64) !void { + @memset(want, 0); + @memset(mag, 0); + } + + /// tf_glm_top1's words on the same logits, then every row's pick against the host's scan. + pub fn check(self: *Pick, _: g.Gate) !?[]const u8 { + const got = try self.view(); + try launch(&self.rig, self.plain, self.in, self.base, self.logits.shape); + const want = try words(&self.want, self.rig.gpu.gpa, try self.rig.bytes(self.base, self.logits.shape.rows * 16), 0, 8); + if (std.mem.indexOfDiff(u8, got, want)) |at| return try std.fmt.bufPrint(&self.msg, "byte {d} of {d} differs from tf_glm_top1's", .{ at, got.len }); + for (0..self.logits.shape.rows) |r| { + const t = self.logits.top(r); + const v = std.mem.readInt(u32, got[r * 8 ..][0..4], .little); + const id = std.mem.readInt(u32, got[r * 8 + 4 ..][0..4], .little); + const due: u32 = lo + @as(u32, @intCast(t.i orelse 0)); + if (v != @as(u32, @bitCast(t.v)) or id != due) return try std.fmt.bufPrint(&self.msg, "row {d}: {x} at {d}, the host's scan gives {x} at {d}", .{ r, v, id, @as(u32, @bitCast(t.v)), due }); + } + return null; + } +}; + +/// tf_glm_top1_sums' third word a launch: the slice's sum of exp(logit - max), against float64 at the same max. +pub const Sum = struct { + rig: rig_.Rig, + f: cuda.Function, + logits: Logits = .{}, + in: u64 = 0, + out: u64 = 0, + got: std.ArrayList(u8) = .empty, + + const vt = withOutput(Sum); + + pub fn deinit(self: *Sum) void { + const a = self.rig.gpu.gpa; + self.logits.deinit(a); + self.got.deinit(a); + self.rig.deinit(); + } + + pub fn kernel(self: *Sum) g.Kernel { + return .{ .spec = sumSpec(), .ctx = self, .vt = &vt }; + } + + pub fn prepare(self: *Sum, shape: c.Shape, fill: g.Fill, seed: u64) !bool { + if (shape.k == 0 or shape.rows == 0) return false; + self.rig.reset(); + try self.logits.fill(self.rig.gpu.gpa, shape, fill, seed); + self.in = try self.rig.input(std.mem.sliceAsBytes(self.logits.host)); + self.out = try self.rig.output(shape.rows * 16); + return true; + } + + pub fn run(self: *Sum) !void { + try launch(&self.rig, self.f, self.in, self.out, self.logits.shape); + } + + pub fn view(self: *Sum) ![]const u8 { + return words(&self.got, self.rig.gpu.gpa, try self.rig.outputBytes(), 8, 4); + } + + pub fn count(self: *Sum) usize { + return self.logits.shape.rows; + } + + pub fn reference(self: *Sum, want: []f64, mag: []f64) !void { + const a = self.rig.gpu.gpa; + const t = try a.alloc(f64, self.logits.shape.k); + defer a.free(t); + for (want, mag, 0..) |*w, *m, r| { + self.logits.terms(r, t); + var s: f64 = 0; + for (t) |x| s += x; + w.* = s; + m.* = if (std.math.isFinite(s)) s else 0; + } + } + + /// The generic bound plus __expf's error: under 2 + 1.2 |x| ulps of exp(x) by CUDA's intrinsic table, none at 0. + pub fn bounds(self: *Sum, _: []const f64, _: []const f64, allow: []f64) !void { + for (allow, 0..) |*l, r| { + const m: f64 = self.logits.top(r).v; + for (0..self.logits.shape.k) |i| { + const x = @as(f64, self.logits.at(r, i)) - m; + if (std.math.isFinite(x) and x != 0) l.* += (2 + 1.2 * @abs(x)) * 0x1p-23 * @exp(x); + } + } + } + + /// Each row's terms summed in `acc` in `order` (gate 4). + pub fn simulate(self: *Sum, acc: c.Accum, order: g.Order, out: []f64) !void { + const a = self.rig.gpu.gpa; + const t = try a.alloc(f64, self.logits.shape.k); + defer a.free(t); + for (out, 0..) |*o, r| { + self.logits.terms(r, t); + o.* = rows.sumIn(acc, order, t); + } + } +}; + +/// The pick and the sum on the heap, so the kernels' contexts keep their address; registered into `kernels`. +pub const Top1 = struct { + pick: Pick, + sum: Sum, + + pub fn create(a: std.mem.Allocator, gpu: @import("check.zig").Gpu, s: cuda.Stream, fns: glm.glue.Kernels, kernels: *std.ArrayList(g.Kernel)) !*Top1 { + const self = try a.create(Top1); + errdefer a.destroy(self); + self.* = .{ .pick = .{ .rig = .{ .gpu = gpu, .s = s }, .sums = fns.top1_sums, .plain = fns.top1 }, .sum = .{ .rig = .{ .gpu = gpu, .s = s }, .f = fns.top1_sums } }; + try kernels.append(a, self.pick.kernel()); + try kernels.append(a, self.sum.kernel()); + return self; + } + + pub fn destroy(self: *Top1, a: std.mem.Allocator) void { + self.sum.deinit(); + self.pick.deinit(); + a.destroy(self); + } +}; diff --git a/zig/tests/cuda/contract_tests.zig b/zig/tests/cuda/contract_tests.zig index 2c4b07526fc..e3e14993798 100644 --- a/zig/tests/cuda/contract_tests.zig +++ b/zig/tests/cuda/contract_tests.zig @@ -540,6 +540,8 @@ pub fn run(gpu: check.Gpu) !void { try glm_index.append(a, &kernels); const glm_fast = try @import("contract_glm_pools.zig").Fast.create(a, gpu, s, glm_fns, &kernels); defer glm_fast.destroy(a); + const glm_top1 = try @import("contract_glm_top1.zig").Top1.create(a, gpu, s, glm_fns, &kernels); + defer glm_top1.destroy(a); var glm_ops = try cuda.Module.load(gpu.d, kk.glm_ops); defer glm_ops.unload(); var glm_tokens = glm_index_k.Tokens{ .rig = .{ .gpu = gpu, .s = s }, .f = try glm_ops.function("tf_glm_dsa_tokens") }; diff --git a/zig/tests/cuda/glm_lanes_tests.zig b/zig/tests/cuda/glm_lanes_tests.zig index 777cf28e43f..dda400fa1c5 100644 --- a/zig/tests/cuda/glm_lanes_tests.zig +++ b/zig/tests/cuda/glm_lanes_tests.zig @@ -259,7 +259,7 @@ pub fn sharedCheck(gpu: Gpu, checkpoint: []const u8, dc_path: []const u8, rank: } first[i] = t; var held: [glm.engine.max_drafts]u32 = undefined; - try x.draft(true, &.{t}, 1, &held); + try x.draft(true, &.{t}, 1, &held, null); } const lone = try a.alloc(u16, 4 * V); const mine = try a.alloc(u16, 4 * V); @@ -296,7 +296,7 @@ pub fn sharedCheck(gpu: Gpu, checkpoint: []const u8, dc_path: []const u8, rank: for ([_]u32{ @intCast(S + i), @intCast(i) }, [_]*[glm.engine.max_drafts]u32{ &d1, &d0 }) |slot, d| { try x.bind(slot); try x.keep(keep); - try x.draft(false, outs[i][0..keep], 2, d); + try x.draft(false, outs[i][0..keep], 2, d, null); } if (!std.mem.eql(u32, d0[0..2], d1[0..2])) { std.debug.print("FAIL shared: round {d}, stream {d}: drafts {any} against its twin's {any}\n", .{ round, i, d0[0..2], d1[0..2] }); diff --git a/zig/tests/cuda/glm_paged_tests.zig b/zig/tests/cuda/glm_paged_tests.zig index 29faf94876a..5a993a82bb2 100644 --- a/zig/tests/cuda/glm_paged_tests.zig +++ b/zig/tests/cuda/glm_paged_tests.zig @@ -69,7 +69,7 @@ pub fn pagedCheck(gpu: Gpu, checkpoint: []const u8, rank: c_int, world: c_int, i if (slot == paged_slot) try x.beginOn(null, held) else try x.begin(null); first[j] = try x.prefill(ids, null, null, null); try gpu.d.check(gpu.d.api.cuMemcpyDtoH_v2(if (j == 0) mine.ptr else twin.ptr, e.bp.logits, V * 2), "cuMemcpyDtoH"); - try x.draft(true, &.{first[j]}, 2, &drafts[j]); + try x.draft(true, &.{first[j]}, 2, &drafts[j], null); } if (first[0] != first[1] or !std.mem.eql(u16, mine[0..V], twin[0..V]) or !std.mem.eql(u32, drafts[0][0..2], drafts[1][0..2])) { std.debug.print("FAIL paged: a {d}-token prompt's first token {d}, logits or drafts differ from its twin's ({d})\n", .{ len, first[0], first[1] }); @@ -86,7 +86,7 @@ pub fn pagedCheck(gpu: Gpu, checkpoint: []const u8, rank: c_int, world: c_int, i try gpu.d.check(gpu.d.api.cuMemcpyDtoH_v2(if (j == 0) mine.ptr else twin.ptr, e.bd.logits, rows * V * 2), "cuMemcpyDtoH"); const keep = 1 + (round + k) % rows; try x.keep(keep); - try x.draft(false, outs[j][0..keep], 2, &drafts[j]); + try x.draft(false, outs[j][0..keep], 2, &drafts[j], null); } if (!std.mem.eql(u16, mine[0 .. rows * V], twin[0 .. rows * V]) or !std.mem.eql(u32, outs[0][0..rows], outs[1][0..rows]) or !std.mem.eql(u32, drafts[0][0..2], drafts[1][0..2])) { std.debug.print("FAIL paged: a {d}-token prompt's window {d} ({d} rows) differs from its twin's\n", .{ len, round, rows });