Repository navigation
perf(trainer): zero-copy top-logprob decode, row-copy top logprobs; log load timing - #4192
Closed
mikasenghaas wants to merge 2 commits into
Closed
mikasenghaas wants to merge 2 commits into
mikasenghaas wants to merge 2 commits into
Conversation
…outing on GPU; log load timing Binary wire fields decode as memoryviews into the received frame instead of copies. Top logprobs whose rows are all-or-nothing copy rows instead of scattering elements. uint8 routed experts stay a view and widen to int32 after the host-to-device copy. Batch wait, decode/convert and time to the first micro batch log at info. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mikasenghaas
force-pushed
the
perf/trainer-batch-load
branch
from
October 27, 2026 16:27
d58f869 to
6dc0516
Compare
…rame A memoryview into the frame kept the whole frame (top logprobs, masks, streams) alive for the step through the routing tensor. Drop the duplicate raw-buffers comment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
Author
|
Closing: most of this PR's gain already landed on Re-measured against current
|
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
Logs the trainer's batch load at info and trims the top-logprob part of it. Output tensors are unchanged.
TopLogprobsandSamplingMaskbuffers decode asmemoryviews into the received frame instead ofbytescopies. Both are copied into their[tokens, width]grids during conversion, so no view outlivesget_batch.RoutedExperts.datastaysbytes: routing is kept as a tensor for the whole step, and a view would keep the entire frame alive with it.Measurements
One 262,144-token micro batch, decoded from its msgpack frame and converted single-threaded (
OMP_NUM_THREADS=1, as under torchrun). Median of 15, three repeats,main@ 14ef914 vs this branch on the same machine:mainMost of the earlier load-time gain landed on
mainwith #4226. What is left here is about 5-8% on router-replay batches, none measurable on score-centering batches, and the timing logs.Verification
_micro_batch_to_tensoroutput compared tensor by tensor againstmainon four frames (router replay with full-width and with ragged top-k rows; score-centering masks with full-width and with ragged rows): 10 tensors each, all equal in value, dtype and shape.tests/unit/transports,tests/unit/orchestratorandtests/unit/train/rl(CPU) pass.🤖 Generated with Claude Code
Note
Medium Risk
Touches RL batch decoding and top-logprob tensor assembly on the training hot path; behavior is intended to be identical but mistakes could skew replay or masks.
Overview
Speeds up trainer batch decode/convert (~2.7× on router-replay + top-k workloads) without changing output tensors, and surfaces load timing at info level.
Wire structs
SamplingMaskandTopLogprobsnow decode buffer fields asmemoryviews into the received ZMQ frame (zero-copy);RoutedExperts.datastaysbytesso routing tensors do not pin the whole frame.get_batchlogs micro-batch count, token count, and separate decode vs. convert durations;train.pypromotes batch-wait logging to info and logs time until the first micro batch hits the GPU (including cross-rank loss-scale sync).Top logprobs assembly adds a single-head fast path and, when every row is either full-width or empty, row-wise reshape into the
[tokens, width]grid instead of masked scatter; ragged rows keep the prior scatter behavior.Reviewed by Cursor Bugbot for commit 5bd0b77. Bugbot is set up for automated code reviews on this repo. Configure here.