Fix qkv slice in dflash - #10
Draft
apinge wants to merge 2 commits into
Draft
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves DFlash’s “KV-only projection” fast path by correctly handling (and explicitly validating) different fused-QKV weight layouts, including the ROCm/AITER-transposed weight case.
Changes:
- Tightens eligibility checks for slicing KV weights from a fused QKV linear layer (adds shape/layout validation and rejects AITER-transposed weights for the row-slice path).
- Adds a dedicated eligibility check for AITER-transposed QKV weights (column-slice path).
- Adds a new KV-only projection fast path in
DFlashAttention.kv_proj_only()that slices AITER-transposed weights and runs the ROCm AITER GEMM.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| python/sglang/srt/speculative/dflash_utils.py | Adds stricter sliceability validation and introduces a new validator for AITER-transposed QKV weights. |
| python/sglang/srt/models/dflash.py | Adds an AITER-transposed fast path for KV-only projection using ROCm AITER GEMM. |
Suppressed comments (1)
python/sglang/srt/speculative/dflash_utils.py:576
- Same issue as above:
getattr(qkv_proj, "input_size")/getattr(qkv_proj, "output_size_per_partition")are used without defaults, which can raise and break DFlash initialization for models that don't expose these exact attributes. This should return(False, reason)rather than throwing so the code can safely fall back.
expected_shape = (
int(getattr(qkv_proj, "input_size")),
int(getattr(qkv_proj, "output_size_per_partition")),
)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+542
to
+545
| expected_shape = ( | ||
| int(getattr(qkv_proj, "output_size_per_partition")), | ||
| int(getattr(qkv_proj, "input_size")), | ||
| ) |
Comment on lines
+226
to
+237
| can_slice_aiter_qkv_weight, _ = ( | ||
| can_dflash_slice_aiter_trans_qkv_weight(self.qkv_proj) | ||
| ) | ||
| if can_slice_aiter_qkv_weight: | ||
| kv_slice = slice(self.q_size, self.q_size + 2 * self.kv_size) | ||
| weight = self.qkv_proj.weight[:, kv_slice] | ||
| bias = ( | ||
| self.qkv_proj.bias[kv_slice] if self.qkv_proj.bias is not None else None | ||
| ) | ||
| kv = rocm_aiter_swizzle_hipb_unquantized_gemm(hidden_states, weight, bias) | ||
| k, v = kv.split([self.kv_size, self.kv_size], dim=-1) | ||
| return k, v |
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.
Motivation
Modifications
Accuracy Tests
397B
35B
Speed Tests and Profiling
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ci