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

- Tests: for Qwen3.5 dense EXL3 at TP=2, a rank's column cut of a weight can keep the whole weight's K-split plan (`Weight.pinnedColumns`), and `tf-cuda-test qwen35-tp-cut PACK` compares each rank's columns with one GPU's whole-weight bytes; `--tp 1` is unchanged and `--tp 2` stays refused (#3602). Thanks to @Nipale-ai.

- Server: a checkpoint no native backend serves is pointed to the Python engine 0.6.6 only when 0.6.6 serves its model type (DeepSeek V4, Gemma 4, GLM5-Next, Nemotron-H, Prism Hadamard Qwen3.5, Qwen3.5, Qwen3.5-MoE, Qwen3.8 Flash Next and Qwen4); any other type, such as `hy_v4_flash`, is told no TensorFold release serves it yet and pointed to the recipe book and the runbook (#4008).

- GLM-5.3-Flash on CUDA: the load races the classic and factored expert forms, which give the same bits, at each of its ten timed decode window widths and keeps the faster one at each (classic unless factored is more than 1% faster), instead of one form for every window; a window takes the form of the narrowest timed width that holds it, and `TF_GLM_EXPERT_FORM` names one form for every width (#3249). Thanks to @Bizuayeu.
Expand Down
9 changes: 9 additions & 0 deletions zig/src/cuda/exl3.zig
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ pub const Weight = struct {
if (w.bias != 0) v.bias = w.bias + @as(u64, from) * 2;
return v;
}

/// `columns` that launches the parent's (sk, wk) as it plans for the whole matrix, so each column keeps its bits.
pub fn pinnedColumns(w: Weight, from: u32, n: u32) !Weight {
var v = try w.columns(from, n);
const p = planOf(w);
v.sk = p.sk;
v.wk = p.wk;
return v;
}
};

/// A weight's launch: the family's fixed (sk, wk) when given, else plan()'s; either is the shape's alone.
Expand Down
24 changes: 24 additions & 0 deletions zig/src/cuda/exl3_dense_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,27 @@ test "pick: linear_wc, then the mid-M kernels from min_rows; the linear below th
fixed.wk = 8;
try std.testing.expect(exl3.pick(fixed, 64, true, true, 17).? == .linear); // (unregistered forms otherwise)
}

test "pinnedColumns launches the parent's plan where columns plans its own shape" {
const whole = weight(5120, 12288, 8); // q_proj of the 27B: 1 split, 8 warps; its half plans 4 splits, 4 warps
const p = exl3.planOf(whole);
const own = try whole.columns(6144, 6144);
try expectEqual(@as(u32, 0), own.sk);
try std.testing.expect(exl3.planOf(own).sk != p.sk and exl3.planOf(own).wk != p.wk);
const pinned = try whole.pinnedColumns(6144, 6144);
try expectEqual(p.sk, exl3.planOf(pinned).sk);
try expectEqual(p.wk, exl3.planOf(pinned).wk);
var same = pinned; // the same view of the same columns, only the plan fixed
same.sk = 0;
same.wk = 0;
try expectEqual(own, same);
try std.testing.expect(exl3.pick(pinned, 64, true, true, 17).? == .linear); // a fixed plan keeps the linear
var fixed = whole; // a parent that is itself pinned hands its own plan on
fixed.sk = 2;
fixed.wk = 4;
const view = try fixed.pinnedColumns(128, 256);
try expectEqual(@as(u32, 2), exl3.planOf(view).sk);
try expectEqual(@as(u32, 4), exl3.planOf(view).wk);
try std.testing.expectError(error.Exl3Shape, whole.pinnedColumns(64, 128));
try std.testing.expectError(error.Exl3Shape, whole.pinnedColumns(12160, 256));
}
8 changes: 7 additions & 1 deletion zig/src/families/qwen3_5/cuda.zig
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,14 @@ test "Qwen pages default: the learner's and the prefix share's refusals stop bef
try @import("cuda_admit_test.zig").refusals();
}

pub const shard = @import("cuda_shard.zig");
pub const shard_plan = @import("cuda_shard_plan.zig");
/// The EXL3 tensor checks the loader and the cut-plan runner share.
pub const exl3_admit = @import("cuda_exl3_admit.zig");

test {
_ = @import("cuda_shard.zig");
_ = shard;
_ = shard_plan;
}

test "the shard plan's head widths are the kernels'" {
Expand Down
37 changes: 32 additions & 5 deletions zig/src/families/qwen3_5/cuda_shard.zig
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,20 @@ pub const Shape = struct {
v_heads: usize, // linear-attention value heads
};

/// One rank's spans, each in its weight's own rows (a row-split weight's are columns); even shares, no rank larger.
/// One rank's spans: rows of the weights it cuts, or where its part sits in a gathered input (o, out, mlp).
pub const Share = struct {
rank: usize,
world: usize,
q: Span, // q_proj rows: whole query heads, each head's q and gate rows together
kv: Span, // k_proj and v_proj rows: whole KV heads; past kv_heads ranks one head is kept by its query ranks
o: Span, // o_proj columns (k): the attention width of the same query heads
o: Span, // where this rank's query heads sit in o_proj's gathered input (k); o_proj is cut by `hidden`
qkv: [3]Span, // in_proj_qkv rows: its q, k and v segments each cut evenly, at their offsets
z: Span, // in_proj_z rows: whole value heads
heads: Span, // in_proj_a and in_proj_b rows, A_log and dt_bias: the same value heads
out: Span, // out_proj columns (k): the value heads of z
mlp: Span, // gate_proj and up_proj rows, and down_proj columns
out: Span, // where this rank's value heads sit in out_proj's gathered input (k); out_proj is cut by `hidden`
mlp: Span, // gate_proj and up_proj rows; and where this rank's rows sit in down_proj's gathered input (k)
vocab: Span, // lm_head rows
hidden: Span, // o_proj, out_proj and down_proj rows (n): hidden over the world, each reading its whole k

/// Rank `rank` of `world`; refused where a count does not split evenly or a cut would leave the 128-tiles.
pub fn of(s: Shape, rank: usize, world: usize) Error!Share {
Expand All @@ -57,6 +58,7 @@ pub const Share = struct {
const v = try evenly(s.v_heads, rank, world);
const mlp = try tiles(s.intermediate, rank, world);
const vocab = try tiles(s.vocab, rank, world);
const hidden = try tiles(s.hidden, rank, world);
const keys = s.k_heads * dk;
return .{
.rank = rank,
Expand All @@ -70,6 +72,7 @@ pub const Share = struct {
.out = scale(v, dk),
.mlp = mlp,
.vocab = vocab,
.hidden = hidden,
};
}

Expand Down Expand Up @@ -114,7 +117,7 @@ fn shift(s: Span, by: usize) Span {
}

/// The 27B's widths (cuda_geometry.zig's test of them): 24 query heads over 4 KV heads, 48 value heads over 16.
const qwen27: Shape = .{ .hidden = 5120, .intermediate = 17408, .vocab = 248320, .q_heads = 24, .kv_heads = 4, .k_heads = 16, .v_heads = 48 };
pub const qwen27: Shape = .{ .hidden = 5120, .intermediate = 17408, .vocab = 248320, .q_heads = 24, .kv_heads = 4, .k_heads = 16, .v_heads = 48 };

test "TP=2 halves every weight of the 27B: whole heads, 2,048-wide qkv segments cut at 1,024, the vocabulary at 124,160" {
const r0 = try Share.of(qwen27, 0, 2);
Expand All @@ -138,6 +141,8 @@ test "TP=2 halves every weight of the 27B: whole heads, 2,048-wide qkv segments
try std.testing.expectEqual(Span{ .lo = 8704, .hi = 17408 }, r1.mlp);
try std.testing.expectEqual(Span{ .lo = 0, .hi = 124160 }, r0.vocab); // 970 of 1,940 tiles
try std.testing.expectEqual(Span{ .lo = 124160, .hi = 248320 }, r1.vocab);
try std.testing.expectEqual(Span{ .lo = 0, .hi = 2560 }, r0.hidden); // 20 of 40 tiles
try std.testing.expectEqual(Span{ .lo = 2560, .hi = 5120 }, r1.hidden);
}

test "TP=1 keeps every weight whole" {
Expand All @@ -146,6 +151,7 @@ test "TP=1 keeps every weight whole" {
try std.testing.expectEqual(Span{ .lo = 0, .hi = 1024 }, r.kv);
try std.testing.expectEqual([3]Span{ .{ .lo = 0, .hi = 2048 }, .{ .lo = 2048, .hi = 4096 }, .{ .lo = 4096, .hi = 10240 } }, r.qkv);
try std.testing.expectEqual(Span{ .lo = 0, .hi = 248320 }, r.vocab);
try std.testing.expectEqual(Span{ .lo = 0, .hi = 5120 }, r.hidden);
}

test "TP=4 takes a KV head and 6 query heads a rank; TP=8 keeps each KV head on two ranks and refuses the head's tiles" {
Expand All @@ -154,6 +160,7 @@ test "TP=4 takes a KV head and 6 query heads a rank; TP=8 keeps each KV head on
try std.testing.expectEqual(Span{ .lo = 768, .hi = 1024 }, r3.kv);
try std.testing.expectEqual(Span{ .lo = 13056, .hi = 17408 }, r3.mlp);
try std.testing.expectEqual(Span{ .lo = 186240, .hi = 248320 }, r3.vocab);
try std.testing.expectEqual(Span{ .lo = 3840, .hi = 5120 }, r3.hidden);
// 1,940 vocabulary tiles do not split by 8: refused on the head, the last width read
try std.testing.expectError(error.NotOnTiles, Share.of(qwen27, 5, 8));
var wide = qwen27;
Expand All @@ -162,6 +169,7 @@ test "TP=4 takes a KV head and 6 query heads a rank; TP=8 keeps each KV head on
try std.testing.expectEqual(Span{ .lo = 7680, .hi = 9216 }, r5.q);
try std.testing.expectEqual(Span{ .lo = 512, .hi = 768 }, r5.kv); // KV head 2, kept by ranks 4 and 5
try std.testing.expectEqual(Span{ .lo = 1280, .hi = 1536 }, r5.qkv[0]); // key heads 10 and 11 of 16
try std.testing.expectEqual(Span{ .lo = 3200, .hi = 3840 }, r5.hidden); // 5 of 40 tiles a rank
}

test "a width or a half off the 128-tiles is refused by name, never rounded" {
Expand All @@ -177,6 +185,10 @@ test "a width or a half off the 128-tiles is refused by name, never rounded" {
s = qwen27;
s.vocab = 248320 + 1;
try std.testing.expectError(error.NotOnTiles, Share.of(s, 0, 2));
s = qwen27;
s.hidden = 41 * 128; // on the tiles, but 41 tiles do not halve: o_proj's rows would be cut inside a tile
try std.testing.expectError(error.NotOnTiles, Share.of(s, 0, 2));
_ = try Share.of(s, 0, 1);
}

test "heads that do not split, and ranks that are not there, are refused" {
Expand Down Expand Up @@ -210,3 +222,18 @@ test "a rank keeps the key head of each of its value heads and the KV head of ea
}
};
}

test "the ranks' hidden spans tile the hidden width in whole 128-tiles, in rank order" {
var s = qwen27;
s.vocab = 248832; // 1,944 tiles split by 8 too
for ([_]usize{ 1, 2, 4, 8 }) |world| {
var next: usize = 0;
for (0..world) |rank| {
const h = (try Share.of(s, rank, world)).hidden;
try std.testing.expectEqual(next, h.lo);
try std.testing.expect(h.len() % unit == 0 and h.len() > 0);
next = h.hi;
}
try std.testing.expectEqual(s.hidden, next);
}
}
5 changes: 4 additions & 1 deletion zig/src/families/qwen3_5/cuda_shard_decl_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ fn declaredOf(s: cs.Shape, rank: usize, world: usize) anyerror!cs.Share {
try std.testing.expectEqual(gate, down); // gate_proj, up_proj and down_proj cut one range
const head: shard.Decl = .{ .kind = .vocab, .unit = cs.unit, .rule = .even };
const vocab = try span(head, s.vocab, rank, world, error.NotOnTiles);
const hidden_rows = try span(tile_rows, s.hidden, rank, world, error.NotOnTiles); // o_proj, out_proj and down_proj rows
return .{
.rank = rank,
.world = world,
Expand All @@ -67,6 +68,7 @@ fn declaredOf(s: cs.Shape, rank: usize, world: usize) anyerror!cs.Share {
.out = out,
.mlp = gate,
.vocab = vocab,
.hidden = hidden_rows,
};
}

Expand All @@ -80,7 +82,7 @@ fn expectSame(s: cs.Shape, rank: usize, world: usize) !void {
const qwen27: cs.Shape = .{ .hidden = 5120, .intermediate = 17408, .vocab = 248320, .q_heads = 24, .kv_heads = 4, .k_heads = 16, .v_heads = 48 };

test "the declared shares equal Share.of at every world to 16, its refusals and their order included" {
var shapes: [8]cs.Shape = @splat(qwen27);
var shapes: [9]cs.Shape = @splat(qwen27);
shapes[1].hidden = 5120 + 64; // off the tiles: refused first, at every world
shapes[2].kv_heads = 2; // fewer KV heads than ranks past world 2: kept by their query ranks, or KvHeads
shapes[3].kv_heads = 3; // 3 does not split over 2 or 4 ranks
Expand All @@ -89,6 +91,7 @@ test "the declared shares equal Share.of at every world to 16, its refusals and
shapes[6].q_heads = 20; // two axes wrong at once: the query heads refuse first, where 20 does not split
shapes[6].vocab = 248320 + 64;
shapes[7].v_heads = 0; // nothing to cut: EmptyShare
shapes[8].hidden = 41 * 128; // on the tiles, but 41 tiles do not split past world 1: refused last
for (&shapes) |*s| {
for (1..17) |world| for (0..world) |rank| try expectSame(s.*, rank, world);
try expectSame(s.*, 0, 0);
Expand Down
Loading
Loading