Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 36 additions & 5 deletions tests/kernels/attention/test_rocm_aiter_mla_op_registration.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""ROCm custom op schema test for AITER MLA decode.
"""ROCm custom op schema tests for AITER MLA decode.

A single ``opcheck`` call on ``torch.ops.vllm.rocm_aiter_mla_decode_fwd``
verifies that the custom op is registered and that its schema and fake
implementation are consistent with the real kernel: fake-tensor support for
torch.compile tracing and the ``mutates_args=["o"]`` in-place output aliasing.
``opcheck`` verifies that the decode ops are registered and that their schemas
and fake implementations are consistent with the real kernels: fake-tensor
support for torch.compile tracing and ``mutates_args=["o"]`` in-place output
aliasing.
"""

import pytest
Expand Down Expand Up @@ -77,3 +77,34 @@ def test_mla_decode_fwd_op_schema() -> None:
"reduce_partial_map": None,
},
)


@torch.inference_mode()
def test_mla_decode_fwd_lse_op_schema() -> None:
"""Validate graph registration and mutation schema for LSE decode."""
_require_aiter()
# Import ensures the custom op is registered.
from vllm._aiter_ops import rocm_aiter_ops # noqa: F401

batch_size, nhead = 2, 16
q = torch.randn(batch_size, nhead, Q_HEAD_DIM, dtype=torch.bfloat16, device="cuda")
kv_buffer = torch.randn(32, 1, 1, Q_HEAD_DIM, dtype=torch.bfloat16, device="cuda")
o = torch.zeros(batch_size, nhead, V_HEAD_DIM, dtype=torch.bfloat16, device="cuda")
qo_indptr = torch.arange(batch_size + 1, dtype=torch.int32, device="cuda")
kv_indptr = torch.arange(batch_size + 1, dtype=torch.int32, device="cuda") * 16
kv_indices = torch.arange(32, dtype=torch.int32, device="cuda")
kv_last_page_lens = torch.ones(batch_size, dtype=torch.int32, device="cuda")

opcheck(
torch.ops.vllm.rocm_aiter_mla_decode_fwd_lse,
(q, kv_buffer, o, qo_indptr, 1),
{
"kv_indptr": kv_indptr,
"kv_indices": kv_indices,
"kv_last_page_lens": kv_last_page_lens,
"sm_scale": Q_HEAD_DIM**-0.5,
"logit_cap": 0.0,
"q_scale": None,
"kv_scale": None,
},
)
Loading
Loading