Repository navigation
Qwen TP native executor: submit and read decode steps in two phases (PR6a, stacked on #1830) - #1832
Merged
Merged
Conversation
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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This comment has been minimized.
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>
…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>
jonathan308
added a commit
that referenced
this pull request
Nov 5, 2026
qwen-decode --build-ahead: measured −7.8 % (w1) / −5.7 % (w4) on the pair (PR6c, stacked on #1832; default stays off)
This branch had an error being deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #1830 (base
perf/tp-qwen-build-ahead; retarget todevonce #1830 merges). PR6 part a: the native executor's half of build-ahead. Off in the product:buildsAheadis an executor init option, false by default. Part c turns it on withQwenTensorParallelBatchSettings.buildsAheadand measures on the pair.What
CBv2OwnedRequestState.submitBatch:runBatch's frame, submitted withasyncEvalinstead 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 sameMLX.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. OnedecodeResultbody serves both, so it's the same graph by construction.buildSelectionproduces 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.readSelectionchecks 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/readDecodeonQwenTensorParallelNativeBatchExecutor, 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.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
buildsAheadstays off.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.Hardware (M5 Ultra, 2026-11-05 21:21Z, Mac A load 3.3)
GPU, paged host: PASS 4/4. Covers
buildAheadDecodeTakesTheReadThenBuildTokensAndLogprobsand the existing native selection suites (mixed sampling, folded control, routed experts). Measured pair gain in #1834.Second review fixes (
cfbbf8c77c, 22:05Z)aNativeLaneRetiresAfterABuiltAheadEOSretires a native lane as a clean EOS with exactly one discarded forward. It's red without the schedule's EOS rule.CBv2StageKVHost.submittedDeviceFrontierReadscounts 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).QWEN_TP_BATCH_GPU=1 swift test --filter 'buildAheadDecodeTakesTheReadThenBuildTokensAndLogprobs|aNativeLaneRetiresAfterABuiltAheadEOS'.