Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
3688f3c
CUDA keyed graph cache and device arena, both off until a family inst…
jayleaton Oct 10, 2026
b7be793
A failed CUDA kernel launch names its kernel and launch configuration…
jayleaton Oct 10, 2026
faf5901
fix(cuda): correct RDMA VMM capability attribute
jrb-ai Oct 10, 2026
3cc0397
Graph cache: a capture is freed until the map holds it, the keep floo…
jayleaton Oct 11, 2026
c58d83c
CUDA arena: the address maps are rehashed before tombstones fill them
jayleaton Oct 11, 2026
25c02d3
Tensor parallelism across CUDA processes: bootstrap, NCCL, mailbox an…
jayleaton Oct 10, 2026
6b5404d
TP tests: a drain on rank 0 then its clean stop ends rank 1's loop at…
jayleaton Oct 10, 2026
06c4e75
TP RoCE: with no TF_TP_ROCE_HCA, each rank picks the ports on an IPv4…
jayleaton Oct 11, 2026
062af8b
TP README: when -Dtp-nvcc, TF_TP_ROCE_HCA, NCCL_IB_HCA, NCCL_SOCKET_I…
jayleaton Oct 11, 2026
d7510ef
TP test runner: a binary built without the mailbox kernel refuses the…
jayleaton Oct 11, 2026
e16e331
TP RoCE: every RDMA post is bounds-checked before the verb, and peers…
jayleaton Oct 11, 2026
649e788
TP RoCE: no RDMA write past 1 MiB, and boot refuses any setting that …
jayleaton Oct 11, 2026
664a8e2
TP RoCE: TF_TP_ROCE_CHUNKED_KB gathers strides past the slot in slot-…
jayleaton Oct 11, 2026
4ad5029
TP RoCE: a failed transport halts its QPs, drains them and keeps its …
jayleaton Oct 11, 2026
9bbc21a
TP RoCE: tf-tp-test failfast V transport checks the failed-transport …
jayleaton Oct 11, 2026
cf19042
Fix RoCE test smaps lookup for merged mappings
jayleaton Oct 11, 2026
0ba7d30
Sessions: the page map is rehashed before tombstones fill it
jayleaton Oct 11, 2026
0918809
Let a family's round planner drive the lane host with prompt pieces
jayleaton Oct 10, 2026
361f063
Lane host halt: a stop's drain deadline ends the rounds at the next b…
jayleaton Oct 10, 2026
e9f9210
Round planner test: both prompts queue before the host starts, and it…
jayleaton Oct 10, 2026
96ae865
Server hooks for a model family's own chat rules.
jayleaton Oct 10, 2026
df480e0
Server: a stop logs its signal and the open connections when the acce…
jayleaton Oct 10, 2026
2c4d837
Server: SIGTERM / SIGINT drains before stopping.
jayleaton Oct 10, 2026
55bf0a7
Server tests: a stop that lands between a request's count and its dra…
jayleaton Oct 10, 2026
9fbc2b3
Server: a stream that has not sent its first token gets keepalives ev…
jayleaton Oct 10, 2026
bb53ff4
Server tests: the drain test's reply in progress is held until its dr…
jayleaton Oct 10, 2026
9eb765d
DeepSeek-V4.1 host side: release config, EXL3 pack headers, a rank's …
jayleaton Oct 11, 2026
865335e
DeepSeek-V4.1 weight forms built at load, and prepared weight folders…
jayleaton Oct 11, 2026
7ccfc5c
DeepSeek-V4.1 Engram host side: table layout, n-gram hashes of a wind…
jayleaton Oct 11, 2026
b775815
DeepSeek-V4.1 phase timers: where a serving round's time goes, by nam…
jayleaton Oct 11, 2026
def4859
DeepSeek-V4.1 Engram rows from packed per-rank shards on local NVMe, …
jayleaton Oct 11, 2026
c7d29ea
DeepSeek-V4.1 CUDA kernel sources: CSA2 attention and top-k, mHC, rou…
jayleaton Oct 11, 2026
b17df97
DeepSeek-V4.1 kernel tooling: nvcc in a container for any checkout la…
jayleaton Oct 11, 2026
73be75f
DeepSeek-V4.1 kernel launch bindings and their loader: each kernel's …
jayleaton Oct 11, 2026
e687ad5
DeepSeek-V4.1 device kernel tests: tf-dsv41-test, bit-exact against t…
jayleaton Oct 11, 2026
a7674d2
DeepSeek-V4.1 kernel prototypes: attention merge and phase timing, x3…
jayleaton Oct 11, 2026
c0605f0
DeepSeek-V4.1 device-side load: named weights in device buffers, run-…
jayleaton Oct 11, 2026
46bff5e
DeepSeek-V4.1 block emitter: a decode window as calls (attention, the…
jayleaton Oct 11, 2026
6d44dab
CUDA runtime: prioritized streams, external event records, 2D async c…
jayleaton Oct 11, 2026
63e708f
CUDA AOT sets: aot.json specs parsed and matched without cubins, and …
jayleaton Oct 11, 2026
2eeabf7
CUDA memory: a driver allocation count, the arena's first failed chun…
jayleaton Oct 11, 2026
a89bd4f
Graph cache: named caches publish their counts, the floor's state is …
jayleaton Oct 11, 2026
05977fa
Session store: historyOf returns an entry's ids from RAM or from the …
jayleaton Oct 11, 2026
063e855
Graph cache registry: slots claimed, published, released and read und…
jayleaton Oct 11, 2026
d800c62
DeepSeek-V4.1 KV memory: the family's pages, split KV's exchange, the…
jayleaton Oct 11, 2026
bf5a8e8
DeepSeek-V4.1 forward: decode windows over the block emitter, split K…
jayleaton Oct 11, 2026
cd1e3d8
DeepSeek-V4.1 prefill: prompt segments over the prefill emitter, CED …
jayleaton Oct 11, 2026
4b5a078
DeepSeek-V4.1 keyed sampling: the exact host rule, the ranks' pipelin…
jayleaton Oct 11, 2026
1b1e565
DeepSeek-V4.1 drafting, host side: DSpark's chain, cost-derived depth…
jayleaton Oct 11, 2026
989ca7e
TP RoCE: run_hosts.sh gives NCCL the RoCE picker's ports when neither…
jayleaton Oct 11, 2026
05c5213
Session memory for paged-KV families: page pool, prefix trie, RAM res…
jayleaton Oct 10, 2026
a3303c7
CUDA keyed graph cache and device arena, both off until a family inst…
jayleaton Oct 10, 2026
69e8a65
A failed CUDA kernel launch names its kernel and launch configuration…
jayleaton Oct 10, 2026
d7e89df
fix(cuda): correct RDMA VMM capability attribute
jrb-ai Oct 10, 2026
5826f89
Graph cache: a capture is freed until the map holds it, the keep floo…
jayleaton Oct 11, 2026
5806e55
CUDA arena: the address maps are rehashed before tombstones fill them
jayleaton Oct 11, 2026
d335520
Graph cache: TF_GRAPH_CACHE=0 or off runs every step eagerly in any f…
jayleaton Oct 14, 2026
7ff83d8
Tensor parallelism across CUDA processes: bootstrap, NCCL, mailbox an…
jayleaton Oct 10, 2026
9af2ea2
TP tests: a drain on rank 0 then its clean stop ends rank 1's loop at…
jayleaton Oct 10, 2026
7c9a26e
TP RoCE: with no TF_TP_ROCE_HCA, each rank picks the ports on an IPv4…
jayleaton Oct 11, 2026
8ebb0be
TP README: when -Dtp-nvcc, TF_TP_ROCE_HCA, NCCL_IB_HCA, NCCL_SOCKET_I…
jayleaton Oct 11, 2026
e9e0056
TP test runner: a binary built without the mailbox kernel refuses the…
jayleaton Oct 11, 2026
0472cbf
TP RoCE: every RDMA post is bounds-checked before the verb, and peers…
jayleaton Oct 11, 2026
9688398
TP RoCE: no RDMA write past 1 MiB, and boot refuses any setting that …
jayleaton Oct 11, 2026
72132f0
TP RoCE: TF_TP_ROCE_CHUNKED_KB gathers strides past the slot in slot-…
jayleaton Oct 11, 2026
e65583c
Server hooks for a model family's own chat rules.
jayleaton Oct 10, 2026
bf19238
TP RoCE: a failed transport halts its QPs, drains them and keeps its …
jayleaton Oct 11, 2026
9a486bb
Server: a stop logs its signal and the open connections when the acce…
jayleaton Oct 10, 2026
beae7e8
TP RoCE: tf-tp-test failfast V transport checks the failed-transport …
jayleaton Oct 11, 2026
467504a
Server: SIGTERM / SIGINT drains before stopping.
jayleaton Oct 10, 2026
602aad5
Fix RoCE test smaps lookup for merged mappings
jayleaton Oct 11, 2026
23bf7d8
Server tests: a stop that lands between a request's count and its dra…
jayleaton Oct 10, 2026
890dfc6
TP RoCE: run_hosts.sh gives NCCL the RoCE picker's ports when neither…
jayleaton Oct 11, 2026
5410eac
Session memory for paged-KV families: page pool, prefix trie, RAM res…
jayleaton Oct 10, 2026
a5b8b35
Server: a stream that has not sent its first token gets keepalives ev…
jayleaton Oct 10, 2026
a3e2fb1
TP NCCL: all_reduce's doc says NCCL adds in its ring's order, so its …
jayleaton Oct 14, 2026
0d0bdb2
Sessions: the page map is rehashed before tombstones fill it
jayleaton Oct 11, 2026
2b3cccf
Server tests: the drain test's reply in progress is held until its dr…
jayleaton Oct 10, 2026
62a75ae
TP: keep Linux-only transport host tests off macOS builds
jayleaton Oct 15, 2026
2cf61d3
Sessions: honor zero residency budgets and reserve uncapped requests
jayleaton Oct 15, 2026
9367784
server: keep shared halt and drain on the existing template path
jayleaton Oct 15, 2026
864fe25
Graph cache: effective settings have one digest for ranks to compare …
jayleaton Oct 16, 2026
e2504f6
TP: bootstrap compares the graph cache's effective settings, so a ran…
jayleaton Oct 16, 2026
dcdc30c
Keep the Linux NVMe lane test out of portable host tests
cwschroeder Oct 16, 2026
368a0d3
Keep the Linux NVMe lane test out of portable host tests
cwschroeder Oct 16, 2026
7a6b32f
server: main's drain stop closes the engine without the closed lane-h…
jayleaton Oct 16, 2026
abcad7d
Merge ashhart/main into stack/02-graph-cache-arena
jayleaton Oct 16, 2026
02d455e
Merge stack/02-graph-cache-arena (with ashhart/main) into stack/03-tp…
jayleaton Oct 16, 2026
9266f3f
Merge stack/03-tp-fabric (with ashhart/main) into stack/04-sessions
jayleaton Oct 16, 2026
001ac2e
Merge stack/04-sessions (with ashhart/main) into stack/07-server
jayleaton Oct 16, 2026
33c0ef6
Merge stack/07-server (sessions, TP, graph cache, current main) into …
jayleaton Oct 16, 2026
af0bc53
Server tests: the drain test imports the named json module
jayleaton Oct 16, 2026
7051a3c
Merge stack/07-server's drain-test json import fix into stack/08a-config
jayleaton Oct 16, 2026
e6df8ad
merge origin/main: the round planner and halt on main's split lane host
jayleaton Oct 16, 2026
4da2618
Merge shared/lane-host-core (#861, on current main) into stack/08a-co…
jayleaton Oct 16, 2026
6b9bede
Merge stack/08a-config (current main, shared layers, #861) into stack…
jayleaton Oct 16, 2026
f17db02
Merge stack/08b-engram (current main, shared layers, #861) into stack…
jayleaton Oct 16, 2026
0137ac2
Merge stack/08c-kernels (current main, shared layers, #861) into stac…
jayleaton Oct 16, 2026
cf649ff
Merge stack/08e-block (current main, shared layers, #861) into stack/…
jayleaton Oct 16, 2026
4a02606
Merge stack/08r-runtime (current main, shared layers, #861) into stac…
jayleaton Oct 16, 2026
968a4f2
Merge stack/09a-kv (current main, shared layers, #861) into stack/09b…
jayleaton Oct 16, 2026
1d0b2d7
Merge stack/09b-forward (current main, shared layers, #861) into stac…
jayleaton Oct 16, 2026
ed4239b
Merge stack/10-prefill (current main, shared layers, #861) into stack…
jayleaton Oct 16, 2026
a6bc6c4
Merge stack/11a-sampling (current main, shared layers, #861) into sta…
jayleaton Oct 16, 2026
8900c7c
Sessions: a failed prefix insert leaves the index as it was
jayleaton Oct 17, 2026
3aeebb9
CUDA arena: a reuse whose address-map insertion fails keeps its range…
jayleaton Oct 17, 2026
46161ac
Merge stack/02-graph-cache-arena (the #635 arena fix) into stack/03-t…
jayleaton Oct 17, 2026
78ce706
Merge stack/03-tp-fabric (the #635 arena and #637 prefix fixes) into …
jayleaton Oct 17, 2026
9c5bd60
Merge stack/04-sessions (the #635 arena and #637 prefix fixes) into s…
jayleaton Oct 17, 2026
eaa7953
Merge stack/07-server (the #635 arena and #637 prefix fixes) into sta…
jayleaton Oct 17, 2026
4370f91
Merge stack/08a-config (the #635 arena and #637 prefix fixes) into st…
jayleaton Oct 17, 2026
a0f9598
Merge stack/08b-engram (the #635 arena and #637 prefix fixes) into st…
jayleaton Oct 17, 2026
98a1695
Merge stack/08c-kernels (the #635 arena and #637 prefix fixes) into s…
jayleaton Oct 17, 2026
28e33cc
Merge stack/08e-block (the #635 arena and #637 prefix fixes) into sta…
jayleaton Oct 17, 2026
f5a0b8b
Merge the layer below (the #635 arena and #637 prefix fixes) into sta…
jayleaton Oct 17, 2026
3b7681f
Merge the layer below (the #635 arena and #637 prefix fixes) into sta…
jayleaton Oct 17, 2026
334ce65
Merge the layer below (the #635 arena and #637 prefix fixes) into sta…
jayleaton Oct 17, 2026
6b97211
Merge the layer below (the #635 arena and #637 prefix fixes) into sta…
jayleaton Oct 17, 2026
fc25bef
Merge the layer below (the #635 arena and #637 prefix fixes) into sta…
jayleaton Oct 17, 2026
88418d8
test(tp): reject malformed runner commands before configuration
cwschroeder Oct 17, 2026
4c69b0d
fix(tp): parse runner commands before opening sessions
cwschroeder Oct 17, 2026
4df28ce
test(tp): retain verbs load failures in HCA diagnostics
cwschroeder Oct 17, 2026
0a80da0
fix(tp): distinguish verbs load errors from absent HCA ports
cwschroeder Oct 17, 2026
999cb03
Merge stack/03-tp-fabric (adopted #636 runner CLI validation and HCA …
jayleaton Oct 18, 2026
5f14a64
Merge the layer below (adopted #636 runner CLI validation and HCA ver…
jayleaton Oct 18, 2026
749240a
Merge the layer below (adopted #636 runner CLI validation and HCA ver…
jayleaton Oct 18, 2026
7122563
Merge the layer below (adopted #636 runner CLI validation and HCA ver…
jayleaton Oct 18, 2026
6390cf1
Merge the layer below (adopted #636 runner CLI validation and HCA ver…
jayleaton Oct 18, 2026
829c4c9
Merge the layer below (adopted #636 runner CLI validation and HCA ver…
jayleaton Oct 18, 2026
b81382d
Merge the layer below (adopted #636 runner CLI validation and HCA ver…
jayleaton Oct 18, 2026
2be028e
Merge the layer below (adopted #636 runner CLI validation and HCA ver…
jayleaton Oct 18, 2026
e47ed0e
Merge the layer below (adopted #636 runner CLI validation and HCA ver…
jayleaton Oct 18, 2026
e548a60
Merge the layer below (adopted #636 runner CLI validation and HCA ver…
jayleaton Oct 18, 2026
2fc04e3
Merge the layer below (adopted #636 runner CLI validation and HCA ver…
jayleaton Oct 18, 2026
92ff736
Merge the layer below (adopted #636 runner CLI validation and HCA ver…
jayleaton Oct 18, 2026
cdde1a4
Merge ashhart/main (1.1.0, 76aafcf2) into stack/02-graph-cache-arena
jayleaton Oct 18, 2026
adbdb8a
CUDA launches: a not-ready launch returns NotReady unlogged, as Drive…
jayleaton Oct 18, 2026
3bd6a6a
Merge stack/02-graph-cache-arena (adbdb8ab, main 76aafcf2) into stack…
jayleaton Oct 18, 2026
54141a1
Merge stack/03-tp-fabric (3bd6a6ab, main 76aafcf2) into stack/04-sess…
jayleaton Oct 18, 2026
80d4ed5
Merge stack/04-sessions (54141a1e, main 76aafcf2) into stack/07-server
jayleaton Oct 18, 2026
aebceae
Merge stack/07-server (80d4ed5c, main 76aafcf2) into stack/08a-config
jayleaton Oct 18, 2026
1003f08
Build: DeepSeek-V4.1's host tests on hosts other than Windows, whose …
jayleaton Oct 18, 2026
aa96782
Merge stack/08a-config (1003f08f, main 76aafcf2) into stack/08b-engram
jayleaton Oct 18, 2026
3f758dc
Merge stack/08b-engram (aa967828, main 76aafcf2) into stack/08c-kernels
jayleaton Oct 18, 2026
ea54d42
Merge stack/08c-kernels (3f758dcf, main 76aafcf2) into stack/08e-block
jayleaton Oct 18, 2026
d6190dc
Merge stack/08e-block (ea54d42d, main 76aafcf2) into stack/08r-runtime
jayleaton Oct 18, 2026
6742872
Merge stack/08r-runtime (d6190dcf, main 76aafcf2) into stack/09a-kv
jayleaton Oct 18, 2026
a88da5d
Build: DeepSeek-V4.1's KV host tests also skip Windows, like the fami…
jayleaton Oct 18, 2026
696e58a
Merge stack/09a-kv (a88da5de, main 76aafcf2) into stack/09b-forward
jayleaton Oct 18, 2026
4ac0c37
Merge stack/09b-forward (696e58a7, main 76aafcf2) into stack/10-prefill
jayleaton Oct 18, 2026
a4ca6d3
Merge stack/10-prefill (4ac0c37d, main 76aafcf2) into stack/11a-sampling
jayleaton Oct 18, 2026
5e6e8c6
Merge stack/11a-sampling (a4ca6d39, main 76aafcf2) into stack/11b-draft
jayleaton Oct 18, 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
merge origin/main: the round planner and halt on main's split lane host
Main (46a08c1) moved the lane host's endings to lane_host_end.zig, its
disk asks to lane_host_rows.zig, added Recall readers and Copy proposals,
and made deliver() take a finished job off `admitted` itself. #861's
changes go onto that shape:

- lane_stream.open carries main's stream fields (cacheKey/bornLen, Recall
  reader, images, key, fill_on); freeProposer also releases the Recall reader.
- halt's reason reaches main's ends.closeAll; failAll keeps its warning.
- the round planner's loop answers disk asks, refuses on a stale learner,
  writes on idle turns and flushes on its last stop, as main's loop does.
- the round planner no longer removes a delivered job again: with main's
  deliver it removed the next live job, or panicked at the list's end
  (lane_rounds_test's first test, index out of bounds, before this fix).
- windows.copyProposal: a priced proposer's copy stands as given, its none
  too, ahead of main's Recall fallback; new recall_engine_test case.
- engine_api.zig stays at 600 lines: Opened on one line, Rounds exported
  beside LaneHost, the redundant lane_host_test import dropped (lane_host.zig's
  test block imports it).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Loading branch information
jayleaton and claude committed Oct 16, 2026
commit e6df8ad5b9fdcac67029e1a67d64ac2bb1c6d45f
21 changes: 4 additions & 17 deletions zig/src/core/engine_api.zig
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,8 @@ pub const Decision = struct {
arena: ?std.mem.Allocator = null, // the request's, for what the engine hands back
};

/// An opened engine; ``close`` stops its thread and frees its backend.
pub const Opened = struct {
engine: Engine,
close: *const fn (ctx: *anyopaque) void,
ctx: *anyopaque,
/// A drain's deadline: rounds end at the next boundary, what is left fails with `reason`; null: `close` alone.
halt: ?*const fn (ctx: *anyopaque, reason: []const u8) void = null,
};
/// An opened engine; ``close`` stops its thread and frees its backend; ``halt`` (null: none) a drain's deadline.
pub const Opened = struct { engine: Engine, close: *const fn (ctx: *anyopaque) void, ctx: *anyopaque, halt: ?*const fn (ctx: *anyopaque, reason: []const u8) void = null };

pub const Memory = struct { active: u64 = 0, cache: u64 = 0, peak: u64 = 0, pinned: u64 = 0, limit: ?u64 = null };

Expand Down Expand Up @@ -565,9 +559,8 @@ pub const LoneHooks = struct {
resumed: bool = false, // the stream comes from the lane core between rounds: no prompt pass, its drafts the core's
};

/// The lane core served to the HTTP threads (lane_host.zig).
/// The lane core served to the HTTP threads (lane_host.zig), and a family's opt-in round planner (lane_rounds.zig).
pub const LaneHost = @import("lane_host.zig").LaneHost;
/// An opt-in family round planner for the lane host, in place of its `prefill_step` chunks (lane_rounds.zig).
pub const Rounds = @import("lane_host.zig").Rounds;

/// Exact prompt reuse between requests, for any family (prompt_cache.zig).
Expand Down Expand Up @@ -598,13 +591,7 @@ pub const keepalive = @import("keepalive.zig");
pub const originals = @import("originals.zig");

test {
_ = @import("lane_host.zig");
_ = @import("lane_host_test.zig");
_ = @import("lane_rounds_test.zig");
_ = @import("lane_halt_test.zig");
_ = @import("lane_host_reuse_test.zig");
_ = @import("lane_host_warm_test.zig");
_ = @import("lane_host_fill_test.zig");
_ = @import("lane_host.zig"); // its test block imports lane_host_test.zig and the other lane host tests
_ = @import("prompt_cache.zig");
_ = @import("prompt_radix.zig");
_ = @import("prompt_imprint.zig");
Expand Down
72 changes: 4 additions & 68 deletions zig/src/core/lane_host.zig
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub const LaneHost = struct {
filling: std.ArrayList(*Job) = .empty, // admitted jobs whose prompt is still going in, a chunk a round, oldest first
cancels: std.ArrayList(Id) = .empty,
closing: bool = false,
stale: bool = false, // the learner's last step: a put-back has not reached the device, so replies are refused
/// `halt`'s reason: what is left finishes failed with it (null: a stop cancels what is left)
halt_reason: ?[]const u8 = null,
thread: ?std.Thread = null,
Expand All @@ -65,6 +66,7 @@ pub const LaneHost = struct {
admissions: u64 = 0, // jobs admitted so far: each job's `seq`
memory_lanes: ?usize = null, // lanes the backend had memory for at its last LaneMemory, until a job ends
warm_quiet: u64 = 0, // ns a warm pass waits for other work before its first chunk (0: none), set by its family
disk: rows_host.Disk = .{}, // the Mac app's questions about kept states, and the disk writer's quiet
/// Runs first on the engine thread: a backend whose API state is per thread (a CUDA context) binds it there.
on_thread: ?ThreadInit = null,
/// opt-in: a family round planner (prompt pieces, decode rows in one pass); null: whole or `prefill_step` prompts
Expand All @@ -85,6 +87,7 @@ pub const LaneHost = struct {
proposer: lanes.SuffixLookup = undefined,
/// the family's proposer (LaneHost.proposers), in place of `proposer`
custom: ?lanes.proposer.Proposer = null,
recall: recalls.Slot = .{}, // its reads of Recall's record (lane_host_recall.zig)
delivered: usize = 0,
started: bool = false,
prefill_sent: bool = false, // a lone driver's prefilled event went out
Expand Down Expand Up @@ -290,35 +293,6 @@ pub const LaneHost = struct {
h.gpa.destroy(job);
}

/// Cancels queued and admitted jobs named since the last round.
pub fn takeCancels(h: *LaneHost) void {
h.mutex.lockUncancelable(h.io);
const ids = h.gpa.dupe(Id, h.cancels.items) catch &.{};
h.cancels.clearRetainingCapacity();
var dropped: std.ArrayList(*Job) = .empty;
for (ids) |id| {
for (h.queued.items, 0..) |job, i| if (job.id == id) {
dropped.append(h.gpa, h.queued.orderedRemove(i)) catch {};
break;
};
}
h.mutex.unlock(h.io);
for (dropped.items) |job| h.finish(job, .cancelled, "");
dropped.deinit(h.gpa);
for (ids) |id| {
for (h.admitted.items, 0..) |job, i| if (job.id == id) {
fill.unfill(h, job);
if (!job.stream.finished) h.core.discard(&job.stream);
h.lock();
_ = h.admitted.orderedRemove(i);
h.unlock();
h.finish(job, .cancelled, "");
break;
};
}
h.gpa.free(ids);
}

pub fn lock(h: *LaneHost) void {
h.mutex.lockUncancelable(h.io);
}
Expand Down Expand Up @@ -449,14 +423,6 @@ 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 {
if (job.stream.grammar) |g| g.deinit(h.gpa); // the next admission compiles its own
job.stream.deinit(h.gpa);
lane_stream.freeProposer(h, job);
job.started = false;
job.fill_began = false;
job.entry = null; // looked up again at its next admission
h.gpa.free(job.marks);
job.marks = &.{};
h.lock();
for (h.admitted.items, 0..) |j, i| if (j == job) {
_ = h.admitted.orderedRemove(i);
Expand All @@ -476,8 +442,7 @@ pub const LaneHost = struct {
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();
recalls.release(job);
lane_stream.freeProposer(h, job);
job.started = false;
job.fill_began = false;
job.entry = null; // looked up again at its next admission
Expand Down Expand Up @@ -562,37 +527,8 @@ pub const LaneHost = struct {
lone.reclaim(h);
}
}

/// A failed round ends every stream it held, with the backend's error.
pub fn failAll(h: *LaneHost, message: []const u8) void {
std.log.warn("lane host: a round failed ({s}): every admitted stream fails", .{message});
h.lock();
const jobs = h.gpa.dupe(*Job, h.admitted.items) catch &.{};
h.admitted.clearRetainingCapacity();
h.filling.clearRetainingCapacity();
h.unlock();
for (jobs) |job| {
if (!job.stream.finished) h.core.discard(&job.stream);
h.finish(job, .failed, message);
}
h.gpa.free(jobs);
}

pub fn closeAll(h: *LaneHost) void {
if (h.halt_reason) |reason| return lane_halt.haltAll(h, reason);
h.lock();
for (h.queued.items) |job| h.cancels.append(h.gpa, job.id) catch {};
for (h.admitted.items) |job| h.cancels.append(h.gpa, job.id) catch {};
h.unlock();
h.takeCancels();
}
};

/// The prompt length a request's kept states count as: its own, or for a warm pass the request whose reply it prefills.
pub fn born(r: *const Request) u32 {
return if (r.born > 0) r.born else @intCast(r.prompt.len);
}

test {
_ = @import("lane_host_test.zig");
_ = @import("lane_rounds_test.zig");
Expand Down
3 changes: 3 additions & 0 deletions zig/src/core/lane_host_end.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const std = @import("std");
const api = @import("engine_api.zig");
const fill = @import("lane_host_fill.zig");
const lane_halt = @import("lane_halt.zig");
const LaneHost = @import("lane_host.zig").LaneHost;
const Job = LaneHost.Job;
const Id = api.Id;
Expand Down Expand Up @@ -40,6 +41,7 @@ pub fn takeCancels(h: *LaneHost) void {

/// A failed round ends every stream it held, with the backend's error.
pub fn failAll(h: *LaneHost, message: []const u8) void {
std.log.warn("lane host: a round failed ({s}): every admitted stream fails", .{message});
h.lock();
const jobs = h.gpa.dupe(*Job, h.admitted.items) catch &.{};
h.admitted.clearRetainingCapacity();
Expand All @@ -53,6 +55,7 @@ pub fn failAll(h: *LaneHost, message: []const u8) void {
}

pub fn closeAll(h: *LaneHost) void {
if (h.halt_reason) |reason| return lane_halt.haltAll(h, reason);
h.lock();
for (h.queued.items) |job| h.cancels.append(h.gpa, job.id) catch {};
for (h.admitted.items) |job| h.cancels.append(h.gpa, job.id) catch {};
Expand Down
24 changes: 13 additions & 11 deletions zig/src/core/lane_rounds.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const host = @import("lane_host.zig");
const lane_stream = @import("lane_stream.zig");
const learn = @import("lane_host_learn.zig");
const status = @import("lane_host_status.zig");
const ends = @import("lane_host_end.zig");
const rows_host = @import("lane_host_rows.zig");
const LaneHost = host.LaneHost;
const Job = LaneHost.Job;
const Allocator = std.mem.Allocator;
Expand Down Expand Up @@ -84,7 +86,7 @@ fn round(h: *LaneHost, rd: Rounds) bool {
h.unlock();
for (refused.items) |x| h.finish(x.job, .failed, x.why);
rd.vtable.admitted(rd.ctx) catch |e| {
h.failAll(h.words(e));
ends.failAll(h, h.words(e));
return true;
};
for (admits.items) |job| {
Expand All @@ -99,7 +101,7 @@ fn round(h: *LaneHost, rd: Rounds) bool {
}
// this round's pieces, a decode round of the streams decoding, then the prompts whose rows are in
rd.vtable.plan(rd.ctx, &h.pieces, &h.finals) catch |e| {
h.failAll(h.words(e));
ends.failAll(h, h.words(e));
return true;
};
const t0 = std.Io.Clock.awake.now(h.io).toNanoseconds();
Expand Down Expand Up @@ -148,7 +150,7 @@ fn round(h: *LaneHost, rd: Rounds) bool {
if (h.core.activeCount() > 0) {
did = true;
h.core.step() catch |e| {
h.failAll(@errorName(e));
ends.failAll(h, @errorName(e));
return true;
};
}
Expand All @@ -160,11 +162,8 @@ fn round(h: *LaneHost, rd: Rounds) bool {
var i: usize = 0;
while (i < h.admitted.items.len) {
const job = h.admitted.items[i];
if (job.started and h.deliver(job)) {
h.lock();
_ = h.admitted.orderedRemove(i);
h.unlock();
} else i += 1;
if (job.started and h.deliver(job)) continue; // it left the list: the next job slid into slot i
i += 1;
}
rd.vtable.after(rd.ctx, seconds(t1 - t0), seconds(t2 - t1));
return did;
Expand Down Expand Up @@ -247,7 +246,9 @@ fn runFinals(h: *LaneHost) void {
/// The engine thread under a round planner; an idle round waits for an arrival, a cancel or a short timeout.
pub fn run(h: *LaneHost, rd: Rounds) void {
while (true) {
h.takeCancels();
ends.takeCancels(h);
rows_host.answer(h);
learn.refuse(h);
h.lock();
if (h.closing) {
const left = h.queued.items.len + h.admitted.items.len;
Expand All @@ -256,8 +257,8 @@ pub fn run(h: *LaneHost, rd: Rounds) void {
h.learner.?.abort(h.learner.?.ctx);
h.lesson_open = false;
}
if (left == 0) return;
h.closeAll();
if (left == 0) return rows_host.flush(h);
ends.closeAll(h);
continue;
}
const work = h.admitted.items.len > 0 or (h.queued.items.len > 0 and h.admitted.items.len < h.info_.lanes);
Expand All @@ -267,6 +268,7 @@ pub fn run(h: *LaneHost, rd: Rounds) void {
continue;
}
if (!work) {
if (rows_host.idle(h)) continue;
if (h.cancels.items.len == 0) h.wake.waitTimeout(h.io, &h.mutex, .{ .duration = .{ .raw = .fromMilliseconds(100), .clock = .awake } }) catch {};
h.unlock();
continue;
Expand Down
14 changes: 10 additions & 4 deletions zig/src/core/lane_stream.zig
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
//! A request's stream on the lane host: its kept prefix looked up, its drafter made, the stream set up.
const std = @import("std");
const lanes = @import("lanes");
const host = @import("lane_host.zig");
const LaneHost = host.LaneHost;
const recalls = @import("lane_host_recall.zig");
const LaneHost = @import("lane_host.zig").LaneHost;
const Job = LaneHost.Job;

/// A job's drafter freed: the family's (LaneHost.proposers) or the built-in one.
/// A job's drafters freed: the family's (LaneHost.proposers) or the built-in one, and its Recall reader.
pub fn freeProposer(h: *LaneHost, job: *Job) void {
if (job.custom) |c| h.proposers.?.free(h.proposers.?.ctx, c) else job.proposer.deinit();
job.custom = null;
recalls.release(job);
}

/// An admitted job's stream (its kept prefix looked up, its drafter): false when it failed (the job is finished).
pub fn open(h: *LaneHost, job: *Job) bool {
const r = job.request;
var reuse: lanes.stream.Reuse = .{};
// the entry stays alive until the backend restores it: nothing keeps between here and this stream's own pass
if (h.cache) |store| if (r.prompt_logprobs == null and !r.untaught) if (store.lookupRewind(h.gpa, r.prompt, host.born(r), r.history_len, r.rewind_len, r.shared_prefixes, r.chunks, h.spans(r))) |l| {
if (h.cache) |store| if (r.prompt_logprobs == null and !r.untaught) if (store.lookupRewind(h.gpa, r.cacheKey(), r.bornLen(), r.history_len, r.rewind_len, r.shared_prefixes, r.chunks, h.spans(r))) |l| {
job.entry = l.entry;
job.kept0 = store.counts.kept;
job.marks = l.marks;
Expand All @@ -25,6 +26,7 @@ pub fn open(h: *LaneHost, job: *Job) bool {
if (h.proposers) |ps| {
job.custom = ps.make(ps.ctx, h.gpa, r.prompt, r.eos) catch return !h.drop(job, "the drafter could not start");
} else job.proposer = lanes.SuffixLookup.init(h.gpa, .{ .min_match = h.min_match }) catch return !h.drop(job, "the drafter could not start");
const recall = recalls.reader(h, job);
job.stream = lanes.Stream.init(h.gpa, .{
.id = "request",
.prompt = r.prompt,
Expand All @@ -33,6 +35,7 @@ pub fn open(h: *LaneHost, job: *Job) bool {
.sampling = r.sampling,
.drafts = r.drafts,
.proposer = job.custom orelse job.proposer.proposer(),
.recall = recall,
.stop_check = if (r.stop) |s| .{ .ptr = s.ctx, .check = s.check } else null,
.cancel_check = .{ .ptr = job, .check = LaneHost.cancelled },
.yield_check = if (r.background and r.max_tokens == 0) .{ .ptr = job, .check = LaneHost.yieldsTo } else null,
Expand All @@ -53,11 +56,14 @@ pub fn open(h: *LaneHost, job: *Job) bool {
.decode_spans = h.spans(r),
.decide = r.decide,
.untaught = r.untaught,
.images = r.images,
.key = r.cache_key,
}) catch {
freeProposer(h, job);
return !h.drop(job, "out of memory");
};
job.started = true;
job.fill_on.store(true, .release); // status readers count the fill from here until the pass reports
job.began = std.Io.Clock.awake.now(h.io).toNanoseconds();
return true;
}
Loading
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.