Skip to content

add mla for head_num=128 (tp1), with mtp support - #322

Merged
valarLip merged 10 commits into
mainfrom
mla_rui
Apr 20, 2025
Merged

valarLip merged 10 commits into
mainfrom
mla_rui

Conversation

@valarLip

Copy link
Copy Markdown
Collaborator

No description provided.

@carlushuang carlushuang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@valarLip
valarLip merged commit 939f741 into main Apr 20, 2025
@valarLip
valarLip deleted the mla_rui branch April 20, 2025 14:55
valarLip added a commit that referenced this pull request Mar 18, 2026
* mdf_1

* update, mtp pass

* update test

* update

* update kvsplit logic

* force override signature

* update

* update

* update

---------

Co-authored-by: ruitang3 <[email protected]>
peizhang56 added a commit to peizhang56/aiter that referenced this pull request Sep 2, 2026
get_meta_param() was wholly @functools.lru_cache'd, so it returned a cached
device tensor for num_kv_splits_indptr. A CUDA graph capturing a cache hit
records only a pointer and no producing kernel, so once the LRU drops that
entry (it was the tensor's only owner) the storage is recycled and replay
reads garbage. Eviction is routine: total_kv is in the key and changes almost
every decode step, while captured entries are never looked up again.

This restores the cache to its original scope rather than removing an
optimization. ROCm#322 added the decorator when the function returned two plain
integers; ROCm#1233 added the torch.arange at the call site, outside the cache;
ROCm#1390 folded it in and tightened the decorator to maxsize=1; ROCm#1445 widened
that back to 128.

Split the function. The split-count heuristic is pure and stays cached as
_get_num_kv_splits(); get_meta_param() is now uncached and rebuilds the indptr
with torch.arange, which is a fill kernel and so is recorded into the graph and
re-runs on replay. This also drops a latent multi-device bug: the cached tensor
was allocated on the then-current device with no device in the key.

Costs nothing on the decode path, where the old cache took 0 hits in 2000
steps and was already rebuilding the arange every step (6.65 -> 6.69 us/call).
It only paid on a repeating key, which is the graph-capture case, where the
arange is recorded once and is free at replay.

Adds op_tests/test_mla_split_indptr_cudagraph.py, which fails on the old code
at bs=480 and passes with the fix.

Co-Authored-By: Claude Opus 5 <[email protected]>
peizhang56 added a commit to peizhang56/aiter that referenced this pull request Sep 2, 2026
get_meta_param() was wholly @functools.lru_cache'd, so it returned a cached
device tensor for num_kv_splits_indptr. A CUDA graph capturing a cache hit
records only a pointer and no producing kernel, so once the LRU drops that
entry (it was the tensor's only owner) the storage is recycled and replay
reads garbage. Eviction is routine: total_kv is in the key and changes almost
every decode step, while captured entries are never looked up again.

This restores the cache to its original scope rather than removing an
optimization. ROCm#322 added the decorator when the function returned two plain
integers; ROCm#1233 added the torch.arange at the call site, outside the cache;
ROCm#1390 folded it in and tightened the decorator to maxsize=1; ROCm#1445 widened
that back to 128.

Split the function. The split-count heuristic is pure and stays cached as
_get_num_kv_splits(); get_meta_param() is now uncached and rebuilds the indptr
with torch.arange, which is a fill kernel and so is recorded into the graph and
re-runs on replay. This also drops a latent multi-device bug: the cached tensor
was allocated on the then-current device with no device in the key.

Costs nothing on the decode path, where the old cache took 0 hits in 2000
steps and was already rebuilding the arange every step (6.65 -> 6.69 us/call).
It only paid on a repeating key, which is the graph-capture case, where the
arange is recorded once and is free at replay.

Adds op_tests/test_mla_split_indptr_cudagraph.py, runnable both as a plain
script (as .github/scripts/aiter_test.sh invokes it) and under pytest. Fails
on the old code at bs=480, passes with the fix.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: pei.zhang <[email protected]>
peizhang56 added a commit to peizhang56/aiter that referenced this pull request Oct 1, 2026
get_meta_param() was wholly @functools.lru_cache'd, so it returned a cached
device tensor for num_kv_splits_indptr. A CUDA graph capturing a cache hit
records only a pointer and no producing kernel, so once the LRU drops that
entry (it was the tensor's only owner) the storage is recycled and replay
reads garbage. Eviction is routine: total_kv is in the key and changes almost
every decode step, while captured entries are never looked up again.

This restores the cache to its original scope rather than removing an
optimization. ROCm#322 added the decorator when the function returned two plain
integers; ROCm#1233 added the torch.arange at the call site, outside the cache;
ROCm#1390 folded it in and tightened the decorator to maxsize=1; ROCm#1445 widened
that back to 128.

Split the function. The split-count heuristic is pure and stays cached as
_get_num_kv_splits(); get_meta_param() is now uncached and rebuilds the indptr
with torch.arange, which is a fill kernel and so is recorded into the graph and
re-runs on replay. This also drops a latent multi-device bug: the cached tensor
was allocated on the then-current device with no device in the key.

Costs nothing on the decode path, where the old cache took 0 hits in 2000
steps and was already rebuilding the arange every step (6.65 -> 6.69 us/call).
It only paid on a repeating key, which is the graph-capture case, where the
arange is recorded once and is free at replay.

Adds op_tests/test_mla_split_indptr_cudagraph.py, runnable both as a plain
script (as .github/scripts/aiter_test.sh invokes it) and under pytest. Fails
on the old code at bs=480, passes with the fix.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: pei.zhang <[email protected]>
peizhang56 added a commit to peizhang56/aiter that referenced this pull request Oct 2, 2026
get_meta_param() was wholly @functools.lru_cache'd, so it returned a cached
device tensor for num_kv_splits_indptr. A CUDA graph capturing a cache hit
records only a pointer and no producing kernel, so once the LRU drops that
entry (it was the tensor's only owner) the storage is recycled and replay
reads garbage. Eviction is routine: total_kv is in the key and changes almost
every decode step, while captured entries are never looked up again.

This restores the cache to its original scope rather than removing an
optimization. ROCm#322 added the decorator when the function returned two plain
integers; ROCm#1233 added the torch.arange at the call site, outside the cache;
ROCm#1390 folded it in and tightened the decorator to maxsize=1; ROCm#1445 widened
that back to 128.

Split the function. The split-count heuristic is pure and stays cached as
_get_num_kv_splits(); get_meta_param() is now uncached and rebuilds the indptr
with torch.arange, which is a fill kernel and so is recorded into the graph and
re-runs on replay. This also drops a latent multi-device bug: the cached tensor
was allocated on the then-current device with no device in the key.

Costs nothing on the decode path, where the old cache took 0 hits in 2000
steps and was already rebuilding the arange every step (6.65 -> 6.69 us/call).
It only paid on a repeating key, which is the graph-capture case, where the
arange is recorded once and is free at replay.

Adds op_tests/test_mla_split_indptr_cudagraph.py, runnable both as a plain
script (as .github/scripts/aiter_test.sh invokes it) and under pytest. Fails
on the old code at bs=480, passes with the fix.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: pei.zhang <[email protected]>
peizhang56 added a commit to peizhang56/aiter that referenced this pull request Oct 2, 2026
get_meta_param() was wholly @functools.lru_cache'd, so it returned a cached
device tensor for num_kv_splits_indptr. A CUDA graph capturing a cache hit
records only a pointer and no producing kernel, so once the LRU drops that
entry (it was the tensor's only owner) the storage is recycled and replay
reads garbage. Eviction is routine: total_kv is in the key and changes almost
every decode step, while captured entries are never looked up again.

This restores the cache to its original scope rather than removing an
optimization. ROCm#322 added the decorator when the function returned two plain
integers; ROCm#1233 added the torch.arange at the call site, outside the cache;
ROCm#1390 folded it in and tightened the decorator to maxsize=1; ROCm#1445 widened
that back to 128.

Split the function. The split-count heuristic is pure and stays cached as
_get_num_kv_splits(); get_meta_param() is now uncached and rebuilds the indptr
with torch.arange, which is a fill kernel and so is recorded into the graph and
re-runs on replay. This also drops a latent multi-device bug: the cached tensor
was allocated on the then-current device with no device in the key.

Costs nothing on the decode path, where the old cache took 0 hits in 2000
steps and was already rebuilding the arange every step (6.65 -> 6.69 us/call).
It only paid on a repeating key, which is the graph-capture case, where the
arange is recorded once and is free at replay.

Adds op_tests/test_mla_split_indptr_cudagraph.py, runnable both as a plain
script (as .github/scripts/aiter_test.sh invokes it) and under pytest. Fails
on the old code at bs=480, passes with the fix.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: pei.zhang <[email protected]>
peizhang56 added a commit to peizhang56/aiter that referenced this pull request Oct 3, 2026
get_meta_param() was wholly @functools.lru_cache'd, so it returned a cached
device tensor for num_kv_splits_indptr. A CUDA graph capturing a cache hit
records only a pointer and no producing kernel, so once the LRU drops that
entry (it was the tensor's only owner) the storage is recycled and replay
reads garbage. Eviction is routine: total_kv is in the key and changes almost
every decode step, while captured entries are never looked up again.

This restores the cache to its original scope rather than removing an
optimization. ROCm#322 added the decorator when the function returned two plain
integers; ROCm#1233 added the torch.arange at the call site, outside the cache;
ROCm#1390 folded it in and tightened the decorator to maxsize=1; ROCm#1445 widened
that back to 128.

Split the function. The split-count heuristic is pure and stays cached as
_get_num_kv_splits(); get_meta_param() is now uncached and rebuilds the indptr
with torch.arange, which is a fill kernel and so is recorded into the graph and
re-runs on replay. This also drops a latent multi-device bug: the cached tensor
was allocated on the then-current device with no device in the key.

Costs nothing on the decode path, where the old cache took 0 hits in 2000
steps and was already rebuilding the arange every step (6.65 -> 6.69 us/call).
It only paid on a repeating key, which is the graph-capture case, where the
arange is recorded once and is free at replay.

Adds op_tests/test_mla_split_indptr_cudagraph.py, runnable both as a plain
script (as .github/scripts/aiter_test.sh invokes it) and under pytest. Fails
on the old code at bs=480, passes with the fix.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: pei.zhang <[email protected]>
peizhang56 added a commit to peizhang56/aiter that referenced this pull request Oct 5, 2026
get_meta_param() was wholly @functools.lru_cache'd, so it returned a cached
device tensor for num_kv_splits_indptr. A CUDA graph capturing a cache hit
records only a pointer and no producing kernel, so once the LRU drops that
entry (it was the tensor's only owner) the storage is recycled and replay
reads garbage. Eviction is routine: total_kv is in the key and changes almost
every decode step, while captured entries are never looked up again.

This restores the cache to its original scope rather than removing an
optimization. ROCm#322 added the decorator when the function returned two plain
integers; ROCm#1233 added the torch.arange at the call site, outside the cache;
ROCm#1390 folded it in and tightened the decorator to maxsize=1; ROCm#1445 widened
that back to 128.

Split the function. The split-count heuristic is pure and stays cached as
_get_num_kv_splits(); get_meta_param() is now uncached and rebuilds the indptr
with torch.arange, which is a fill kernel and so is recorded into the graph and
re-runs on replay. This also drops a latent multi-device bug: the cached tensor
was allocated on the then-current device with no device in the key.

Costs nothing on the decode path, where the old cache took 0 hits in 2000
steps and was already rebuilding the arange every step (6.65 -> 6.69 us/call).
It only paid on a repeating key, which is the graph-capture case, where the
arange is recorded once and is free at replay.

Adds op_tests/test_mla_split_indptr_cudagraph.py, runnable both as a plain
script (as .github/scripts/aiter_test.sh invokes it) and under pytest. Fails
on the old code at bs=480, passes with the fix.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: pei.zhang <[email protected]>
peizhang56 added a commit to peizhang56/aiter that referenced this pull request Oct 6, 2026
get_meta_param() was wholly @functools.lru_cache'd, so it returned a cached
device tensor for num_kv_splits_indptr. A CUDA graph capturing a cache hit
records only a pointer and no producing kernel, so once the LRU drops that
entry (it was the tensor's only owner) the storage is recycled and replay
reads garbage. Eviction is routine: total_kv is in the key and changes almost
every decode step, while captured entries are never looked up again.

This restores the cache to its original scope rather than removing an
optimization. ROCm#322 added the decorator when the function returned two plain
integers; ROCm#1233 added the torch.arange at the call site, outside the cache;
ROCm#1390 folded it in and tightened the decorator to maxsize=1; ROCm#1445 widened
that back to 128.

Split the function. The split-count heuristic is pure and stays cached as
_get_num_kv_splits(); get_meta_param() is now uncached and rebuilds the indptr
with torch.arange, which is a fill kernel and so is recorded into the graph and
re-runs on replay. This also drops a latent multi-device bug: the cached tensor
was allocated on the then-current device with no device in the key.

Costs nothing on the decode path, where the old cache took 0 hits in 2000
steps and was already rebuilding the arange every step (6.65 -> 6.69 us/call).
It only paid on a repeating key, which is the graph-capture case, where the
arange is recorded once and is free at replay.

Adds op_tests/test_mla_split_indptr_cudagraph.py, runnable both as a plain
script (as .github/scripts/aiter_test.sh invokes it) and under pytest. Fails
on the old code at bs=480, passes with the fix.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: pei.zhang <[email protected]>
peizhang56 added a commit to peizhang56/aiter that referenced this pull request Nov 3, 2026
get_meta_param() was wholly @functools.lru_cache'd, so it returned a cached
device tensor for num_kv_splits_indptr. A CUDA graph capturing a cache hit
records only a pointer and no producing kernel, so once the LRU drops that
entry (it was the tensor's only owner) the storage is recycled and replay
reads garbage. Eviction is routine: total_kv is in the key and changes almost
every decode step, while captured entries are never looked up again.

This restores the cache to its original scope rather than removing an
optimization. ROCm#322 added the decorator when the function returned two plain
integers; ROCm#1233 added the torch.arange at the call site, outside the cache;
ROCm#1390 folded it in and tightened the decorator to maxsize=1; ROCm#1445 widened
that back to 128.

Split the function. The split-count heuristic is pure and stays cached as
_get_num_kv_splits(); get_meta_param() is now uncached and rebuilds the indptr
with torch.arange, which is a fill kernel and so is recorded into the graph and
re-runs on replay. This also drops a latent multi-device bug: the cached tensor
was allocated on the then-current device with no device in the key.

Costs nothing on the decode path, where the old cache took 0 hits in 2000
steps and was already rebuilding the arange every step (6.65 -> 6.69 us/call).
It only paid on a repeating key, which is the graph-capture case, where the
arange is recorded once and is free at replay.

Verified locally with a throwaway capture/evict/replay harness (not added to
the tree, per review): on the old code bs=480 replays a corrupted indptr
(reads 3072, 3080, ... instead of 0, 8, 16, ...); with this fix bs=8 and
bs=480 both replay the correct values.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: pei.zhang <[email protected]>
jamestangg pushed a commit that referenced this pull request Nov 3, 2026
get_meta_param() was wholly @functools.lru_cache'd, so it returned a cached
device tensor for num_kv_splits_indptr. A CUDA graph capturing a cache hit
records only a pointer and no producing kernel, so once the LRU drops that
entry (it was the tensor's only owner) the storage is recycled and replay
reads garbage. Eviction is routine: total_kv is in the key and changes almost
every decode step, while captured entries are never looked up again.

This restores the cache to its original scope rather than removing an
optimization. #322 added the decorator when the function returned two plain
integers; #1233 added the torch.arange at the call site, outside the cache;
#1390 folded it in and tightened the decorator to maxsize=1; #1445 widened
that back to 128.

Split the function. The split-count heuristic is pure and stays cached as
_get_num_kv_splits(); get_meta_param() is now uncached and rebuilds the indptr
with torch.arange, which is a fill kernel and so is recorded into the graph and
re-runs on replay. This also drops a latent multi-device bug: the cached tensor
was allocated on the then-current device with no device in the key.

Costs nothing on the decode path, where the old cache took 0 hits in 2000
steps and was already rebuilding the arange every step (6.65 -> 6.69 us/call).
It only paid on a repeating key, which is the graph-capture case, where the
arange is recorded once and is free at replay.

Verified locally with a throwaway capture/evict/replay harness (not added to
the tree, per review): on the old code bs=480 replays a corrupted indptr
(reads 3072, 3080, ... instead of 0, 8, 16, ...); with this fix bs=8 and
bs=480 both replay the correct values.

Signed-off-by: pei.zhang <[email protected]>
Co-authored-by: Claude Opus 5 <[email protected]>
shantipriya-amd pushed a commit to shantipriya-amd/aiter that referenced this pull request Nov 18, 2026
…#5194)

get_meta_param() was wholly @functools.lru_cache'd, so it returned a cached
device tensor for num_kv_splits_indptr. A CUDA graph capturing a cache hit
records only a pointer and no producing kernel, so once the LRU drops that
entry (it was the tensor's only owner) the storage is recycled and replay
reads garbage. Eviction is routine: total_kv is in the key and changes almost
every decode step, while captured entries are never looked up again.

This restores the cache to its original scope rather than removing an
optimization. ROCm#322 added the decorator when the function returned two plain
integers; ROCm#1233 added the torch.arange at the call site, outside the cache;
ROCm#1390 folded it in and tightened the decorator to maxsize=1; ROCm#1445 widened
that back to 128.

Split the function. The split-count heuristic is pure and stays cached as
_get_num_kv_splits(); get_meta_param() is now uncached and rebuilds the indptr
with torch.arange, which is a fill kernel and so is recorded into the graph and
re-runs on replay. This also drops a latent multi-device bug: the cached tensor
was allocated on the then-current device with no device in the key.

Costs nothing on the decode path, where the old cache took 0 hits in 2000
steps and was already rebuilding the arange every step (6.65 -> 6.69 us/call).
It only paid on a repeating key, which is the graph-capture case, where the
arange is recorded once and is free at replay.

Verified locally with a throwaway capture/evict/replay harness (not added to
the tree, per review): on the old code bs=480 replays a corrupted indptr
(reads 3072, 3080, ... instead of 0, 8, 16, ...); with this fix bs=8 and
bs=480 both replay the correct values.

Signed-off-by: pei.zhang <[email protected]>
Co-authored-by: Claude Opus 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants