Repository navigation
[trainer throughput] Give the MoE token permute a faster backward - #318
Merged
Micah Yong (micahtyong) merged 3 commits intoNov 17, 2026
Merged
Conversation
Megatron's unfused MoE permute gathers tokens with index_select, whose backward is a BF16 index_add_. A scatter_add_ backward computes the same gradient faster. The patch applies only when the pinned Megatron permute's source hash matches and nothing has wrapped it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # CHANGELOG.md
Micah Yong (micahtyong)
marked this pull request as ready for review
November 17, 2026 02:23
Micah Yong (micahtyong)
requested a review
from Kailash Ranganathan (kailash109)
as a code owner
November 17, 2026 02:23
# Conflicts: # src/spindle/backends/miles_runtime/actor.py
Micah Yong (micahtyong)
deleted the
micah/moe-permute-scatter-backward
branch
November 17, 2026 02:31
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.
Summary
In a mixture-of-experts layer, the trainer reorders tokens so each expert's tokens sit together. With permute fusion off, which LoRA on expert weights requires, Megatron does this with
index_select. Its backward pass is a BF16index_add_, which is slow: 2.5–3.1 ms per call on H200.This PR gives the permute a
scatter_add_backward, which computes the same gradient in about 0.6 ms. It applies on the default Miles images when the pinned Megatronpermutematches a known source hash and nothing else has wrapped it. Otherwise it leaves Megatron alone and logs that it skipped. Themiles-v0.2.0image is unaffected.E2E results
Setup: stock Tinker SDK, LoRA rank 32, 128 rows of about 1,600 tokens per step. Times are the trainer's
forward_backwardmedian. Per-token log probabilities are within run-to-run noise.On Nemotron the time in token reordering goes from 0.69 to 0.41 s per step. gpt-oss-20b on two H200s also gets faster: 9.35 → 8.61 s together with the logits change in #317 (before, after).