Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
477403d
glm: a kept state that goes stale drops its cache entry at once
heitke Oct 14, 2026
8be4d32
glm: expire dead cache states at the host boundary, borrow safely
heitke Oct 14, 2026
027ddea
Merge remote-tracking branch 'origin/main' into glm-cache-slot-guard
heitke Oct 14, 2026
5a4987b
Living Weights: the learner, pocket and fits move to zig/src/living, …
ZackSample Oct 15, 2026
75978a1
Living Weights learns into any family described as data: the family's…
ZackSample Oct 15, 2026
c6418f3
Flash Next's embedding row matches the host dequant of the same MLX g…
AdrianBinDC Oct 7, 2026
1dca5c1
Layer 0's first hyper-connection matches its host check on one token,…
AdrianBinDC Oct 7, 2026
cd57bfc
Layer 0's linear-attention projection matches the host group-32 dot o…
AdrianBinDC Oct 7, 2026
37dec96
Layer 0's linear-attention convolution, recurrence and output multipl…
AdrianBinDC Oct 7, 2026
2590dfc
Layer 0's second hyper-connection matches its host check on one token…
AdrianBinDC Oct 7, 2026
58fed6c
Layer 0's experts match the host check on one token, the top 10 and t…
AdrianBinDC Oct 7, 2026
69c4888
Layer 3's full attention matches the host check on one decode token, …
AdrianBinDC Oct 7, 2026
8a4add2
Layer 7's full attention matches the host check on one decode token, …
AdrianBinDC Oct 7, 2026
40472fb
Layer 11's full attention matches the host check on one decode token,…
AdrianBinDC Oct 7, 2026
307312a
Layer 15's full attention matches the host check on one decode token,…
AdrianBinDC Oct 7, 2026
d91b049
Layer 19's full attention matches the host check on one decode token,…
AdrianBinDC Oct 7, 2026
fcd0c15
Layer 23's full attention matches the host check on one decode token,…
AdrianBinDC Oct 7, 2026
0b4eab2
Layer 27's full attention matches the host check on one decode token,…
AdrianBinDC Oct 7, 2026
fbb2776
Layer 31's full attention matches the host check on one decode token,…
AdrianBinDC Oct 7, 2026
43961f6
Layer 35's full attention matches the host check on one decode token,…
AdrianBinDC Oct 7, 2026
8949cd1
Layer 39's full attention matches the host check on one decode token,…
AdrianBinDC Oct 7, 2026
2bb8a78
Layer 43's full attention matches the host check on one decode token,…
AdrianBinDC Oct 7, 2026
8c50b42
Layer 47's full attention matches the host check on one decode token,…
AdrianBinDC Oct 7, 2026
1bbed57
Layer 2's n-gram table matches the host dequant on one decode token, …
AdrianBinDC Oct 7, 2026
994c2ff
The final mix and the word scores match the host check on one decode …
AdrianBinDC Oct 7, 2026
7f0794d
One drafts-off prompt matches the Python engine, eight greedy token i…
AdrianBinDC Oct 7, 2026
0d04c43
Keep the drafts-off prompt match after splitting the forward and pack…
AdrianBinDC Oct 7, 2026
785896e
Flash Next CUDA: prompt ids and positions upload on the compute strea…
ZackSample Oct 11, 2026
8391cac
native/cuda.zig takes each CUDA family's prompt-cache copies, cache r…
ZackSample Oct 15, 2026
bd35940
CUDA experts over a window's or a prompt chunk's rows, each row with …
ZackSample Oct 15, 2026
2484c93
triton_aot_pack.py: a constexpr Triton folded from None is left out, …
ZackSample Oct 15, 2026
5cf4291
Flash Next CUDA: prompts and decode rounds on one batched pass, with …
ZackSample Oct 15, 2026
035b7f9
Flash Next CUDA: the MTP head, its draft chains, verify windows and t…
ZackSample Oct 15, 2026
1ac9bd0
Flash Next CUDA serves several streams through the lane core: drafted…
ZackSample Oct 15, 2026
62865ab
Flash Next CUDA: buffers are zeroed on the compute stream, so a pass …
ZackSample Oct 15, 2026
8d32cd3
Docs: Flash Next on CUDA, its recipe, the CUDA and Flash Next pages, …
ZackSample Oct 15, 2026
b45e26a
Flash Next CUDA refuses the config.json settings its kernels fix: RMS…
ZackSample Oct 15, 2026
9fa628b
Flash Next CUDA: a failed zero fill frees the buffer it was filling
ZackSample Oct 15, 2026
475df92
Flash Next CUDA: a pass's uploads read pinned staging the scratch own…
ZackSample Oct 15, 2026
1e86036
Core: router logits and softmax top-k rows for every CUDA family (rou…
ZackSample Oct 15, 2026
794d273
Core: token rows in groups of 32 with a copy a stream, and RMS rows w…
ZackSample Oct 15, 2026
ea7d098
Flash Next CUDA: its own glue kernels, flashnext_hc.cu and flashnext_…
ZackSample Oct 15, 2026
38c9c63
Flash Next CUDA boots on its own glue; a captured set that holds ever…
ZackSample Oct 15, 2026
235ea01
Flash Next CUDA: TF_FLASHNEXT_OWNED runs named entry points on our gl…
ZackSample Oct 15, 2026
7746bb9
Docs: Flash Next on CUDA boots on its own kernels; a captured set is …
ZackSample Oct 15, 2026
e7163c5
Flash Next CUDA: each layer_types label must be the exact role the ke…
ZackSample Oct 15, 2026
4b46157
Flash Next CUDA: a failed upload or record drains the stream before t…
ZackSample Oct 15, 2026
354f60d
CUDA: a Gated DeltaNet layer's input-gradient backward, every gradien…
ZackSample Oct 15, 2026
c106f2e
CUDA: input gradients of 4-bit (group 32) products, routed SwiGLU exp…
ZackSample Oct 15, 2026
a41cc2c
CUDA: gated attention's input gradients over 4-bit projections (a hea…
ZackSample Oct 15, 2026
0211f4d
Flash Next CUDA: the hyper-connections' and the pocket's input gradie…
ZackSample Oct 15, 2026
8e234db
Merge lw-b-core (#878, Living Weights as a core module) onto lw-c-fnb…
ZackSample Oct 15, 2026
e2779f6
Flash Next CUDA: a taught folder's pocket in every pass, and the batc…
ZackSample Oct 15, 2026
41ad4d4
Flash Next CUDA: Living Weights' trainer over the batched pass, and f…
ZackSample Oct 15, 2026
f5d6a4c
Living Weights learns into Qwen3.8 Flash Next on CUDA (--slide, GB10)…
ZackSample Oct 15, 2026
bad3a2a
Docs: Living Weights on Qwen3.8 Flash Next (CUDA, GB10), as measured;…
ZackSample Oct 15, 2026
514e4ee
Flash Next's pocket leaves an untaught stream's rows: a lesson writer…
ZackSample 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
Flash Next's pocket leaves an untaught stream's rows: a lesson writer…
…'s and judge's reads see the model as shipped

A lane stream's untaught flag rides its Seq. A prompt or window pass of an untaught stream runs without the pockets; a
decode round of untaught streams alone leaves them out, and a mixed one scales the pocket by 0 on the untaught rows, as
Nemotron's pocket skips untaught segments. fn-pocket checks that a 0-scaled row keeps every output bit.
  • Loading branch information
ZackSample committed Oct 16, 2026
commit 514e4ee8e1dcbeb99599e83e5bd76037553e1e09
1 change: 1 addition & 0 deletions zig/src/families/flashnext/cuda_lanes.zig
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ pub fn Namespace(comptime Tri: type) type {
return err;
} };
const l = gop.value_ptr;
l.seq.untaught = s.untaught;
errdefer {
dropLane(self, l);
self.lanes.removeByPtr(gop.key_ptr);
Expand Down
38 changes: 38 additions & 0 deletions zig/src/families/flashnext/cuda_pocket.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub const Rows = struct { gate: cuda.DeviceBuffer, up: cuda.DeviceBuffer, down:
pub const Pockets = struct {
layers: [layers_n]?Rows = @splat(null),
k: ?fb.Kernels = null,
/// fp32 a row of a pass with taught and untaught streams: the pocket's scale on each (made on first use).
scales: ?cuda.DeviceBuffer = null,

pub fn deinit(p: *Pockets) void {
for (&p.layers) |*slot| if (slot.*) |*pk| {
Expand All @@ -24,6 +26,22 @@ pub const Pockets = struct {
};
if (p.k) |*k| k.deinit();
p.k = null;
if (p.scales) |*b| b.free();
p.scales = null;
}

/// A pass's row scales on the device (Pocket.scale), stream-ordered after the passes that read the last ones.
pub fn rowScales(p: *Pockets, d: *cuda.Driver, s: *cuda.Stream, scales: []const f32) !u64 {
const need = scales.len * 4;
if (p.scales) |*b| if (b.len < need) {
try s.synchronize();
b.free();
p.scales = null;
};
if (p.scales == null) p.scales = try cuda.DeviceBuffer.alloc(d, @max(need, 64 * 4));
try p.scales.?.uploadAsync(0, std.mem.sliceAsBytes(scales), s.handle);
try s.synchronize(); // the host copy must outlive the async upload
return p.scales.?.ptr;
}

/// Layer `layer`'s neurons: gate, up and output rows fp32 [n, dims], the first `used` live; made on first use.
Expand Down Expand Up @@ -77,6 +95,17 @@ pub const Pockets = struct {
}
};

/// Which rows of a pass the pocket acts on: every one, none (every stream untaught), or some (by row scales).
pub const Reads = enum { all, none, some };

/// The rows the pocket acts on from each row's stream's untaught flag; for `.some`, `scales` 1 on a taught row, else 0.
pub fn reads(untaught: []const bool, scales: []f32) Reads {
if (std.mem.indexOfScalar(bool, untaught, true) == null) return .all;
if (std.mem.indexOfScalar(bool, untaught, false) == null) return .none;
for (scales, untaught) |*v, u| v.* = if (u) 0 else 1;
return .some;
}

/// The neurons in use of a pocket read from the shards: the first ones, up to the last with a nonzero input row.
pub fn usedOf(up: []const f32, n: usize) usize {
var used: usize = 0;
Expand All @@ -95,3 +124,12 @@ test "a pocket's neurons in use end at its last nonzero input row" {
try std.testing.expectEqual(@as(u64, 0), p.mask());
try std.testing.expect(p.of(5, 0) == null);
}

test "an untaught stream's rows scale the pocket by 0; a pass of untaught streams alone reads none of it" {
var scales: [4]f32 = @splat(7);
try std.testing.expectEqual(Reads.all, reads(&.{ false, false }, scales[0..2]));
try std.testing.expectEqual(Reads.none, reads(&.{ true, true, true }, scales[0..3]));
try std.testing.expectEqualSlices(f32, &.{ 7, 7, 7, 7 }, &scales);
try std.testing.expectEqual(Reads.some, reads(&.{ false, true, true, false }, &scales));
try std.testing.expectEqualSlices(f32, &.{ 1, 0, 0, 1 }, &scales);
}
27 changes: 24 additions & 3 deletions zig/src/families/flashnext/cuda_prompt.zig
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ pub const Engine = struct {
chunk: usize,
/// Each layer's Living Weights pocket, from a taught folder's shards or the learner: every pass adds it.
pockets: pocket.Pockets = .{},
/// During a round of taught and untaught streams: its rows' pocket scales (0 on an untaught row); 0: none.
taught_rows: u64 = 0,

pub fn init(gpa: std.mem.Allocator, io: std.Io, driver: *cuda.Driver, stream: *cuda.Stream, model_dir: []const u8) !*Engine {
if (!cuda.kernels.available) return error.BuiltWithoutKernels;
Expand Down Expand Up @@ -238,7 +240,8 @@ pub const Engine = struct {
/// Every pass's adds to the MoE outputs: each taught layer's pocket behind its shared gate.
fn servePocket(ctx: *anyopaque, layer: usize, x: u64, ids: u64, wts: u64, out: u64, rows: usize) anyerror!void {
const e: *Engine = @ptrCast(@alignCast(ctx));
const pk = e.pocketOf(layer) orelse return;
var pk = e.pocketOf(layer) orelse return;
pk.scale = e.taught_rows;
try e.pocketOps().?.pocketRows(pk, .{ .x = x, .ids = ids, .wts = wts }, out, true, rows, dims, slots - 1);
}

Expand All @@ -248,6 +251,13 @@ pub const Engine = struct {
return .{ .table_w = e.table.w.ptr, .table_s = e.table.s.ptr, .table_b = e.table.b.ptr, .layers = e.layers[0..e.n_layers], .mixer = e.mixer, .head = e.head_q, .ngram = &e.ngram, .pocket = if (m != 0) .{ .ctx = e, .add = servePocket, .layers = m } else null };
}

/// The weights a pass of streams that read the model as shipped reads (untaught): the pockets left out.
fn shipped(e: *Engine) batch.Model {
var m = e.model();
m.pocket = null;
return m;
}

/// A fresh cache. `cap` is how many tokens it can hold, prompt plus generated.
pub fn newSeq(e: *Engine, cap: usize) !Seq {
if (cap == 0) return error.UnexpectedTensor;
Expand Down Expand Up @@ -326,7 +336,7 @@ pub const Engine = struct {
.tri = tri,
.k = &e.batch_k,
.s = s,
.m = e.model(),
.m = if (seq.untaught) e.shipped() else e.model(),
.seq = seq.view(scores),
.hooks = hooks,
};
Expand Down Expand Up @@ -357,14 +367,23 @@ pub const Engine = struct {
// each row's attention runs alone on the block scores
const scores = try e.reserveScores(cap, 1);
for (rows, seqs) |*l, q| l.* = .{ .seq = q.view(scores), .pos = q.fed };
// an untaught stream's row reads no pocket: a round of them alone leaves it out, a mixed one scales it by 0
const untaught = try e.gpa.alloc(bool, seqs.len);
defer e.gpa.free(untaught);
const scales = try e.gpa.alloc(f32, seqs.len);
defer e.gpa.free(scales);
for (untaught, seqs) |*u, q| u.* = q.untaught;
const reads = pocket.reads(untaught, scales);
defer e.taught_rows = 0;
if (reads == .some and e.pockets.mask() != 0) e.taught_rows = try e.pockets.rowScales(e.driver, e.stream, scales);
var p: batch.Pass(Tri) = .{
.gpa = e.gpa,
.io = e.io,
.stream = e.stream.*,
.tri = tri,
.k = &e.batch_k,
.s = s,
.m = e.model(),
.m = if (reads == .none) e.shipped() else e.model(),
.seq = rows[0].seq,
.lanes = rows,
.hooks = .{ .logits = .all, .logits_out = out },
Expand Down Expand Up @@ -392,6 +411,8 @@ pub const Seq = struct {
fed: usize,
logits: []u8,
cap: usize,
/// The model as shipped: no learned neuron acts on its rows (a lesson writer's and its judge's reads).
untaught: bool = false,

/// The caches a batched pass reads and leaves; `scores` the engine's block scores (Engine.reserveScores).
pub fn view(s: *Seq, scores: u64) batch.SeqState {
Expand Down
30 changes: 30 additions & 0 deletions zig/tests/cuda/fn_pocket_tests.zig
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,31 @@ fn empty(r: *Rig, rows: usize, out_f32: bool) !void {
try check.sameBytes("fn-pocket, no neuron in use: the output as it was", try r.get(out, in.out.len), in.out);
}

/// An untaught stream's rows (scale 0) keep every output bit, as with no pocket; the others' as the pocket on all.
fn untaught(r: *Rig, rows: usize, used: usize) !void {
const c: Case = .{ .d = 2560, .rows = rows, .used = used, .out_f32 = true, .rs = true };
const in = try inputs(r, c);
for (in.rs, 0..) |*v, i| v.* = if (i % 3 == 1) 0 else 1;
var plain = c;
plain.rs = false;
const act = try r.dev(try r.a.alloc(u8, rows * fb.max_pocket * 4));
const scaled = try r.dev(in.out);
const whole = try r.dev(in.out);
try r.gpu.ctx.synchronize();
try split(r, c, try upload(r, c, in), act, scaled);
try split(r, plain, try upload(r, plain, in), act, whole);
const got = try r.get(scaled, in.out.len);
const all = try r.get(whole, in.out.len);
const row = c.d * 4;
for (0..rows) |i| {
const want = if (i % 3 == 1) in.out else all;
try check.sameBytes("fn-pocket, a row scaled by 0 or 1", got[i * row ..][0..row], want[i * row ..][0..row]);
}
const what = "fn-pocket untaught rows={d} used={d}: the first (taught) row moved {d} of {d} values";
const moved = differing(all[0..row], in.out[0..row], 4);
try check.expect(moved * 2 > c.d, what, .{ rows, used, moved, c.d });
}

/// GPU microseconds a launch, medians over `reps`, the L2 cache flushed before each: tf_fn_pocket_rows, then the two.
fn timing(r: *Rig, c: Case, reps: usize) !void {
const in = try inputs(r, c);
Expand Down Expand Up @@ -305,6 +330,11 @@ pub fn run(gpu: Gpu, reps: usize) !void {
r.reset(&arena);
};
check.pass("fn-pocket: no neuron in use launches nothing and keeps every output bit, -0.0 included", .{});
for ([_]usize{ 2, 5, 70, 300 }) |rows| for ([_]usize{ 13, 64 }) |used| {
try untaught(&r, rows, used);
r.reset(&arena);
};
check.pass("fn-pocket: untaught rows keep every output bit; the taught ones' bytes as the pocket on all", .{});
if (reps == 0) return;
for ([_]usize{ 1, 2, 4, 8, 16, 32, 63, 64, 128, 255, 256, 512, 1536 }) |rows| for ([_]usize{ 4, 13, 64 }) |used| {
try timing(&r, .{ .d = 2560, .rows = rows, .used = used, .out_f32 = true }, reps);
Expand Down
Loading