Conversation
Flat (no-load-balance) sharding gives CP rank r the contiguous global token range [r * s_local, (r + 1) * s_local). For cp_comm_type='a2a' the exchange already restores the full sequence on every rank before attention, so the dual-chunk reordering is a no-op that costs a full extra copy of q, k and v. a2a never divides cu_seqlens or max_seqlen: after the exchange each rank holds the whole sequence and only its own head slice, so the sequence metadata, the mask and the attention math are identical to cp_size = 1. Every attn_mask_type and window_size therefore stays valid, and THD needs no new per-step metadata. Skipping the reorder also removes its view(cp_size * 2, ...), which is the only reason the local sequence length had to be even. The per-sequence divisibility requirement drops from 2 * cp_size to cp_size; for THD no individual sequence needs padding at all, only the packed total. Measured on 8xH200 for one before_attn exchange of q+k+v (bshd, cp=8, h=40, d=128), max over ranks: -12.0% at s=8192, -29.5% at s=32768 and -31.7% at s=75600. The gain grows with payload because the removed index_select is bandwidth bound. Scope matches the existing all_gather strategy: FP8 and CUDA graph capture stay rejected, and a2a+p2p is not covered. The p2p path is unchanged. Tests add flat a2a coverage over bshd, sbhd and THD, including a config whose sequence length is divisible by cp_size but not by 2 * cp_size, and a causal config. All 9 pass; dual-chunk a2a on the same configs and the existing all_gather no-load-balance tests still pass. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Rudin6 <41809200+Rudin6@users.noreply.github.com>
Contributor
|
Comment on lines
+516
to
+529
| if no_load_balance: | ||
| # Flat shard: rank r owns the contiguous global range | ||
| # [r * s_local, (r + 1) * s_local). No chunk swap, so no 2 * cp factor. | ||
| # clone(), not contiguous(): for sbhd the narrowed slice is already | ||
| # contiguous, so contiguous() is a no-op and leaves a nonzero | ||
| # storage_offset, which get_qkv_layout rejects. | ||
| q_, k_, v_, dout_ = [ | ||
| x.narrow( | ||
| seq_dim, | ||
| rank * (x.shape[seq_dim] // world_size), | ||
| x.shape[seq_dim] // world_size, | ||
| ).clone() | ||
| for x in [q_, k_, v_, dout_] | ||
| ] |
Contributor
There was a problem hiding this comment.
This flat bshd/sbhd branch does not initialize seq_idx, but the later attention-bias setup still reads it and assumes a 2 * world_size dual-chunk layout. As a result, any flat-a2a test configured with attention bias will fail with an unbound-variable error instead of validating the feature. The new configurations all use no_bias, so they do not cover this path.
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.
Flat (no-load-balance) sharding gives CP rank r the contiguous global token range [r * s_local, (r + 1) * s_local). For cp_comm_type='a2a' the exchange already restores the full sequence on every rank before attention, so the dual-chunk reordering is a no-op that costs a full extra copy of q, k and v.
a2a never divides cu_seqlens or max_seqlen: after the exchange each rank holds the whole sequence and only its own head slice, so the sequence metadata, the mask and the attention math are identical to cp_size = 1. Every attn_mask_type and window_size therefore stays valid, and THD needs no new per-step metadata.
Skipping the reorder also removes its view(cp_size * 2, ...), which is the only reason the local sequence length had to be even. The per-sequence divisibility requirement drops from 2 * cp_size to cp_size; for THD no individual sequence needs padding at all, only the packed total.
Measured on 8xH200 for one before_attn exchange of q+k+v (bshd, cp=8, h=40, d=128), max over ranks: -12.0% at s=8192, -29.5% at s=32768 and -31.7% at s=75600. The gain grows with payload because the removed index_select is bandwidth bound.
Scope matches the existing all_gather strategy: FP8 and CUDA graph capture stay rejected, and a2a+p2p is not covered. The p2p path is unchanged.
Tests add flat a2a coverage over bshd, sbhd and THD, including a config whose sequence length is divisible by cp_size but not by 2 * cp_size, and a causal config. All 9 pass; dual-chunk a2a on the same configs and the existing all_gather no-load-balance tests still pass.
Description
Please include a brief summary of the changes, relevant motivation and context.
Fixes # (issue)
Type of change
Changes
Please list the changes introduced in this PR:
Checklist: