[GG] fix MLA query BMM cuBLAS read-ahead without query copies - #173
Conversation
|
Warning Review limit reached
Next review available in: 56 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughAdds a CUDA BF16 ChangesSafe MLA Query BMM
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant B12xMLASparseImpl
participant MLAAttention
participant _run_mla_query_bmm
participant safe_mla_query_bmm
participant cuBLAS
B12xMLASparseImpl->>MLAAttention: provide safe BMM capability
MLAAttention->>_run_mla_query_bmm: pass MQA query projection tensors
_run_mla_query_bmm->>safe_mla_query_bmm: dispatch CUDA BF16 operation
safe_mla_query_bmm->>cuBLAS: execute strided batched GEMM
cuBLAS-->>safe_mla_query_bmm: write output tensor
safe_mla_query_bmm-->>MLAAttention: return populated output
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
CMakeLists.txt (1)
384-416: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winAdd the BLAS dependency for the stable MLA BMM helper.
csrc/libtorch_stable/attention/mla/safe_query_bmm.cuis unconditionally added to_C_stable_libtorch, but it usescublasGemmStridedBatchedExand the current cuBLAS discovery/linking only runs whenVLLM_GPU_LANG == "CUDA". This needs a matching BLAS link for ROCm builds that cover the HIP-generated symbols, otherwise the stable extension will fail to resolve libblas/hipblas/rocblas during link time.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@CMakeLists.txt` around lines 384 - 416, Update the _C_stable_libtorch build configuration to discover and link the appropriate BLAS dependency for HIP builds as well as CUDA builds, covering the cuBLAS/hipBLAS/rocBLAS symbols used by safe_query_bmm.cu. Ensure the stable extension target links that dependency whenever VLLM_GPU_LANG is CUDA or HIP, without changing the source list.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/v1/attention/test_mla_backends.py`:
- Around line 865-877: The sparse profile test double used by
MLAAttention.forward_impl must define use_safe_mla_query_bmm before execution.
Update the manual MLAAttention setup around ProfileSparseImpl to initialize this
attribute consistently with the existing sparse unit-path test double.
---
Outside diff comments:
In `@CMakeLists.txt`:
- Around line 384-416: Update the _C_stable_libtorch build configuration to
discover and link the appropriate BLAS dependency for HIP builds as well as CUDA
builds, covering the cuBLAS/hipBLAS/rocBLAS symbols used by safe_query_bmm.cu.
Ensure the stable extension target links that dependency whenever VLLM_GPU_LANG
is CUDA or HIP, without changing the source list.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: a9163e0e-a5f7-48c3-91cd-f0d4fdbfecfc
📒 Files selected for processing (8)
CMakeLists.txtcsrc/libtorch_stable/attention/mla/safe_query_bmm.cucsrc/libtorch_stable/ops.hcsrc/libtorch_stable/torch_bindings.cpptests/kernels/test_safe_mla_query_bmm.pytests/v1/attention/test_mla_backends.pyvllm/model_executor/layers/attention/mla_attention.pyvllm/v1/attention/backends/mla/b12x_mla_sparse.py
|
Review follow-up pushed in
Validation: both affected CPU tests pass in the CUDA test image; Ruff and |
|
Added |
Summary
torch.ops._C.safe_mla_query_bmm, for the MLA query absorption BMM shape used by B12X sparse MLA decode..contiguous().torch.bmm.Root Cause
The B12X sparse MLA query absorption path feeds a head-major, non-contiguous BF16 query view into
torch.bmmwith shape[heads, tokens, q_dim] x [heads, q_dim, latent] -> [heads, tokens, latent]. Tight custom/DCP allocations can expose cuBLAS BF16 kernels reading past the logical tensor tail for alignment. The broad.contiguous()workaround made the input safe but added a per-layer copy on the hot decode path.This PR keeps the same math but calls cuBLAS directly with the row-major mapping for this exact layout, using
CUBLAS_COMPUTE_32F_PEDANTICandCUBLAS_GEMM_DEFAULT. It does not mutate the global cuBLAS math mode and does not add tail padding or reduce KV cache.Validation
ruff format tests/kernels/test_safe_mla_query_bmm.py tests/v1/attention/test_mla_backends.py vllm/model_executor/layers/attention/mla_attention.py vllm/v1/attention/backends/mla/b12x_mla_sparse.pyruff check tests/kernels/test_safe_mla_query_bmm.py tests/v1/attention/test_mla_backends.py vllm/model_executor/layers/attention/mla_attention.py vllm/v1/attention/backends/mla/b12x_mla_sparse.pygit diff --check lil/dev/gilded-gnosis...HEADvoipmonitor/vllm:gilded-gnosis-v20-safeqbmm-vllm9fdb155-si055f839-fi801d57a-cu132-20260723safe_mla_query_bmmmatchestorch.bmm(query.contiguous(), weight)for(heads,tokens) = (8,1), (8,2), (8,6), (8,11), (11,6), (16,6)and replays under CUDA graph capture.MAX_NUM_SEQS=1,GRAPH=6: aggregate decode87.46and87.41tok/s, KV budget570,688tokens.Host pytest note: targeted CPU pytest in this checkout is blocked by missing
fastapiin the host environment duringtests/conftest.pyimport, before these tests run.Summary by CodeRabbit
New Features
Bug Fixes
Tests