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
Next Next commit
Flash Next CUDA: Living Weights' trainer over the batched pass, and f…
…lashnext-learn against the serving forward

cuda_train.zig runs the learner's passes (keys, loss, target) with sequences side by side on the engine's own batched
pass (cuda_batch_train.zig: the row-wise launches over every row, the n-gram block, DeltaNet and attention one
sequence at a time from zeros), the open fact's pocket neurons scaled per sequence and each nudge added to its layer's
MoE output; then the loss's gradient from the 4-bit head down to the lowest nudged layer with flashnext.fn_back and
cuda.gdn_train, reading the engine's packed experts where they sit and MLX copies of the small linears
(cuda_train_buf.zig, 10.2 GiB beside the engine). A captured set's glue keeps no up rows, so the trainer runs on our
own. zig build flashnext-learn: a row's scores never depend on later rows; the trainer's MoE inputs, shared gates and
scores equal the serving forward's byte for byte (untaught and with a pocket neuron); packed sequences give each
one's loss as alone; the push against finite differences over four windows of the prompt (the direct path's median
must agree at small steps; the cross-row paths are reported); a pocket neuron moves the forward as gate act v.
  • Loading branch information
ZackSample committed Oct 15, 2026
commit 41ad4d4a7f6a5e09dd550f1887751b1b34293d3a
10 changes: 10 additions & 0 deletions zig/build/cuda.zig
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ fn family(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin
flashnext.addImport("cuda", cuda);
flashnext.addImport("core", core);
flashnext.addImport("lanes", lanes);
flashnext.addImport("living", living);
return .{ .core = core, .lanes = lanes, .nemotron = nemotron, .flashnext = flashnext, .tokenizer = tokenizer, .heat = heat, .living = living };
}

Expand Down Expand Up @@ -192,6 +193,15 @@ pub fn targets(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.bu
const select_run = b.addRunArtifact(b.addExecutable(.{ .name = "flashnext-select", .root_module = select_check }));
if (b.option([]const u8, "flashnext_fixtures", "capture_sparse.sh's selection fixtures folder")) |dir| select_run.addArgs(&.{dir});
b.step("flashnext-select", "fn_qsa_select against Triton's _select / _select_tiles lists on captured score rows").dependOn(&select_run.step);
// not installed: the trainer against the serving forward and finite differences
const learn_check = b.createModule(.{ .root_source_file = b.path("zig/src/families/flashnext/cuda_learn_main.zig"), .target = target, .optimize = optimize, .link_libc = true });
learn_check.addImport("cuda", cuda);
learn_check.addImport("flashnext", mods.flashnext);
const learn_exe = b.addExecutable(.{ .name = "flashnext-learn", .root_module = learn_check });
const learn_run = b.addRunArtifact(learn_exe);
if (embed_model != null and prompt_ids != null) learn_run.addArgs(&.{ embed_model.?, prompt_ids.? });
b.step("flashnext-learn", "Flash Next's trainer: the serving forward's bytes, push against finite differences, a pocket neuron").dependOn(&learn_run.step);
b.step("flashnext-learn-exe", "Build flashnext-learn into zig-out/bin").dependOn(&b.addInstallArtifact(learn_exe, .{}).step);
nativeServer(b, target, optimize, cuda, mods.core, mods.lanes, mods.nemotron, mods.flashnext, mods.tokenizer, mods.living, build_options, true).root_module.strip = strip;
}

Expand Down
106 changes: 106 additions & 0 deletions zig/src/families/flashnext/cuda_batch_train.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
//! A training pass on the batched pass: sequences side by side, each from position 0 and a fresh state.
const std = @import("std");
const cuda = @import("cuda");
const batch = @import("cuda_batch.zig");
const gdn = @import("cuda_gdn.zig");
const wt = @import("cuda_prompt_wt.zig");

const dims = wt.dims;
const wide = wt.wide;
const streams = wt.streams;
const q_heads = wt.q_heads;
const kv_heads = wt.kv_heads;
const head_dim = wt.head_dim;
const out_k = wt.out_k;
const nch = wt.nch;
const out_sk = wt.out_sk;
const state_n = wt.state_n;
const ple_layer = wt.ple_layer;
const ple_tail_n = wt.ple_tail_n;
const pss_n = batch.pss_n;

/// Each list[i]'s rows of `ids` (`at` even) side by side: row-wise launches take all, a mixer one sequence at a time.
pub fn spans(comptime Tri: type, p: *batch.Pass(Tri), ids: []const u32, list: []const batch.Span, eos: i64) !void {
const base = p.s;
const n = ids.len;
if (n == 0 or n > base.cap) return error.UnexpectedTensor;
for (list) |sp| if (sp.at % 2 != 0 or sp.rows == 0 or sp.at + sp.rows > n or sp.rows > nch * 512 or sp.rows > p.seq.cap) return error.UnexpectedTensor;
defer p.s = base;
p.rows = n;
p.pos0 = 0;
p.pending = null;
p.pending_f32 = false;
// each sequence's n-gram rows from its own start, staged in the scratch's pinned rows
try base.ready();
const emb = base.hostEmb(n);
const xs = base.hostXs(n);
@memset(emb, 0);
@memset(xs, 0);
for (list) |sp| {
var hist = [2]i64{ eos, eos };
try p.m.ngram.rows(&hist, ids[sp.at..][0..sp.rows], emb[sp.at * dims ..][0 .. sp.rows * dims], xs[sp.at * (dims / 32) ..][0 .. sp.rows * (dims / 32)]);
}
try p.stage(ids);
try p.tri.embed(base.ids, p.m.table_w, p.m.table_s, p.m.table_b, base.h, dims, streams, n);
const zero = struct {
fn f(pp: *batch.Pass(Tri), ptr: u64, words: usize) !void {
const dr = pp.stream.d;
try dr.check(dr.api.cuMemsetD32Async(ptr, 0, words, pp.stream.handle), "cuMemsetD32Async");
}
}.f;
for (p.m.layers, 0..) |*lw, layer| {
const keep: batch.LayerKeep = if (p.hooks.keep) |kp| kp.layers[layer] else .{};
if (layer == ple_layer) {
try p.upload(base.ple_emb, std.mem.sliceAsBytes(emb));
try p.upload(base.ple_xs, std.mem.sliceAsBytes(xs));
try base.uploaded();
if (p.pending != null) try p.writeback(0, n);
for (list) |sp| {
try zero(p, p.seq.tail.ptr, ple_tail_n * wide / 2);
var view = base.*;
view.h += sp.at * wide * 2;
view.ple_emb += sp.at * dims * 2;
view.ple_xs += sp.at * (dims / 32) * 4;
p.s = &view;
p.rows = sp.rows;
try p.pleBlock(lw, ids[sp.at..][0..sp.rows]);
p.s = base;
p.rows = n;
}
}
try p.writeback(0, n);
try p.readoutKeep(lw.attn_hc, 0, n, keep.attn_hc);
for (list) |sp| {
var view = base.*;
view.mixed += sp.at * dims * 2;
view.xsm += sp.at * (dims / 32) * 4;
var k = keep;
k.hist = 0;
k.state_out = 0;
if (k.proj != 0) k.proj += sp.at * gdn.proj_width * 2;
if (k.pq != 0) k.pq += sp.at * q_heads * 2 * head_dim * 2;
if (k.pk != 0) k.pk += sp.at * kv_heads * head_dim * 2;
if (k.pv != 0) k.pv += sp.at * kv_heads * head_dim * 2;
if (k.gated != 0) k.gated += sp.at * out_k * 2;
p.s = &view;
p.rows = sp.rows;
if (lw.linear) {
const li = wt.linearIndex(layer);
try zero(p, p.seq.conv[li].ptr, (gdn.taps - 1) * gdn.conv_dim / 2);
try zero(p, p.seq.state[li].ptr, state_n);
try p.gdnBlock(lw, li, k);
} else {
try p.attnBlockKeep(lw, wt.attnIndex(layer), k);
}
if (keep.mix_branch != 0) try p.sumSlices(base.part, keep.mix_branch + sp.at * dims * 2, true, sp.rows * dims, out_sk);
try p.tri.hcWriteback(base.h + sp.at * wide * 2, base.h + sp.at * wide * 2, base.pss + sp.at * pss_n * 4, base.part, "*fp32", base.inj + sp.at * streams * 2, base.dummy, "*bf16", base.dummy, "*bf16", sp.rows * dims, sp.rows, dims, streams, 4, 1, 1, out_sk);
p.s = base;
p.rows = n;
}
try p.readoutKeep(lw.mlp_hc, 0, n, keep.mlp_hc);
try p.moeBlockKeep(lw, keep);
try p.moeAdds(layer, keep);
p.pending = layer;
}
try p.head(null);
}
3 changes: 3 additions & 0 deletions zig/src/families/flashnext/cuda_launch.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub const mtp = @import("cuda_mtp.zig");
pub const fn_back = @import("cuda_fn_back.zig");
/// Each layer's Living Weights pocket in the forward
pub const pocket = @import("cuda_pocket.zig");
/// Living Weights' trainer over the batched pass
pub const train = @import("cuda_train.zig");
pub const native = @import("cuda_lanes.zig").Namespace(Tri);
/// Our own glue kernels, which every launch takes when no captured set is loaded
pub const Glue = glue_.Glue;
Expand Down Expand Up @@ -367,6 +369,7 @@ test {
_ = @import("cuda_mtp_check.zig");
_ = fn_back;
_ = pocket;
_ = train;
}

test "embed grid is one program per row and per group of 32" {
Expand Down
Loading