Repository navigation
Conversation
… its cut (TENSORFOLD_PREFIX_WAIT_MS) With prompts filling a chunk a step between decode rounds (prefill_step, GLM-5.3-Flash on CUDA by default), requests that arrive together all start filling at once, and each computes a system prompt none of them has kept yet. Whole passes never did: each ends before the next lookup, which finds the cut. - lane_host_prefix: before a queued request takes a lane, if an admitted fill still has a mark ahead that the request's prompt shares, that its own lookup would resume and that adds at least the store's min_gap past what is kept for it now, the request stays in the queue, passed over, holding no lane. It goes on in queue order once that fill has stood at the mark (kept or not), the fill has left the filling list (prompt in, cancelled, failed, requeued), or TENSORFOLD_PREFIX_WAIT_MS passed (60000 by default, 0 off). Its ordinary lookup then resumes the cut. A request waits once and only for an admitted fill, which never waits, so there is no cycle and the oldest fill always runs. Never for background fills, pictures, embeddings, prompt logprobs or untaught requests; whole passes and rounds planners never wait. - prompt_cache: Store.wouldServe, a state another pass will keep judged as find judges a kept one (eligible, same tokens through the lookahead, same decoded spans). - lane_host_admit.pick releases waiters, passes over the ones still waiting and asks the wait of the one it picks; Job.kept records the furthest mark a pass has stood at. lane_host.zig only carries the setting. Tests (lane_host_prefix_test.zig, the stepped fake backend on a 16-row grid with lookahead 1, as GLM's CUDA rules): four requests on one system prompt and an unrelated one, all queued together, compute it once (three resume the cut, replies equal to the wait off), the unrelated one neither waits nor is waited for; with the wait off every one computes it (main's behaviour); a cancelled leader releases its waiter, which computes the prefix itself; a cancelled waiter leaves the queue once; the bound releases and counts; whole passes never wait; a cut under min_gap is not waited for; the setting's parsing. Five of the seven failed with the plumbing and stubbed decisions.
Owner
|
Landed on main in 6588b5a (rebased onto current main), with a changelog line. Thanks @wojo. Device checks, main vs this PR:
|
ashhart
added a commit
that referenced
this pull request
Oct 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
When prompts fill a chunk a step, the lane host holds back a queued request whose prompt shares a cut that another
admitted prompt is still filling. The request waits, holding no lane, until that fill stands at the cut, then resumes
the kept state. So requests that arrive together on a new system prompt compute it once, not once each.
TENSORFOLD_PREFIX_WAIT_MSbounds the wait: 60000 by default, and 0 turns it off.Fixes #1310
What is wrong on main (67cc8fb)
takeJob(zig/src/core/lane_host.zig:298-320) admits the queue's head whenever a lane is free, andlane_stream.open(lane_stream.zig:27) looks it up. A lookup can only return states that are already kept(
prompt_cache.zig:243,:288).prefill_stepthe pass goes on the filling list (lane_host.zig:345-348) and advances a chunk between rounds(
lane_host_fill.zig:80). It keeps the shared cut only when it stands there (Job.kept,lane_job.zig:51).the first. GLM-5.3-Flash on CUDA fills in steps by default (
families/glm/cuda_lanes.zig:93-100).172,032 duplicate prefill tokens at 2 / 4 / 8 at once: every request that started while the first was still
filling. Whole passes do not do this, because each pass ends before the next lookup.
The change
lane_host_prefix.zig(new, 84 lines) holds the wait, which runs at admission:waitsruns whenadmit.pickhas chosen a request. The request waits for the furthest mark of an admitted,unfinished, foreground fill when three things hold. The mark is past where that fill has stood. It adds at least
the store's
min_gappast whatfindholds for this request now. And it would serve this request's own lookup.A waiting request stays in the queue in its place and is passed over.
releaseruns at the top of each pick. It lets a request go on once its fill has stood at the mark (kept orrefused), once the fill is no longer on the filling list (prompt in, cancelled, failed, requeued: matched by
pointer and id), or once the bound has passed (
timeoutscounts those). Its ordinary lookup then resumes the cut,or finds nothing and fills.
cycle, and the oldest fill always runs.
prefill_stepfills and a prompt cache. Never for background fills, pictures, embeddings,prompt logprobs or untaught requests. Whole passes never wait (
core.fills()is false). Family round planners(
LaneHost.rounds) admit on their own path and never wait either.prompt_cache.zig:Store.wouldServe, which judges a state another pass will keep the wayfindjudges a keptone. The state must be eligible on this request's starts, have the same tokens through the lookahead, and have the
same decoded spans.
lane_host_admit.zig:pickreleases waiters, passes over the ones that still wait, and asks about the one itpicks.
lane_job.zig:Job.keptrecords the furthest mark (reached), and a requeue resets it.lane_host.zigcarries only the setting (prefix, read ininitthe wayshareis). It goes from 584 to 586 lines.RUNBOOK.md: one paragraph on the wait and its setting.Why on by default. A waiter holds no lane and no memory. It waits only for rows that would otherwise be computed
twice, and the fill it waits for runs without that competition, so it reaches the cut sooner. The wait ends as soon as
the cut is reached or cannot come, and the bound is a ceiling on top of that. Replies do not change: the waiter resumes
a state kept by the same arithmetic it would have computed, which is the cache's existing resume contract. That is
checked here by token hash against the wait-off replies. Off, every request computes its own prefix, as on main.
Tests
zig/src/core/lane_host_prefix_test.ziguses the stepped fake backend with the store's rules set as GLM's CUDA rulesare: a planned 16-row grid, lookahead 1,
min_gap256. Requests are queued before the host starts, so they arrivetogether.
prompt, and requests 2-4 wait and resume at the 1,024-token cut (
cached0, 1024, 1024, 1024, 0). The unrelatedrequest neither waits nor is waited for. Every reply equals its run with the wait off, by tokens.
waitsis 3,there are no timeouts, and nothing is left queued.
cachedall 0). This is main's behaviour.cached0) and finishes.cached0, 1024, 1024, 1024, 0).min_gap(128 tokens) is not waited for.TENSORFOLD_PREFIX_WAIT_MSparsing: unset, blank, signed, fractional or garbage values give the default,0turnsthe wait off, and
250is 250 ms.Before the decisions were implemented, five of the seven failed. That run had the fields, the pick plumbing and the
tests in place, with
waitsreturning false,releasedoing nothing and the parser returning the default:Receipt
67cc8fbc, branch commit4aa0a98d; Zig 0.17.0; Apple M4 Mac, macOS 27.0.1. TheXcode Metal Toolchain component is not installed, so the Metal library builds in
zig build testfail on both baseand branch.
67cc8fbc("before") against branch4aa0a98d("after"), bothtensorfold-nativebuilt alike (Zig 0.17.0,
aarch64-linux-gnu,-Doptimize=fast) with the same 97 embedded CUDA kernel images (onefatbin set, nvcc 13.0 V13.0.88, sm_121). Two NVIDIA DGX Spark (GB10, 121 GiB unified memory), driver 580.178.04
(CUDA 13.0), cuBLASLt 13.1.1.3, NCCL 2.30.7, glibc 2.39, Ubuntu 24.04.5 LTS, kernel 6.17.0-1032-nvidia, aarch64;
TP=2 over RoCE, one model process on each. Checkpoint
Mia-AiLab/GLM-5.3-Flash-EXL3-4bpw-TensorFold@078455ff, MTPdrafts. The same serve arguments on every start:
serve <checkpoint> --backend cuda --parallel 8 --context 131072 --no-update-check, with the default prompt cache andTENSORFOLD_CUDA_KERNELS=native. Each case ran on a freshlystarted server. The after cases ran as the server's first traffic; the before case followed two unrelated 32-token
requests on its start (other prompts; the fan-out's are salted and new at each level). Both start-up lines:
8 streams at once, 1.77 GiB each at a 131072-token window.prefix_fanout.py,sends 8 chat requests per level. They share a system prompt of ~26,600 tokens (26,588 to 26,615; the client's
--system-tokens 28000target) that is new at each level, each asks its own short question, and they go 1, 2, 4and 8 at a time, greedy, 32 tokens each. Duplicate prefill is the sum of computed prompt tokens (prompt less
cached_tokens) minus the ideal: the first prompt whole, plus each other prompt less the shared cut on the2,048-row grid (24,576 tokens at every level). The after runs reuse the before run's exact prompts and compare every
reply by token hash.
TENSORFOLD_PREFIX_WAIT_MS=0After, every follower at every level reports
cached_tokens24,576. With the wait off, the c8 level reports 0 on alleight, as before.
bench_concurrent.py --levels 1,4 --alone --serial: before, alone 30/30 equal and serial 4/4 equal; after, the same(0 unequal, 0 failed on both).
bench_openai.py --tokens 256 --reps 3 --temperatures 0(median of the 3 reps): before 48.37 tok/s(
fibonacci-raw) and 27.31 tok/s (gpu-chat-no-think), after 47.21 and 26.56. One serve per tree, not repeated oralternated, so this is a single sample each. Decode does not reach the change: it acts only at admission.
zig build test-cuda-host, base 253/253 steps and 3253/3267 tests passed (14 skipped), branch 253/253 and3260/3274 (14 skipped; the 7 new tests).
zig build test: base393/490 steps, 2400/2414 tests passed (13 skipped, 1 failed); branch 393/490 steps,
2407/2421 tests passed (13 skipped, 1 failed; the 7 new tests). The steps that fail on both
are the 55 Metal library builds (no Metal toolchain here) and
cortheon fuzz: every reader takes linear time on long inputs, a timing test that fails on this machine on base too. The engine seam's own module (engine_api.zig, whichmacOS runs only beside the Metal libraries) passes 279/279 on base and 286/286 on the branch.
python3 tools/zig/lean_check.py: 434 problems on base and 434 on the branch (all inherited; none in the files thistouches).
take the same host path, which the fake backend tests. TP=1 and TP=3 or more, other CUDA families, HIP and XPU served
runs,
fuzz-cortheonandbench_cache.pywere not run either: a cold single prompt never waits. One served run pertree (and one for the wait off), so the walls and the decode figures are single samples.
Limits and follow-ups
LaneHost.prefix.waits,.timeouts) are not exported to/metrics. The fan-out effect already showsin
cached_tokensand the prompt-cache counters. I can add them in a follow-up if you want them there.after the one it waits for.
TENSORFOLD_PREFILL_SHAREreaches its cut later, and thewaiter's own fill would have been throttled the same way.
Checklist
only. The waiter's pass is an ordinary resumed fill.)
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.(Resumed equals fresh: 32/32 token hashes, wait on and off. Concurrent equals solo:
bench_concurrentalone 30/30and serial 4/4 on both trees.
"draft": falsewas not run, because the change does not touch drafting.)arithmetic changes.)
SUMMARYline is in the receipt. (No kernel is added or changed.)not reach the change, and the fan-out walls are above.)
Apple M4 without the Metal toolchain, and a served CUDA run on two GB10s. No Metal device run.)
fail with the decisions stubbed. They are host tests with nothing to skip on.)
By Robert Wojciechowski (wojo on GitHub, @rwojo on X)