Revert "[WIP][Megatron-LM] feat: reduce extra qkv transpose in attn"#641
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Reverts prior work in Megatron-LM Primus-Turbo attention intended to reduce extra QKV transposes, restoring earlier QKV layout handling and output layout conversion behavior.
Changes:
- Updates
PrimusTurboAttention.forward()QKV layout validation and conditional transpose behavior based onqkv_format. - Adjusts attention output reshaping/transposition back to expected
(S, B, ...)layout.
| ), f"qkv_format only support {SUPPORTED_QKV_FORMATS}, but got {qkv_format}" | ||
| # NOTE(ruibin): The layout of q, k and v is (S, B, H, D). But attn accept the shape of qkv is (B, S, H, D). | ||
| query, key, value = [x.permute(1, 0, 2, 3) for x in (query, key, value)] | ||
| assert qkv_format in ("sbhd", "bhsd"), "qkv_format only support bshd, but got {qkv_format}" |
There was a problem hiding this comment.
The qkv_format validation looks inconsistent: it allows ("sbhd", "bhsd") but the error text says "bshd", and {qkv_format} won’t be interpolated because this isn’t an f-string. If the intended formats are SBHD and BSHD (matching the comment removed in this revert), update the allowed tuple and make the message an f-string (or use ValueError) so the reported format is correct.
Suggested change
| assert qkv_format in ("sbhd", "bhsd"), "qkv_format only support bshd, but got {qkv_format}" | |
| assert qkv_format in ("sbhd", "bshd"), f"qkv_format only supports 'sbhd' and 'bshd', but got {qkv_format}" |
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.
Reverts #625