Repository navigation
Gemma 4 TP: one shared expert dispatch per registered prompt chunk (prefill 1.87×, same bytes) - #387
Merged
Merged
Conversation
Under the registered prompt policy a tensor-parallel rank ran one SwitchGLU forward per token of the chunk (512 per layer per 512-token chunk), then one collective. It now computes every token's expert rows in one shared dispatch per projection (SwitchGLU.expertRowsByRow: gathers not told the rows are sorted, so each (token, expert) pair stays the native M=1 product its own call computes, as callAndWeightedReduceRows does for the unsharded model), packs them with the dense partial into the same single collective, and weights them as before. M5 Ultra pair over JACCL, 9,651-token prompt: 569 -> 1,066 tok/s, same tokens at 2.6K/5.2K/9.7K. TensorParallelSwitchLinear.forwards counts the projection's forwards (tests). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ne rows path - TensorParallelSwitchLinear.forwards (public, read on every expert down forward) is removed: d-inference's test observes the gate projection instead and also checks every gather's sorted hint (false). - tensorParallelCall's remaining loop serves only scoped batch decode rows: the byToken branches after the prompt chunk's early return are gone (count = B, row slices, axis 0); same ops for those rows. - callAndWeightedReduceRows is weightedExpertSum(expertRowsByRow(...)): the identical graph, one rows path for the unsharded and the TP prompt chunk. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308
added a commit
that referenced
this pull request
Nov 6, 2026
The changelog keeps both entries (the parts entry now states the measured best: 4 parts, +13 %). Two new lines over 100 columns are wrapped (a local Part typealias). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308
added a commit
that referenced
this pull request
Nov 6, 2026
The changelog keeps main's entries, then this branch's; fork.yaml merged without conflict. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What this does
Under the registered prompt policy, a Gemma 4 tensor-parallel rank ran one
SwitchGLUforward per token of each prompt chunk (Gemma4Experts.tensorParallelCall,byToken: 512 expert forwards per layer per 512-token chunk), then one collective. The unsharded model under the same policy makes one shared call (callAndWeightedReduceRows).The rank now computes every token's expert rows in one shared dispatch per projection (
SwitchGLU.expertRowsByRow): the gathers are not told the rows are sorted, so each (token, expert) pair stays the native M=1 product its own call computes. The rows go into the same single packed collective with the dense partial and are weighted as before. Every row's bytes are unchanged; only the dispatch count changes (S → 1 per layer).TensorParallelSwitchLinear.forwards(a task-local counter, nil by default) lets tests count the projection's forwards.Evidence
darkbloom-cluster-tp-check gemma run --mode tp --path paged, real QAT 4-bit weights, real text, chunk 512, warm): prefill 561 / 564 / 569 → 1,060 / 1,044 / 1,066 tok/s at 2,586 / 5,188 / 9,651 tokens. Tokens are identical (sametokenIDsSHA256) at all three lengths.--mode shard, 9,651 tokens): 12.59 s → 5.37 s.Gemma4TensorParallelTests.scopedSlicesPackIntoOneCollective): the TP expert output and dense sum equal the split-sum oracle bit for bit for a 6-token chunk and a 24-token chunk (96 routes, past the gather's sort threshold of 64). A new check requires one expert down-projection forward per prompt chunk: it fails without this change (6 and 24 forwards) and passes with it.Root-cause write-up (Gemma TP prefill ~10× slower than one Mac): the per-token expert loop, the registered M=1 prompt policy (4.4× on one Mac too), and the 9-row exchange (3.38 MB per token). This PR fixes the first.
Review fixes (
1068c346, 03:31Z)sortedIndices(must befalse) on CPU chunks of 2, 6, 16 (exactly 64 routes) and 24 tokens;hintsSorted: trueinexpertRowsByRow) now fails both, with 46 issues including the GPU bytes.tensorParallelCall's loop serves only batch decode rows (count = B, row slices, axis 0), with the same ops for those rows.callAndWeightedReduceRowsis nowweightedExpertSum(expertRowsByRow(...)), the identical graph.TensorParallelSwitchLinear.forwardswas read on every expert down forward; the test observes the gate instead.AI usage
Written with Claude (Co-Authored-By trailer on each commit). Reviewed by an independent review pass; every claim above was re-run.
Checklist