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
glm: expire dead cache states at the host boundary, borrow safely
The prefill path read a snap after pool admission could free it, and
overwrite walked snaps while expiry dropped them. A resident state that
dies now expires its cache entry at the host boundary; each lookup
borrows its entry and snap until resumed or release ends that ownership;
reclamation runs at host boundaries and skips active borrowers.
  • Loading branch information
heitke committed Oct 14, 2026
commit 8be4d3207dfe09effdbe0ccc343a84a3c710920e
2 changes: 2 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const std = @import("std");
const glm_expiry_build = @import("zig/build/glm_expiry.zig");
const builtin = @import("builtin");
const cuda_build = @import("zig/build/cuda.zig");
const dist_build = @import("zig/build/dist.zig");
Expand Down Expand Up @@ -174,6 +175,7 @@ pub fn build(b: *std.Build) void {
const disk_run = b.addRunArtifact(disk_cpu);
test_step.dependOn(&disk_run.step);
b.step("test-learn-recovery", "CPU learned-state recovery and admission tests").dependOn(&disk_run.step);
glm_expiry_build.steps(b, test_step, lanes_cpu);
const warning = b.addExecutable(.{ .name = "learned-warning-test", .root_module = b.createModule(.{
.root_source_file = b.path("zig/src/learned_warning_test.zig"),
.target = b.graph.host,
Expand Down
17 changes: 17 additions & 0 deletions zig/build/glm_expiry.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//! Check snapshot ownership and peer ordering on host memory, with no Metal frameworks or checkpoint.
const std = @import("std");

pub fn steps(b: *std.Build, test_step: *std.Build.Step, lanes: *std.Build.Module) void {
const metal = b.createModule(.{ .root_source_file = b.path("zig/src/metal/metal.zig"), .target = b.graph.host });
const fabric = b.createModule(.{ .root_source_file = b.path("zig/src/fabric/fabric.zig"), .target = b.graph.host, .link_libc = true });
const tests = b.addTest(.{ .filters = &.{"GLM expiry"}, .root_module = b.createModule(.{
.root_source_file = b.path("zig/src/glm_expiry_tests.zig"),
.target = b.graph.host,
.optimize = .debug,
.link_libc = true,
.imports = &.{ .{ .name = "metal", .module = metal }, .{ .name = "lanes", .module = lanes }, .{ .name = "fabric", .module = fabric } },
}) });
const run = b.addRunArtifact(tests);
test_step.dependOn(&run.step);
b.step("test-glm-expiry", "CPU GLM expiry, borrowed snapshots and peer command ordering").dependOn(&run.step);
}
1 change: 1 addition & 0 deletions zig/src/core/engine_api.zig
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ test {
_ = @import("lane_host.zig");
_ = @import("lane_host_test.zig");
_ = @import("lane_host_reuse_test.zig");
_ = @import("lane_host_cache_lifetime_test.zig");
_ = @import("lane_host_warm_test.zig");
_ = @import("lane_host_fill_test.zig");
_ = @import("prompt_cache.zig");
Expand Down
5 changes: 3 additions & 2 deletions zig/src/core/lane_host.zig
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ pub const LaneHost = struct {
const e = job.entry orelse return;
job.entry = null;
const store = job.host.cache orelse return;
if (!job.started) return;
if (!job.started) return store.release(e);
job.stream.reuse.saved = null; // the backend restores before its first chunk; a later keep may free it
if (job.stream.reuse_failed) store.resumed(e, job.request.prompt, false) else if (job.stream.cached == e.at) store.resumed(e, job.request.prompt, true);
if (job.stream.reuse_failed) store.resumed(e, job.request.prompt, false) else if (job.stream.cached == e.at) store.resumed(e, job.request.prompt, true) else store.release(e);
}
};

Expand Down Expand Up @@ -445,6 +445,7 @@ pub const LaneHost = struct {

/// No memory for another lane yet: the job waits at the queue's head, and admission holds until a job ends.
fn requeue(h: *LaneHost, job: *Job) bool {
job.reported();
if (job.stream.grammar) |g| g.deinit(h.gpa); // the next admission compiles its own
job.stream.deinit(h.gpa);
job.proposer.deinit();
Expand Down
108 changes: 108 additions & 0 deletions zig/src/core/lane_host_cache_lifetime_test.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//! Lookup ownership is returned on cancellation and on failures before a stream can be initialized.
const std = @import("std");
const lanes = @import("lanes");
const api = @import("engine_api.zig");
const pc = @import("prompt_cache.zig");
const a = std.testing.allocator;

const Box = struct {
reason: api.Reason = .failed,
done: std.atomic.Value(bool) = .init(false),
fn event(ctx: *anyopaque, _: api.Id, e: *const api.Event) void {
const b: *Box = @ptrCast(@alignCast(ctx));
if (e.* == .finished) {
b.reason = e.finished.reason;
b.done.store(true, .release);
}
}
fn wait(b: *Box) !api.Reason {
const began = std.Io.Clock.awake.now(std.testing.io).toNanoseconds();
while (!b.done.load(.acquire)) {
if (std.Io.Clock.awake.now(std.testing.io).toNanoseconds() - began > 2 * std.time.ns_per_s) return error.RequestTimedOut;
std.Io.sleep(std.testing.io, .fromMilliseconds(1), .awake) catch {};
}
return b.reason;
}
};

const Snaps = struct {
f: *lanes.fake.Fake,
store: *pc.Store = undefined,
host: *api.LaneHost = undefined,
live: usize = 0,
fn of(ctx: *anyopaque) *Snaps {
return @ptrCast(@alignCast(ctx));
}
fn bytes(_: *anyopaque, _: u32) u64 {
return 1;
}
fn save(ctx: *anyopaque, owner: ?*anyopaque, at: u32) !pc.Saved {
const s = of(ctx);
const saved = try s.f.save(@ptrCast(@alignCast(owner.?)), at);
s.live += 1;
return saved;
}
fn restore(_: *anyopaque, _: ?*anyopaque, _: pc.Saved) !void {
return error.BackendRestores;
}
fn drop(ctx: *anyopaque, saved: pc.Saved) void {
const s = of(ctx);
s.live -= 1;
s.f.drop(saved);
}
fn cancel(ctx: *anyopaque, stream: *lanes.Stream, _: usize) void {
const s = of(ctx);
const saved = stream.reuse.saved orelse return;
s.store.expired(saved);
s.host.engine().cancel(2);
}
};

fn check(cancelled: bool) !void {
var cfg = try lanes.Config.init(a, .{ .exact_width = 8, .gpu_tokens = true, .hidden_rows = true }, 8, 7);
defer cfg.deinit(a);
var target: lanes.fake.Fake = .{ .gpa = a };
defer target.deinit();
var clock: lanes.fake.FixedClock = .{};
var core = lanes.Engine.init(a, &cfg, target.backend(), clock.clock());
defer core.deinit();
var snaps: Snaps = .{ .f = &target };
var store = pc.Store.init(a, .{ .ptr = &snaps, .vtable = &.{ .bytes = Snaps.bytes, .save = Snaps.save, .restore = Snaps.restore, .drop = Snaps.drop } }, .{ .min_prompt = 0 }, 1000);
defer store.deinit();
var host = api.LaneHost.init(a, std.testing.io, &core, .{ .lanes = 1 });
host.cache = &store;
snaps.store = &store;
snaps.host = &host;
try host.start();
defer host.stop();
const prompt = [_]u32{ 1, 2, 3, 4, 5, 6 };
const first: api.Request = .{ .prompt = &prompt, .max_tokens = 2, .history_len = 4 };
var first_box: Box = .{};
try host.engine().submit(1, &first, .{ .ctx = &first_box, .event = Box.event });
try std.testing.expectEqual(api.Reason.length, try first_box.wait());
try std.testing.expectEqual(@as(usize, 1), snaps.live);
if (cancelled) {
target.prefill_hook = Snaps.cancel;
target.prefill_hook_ctx = &snaps;
}
const second: api.Request = .{ .prompt = &prompt, .max_tokens = 2, .history_len = 4, .structure = if (cancelled) null else .{ .kind = .json } };
var second_box: Box = .{};
try host.engine().submit(2, &second, .{ .ctx = &second_box, .event = Box.event });
try std.testing.expectEqual(if (cancelled) api.Reason.cancelled else api.Reason.failed, try second_box.wait());
if (!cancelled) {
const entry = store.find(&prompt, &.{}, &.{}).?;
try std.testing.expectEqual(@as(u32, 0), entry.borrowers);
store.expired(entry.saved);
store.collectExpired();
}
try std.testing.expectEqual(@as(usize, 0), snaps.live);
try std.testing.expectEqual(@as(u64, 0), store.held);
}

test "a cancelled prefill releases its invalidated restore lookup" {
try check(true);
}

test "failed stream initialization releases its restore lookup" {
try check(false);
}
Loading