Skip to content

Qwen TP batch driver: build-ahead protocol (gated, off until the native executor submits steps) - #1830

Merged
jonathan308 merged 3 commits into
devfrom
perf/tp-qwen-build-ahead
Nov 5, 2026
Merged

jonathan308 merged 3 commits into
devfrom
perf/tp-qwen-build-ahead

Conversation

@jonathan308

@jonathan308 jonathan308 commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

What

The driver protocol for Qwen tensor-parallel build-ahead (PR6 part b; design in overnight/tp-perf/REPORT.md "PR6 design"). The batch driver can build a plain decode step before it reads the step before it, so the GPU and the collectives keep running while the host reads tokens, publishes and services the owner. Window 1 measured ~1.9 ms of GPU idle at each token boundary of a ~23 ms step. The expected gain is 8–10 %, to be measured once the native executor opts in.

Off in the product. The native executor does not submit decode steps yet (buildsAhead false, the protocol default), so nothing changes until part a (native two-phase submitDecode/readDecode) and part c (opt-in) land with their GPU suites.

Protocol (both ranks)

  • Decision words. Every folded plain decode step's selection sum also carries two decision words (each rank's barrier flag, 0/1) for the step two later. When neither rank asks for a barrier and the unread step decoded the same lanes the decision covered, both ranks build that step on the unread step's selection rows. Then they read the unread step.

  • Barrier = today's path. A rank asks for a barrier whenever anything needs a plan:

    • rank 0 read an owner's stop, or the answer to a request's last token (the answer is kept for that plan and the lane publishes nothing more);
    • a request waits to join;
    • a lane is idle;
    • cancel or deadline;
    • a lane ended;
    • a lane would pass its output count;
    • more than 4 tokens are held unpublished.

    At a barrier both ranks read every submitted step, and the next plan is made and exchanged with nothing in flight, through today's makePlan/validate/leave/join. No plan ever carries in-flight counts.

  • Lockstep. Every input to a decision and to a build is agreed state (read sums, read tokens, plans), so both ranks submit the same collectives in the same order. A rank's own decision word is checked unchanged in transit.

  • Held tokens. Held tokens are a queue (heldLogprobs): one published per "go on" answer, in order, never past a stop. A client stop drops up to 4 held tokens: validate's dropsOne becomes dropsHeld, still exactly 1 without build-ahead.

  • EOS after a built step. An EOS read after the next step was built discards that one forward on both ranks; its token is never selected. QwenLayerStageGenerationSchedule.finish now accepts one declared discarded forward after an EOS (a client stop already could; a length finish still can't). No step is built past a request's output count.

  • Version gate. QwenTensorParallelBatchSettings.buildsAhead adds qwen-tp-batch-build-ahead-v1 to the load agreement, so ranks on different protocols refuse each other before loading weights. A pair that disagrees anyway fails closed on both ranks at the first folded step (the sum shapes differ); it never runs out of step. The driver refuses build-ahead on an executor that can't submit steps or doesn't fold control.

Tests (model-free, CPU; run locally: 71 tests in the driver, settings, schedule-adjacent and other batch-driver suites, all pass)

New in QwenTensorParallelBatchDriverTests (two ranks, fake executor):

  • steadyDecodeBuildsAheadAndTakesTheReadThenBuildTokens, widths 1/2/4: ≥ 10 steps built before the previous one was read. Both ranks submit and read in the same order. Tokens, finishes and forwards equal the read-then-build oracle (none past length).
  • anEOSReadAfterTheNextStepWasBuiltDiscardsThatForwardOnly: EOS beside length rows; ≤ 1 forward past an EOS, none past a length end.
  • aHostStopUnderBuildAheadPublishesOnlyWhatTheOwnerSaw: answers at once and one poll late; nothing published past what the owner saw; clean client stop on both ranks.
  • lateCreditsUnderBuildAheadPublishInOrder.
  • joinsPromptsAndCancellationInterleaveWithBuildAhead.
  • ranksThatDisagreeOnBuildAheadFailClosed.
  • buildAheadNeedsAnExecutorThatSubmitsAndFolds.
  • readThenBuildNeverBuildsAhead.
  • theScheduleAcceptsAnEOSWithTheForwardBuiltPastIt.

Also: QwenTensorParallelBatchSettingsTests (the gate field appears only when on). All 21 existing driver cases pass unchanged.

Red → green: with the build-ahead path disabled, 3 tests fail with 6 issues (steady build-ahead count, joins build-ahead count, disagreeing ranks not failing). With it, all pass.

Token identity against the read-then-build oracle is checked in every new case, through the fake executor's deterministic histories. On real hardware it comes with part a's GPU suite (build-ahead equals read-then-build bitwise for greedy and sampled rows), queued in the REPORT's GPU slot queue.

Docs: docs/architecture/inference.md (Qwen TP folded control → "Build-ahead"). No changelog fragment: no user-visible change while the native executor keeps it off.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Review fixes (2c22a0ecd0, 21:19Z)

  • Must-fixes: the runtime passes settings.buildsAhead into the driver (and, in Qwen TP native executor: submit and read decode steps in two phases (PR6a, stacked on #1830) #1832, into the executor), so the gate and the behaviour are one value. A submitted, unread step is drained before retireAll.
  • Nits: decisions see the peer's reported cancellations; the schedule accepts exactly one discarded forward after an EOS; after a barrier the next step carries its successor's plan again, so only one step runs read-then-build.
  • Tests: the build-ahead path is asserted in the EOS, owner-stop and late-credit cases; disagreement in both directions fails both ranks at the first folded step; new cases cover a corrupted decision word, the held bound, an assisted row beside plain rows, and a failure while a step is pending. Harness bounds are tightened to the driver's.
  • Red/green: with the path disabled, 9 tests fail (24 issues); with it, all 30 pass.
  • Measured in qwen-decode --build-ahead: measured −7.8 % (w1) / −5.7 % (w4) on the pair (PR6c, stacked on #1832; default stays off) #1834: −7.8 % (width 1), −5.7 % (width 4), same tokens.

Second review fixes (0f0818add8, 22:02Z)

  • N1 fixed: when a read fails in the continuation branch, pending is already the newer step, so the cleanup drains it exactly once and never re-reads the failed step. aReadFailureWhileTheNextStepIsBuiltDrainsTheNewerStepOnce is red before the fix (step 6 read twice, step 7 never) and green after.
  • N2: the pending-failure test checks that every submitted step is read exactly once, and the failed one never.
  • N4: a built-ahead EOS leaves exactly one discarded forward.
  • 31 driver tests pass. Build-ahead stays off in 0.10.10; the soak plan for 0.10.11 is in the tp-perf REPORT.

The driver can build a plain decode step before it reads the step before
it, so the GPU and the collectives run while the host reads, publishes and
answers (window 1 measured ~1.9 ms of GPU idle at each token boundary).

- Every folded step's selection sum also carries two decision words (each
  rank's barrier flag) for the step two later. With no barrier and the
  unread step decoding the same lanes, both ranks build that step on the
  unread step's selection rows (executor submitDecode/readDecode, new,
  default unsupported).
- Any event that needs a plan (owner stop or the answer to an ending token,
  join, idle lane, cancel or deadline, ended lane, output count, more than
  four held tokens) is a barrier: both ranks read every submitted step and
  the next plan is made and exchanged with nothing in flight, as today.
- Held tokens are a queue (one published per answer); a decision that
  reads a stop marks the lane leaving and keeps the answer for the plan.
- An EOS read after the next step was built discards that one forward;
  the generation schedule accepts one declared discarded forward after an
  EOS (a length finish still none).
- Gate: QwenTensorParallelBatchSettings.buildsAhead adds
  qwen-tp-batch-build-ahead-v1 to the load agreement. Off: the native
  executor does not submit decode steps yet, so the product is unchanged.

Tests: six two-rank fake-executor cases (steady decode at widths 1/2/4,
EOS, owner stops at once and late, late credits, joins + prompts +
cancellation, ranks that disagree failing closed), the gate, the schedule's
EOS rule. With the build-ahead path disabled 3 fail; with it all pass,
and every existing driver case is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
d-inference Error Error Nov 5, 2026 10:04pm UTC
d-inference-console-ui-dev Error Error Nov 5, 2026 10:04pm UTC
d-inference-landing Ready Ready Preview Nov 5, 2026 10:04pm UTC
darkbloom-status Ready Ready Preview Nov 5, 2026 10:04pm UTC
eigen-homepages-darkbloom Ready Ready Preview Nov 5, 2026 10:04pm UTC

Request Review

@blacksmith-sh

This comment has been minimized.

…, tests)

Review of #1830:
- The runtime passes QwenTensorParallelBatchSettings.buildsAhead (the load
  agreement's value) into the driver, so the gate and the behaviour are one
  value.
- On a failure, a submitted unread step is drained before retireAll.
- Decisions see the peer's reported cancellations (no publish, barrier).
- The schedule accepts exactly one discarded forward after an EOS.
- After a barrier the next step carries its successor's plan again, so only
  one step runs read-then-build instead of two.
- Tests: the build-ahead path is asserted in the EOS, owner-stop and
  late-credit cases; disagreement in both directions fails both ranks at
  the first folded step; a corrupted decision word fails both; the held
  bound; an assisted row beside plain rows; a failure while a step is
  pending retires every lane. Harness bounds tightened to the driver's.
  With the build-ahead path disabled, 9 tests fail; with it, all 30 pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review of #1830-#1834, N1: in the continuation branch a failing read of
the previous step left pending pointing at it, so the cleanup read it a
second time and never drained the step already built ahead (probe: submit
4, read 3, read 3). pending now becomes the newer step before the read.

Tests: aReadFailureWhileTheNextStepIsBuiltDrainsTheNewerStepOnce (red
before: step 6 read twice, step 7 never; green after); the pending-failure
test now checks every submitted step is read exactly once and the failed
one never (N2); a built-ahead EOS leaves exactly one discarded forward (N4).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308 added a commit that referenced this pull request Nov 5, 2026
…s no device frontier

Review of #1830-#1834, N5 and the device-read gap:
- aNativeLaneRetiresAfterABuiltAheadEOS: a native lane whose EOS is read
  after its next step was built retires as a clean EOS with exactly one
  discarded forward; red without the schedule's EOS rule.
- CBv2StageKVHost.submittedDeviceFrontierReads counts the frontier checks a
  submitted frame reads from the device; the token-identity suite asserts
  none on a paged host (GPU) and that the counter is live on a contiguous one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jonathan308
jonathan308 merged commit 8259a61 into dev Nov 5, 2026
18 of 22 checks passed
jonathan308 added a commit that referenced this pull request Nov 5, 2026
QwenStageTokenSampler.takePendingStepLogprobs came in from #1824 too: one
copy kept, its doc naming both users (Gemma's one-token loop, Qwen's
build-ahead). #1820's stride, #1822/#1824's CBv2OwnedRequestState.submit and
#1830 are kept as on dev.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308 added a commit that referenced this pull request Nov 5, 2026
Qwen TP native executor: submit and read decode steps in two phases (PR6a, stacked on #1830)

This branch had an error being deployed

2 failed and 3 active deployments
Preview – d-inference-landing — 0f0818ad Deployed Nov 5, 2026 by vercel[bot]
Preview – eigen-homepages-darkbloom — 0f0818ad Deployed Nov 5, 2026 by vercel[bot]
Preview – darkbloom-status — 0f0818ad Deployed Nov 5, 2026 by vercel[bot]
Preview – d-inference — 0f0818ad Deployed Nov 5, 2026 by vercel[bot]
Preview – d-inference-console-ui-dev — 0f0818ad Deployed Nov 5, 2026 by vercel[bot]
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