Skip to content

Qwen TP native executor: submit and read decode steps in two phases (PR6a, stacked on #1830) - #1832

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

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

Conversation

@jonathan308

@jonathan308 jonathan308 commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #1830 (base perf/tp-qwen-build-ahead; retarget to dev once #1830 merges). PR6 part a: the native executor's half of build-ahead. Off in the product: buildsAhead is an executor init option, false by default. Part c turns it on with QwenTensorParallelBatchSettings.buildsAhead and measures on the pair.

What

  • CBv2OwnedRequestState.submitBatch: runBatch's frame, submitted with asyncEval instead of evaluated. Rows commit on host-held facts: a paged host's frontiers and bindings, with no device read; the recurrent generation; each state's shape. Native errors surface at the read, under the same MLX.withError. A contiguous host reads its frontiers from the device, which waits for the frame: still exact, just without overlap (used by the CPU test). Packed storage is refused.
  • QwenTensorParallelBatchSession.submitDecode(_:tokens:): decode's forward on lazy [B] int32 tokens, the previous step's unread selection. One decodeResult body serves both, so it's the same graph by construction.
  • Selection in two phases:
    • buildSelection produces graph nodes. Each sampled row's lazy logprob gather is kept with its step (QwenStageTokenSampler.takePendingStepLogprobs, as Gemma TP: build sampled steps one ahead too (stacked on #1822) #1824 adds for Gemma), because a step built ahead draws again before this one is read. A submitted step defers the gathered rows' finiteness check to its read, which fails both ranks before any history advances.
    • readSelection checks the rows, then advances rank 0's sampler history and logprobs.
    • select = build + read, so the read-then-build order is unchanged, gathered-row check included.
  • submitDecode/readDecode on QwenTensorParallelNativeBatchExecutor, for plain lanes only (no assistant, nothing accepted).

Token identity

QwenTensorParallelBatchSessionTests.buildAheadDecodeTakesTheReadThenBuildTokensAndLogprobs (new) runs two ranks on greedy rows, sampled rows (penalties, logit bias, top-p/k, min-p) and logprob rows, at widths 1, 2 and 4, for six steps. Each step is submitted on the previous step's unread selection before that step is read. Tokens, logprobs and folded control words equal the same cohort decoded read-then-build.

  • CPU, run locally: passes (contiguous host, all-attention fixture).
  • Red: with the old one-slot logprobs, it fails (2 issues, logprobs).
  • GPU (paged host): queued for the next slot: QWEN_TP_BATCH_GPU=1 swift test --filter buildAheadDecodeTakesTheReadThenBuildTokensAndLogprobs.

Regression check: 48 tests pass on the CPU: the existing native selection suites (mixed sampling, folded control, greedy ties, non-finite rows on one or both ranks), the driver and settings suites, and the sampling suite. The worker's Release build compiles (Xcode 27.2).

No changelog fragment: nothing user-visible while buildsAhead stays off.


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

Hardware (M5 Ultra, 2026-11-05 21:21Z, Mac A load 3.3)

GPU, paged host: PASS 4/4. Covers buildAheadDecodeTakesTheReadThenBuildTokensAndLogprobs and the existing native selection suites (mixed sampling, folded control, routed experts). Measured pair gain in #1834.

Second review fixes (cfbbf8c77c, 22:05Z)

  • N5: aNativeLaneRetiresAfterABuiltAheadEOS retires a native lane as a clean EOS with exactly one discarded forward. It's red without the schedule's EOS rule.
  • Paged host, no device reads: CBv2StageKVHost.submittedDeviceFrontierReads counts the device reads a submitted frame makes. The token-identity suite asserts none on a paged host (GPU) and checks the counter is live on a contiguous one (CPU).
  • Queued for the next GPU slot: QWEN_TP_BATCH_GPU=1 swift test --filter 'buildAheadDecodeTakesTheReadThenBuildTokensAndLogprobs|aNativeLaneRetiresAfterABuiltAheadEOS'.

PR6 part a (stacked on #1830's driver protocol). The native batch executor
can submit a plain decode rectangle without reading it, on the host's
tokens or the previous rectangle's unread selection, and read it later:

- CBv2OwnedRequestState.submitBatch: runBatch's frame submitted
  (asyncEval) and committed on host-held facts (a paged host's frontiers;
  a contiguous host reads them from the device, exact without overlap).
- QwenTensorParallelBatchSession.submitDecode: decode's forward on lazy
  int32 tokens (one decodeResult body for both).
- Selection split into buildSelection (graph nodes, each sampled row's
  lazy logprob gather kept with its step; a submitted step defers the
  gathered rows' finiteness check to its read) and readSelection (checks,
  then sampler history and logprobs on rank 0). select = build + read, the
  read-then-build order unchanged.
- submitDecode/readDecode on the executor; buildsAhead is an init option,
  off by default, so the product is unchanged until part c.

Test: buildAheadDecodeTakesTheReadThenBuildTokensAndLogprobs (two ranks,
greedy, sampled with penalties and bias, and logprob rows, widths 1/2/4):
build-ahead tokens, logprobs and folded control words equal the
read-then-build cohort's. Passes on the CPU; with the old one-slot logprobs
it fails (2 issues). GPU run queued (QWEN_TP_BATCH_GPU=1, paged host).

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:34pm UTC
d-inference-console-ui-dev Error Error Nov 5, 2026 10:34pm UTC
d-inference-landing Ready Ready Preview Nov 5, 2026 10:34pm UTC
darkbloom-status Ready Ready Preview Nov 5, 2026 10:34pm UTC
eigen-homepages-darkbloom Ready Ready Preview Nov 5, 2026 10:34pm UTC

Request Review

@blacksmith-sh

This comment has been minimized.

Review of #1830 (must-fix 1), executor half: QwenTensorParallelBatchSettings
.buildsAhead now reaches both the driver and the native executor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308 and others added 2 commits November 5, 2026 14:02
…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>
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>

This branch had an error being deployed

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