Skip to content

lanes: a stream whose next rows find no memory ends with length; the round's other streams run on - #3378

Merged
ashhart merged 3 commits into
ashhart:mainfrom
CodingEmil:lanes-outgrown-length
Dec 2, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
CodingEmil:lanes-outgrown-length

Conversation

@CodingEmil

Copy link
Copy Markdown
Contributor

What this changes

Before, a backend could only report missing memory for a stream's next rows by failing its verify. Then core.step() failed and lane_host_end.failRound failed every stream in the round. With this change, a backend may answer an optional Backend.grow before the verify. A stream whose window finds no memory finishes with length and a message before the forward, and the round verifies the other streams' windows. Qwen3.8-27B on Metal with TF_QWEN27_METAL_KV_PAGES=1 answers it: before the round, its slot covers the window's rows through slot_pages, and a slot the pool cannot cover ends its stream. A backend without the hook runs exactly as before.

Checks on this head

  • Head commit: 542961fdb on 864e6f1d5.
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 341 on the base, 341 on the head, 0 new (tools/zig/lean_new.py). The 341 are inherited.
    • zig/src/core/lanes/engine.zig stays at 600 lines: the new logic is in zig/src/core/lanes/outgrown.zig, and the engine's two verify calls go through it.
    • The qwen27 caller is qwen27_slots.grow (qwen27_slots.zig 558 lines, qwen27_lanes.zig 562).
  • Tests run, with the command and pass, fail and skip counts:
    • The lanes module's tests (the same test binary zig build test builds from zig/src/core/lanes/lanes.zig), run on their own: base 367 passed, 1 skipped; head 370 passed, 1 skipped (the 3 new tests in outgrown_test.zig).
    • zig build test-qwen27-outgrown-host (new): 2/2 passed. Its test runs the lane engine with the core's fake backend, whose grow covers each slot through slot_pages over a host pool of three pages, as qwen27_slots.grow does.
      • "a" runs out where its second page begins and ends with length and its message.
      • "b" gives the same tokens as it gives alone.
      • Once both slots are released, every page is free and nothing is promised.
    • zig build test-qwen27 test-qwen27-reply-cache-host test-qwen27-startup-host test-lane-api-host test-lane-strand-host test-lane-halt-host test-lane-lone-host test-lane-interrupted-host test-kv-pool test-prefill-service-host test-flashnext-batch-host: 84/84 steps, 1109 passed, 2 skipped.
    • zig build native tf-qwen27-attention-pages tf-qwen27-pages-resume -Dcpu=apple_m1: builds.
    • zig build test test-golden -Dcpu=apple_m1 --summary all, with the GPU free: 870/870 steps succeeded, 13443 passed, 115 skipped, 0 failed. Six test steps came from the build cache (the lanes module's among them, counted in the line above), and the summary does not count their tests.
    • tf-qwen27-attention-pages (plain and --shared-prefix) and tf-qwen27-pages-resume on this head, on the device: PASS.
    • zig fmt --check build.zig zig and git diff --check: clean.
    • python3 tools/pr_check.py: 0 errors, 1 warning (it asks for --pr NUMBER to check the Unreleased line).
    • Failing before: with the base's engine.zig and this head's hook and tests, all four new tests fail:
      • the shared-round test, at the stream's message: "a" runs to its max_new instead of ending after 5 tokens;
      • the lone test: expected 3, found 24;
      • the "without grow" test, at asked > 0: the base never asks the hook;
      • qwen27 outgrown:, at the cut stream's message: "a" runs to its max_new.
  • CI: not run yet (nothing pushed).
  • Not run, and why:
    • zig build dev-tools: the change adds an optional vtable field with a default;
    • Linux test-host: no Linux machine with Zig here; CI will run it. The new host step is listed in zig/build/host_ci.zig beside the other qwen27 host steps.

Receipt

  • Main against branch: no timing cells planned. qwen27_slots.grow covers the window's rows one call earlier than the verify would (the verify's own cover then finds them held). Every other backend runs as before:

    • the lone verify checks a null hook and calls verify as before;
    • the shared verify walks the round's windows once and keeps every one in place.

    If you want the paged default measured, I can add a bench_concurrent --levels 1,2 --alone --serial cell and a decode A-B-B-A against the demand-pages head on an M5 Ultra.

  • When a stream ends this way on qwen27 with only this stack: never on its own. Each slot holds at most its window, and the pool has every slot's window (see qwen27 metal pages: a stream promises its pages as its rows come and gives them back when it leaves #3377). The false answer is reached once something else holds pages of the same pool, as kept states will in Metal: KV pages from the core pool #1293 step 4. This pull request makes that case end one stream instead of the round.

  • Boxes it reaches: every engine on the lane core, through zig/src/core/lanes/engine.zig. Only a backend that sets grow changes behaviour; on main with this stack, that is Qwen3.8-27B on Metal with TF_QWEN27_METAL_KV_PAGES=1.

  • New switch? Default, accepted values, profile row: none. Backend.grow is an optional vtable hook, null by default.

  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: 542961fdb on 864e6f1d5, Zig 0.17.0, Apple M5 Ultra, 96 GB, macOS 27.2. Host tests, the full test run and the page tools; no served checkpoint.

  • Paths and platforms the change reaches, which I ran and which I could not:

    • Reached, when a backend sets grow:
      • a lone stream's verify window (familyRound: drafts with family_mtp, non-pipelined engines, logprobs, grammars);
      • a pipelined stream's copied continuation, which verifies through familyRound;
      • a shared round's windows (roundStreams).
    • Not reached:
      • a pipelined stream's queued one-token steps (queue);
      • prompt passes and the first token;
      • admission (a LaneMemory promise still requeues the request);
      • the qwen27 lone driver's serial loop;
      • backends behind the recorder.zig and drafted.zig wrappers, whose own vtables do not pass grow on.
    • Ran: the host tests above, on macOS / M5 Ultra. Not run: Linux, CUDA, HIP, M1 to M4. The change has no device code.
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false: not run on a device. In the host tests, the stream that keeps running gives the same tokens as alone, both in the core test and in the qwen27 one over a host pool. A backend whose hook always holds gives the same tokens, steps and shared rounds as a backend without it.

  • Main against this branch, same machine and checkpoint, posted before asking for a run on our machines (or why you can't): not asking for a run; see above.

  • Decode speed before and after, from tools/bench_openai.py: not measured; the qwen27 cost is the window's page check one call earlier.

  • Prompt speed before and after: n/a, the change does not reach prompt passes.

  • Licence of any new weights or drafter, or "n/a": n/a, none.

Checklist

  • The title and description match the head commit, including the receipt and the stack.

  • New tests fail before the change, pass after it, and skip cleanly without their dependency (fake backend and host pool, no device).

  • Comments and docstrings are one line. No measurements or history in the source.

  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

  • 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: not measured on a device. Without a slot out of pages, every path runs as before.

  • No precision traded for speed. No arithmetic changes.

  • Decode and prompt processing are no slower than main at one stream and the widest admitted: not measured.

@ashhart

ashhart commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Thanks @CodingEmil. The shape is right: a backend hook before the verify, a stream that cannot cover its window finishing with length and a message, the round's other streams still verifying, and a backend without the hook running exactly as before. The three new tests and the host test cover the cases we would have asked for.

Nothing more is needed from you. We'll rebase it onto current main ourselves (the earlier conflicts were changelog lists) and add one sentence to the settings documentation naming the caller that answers the hook. Then we'll check it on Metal with the KV pages setting: one stream running out mid-window beside one that runs on, comparing token hashes with and without the hook.

  • Synthena

@ashhart
ashhart force-pushed the lanes-outgrown-length branch from 930d220 to b7acfee Compare December 2, 2026 12:31
@ashhart

ashhart commented Dec 2, 2026

Copy link
Copy Markdown
Owner

READY to land on this head. Rebased onto current main by us. Code review: without the backend hook the default path is unchanged, a stream whose next rows find no memory ends with length while the round's other streams run on, and the size cap and pins are respected. A Qwen 27B A/B on an M5 Ultra gave equal tokens on every row with flat speed.

  • Synthena

@ashhart
ashhart marked this pull request as ready for review December 2, 2026 13:17
CodingEmil and others added 3 commits December 2, 2026 15:57
…round's other streams run on

A backend may answer Backend.grow before a verify: false means the stream's caches find no memory for
the window's rows. That stream finishes with `length` and a message before the forward, and a shared
round verifies the others' windows; without the hook a round runs as before. Qwen3.8-27B on Metal with
TF_QWEN27_METAL_KV_PAGES=1 answers it: its slot covers the window's rows through slot_pages before the
round, and a slot the pool cannot cover ends its stream instead of failing the round's. Host tests in
lanes/outgrown_test.zig and native/qwen27_outgrown_test.zig (test-qwen27-outgrown-host), part of ashhart#1293.
Main trimmed qwen27_slots.zig to its 600-line cap after this branch was
cut; the slot's grow hook would take it to 617. The hook moves unchanged
to qwen27_grow.zig, and the backend's two vtables name it there. No line
of it changes.

qwen27_served.zig, a pinned serving source, now imports the outgrown host
test beside main's others: re-pinned with ashhart#3378 added to its note.
@ashhart
ashhart force-pushed the lanes-outgrown-length branch from b7acfee to 4666704 Compare December 2, 2026 15:57
@ashhart
ashhart merged commit 0a04bb3 into ashhart:main Dec 2, 2026
6 of 10 checks passed
ashhart added a commit that referenced this pull request Dec 2, 2026
Main trimmed qwen27_slots.zig to its 600-line cap after this branch was
cut; the slot's grow hook would take it to 617. The hook moves unchanged
to qwen27_grow.zig, and the backend's two vtables name it there. No line
of it changes.

qwen27_served.zig, a pinned serving source, now imports the outgrown host
test beside main's others: re-pinned with #3378 added to its note.
@ashhart

ashhart commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Thank you @CodingEmil. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

ashhart added a commit to AbrahamCete/TensorFold that referenced this pull request Dec 2, 2026
ashhart added a commit that referenced this pull request Dec 2, 2026
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