Repository navigation
Opt concat cache mla - #1239
Merged
Merged
Opt concat cache mla#1239
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR optimizes the concat_and_cache_mla kernel for Multi-head Latent Attention (MLA) by implementing a vectorized memory loading approach using buffer_load_dwordx4. The optimization shows significant performance improvements, particularly for larger token counts (up to ~4x speedup for 16K tokens).
Key Changes:
- Introduced optimized kernel variant
concat_and_cache_mla_opt_kernelwith double-buffered vectorized loads - Added conditional dispatch logic to select between original and optimized kernels based on alignment
- Cleaned up commented-out code and test parameter constraints
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| csrc/kernels/cache_kernels.cu | Added optimized MLA cache kernel with vectorized memory operations and updated dispatch logic to use it when dimensions are 8-byte aligned |
| op_tests/test_concat_cache_mla.py | Removed restrictive parameter constraints on dtype argument to allow more flexible test configurations |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
valarLip
approved these changes
Oct 23, 2025
valarLip
pushed a commit
that referenced
this pull request
Mar 18, 2026
* opt concat_and_cache_mla * opt concat_and_cache_mla * fix rebase conflicts * opt to use buffer_load_dwordx4 * add bandwidth(TB/s) in test result * fix lint error
zufayu
added a commit
that referenced
this pull request
Oct 12, 2026
The Windows ROCm torch wheels are built without Kineto. torch.profiler still
runs there, but records no device events, so get_trace_perf finds an empty
device frame and returns 0. Every op test that reports a duration prints
0.00 us, and the ones that divide to show an uplift print nan -- visible in
the Windows CI run of test_rmsnorm2d.py as
[perf] torch avg: 0.00 us, ck avg: 0.00 us, uplift: nan%
test_rmsnorm2d.py:93: RuntimeWarning: invalid value encountered in scalar divide
122 of the 166 files under op_tests/ go through perftest or run_perftest, so
this is most of the suite. The same gap was hit independently in ROCm/FlyDSL
PR #1239, whose author reports the pytest performance wrapper not completing
"because Torch Kineto's DataFrame field is unavailable".
perftest already has a use_cuda_event path that times with torch.cuda.Event
and never touches the profiler; five call sites pass it explicitly. Probe for
Kineto once and take that path automatically when it is missing, rather than
handing the caller a 0. Builds that ship Kineto -- every Linux ROCm wheel --
resolve to the profiler path exactly as before.
The Windows smoke suite added in #6273 measures no performance, so nothing
depends on this today. It matters as soon as any existing op test is pointed
at Windows, which is the next phase rather than this one.
Verified on MI308X, ROCm 7.2.4, torch 2.10.0, a 4096x4096 fp16 mm:
profiler path 785.4 us (unchanged)
cuda.Event path 799.9 us
forced fallback 798.1 us
The two timing methods agree to within 2%, so the fallback is not just
nonzero but comparable.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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
Technical Details
use buffer_load_dwordx4
Test Plan
test_concat_and_cache_mla.py
[aiter] summary:
<style> </style>Submission Checklist