Skip to content

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

Draft
CodingEmil wants to merge 3 commits into
ashhart:mainfrom
CodingEmil:lanes-outgrown-length
Draft

CodingEmil wants to merge 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.

…nit Macs take TF_QWEN27_METAL_KV_PAGES

A 512-key prompt chunk spans exactly two KV pages, so the paged prompt kernels take both page bases
before their 32-key steps instead of reading the page table at every step. The M5 refusal of the flag
goes, now that the paged kernels have run on an M5 Ultra (part of ashhart#1293).
…gives them back when it leaves

With TF_QWEN27_METAL_KV_PAGES=1 a slot no longer holds a promise of its whole window from startup.
A stream opening a slot is promised its prompt and one widest pass; a pass past that promises the rest
before it takes a page, and a promise the pool cannot meet fails with LaneMemory before any page is
taken or table entry written. Leaving, failing or being put back, a reset and a move to slot 0 give
the pages and the promise back; a standing slot 0 keeps the pages of its committed rows. The page
lifecycle is in families/qwen27/slot_pages.zig, its host tests in slot_pages_test.zig (part of ashhart#1293).
…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.

This branch has not been deployed

No deployments
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.

1 participant