Skip to content

Fix reduce-scatter bandwidth in the comms logger - #8695

Open
Arthur031221 wants to merge 1 commit into
deepspeedai:masterfrom
Arthur031221:fix-comms-logger-reduce-scatter-bw
Open

Arthur031221 wants to merge 1 commit into
deepspeedai:masterfrom
Arthur031221:fix-comms-logger-reduce-scatter-bw

Conversation

@Arthur031221

Copy link
Copy Markdown

calc_bw_log puts reduce_scatter and reduce_scatter_tensor in the same branch as the all-gather ops, which multiplies the logged message size by the world size before computing algbw and busbw. That is right for all-gather, but not for reduce-scatter, because timed_op logs a different tensor for each:

  • all_gather_into_tensor(output_tensor, tensor) and all_gather(tensor_list, tensor) log tensor, the per-rank input, so scaling by n gives the size of the whole array.
  • reduce_scatter_tensor(output_tensor, tensor) logs tensor, the full input, and reduce_scatter(output, input_list) logs the sum of input_list. That size already covers every rank, and scaling it by n again reports both bandwidths n times too high.

With the default reduce_scatter: true, ZeRO-3 reduces gradients through reduce_scatter_coalesced, except for the tensors that the quantized all-to-all path (multi-node only) handles itself. That function passes the full flattened gradient buffer to reduce_scatter_fn, which calls reduce_scatter_tensor (or reduce_scatter where that is unavailable). When the comms logger profiles those calls, the reduce-scatter algbw and busbw it reports in log_summary are world size times too high.

The nccl-tests performance notes that the function cites use S, the size of the whole array, for both ops, with busbw = algbw * (n-1)/n.

With a world size of 4, a 1 ms duration, 1024-byte shards and a 4096-byte full array, feeding each op's logged size through calc_bw_log gives:

                         logged size   algbw (Gbps)   busbw (Gbps)
all_gather_into_tensor   1024          0.032768       0.024576
reduce_scatter_tensor    4096          0.131072       0.098304    (master)
reduce_scatter_tensor    4096          0.032768       0.024576    (this PR)

The list forms all_gather and reduce_scatter give the same numbers as their tensor forms. The nccl-tests formulas for S = 4096 bytes in 1 ms give 0.032768 and 0.024576.

The fix moves the two reduce-scatter ops into their own branch without the size *= n. The new test in tests/unit/comm/test_comms_logger.py calls all four ops through timed_op with a mocked backend at world size 4 and checks the recorded algbw and busbw against the nccl-tests formulas. On master the two reduce-scatter cases fail with 4x the expected value, and all 56 tests in the file pass with the fix. pre-commit run passes on both changed files.

calc_bw_log multiplied the message size by the world size for
reduce_scatter and reduce_scatter_tensor, the same as for the all-gather
ops. That scaling is right for all-gather, whose logged size is the
per-rank input, but the logged size of a reduce-scatter is its input,
which already spans every rank. Both algbw and busbw for reduce-scatter
were therefore reported world_size times too high.

Keep the scaling for the all-gather ops only, so both follow the
nccl-tests definition, where S is the size of the whole array.

Signed-off-by: Arthur031221 <[email protected]>
@auto-pr-labeler-with-jev auto-pr-labeler-with-jev Bot added the skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU. label Nov 14, 2026

This branch has not been deployed

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

Labels

skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant