Skip to content

remove maxsize for mla lru cache - #1445

Merged
valarLip merged 8 commits into
mainfrom
mla_fix
Dec 4, 2025
Merged

valarLip merged 8 commits into
mainfrom
mla_fix

Conversation

@Zzz9990

@Zzz9990 Zzz9990 commented Nov 19, 2025

Copy link
Copy Markdown
Contributor

Motivation

Technical Details

Test Plan

Test Result

Submission Checklist

valarLip
valarLip previously approved these changes Nov 23, 2025
@Zzz9990
Zzz9990 marked this pull request as ready for review December 4, 2025 01:05
@valarLip
valarLip merged commit d5481c5 into main Dec 4, 2025
@valarLip
valarLip deleted the mla_fix branch December 4, 2025 09:21
zhuyuhua-v added a commit that referenced this pull request Dec 17, 2025
* remote maxsize for mla lru cache

* enable extenal num_kv_splits & num_kv_splits_ptr

---------

Co-authored-by: Zhu Yuhua <[email protected]>
Co-authored-by: Lingpeng Jin <[email protected]>
ZhangLirong-amd pushed a commit that referenced this pull request Dec 29, 2025
* remote maxsize for mla lru cache

* enable extenal num_kv_splits & num_kv_splits_ptr

---------

Co-authored-by: Zhu Yuhua <[email protected]>
Co-authored-by: Lingpeng Jin <[email protected]>
valarLip added a commit that referenced this pull request Mar 18, 2026
* remote maxsize for mla lru cache

* enable extenal num_kv_splits & num_kv_splits_ptr

---------

Co-authored-by: Zhu Yuhua <[email protected]>
Co-authored-by: Lingpeng Jin <[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