Repository navigation
perf: block-per-pair moe_scatter_dy (30.8 -> 3.7 ms, closes #45) - #49
Merged
Merged
Conversation
feitreim
added a commit
that referenced
this pull request
Jul 25, 2026
Phase 2 of the backward MoE scatter, following #45/#49. float4 row copy: `moe_scatter_dy` walked the `D` row one `f32` per lane per step. When `dim` is a multiple of four every row base `row * dim` is 16-byte aligned, so each lane now moves one `F32x4` (`ld/st.global.v4.f32`) instead; other `dim` keep the scalar walk. The `gate * dy` bin writes stay bit-identical -- only the fixed order the gate dot accumulates in changes, as it already did in #49. Dead-slot zeroing: capacity assignment hands expert `e` the slots `0..min(count[e], C)` and the scatter overwrites exactly those, so the `E*C*D` pre-fill (`backward.router.zero_dy_bins`) rewrote the whole buffer to no effect. `moe_zero_dead_bins` takes the routing `assignment_counts` and clears only the unassigned tail `min(count[e], C)..C`, one block per `(expert, slot)`, also float4 where `dim` allows. The two passes partition the buffer, so the separate `fill_zero` launch is gone. The ops parity harness now poisons the bin gradients rather than zeroing them, so a bin neither pass touches fails the compare, and adds a case pair over a routing with a dropped pair, a half-dead expert, and an entirely unassigned expert at a `D` on the float4 path and one off it.
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.
Closes #45.
What changed
moe_scatter_dygave each(token, slot)pair a single thread that seriallywalked the whole
D=3072gradient row: an uncoalescedgate·dybin copy fusedwith a serial gate dot
Σ_d expert_output·dy. Measured at ~1% of HBM and thetop of the backward-router profile.
Restructured to one block per pair (
grid = N·K,block = 256):Drow so the bin copy is fully coalesced;gate_gradient = 0and skip the row; all writes staydisjoint per surviving slot (semantics preserved exactly).
Launch sites updated in the model backward path and the
gpu/opsparity harness.zero_dy_binsfold-in left as a follow-up (see SPEC §13.9) to keep the diffconfined to the kernel.
Profile —
BASELINE_REF=main ./run.sh model profile(B200, same container, B=12 T=2048)backward.router.scatter_dybackward.router.zero_dy_binsParity
./run.sh ops:./run.sh model:Follow-ups
backward.router.zero_dy_binsinto a dead-slot zeroing pass using therouting
assignment_counts.