Repository navigation
[trainer throughput] Build the logits gradient once per micro-batch - #317
Merged
Micah Yong (micahtyong) merged 4 commits intoNov 17, 2026
Merged
Conversation
Miles slices each row's response logits out of the micro-batch's logits. Each slice's backward writes a full-size zero tensor plus the row's gradient, so a micro-batch of N rows writes N full logits gradients. One split per micro-batch gives the same values and gradient. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 17, 2026
# Conflicts: # CHANGELOG.md
Micah Yong (micahtyong)
marked this pull request as ready for review
November 17, 2026 02:22
Micah Yong (micahtyong)
requested a review
from Kailash Ranganathan (kailash109)
as a code owner
November 17, 2026 02:22
# Conflicts: # src/spindle/backends/miles_runtime/actor.py
# Conflicts: # CHANGELOG.md # src/spindle/backends/miles_runtime/actor.py
Micah Yong (micahtyong)
deleted the
micah/logits-split-per-micro-batch
branch
November 17, 2026 02:38
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
After the forward pass, the trainer scores each row's response tokens. Miles takes each row's response logits by slicing them out of the micro-batch's logits. In the backward pass, every slice writes a zero tensor the size of the whole micro-batch's logits, plus that row's gradient. A micro-batch of N rows therefore writes N full logits gradients. With a 248K-token vocabulary, each one is several GB.
This PR splits the micro-batch's logits once into the per-row pieces. The values and gradients are identical, and the backward pass writes the logits gradient once per micro-batch. It applies to every recipe on the default Miles images. A micro-batch with one row is unchanged.
E2E results
Setup: stock Tinker SDK, LoRA rank 32, 128 rows of about 1,600 tokens per step, one
forward_backwardand oneoptim_stepper step. Times are the trainer'sforward_backwardmedian. Per-token log probabilities are bit-identical on Qwen3.5-4B and within run-to-run noise on Nemotron.On Qwen3.5-4B,
forward_backwardused to climb from 6.0 s at step 1 to about 12 s by step 20. It now stays at 3.7 s.