[Bugfix][ROCm] Drop -1 sentinels when building the ragged sparse-MLA indices (#58058)

Signed-off-by: Mehmet Cagri Kaymak <mehmet.kaymak@amd.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Mehmet Cagri
2026-09-28 18:40:11 -05:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 9b29370524
commit 75fad5bbef
2 changed files with 124 additions and 27 deletions
@@ -8,6 +8,7 @@ import pytest
import torch
from vllm.platforms import current_platform
from vllm.utils.torch_utils import set_random_seed
pytestmark = pytest.mark.skipif(
not current_platform.is_rocm(), reason="Only used by ROCm"
@@ -424,6 +425,37 @@ def test_compute_global_topk_ragged_indices_and_indptr() -> None:
torch.testing.assert_close(actual_lens, expected_lens)
@pytest.mark.parametrize("width", [16, 640, 2176])
@pytest.mark.parametrize("num_queries", [1, 70, 1000])
@torch.inference_mode()
def test_build_ragged_indices_from_dense_drops_invalid_entries(
width: int, num_queries: int
) -> None:
from vllm.v1.attention.ops.rocm_aiter_mla_sparse import (
build_ragged_indices_from_dense,
)
device = torch.device("cuda")
set_random_seed(width + num_queries)
num_rows = 5000
indices = torch.randint(0, num_rows + 100, (num_queries, width))
indices[torch.rand(num_queries, width) < 0.3] = -1
lengths = torch.randint(0, width + 8, (num_queries,))
flat, indptr = build_ragged_indices_from_dense(
indices.to(device, torch.int32),
lengths.to(device, torch.int32),
num_rows=num_rows,
)
# Each row keeps its in-range entries within its length, in order.
expected = [
[x for x in row[:n] if 0 <= x < num_rows]
for row, n in zip(indices.tolist(), lengths.tolist())
]
assert _rows_from_ragged(flat, indptr) == expected
@torch.inference_mode()
def test_combine_topk_swa_indices_adds_image_visibility() -> None:
from vllm.models.deepseek_v4.amd.rocm import combine_topk_swa_indices