Skip to content

feat(lanes): the lane host fills foreground prompts first, then the shortest waiting - #651

Merged
ashhart merged 1 commit into
ashhart:mainfrom
BlivionIaG:core-fill-shortest
Oct 12, 2026
Merged

ashhart merged 1 commit into
ashhart:mainfrom
BlivionIaG:core-fill-shortest

Conversation

@BlivionIaG

@BlivionIaG BlivionIaG commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

lane_host.zig's fillOne (#623) filled the oldest waiting prompt first. That caused two waits:

  • A short request queued behind a long prompt waited for every chunk of it.
  • A foreground request that arrived while a background prompt was filling waited for that prompt to finish. The submit queue already puts foreground first, but not once a background prompt has started filling.

The next chunk now goes to a foreground prompt before a background one, then to the prompt with the fewest tokens left to run (prompt_len - cached), the oldest of equals.

lane_host.zig sat at 600 lines, so the pick and unfill move to lane_host_fill.zig, the way lane_host_learn.zig and lane_host_status.zig did. lane_host.zig ends at 595.

No backend on main gives prefill_step yet (only the test fake does), so no engine that runs today changes. The Qwen3.5 HIP engine (#631) is the first that fills in chunks. Background warm passes (#924104e2's warmPass) do not go through the filling list and are unchanged.

Receipt

  • Environment: base main at d512657, head 3533f64. Zig 0.17.0, on macOS (Apple silicon) and Linux 7.1.7.

  • Exactness: the lane host's tests are unchanged and pass, with every request still getting the fake target's exact tokens. lane_host_fill_test.zig adds two tests:

    • "a lane host fills the shortest waiting prompt first, so a short request waits on no long one": a 16-token and a 4-token prompt are admitted together, and the 4-token one must be prefilled first.
    • "a foreground prompt arriving while a background one fills takes the next chunk": the background prompt's first chunk sends a foreground request, which must be prefilled first.
    • Each fails with its rule taken out: the shortest-first comparison for the first, the foreground rule for the second. Three runs in a row pass.
  • Speed, on our fork with the HIP engine (Qwen3.5-9B MLX 4-bit on a W7800, gfx1100, measured with serve_bench.py there), this change alone with prompt chunks left at 1024 rows, at c=8 with 256- and 8192-token prompts alternating 0.4 s apart:

    oldest first shortest first
    short prompts, worst TTFT 11.4 s 0.73 s
    all requests, mean TTFT 7.7 s 5.4 s
    all requests, worst TTFT 15.3 s 15.7 s
    total output 76 tok/s 75 tok/s

    The cost is that the long prompts finish a little later.

  • Tests run:

    • macOS zig build test test-golden -Dcpu=apple_m1: 139/139 steps, 377/378 tests (1 skipped); golden 309/319 equal, 0 unexpected.
    • Linux zig build test: 39/39 steps, 449/449 tests.
    • zig fmt --check is clean on the changed files.
    • lean_check.py: 534 problems, the same as main.
  • Not run, and why: device runs on main (no backend fills in chunks there).

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Only the order in which prompts are filled changes; each stream's tokens are its own.)
  • No precision traded for speed.
  • Prompt processing is no slower than the last release. (No backend on main fills in chunks.)
  • The description says which platforms I ran and which I could not.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.

…hortest waiting

Prompts waiting for their pass were filled oldest first, so a short request queued behind a long prompt waited for
all of its chunks, and a foreground request that arrived while a background prompt filled waited for it to end.
The next chunk now goes to a foreground prompt before a background one, then to the one with the fewest tokens
left to run (the oldest of equals). The pick lives in lane_host_fill.zig with unfill, so lane_host.zig stays under
600 lines; lane_host_fill_test.zig admits a long and a short prompt together and expects the short one first, and
sends a foreground request during a background prompt's first chunk and expects it prefilled first.
@BlivionIaG BlivionIaG changed the title feat(lanes): the lane host fills the shortest waiting prompt first feat(lanes): the lane host fills foreground prompts first, then the shortest waiting Oct 11, 2026
@ashhart
ashhart merged commit 0a56425 into ashhart:main Oct 12, 2026
2 checks passed
@ashhart

ashhart commented Oct 12, 2026

Copy link
Copy Markdown
Owner

Thank you, @BlivionIaG. This landed in 1.0.8 as your own commit (c4d07a549), rebased for 1.0.8. lane_host.zig sat at exactly 600 lines there too, so before your commit we moved the lane host's lone driver (loneFits and runLone) into lane_host_lone.zig as our own commit (59712419d), with no change in behaviour. The only conflicts were the import lines, where both stay, and remove, which that move made pub. Your added and removed lines are exactly as you wrote them, and lane_host.zig ends at 545 lines. 0a5642529 merges this PR's head (3533f64f2) without changing the tree, so GitHub shows it as merged.

What we checked:

  • Your two tests pass, and each one catches its own rule. Taking out the shortest-first comparison fails the first test only, taking out the foreground rule fails the second only, and going back to oldest-first fails both. The engine seam's test root, which holds the lane host's tests, goes from 107 to 109 tests, all passing.
  • Replies are unchanged. With Nemotron 3.5 Lightning MLX 4-bit on a GB10 (CUDA) and an M5 Max (Metal), the same tree with and without this PR (and cuda: sample.cu's keyed draws as a shared module (sample.zig); Nemotron draws through it #654, which landed beside it) gave the same token sha on every reply: release prompts drafted and "draft": false, greedy and sampled, four at once against alone, one to eight streams, structured output, and conversations resumed from the prompt cache against a server with the cache off.
  • As you said, no engine in 1.0.8 fills prompts in chunks, so we measured that nothing moved. A long prompt went first and three short ones (258 to 377 tokens) followed 0.2 s later, with identical prompts for both builds, A B B A. On the GB10 the short ones waited for the long prompt's whole pass with both builds: 9.6 to 9.9 s behind a 53,068-token prompt and about 3.0 to 3.4 s behind 15,000 to 20,000 tokens, against 0.11 s alone. With this PR against without: the short ones' mean wait x0.999, the slowest x1.000, the long prompt x0.999. The M5 Max showed the same picture, 20.0 to 20.3 s behind the 53,068-token prompt and 6.2 to 7.1 s behind about 20,000 tokens, against 0.16 to 0.18 s alone, and its prompt speed with and without this PR stayed within run-to-run noise. The gain arrives with feat(qwen3_5): the Qwen3.5 / 3.6 engine on HIP (slice 12) #631.

Three small notes for a follow-up, none of them blocking:

  • next ranks by prompt_len - cached, and cached is set when a pass restores its prefix (in the fake, at the first chunk). Until then a resumed turn counts its whole prompt. stream.reuse.at is already known at admission.
  • unfill takes anytype because Job was private. Our move made Job public, so it can take *LaneHost.Job.
  • The filling field's comment still ends "oldest first". That's the list's order, but it now reads like the fill order.

The fake target's stepped prefill made both orders easy to pin down without a GPU.

BobClawblaw pushed a commit to BobClawblaw/TensorFold that referenced this pull request Oct 12, 2026
lane_host.zig was at 600 lines with ashhart#651 still to add. The lone driver (loneFits and runLone: an idle backend's own
loop runs a lone stream and hands it back to the lane core when a foreground request or a cancel waits) moves
unchanged as lone.fits and lone.run, and the host functions it calls become public. lane_host.zig is 550 lines;
lean_check reports the base's 543 problems.
BobClawblaw pushed a commit to BobClawblaw/TensorFold that referenced this pull request Oct 12, 2026
BobClawblaw pushed a commit to BobClawblaw/TensorFold that referenced this pull request Oct 12, 2026
…draws module) into the 1.0.8 candidate
@ashhart ashhart mentioned this pull request Oct 14, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
lane_host.zig was at 600 lines with ashhart#651 still to add. The lone driver (loneFits and runLone: an idle backend's own
loop runs a lone stream and hands it back to the lane core when a foreground request or a cancel waits) moves
unchanged as lone.fits and lone.run, and the host functions it calls become public. lane_host.zig is 550 lines;
lean_check reports the base's 543 problems.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
ashhart#651 landed above as 43be2838b (the author's commit, rebased onto this candidate). This keeps the PR's own head commit in the history, with no change to the tree.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…draws module) into the 1.0.8 candidate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants