Skip to content

Domino/Dflash: avoid blocking syncs#715

Open
zou3519 wants to merge 1 commit into
sgl-project:mainfrom
zou3519:rzou/domino-avoid-scalar-syncs
Open

Domino/Dflash: avoid blocking syncs#715
zou3519 wants to merge 1 commit into
sgl-project:mainfrom
zou3519:rzou/domino-avoid-scalar-syncs

Conversation

@zou3519

@zou3519 zou3519 commented Jul 21, 2026

Copy link
Copy Markdown

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).

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).
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@zou3519
zou3519 marked this pull request as ready for review July 21, 2026 20:21
@zou3519
zou3519 requested a review from FrankLeeeee as a code owner July 21, 2026 20:21
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@zou3519

zou3519 commented Jul 21, 2026

Copy link
Copy Markdown
Author

cc @maocheng23

bs = self.block_size
bsz = loss_mask.shape[0]
max_anchor = max(seq_len - bs, 0)
max_n = max(1, self.num_anchors)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this probably needs careful reading


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))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant