Domino/Dflash: avoid blocking syncs#715
Open
zou3519 wants to merge 1 commit into
Open
Conversation
Converting CUDA Tensors to scalars is generally bad for training so we avoid it. If there are no Tensor-to-scalar conversions on the majority of steps (forward+backward+optimizer), we are able to hide some CPU dataloading latency. There were three main sources of Tensor to scalar conversion or scalar host-to-device syncs that we removed: 1. We used to acquire scalar metrics after each step, even if our log interval was greater than one step. This PR changes it so that we acquire Tensor metrics (that are detached), and only convert them to scalar when needed for the log interval. 2. We used to create an `anchor_positions` tensor with shape `valid_counts.max().item()`. This tensor was padded and masked (with `block_keep_mask`). This PR changes it so the shape is padded to `self.num_anchors`. This may waste more performance but does help us get rid of the `.item()`. 3. We used to create CUDA scalar tensors from Python scalars in the Domino hot path. These tiny host-to-device copies can still introduce stream syncs, so sentinel values now use scalar literals and the `lambda_base` metric is filled on device. We tested this on GB300 with 3 trainers and 1 rollout. At that setup, the net throughput was roughly equal to before. We will actually see perf gains once all of the blocking syncs are removed (I think the last one after this PR is figuring out the ack situation -- the acks happen per-step and are blocking).
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
zou3519
marked this pull request as ready for review
July 21, 2026 20:21
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Author
|
cc @maocheng23 |
zou3519
commented
Jul 21, 2026
| bs = self.block_size | ||
| bsz = loss_mask.shape[0] | ||
| max_anchor = max(seq_len - bs, 0) | ||
| max_n = max(1, self.num_anchors) |
Author
There was a problem hiding this comment.
this probably needs careful reading
zou3519
commented
Jul 21, 2026
|
|
||
| valid = loss_mask[:, : max_anchor + 1] > 0.5 | ||
| valid_counts = valid.sum(dim=1) | ||
| max_n = max(1, min(self.num_anchors, int(valid_counts.max().item()) - 1)) |
Author
There was a problem hiding this comment.
Btw, is the int(valid_counts.max().item()) - 1) intentional? (the -1) thing. It looks like when there are fewer than num_anchor anchors, we just drop one of the anchors.
I tried to replicate this behavior in the diff.
Author
There was a problem hiding this comment.
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.
Converting CUDA Tensors to scalars is generally bad for training so we avoid it. If there are no Tensor-to-scalar conversions on the majority of steps (forward+backward+optimizer), we are able to hide some CPU dataloading latency.
There were three main sources of Tensor to scalar conversion or scalar host-to-device syncs that we removed:
anchor_positionstensor with shapevalid_counts.max().item(). This tensor was padded and masked (withblock_keep_mask). This PR changes it so the shape is padded toself.num_anchors. This may waste more performance but does help us get rid of the.item().lambda_basemetric is filled on device.We tested this on GB300 with 3 trainers and 1 rollout. At that setup, the net throughput was roughly equal to before. We will actually see perf gains once all of the blocking syncs are removed (I think the last one after this PR is figuring out the ack situation -- the acks happen per-step and are blocking).