Repository navigation
Gemma TP: build sampled steps one ahead too (stacked on #1822) - #1824
Merged
Merged
Conversation
Rank 0's draw is the product's CBv2DefaultSampler, which advances its penalty counts with each drawn token on the device and its keyed step index with each draw; QwenStageTokenSampler.selected only configures it at the first draw. A draw built before the previous token is read is therefore the draw at its output index with the history up to it. Each step keeps its own lazy logprob gather (takePendingStepLogprobs), read after its token is agreed. Greedy requests asking for logprobs still read each step first (their top-k gather is a host-evaluated collective). Tests: pipelines() covers sampled requests (red on #1822: 2 failures); SamplingSelectionTests draws one step ahead and matches step-by-step tokens and logprobs (CPU); a GPU suite compares sampled build-ahead with read-then-build on two ranks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…in the loop's step decode and submitDecode built the same forward (stride, decode frame, last row) twice; it is now decodeRow, so the built-ahead step is the read-then-build step's graph by construction. The request loop's step closure builds its select once for both orders. No behaviour change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The docs paragraph keeps #1822's late-stop exception and this PR's sampled part (now naming greedy requests with logit bias or penalties). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review of #1824 (nits 3 and 5): the changelog names greedy requests with logit bias or penalties (they draw through the sampler and are built ahead) and the one late-stop stream edge; the buildsAhead TaskLocal is marked tests-only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308
changed the base branch from
perf/tp-gemma-pipelined-steps
to
dev
November 5, 2026 22:27
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
Brings in the Gemma TP build-ahead steps (#1822, #1824) and the bench layer stride (#1827). Conflict in tp-check's `gemma run` resolved by keeping both: `--mtp-depth`/`--assistant-dir` beside `--layer-stride`, both bound into the ranks' workload digest. Speculative rounds keep their own loop (runRounds), which reads each round's agreement before it builds the next round; the plain loop's build-ahead is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 5, 2026
Open
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 #1822 (base
perf/tp-gemma-pipelined-steps). Retarget todevonce #1822 merges. I stacked it rather than folding it in so #1822's review stays as it is; the diff here is only the sampled part.What
Gemma tensor parallel now builds sampled steps one ahead as well (#1822 did greedy only). Most real traffic is sampled.
Keyed draws are unchanged: the same token for the same key and position. Rank 0's draw is
QwenStageTokenSampler.sample, i.e. the product'sCBv2DefaultSampler:LogitsPipelineV2.commit(sampledTokens:)inside the draw);SamplerV2.commit());selected) only configures it at the first draw, and thestepIndexargument is telemetry only.So step k+1's draw, built before step k's token is read, makes exactly the calls in exactly the order the read-then-build loop makes. This is the same property the product's chained single-Mac decode relies on (
pendingSampledTokens).Logprobs (sampled): they come from rank 0's own draw, as graph nodes with no collective. Each step now carries its own gather:
takePendingStepLogprobs()right after the step is built, read withtokenLogprobsonce its token is agreed. Before, a single slot would have been overwritten by the step built ahead.Greedy requests that ask for logprobs keep reading each step first. Their logprobs come from a vocabulary-split top-k gather, which is a collective evaluated on the host after the token is agreed. Built ahead, it would queue behind the next step and gain nothing. Building that gather lazily into the step's own graph is a possible follow-up.
Tests
Gemma4TensorParallelRuntimeTests.greedyRequestsBuildTheirStepsAheadnow expects sampled requests, with and without logprobs, to build ahead, and greedy-with-logprobs not to. With Gemma TP: build greedy steps one ahead (GLM's step order) #1822's rule it records 2 issues (pipelines(temperature: 1, …)); with this change it passes. Run locally (CPU,swift test).SamplingSelectionTests.drawingOneStepAheadTakesTheStepByStepTokensAndLogprobs. It uses temperature 0.9, top-p 0.95, repetition/frequency/presence penalties, logit bias and 3 logprobs. Drawing each step before reading the previous one gives the same 12 tokens, logprobs, top IDs and history as draw-read-commit. Run locally on the CPU device: passes.Gemma4TensorParallelRuntimeTests.sampledStepsBuiltAheadTakeTheReadThenBuildTokens. On the synthetic checkpoint over two in-process ranks, sampled build-ahead and read-then-build give equal tokens, finish, published tokens and logprobs, both plainly and with an early owner stop. It usesGemma4TensorParallelRequestLoop.buildsAhead, a test-only@TaskLocal. Queued for the next GPU slot, along with Gemma TP: build greedy steps one ahead (GLM's step order) #1822's suites.Docs:
docs/architecture/inference.md(Gemma 4 tensor parallel). Changelog:changelog.d/gemma-tensor-parallel-builds-sampled-steps-ahead.md.Gain: not measured; the Gemma pair needs a hardware slot. The upper bound is the host share of a step. On GLM, building ahead took the step from 13.4 to 12.0 ms.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.Hardware results (M5 Ultra, 2026-11-05 19:55Z, Mac A load 5.7–6.1)
PASS 4/4 at
e9e60ed102:sampledStepsBuiltAheadTakeTheReadThenBuildTokens(tokens, finish, published, logprobs, owner stop equal to read-then-build),theRequestLoopEndsBothRanksAfterTheSameStep,greedyRequestsBuildTheirStepsAhead,theRequestLoopContinuesARestoredPrefixWithTheColdTokens.