[ROCm][ [Perf] sparse attention optimization on minimax-m3 (#46546)
Signed-off-by: Hongxia Yang <hongxia.yang@amd.com> Signed-off-by: tjtanaa <tunjian.tan@embeddedllm.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: yueliu14 <yue.liu4@amd.com> Co-authored-by: tjtanaa <tunjian.tan@embeddedllm.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
yueliu14
tjtanaa
parent
638b1a99cc
commit
c63cd4906c
@@ -27,12 +27,21 @@ from vllm.distributed import get_tensor_model_parallel_world_size
|
||||
from vllm.forward_context import get_forward_context
|
||||
from vllm.logger import init_logger
|
||||
from vllm.model_executor.layers.attention_layer_base import AttentionLayerBase
|
||||
from vllm.models.minimax_m3.common.ops.index_topk import (
|
||||
minimax_m3_index_decode,
|
||||
minimax_m3_index_score,
|
||||
minimax_m3_index_topk,
|
||||
)
|
||||
from vllm.platforms import current_platform
|
||||
|
||||
if current_platform.is_rocm():
|
||||
from vllm.models.minimax_m3.amd.ops.index_topk import (
|
||||
minimax_m3_index_decode,
|
||||
minimax_m3_index_score,
|
||||
minimax_m3_index_topk,
|
||||
)
|
||||
else:
|
||||
from vllm.models.minimax_m3.common.ops.index_topk import (
|
||||
minimax_m3_index_decode,
|
||||
minimax_m3_index_score,
|
||||
minimax_m3_index_topk,
|
||||
)
|
||||
|
||||
from vllm.v1.attention.backend import (
|
||||
AttentionBackend,
|
||||
AttentionCGSupport,
|
||||
|
||||
@@ -31,30 +31,6 @@ _FP8_DTYPES = (
|
||||
torch.float8_e5m2fnuz,
|
||||
)
|
||||
|
||||
_SPARSE_ATTN_NUM_STAGES_KWARG: dict | None = None
|
||||
|
||||
|
||||
def _sparse_attn_num_stages_kwarg() -> dict:
|
||||
"""Triton ``num_stages`` override for the sparse-attn GEMM kernels.
|
||||
|
||||
Forced only where required: CDNA3 (gfx942) caps LDS at
|
||||
64 KB, and the default 2-stage pipeline double-buffers the 128x128 K/V tiles
|
||||
to ~66 KB ("out of resource: shared memory"), so pin gfx942 to a single
|
||||
stage (~32 KB, which fits). Everywhere else (NVIDIA, CDNA4 gfx950) return an
|
||||
empty kwarg and let Triton keep its own default -- don't second-guess it.
|
||||
Cached: the arch is fixed per process.
|
||||
"""
|
||||
global _SPARSE_ATTN_NUM_STAGES_KWARG
|
||||
if _SPARSE_ATTN_NUM_STAGES_KWARG is None:
|
||||
kwarg: dict = {}
|
||||
if current_platform.is_rocm():
|
||||
from vllm.platforms.rocm import on_gfx942
|
||||
|
||||
if on_gfx942():
|
||||
kwarg = {"num_stages": 1}
|
||||
_SPARSE_ATTN_NUM_STAGES_KWARG = kwarg
|
||||
return _SPARSE_ATTN_NUM_STAGES_KWARG
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# GQA block-sparse attention (paged). Main heads attend only to the selected
|
||||
@@ -498,7 +474,6 @@ def minimax_m3_sparse_attn(
|
||||
BLOCK_SIZE_Q=1,
|
||||
BLOCK_SIZE_K=SPARSE_BLOCK_SIZE,
|
||||
USE_FP8=use_fp8,
|
||||
**_sparse_attn_num_stages_kwarg(),
|
||||
)
|
||||
|
||||
|
||||
@@ -574,7 +549,6 @@ def minimax_m3_sparse_attn_decode(
|
||||
NUM_TOPK_CHUNKS=num_topk_chunks,
|
||||
USE_FP8=use_fp8,
|
||||
USE_PDL=use_pdl,
|
||||
**_sparse_attn_num_stages_kwarg(),
|
||||
**pdl_launch,
|
||||
)
|
||||
merge_grid = (total_q, num_heads)
|
||||
|
||||
@@ -24,12 +24,21 @@ from vllm.config import VllmConfig
|
||||
from vllm.config.cache import CacheDType
|
||||
from vllm.forward_context import get_forward_context
|
||||
from vllm.logger import init_logger
|
||||
from vllm.models.minimax_m3.common.ops.sparse_attn import (
|
||||
SPARSE_BLOCK_SIZE,
|
||||
minimax_m3_sparse_attn,
|
||||
minimax_m3_sparse_attn_decode,
|
||||
)
|
||||
from vllm.models.minimax_m3.common.ops.sparse_attn import SPARSE_BLOCK_SIZE
|
||||
from vllm.platforms import current_platform
|
||||
|
||||
# AMD/ROCm uses the gfx942/gfx950-optimized block-sparse kernels in amd.ops;
|
||||
# every other platform uses the generic common.ops implementation.
|
||||
if current_platform.is_rocm():
|
||||
from vllm.models.minimax_m3.amd.ops.sparse_attn import (
|
||||
minimax_m3_sparse_attn,
|
||||
minimax_m3_sparse_attn_decode,
|
||||
)
|
||||
else:
|
||||
from vllm.models.minimax_m3.common.ops.sparse_attn import (
|
||||
minimax_m3_sparse_attn,
|
||||
minimax_m3_sparse_attn_decode,
|
||||
)
|
||||
from vllm.v1.attention.backend import (
|
||||
AttentionBackend,
|
||||
AttentionCGSupport,
|
||||
|
||||
Reference in New Issue
Block a user