[ROCm][Perf][GLM-5.3-Flash] Add AITER topk backend for decodes (#58167)
Signed-off-by: simondanielsson <simon.danielsson99@hotmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent
751fa96a49
commit
98b29aa99a
@@ -1913,6 +1913,11 @@ def _sync_aiter_situv2_moe_env() -> None:
|
||||
os.environ.pop(name, None)
|
||||
|
||||
|
||||
_GFX950_C4A_AITER_MAX_COMPRESSED_SEQ_LEN = 64 * 1024
|
||||
_GFX950_C4A_NATIVE_MAX_ROWS = 256
|
||||
_GFX950_DSV4_NATIVE_MAX_COLUMNS = 1024 * 1024
|
||||
|
||||
|
||||
class rocm_aiter_ops:
|
||||
"""ROCm AITER operations wrapper for AMD GPU acceleration in vLLM.
|
||||
|
||||
@@ -2546,6 +2551,100 @@ class rocm_aiter_ops:
|
||||
"""Whether AITER has DSV4 native-I384 configs through the given M."""
|
||||
return cls._probe_dsv4_i384_fhmoe_capability(num_tokens)
|
||||
|
||||
@classmethod
|
||||
@if_aiter_supported
|
||||
def is_indexer_top_k_enabled(cls) -> bool:
|
||||
"""gfx950 is the only arch with tuned AITER indexer top-k kernels."""
|
||||
from vllm.platforms.rocm import on_gfx950
|
||||
|
||||
return cls._AITER_ENABLED and on_gfx950()
|
||||
|
||||
@classmethod
|
||||
def is_indexer_top_k_supported(
|
||||
cls,
|
||||
*,
|
||||
is_prefill: bool,
|
||||
compress_ratio: int,
|
||||
num_rows: int,
|
||||
max_valid_seq_len: int | None = None,
|
||||
) -> bool:
|
||||
"""Whether AITER's sparse indexer top-k beats the in-tree kernel for
|
||||
this shape."""
|
||||
if compress_ratio <= 1 or not cls.is_indexer_top_k_enabled():
|
||||
return False
|
||||
|
||||
if not is_prefill:
|
||||
assert max_valid_seq_len is not None
|
||||
# AITER v0.1.19 decode is one-block only. This measured gfx950
|
||||
# FP32/k=1024 compressed-row boundary is independent of the native
|
||||
# split-count boundary in sampler.cu.
|
||||
if (
|
||||
num_rows <= _GFX950_C4A_NATIVE_MAX_ROWS
|
||||
and max_valid_seq_len > _GFX950_C4A_AITER_MAX_COMPRESSED_SEQ_LEN
|
||||
):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def dsv4_indexer_prefers_native_top_k(
|
||||
*,
|
||||
num_rows: int,
|
||||
num_columns: int,
|
||||
topk_tokens: int,
|
||||
) -> bool:
|
||||
"""The in-tree decode kernel's measured advantage window over AITER.
|
||||
Tuned on DSV4's compressed-KV logits, so it applies to that indexer
|
||||
only."""
|
||||
return (
|
||||
topk_tokens == 512
|
||||
and 0 < num_rows <= 384
|
||||
and num_columns <= _GFX950_DSV4_NATIVE_MAX_COLUMNS
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def indexer_top_k_decode(
|
||||
logits: torch.Tensor,
|
||||
next_n: int,
|
||||
seq_lens: torch.Tensor,
|
||||
topk_indices: torch.Tensor,
|
||||
topk_tokens: int,
|
||||
) -> None:
|
||||
from aiter.ops.topk import top_k_per_row_decode
|
||||
|
||||
top_k_per_row_decode(
|
||||
logits,
|
||||
next_n,
|
||||
seq_lens,
|
||||
topk_indices,
|
||||
logits.shape[0],
|
||||
logits.stride(0),
|
||||
logits.stride(1),
|
||||
k=topk_tokens,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def indexer_top_k_prefill(
|
||||
logits: torch.Tensor,
|
||||
row_starts: torch.Tensor,
|
||||
row_ends: torch.Tensor,
|
||||
indices: torch.Tensor,
|
||||
topk_tokens: int,
|
||||
) -> None:
|
||||
from aiter.ops.topk import top_k_per_row_prefill
|
||||
|
||||
top_k_per_row_prefill(
|
||||
logits,
|
||||
row_starts,
|
||||
row_ends,
|
||||
indices,
|
||||
None,
|
||||
logits.shape[0],
|
||||
logits.stride(0),
|
||||
logits.stride(1),
|
||||
k=topk_tokens,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def register_ops_once() -> None:
|
||||
global _OPS_REGISTERED
|
||||
|
||||
@@ -167,6 +167,7 @@ SparseIndexerTopkBackend = Literal[
|
||||
"per_row",
|
||||
"flashinfer",
|
||||
"torch",
|
||||
"aiter",
|
||||
]
|
||||
|
||||
# Architectures whose model code wires up the flashinfer moe_ep experts. MTP
|
||||
@@ -289,6 +290,8 @@ class KernelConfig:
|
||||
- "per_row": Use vLLM's top_k_per_row_decode kernel
|
||||
- "flashinfer": Use FlashInfer's top_k_ragged_transform kernel
|
||||
- "torch": Use a plain torch.topk implementation (debug reference)
|
||||
- "aiter": Use AITER's top_k_per_row_decode kernel (ROCm gfx950 only,
|
||||
requires VLLM_ROCM_USE_AITER)
|
||||
|
||||
Explicit values raise RuntimeError when their constraints are not met.
|
||||
"""
|
||||
|
||||
@@ -163,6 +163,14 @@ class SparseIndexerTopk(torch.nn.Module):
|
||||
current_platform.has_device_capability(90)
|
||||
and not current_platform.is_device_capability_family(120)
|
||||
)
|
||||
self._is_rocm = current_platform.is_rocm()
|
||||
self._aiter_enabled = False
|
||||
self._aiter_capable = False
|
||||
if self._is_rocm:
|
||||
from vllm._aiter_ops import rocm_aiter_ops
|
||||
|
||||
self._aiter_enabled = bool(rocm_aiter_ops.is_enabled())
|
||||
self._aiter_capable = bool(rocm_aiter_ops.is_indexer_top_k_enabled())
|
||||
|
||||
def resolve_backend(
|
||||
self, logits: torch.Tensor, topk_tokens: int, num_rows: int
|
||||
@@ -193,6 +201,19 @@ class SparseIndexerTopk(torch.nn.Module):
|
||||
f"inputs violate DeepSelect's constraints: dtype={logits.dtype},"
|
||||
f" stride={logits.stride()}, topk={topk_tokens}"
|
||||
)
|
||||
elif self._backend == "aiter":
|
||||
if not self._is_rocm:
|
||||
failures.append("requires a ROCm platform")
|
||||
elif not self._aiter_enabled:
|
||||
failures.append("requires AITER (VLLM_ROCM_USE_AITER=1)")
|
||||
elif not self._aiter_capable:
|
||||
failures.append(
|
||||
"AITER has no tuned indexer top-k kernels for this GPU arch"
|
||||
)
|
||||
if topk_tokens not in (512, 1024, 2048, 4096):
|
||||
failures.append(
|
||||
f"topk_tokens must be in (512, 1024, 2048, 4096), got {topk_tokens}"
|
||||
)
|
||||
elif self._backend == "flashinfer":
|
||||
if not self._is_cuda:
|
||||
failures.append("requires a CUDA platform")
|
||||
@@ -216,11 +237,14 @@ class SparseIndexerTopk(torch.nn.Module):
|
||||
self, logits: torch.Tensor, topk_tokens: int, num_rows: int
|
||||
) -> str:
|
||||
"""The priority chain: cooperative -> persistent -> per_row.
|
||||
deep_select/flashinfer/torch are opt-in only.
|
||||
aiter/deep_select/flashinfer/torch are opt-in only.
|
||||
|
||||
cooperative_topk is preferred whenever it is applicable, i.e. within
|
||||
its AUTO_COOPERATIVE_MAX_ROWS row limit; larger batches go to
|
||||
persistent_topk.
|
||||
|
||||
aiter not auto-resolved as it does not outperform the per-row on every shape,
|
||||
hence we delegate to the caller to decide when to use it.
|
||||
"""
|
||||
if not self._cooperative_constraints(logits, topk_tokens, num_rows):
|
||||
return "cooperative"
|
||||
@@ -285,7 +309,8 @@ class SparseIndexerTopk(torch.nn.Module):
|
||||
max_seq_len: int,
|
||||
) -> None:
|
||||
"""Run the resolved decode top-k implementation, writing into
|
||||
topk_indices (int32, -1 fill for rows shorter than topk_tokens)."""
|
||||
topk_indices (int32, -1 fill for rows shorter than topk_tokens).
|
||||
"""
|
||||
backend = self.resolve_backend(logits, topk_tokens, logits.shape[0])
|
||||
if backend == "deep_select":
|
||||
row_ends = self._row_ends(seq_lens, next_n, logits.shape[0])
|
||||
@@ -344,15 +369,37 @@ class SparseIndexerTopk(torch.nn.Module):
|
||||
) < row_ends.unsqueeze(1)
|
||||
indices = torch.where(in_range, indices, -1)
|
||||
topk_indices.copy_(indices)
|
||||
else:
|
||||
assert backend == "per_row", f"unknown topk backend: {backend}"
|
||||
ops.top_k_per_row_decode(
|
||||
elif backend == "aiter":
|
||||
from vllm._aiter_ops import rocm_aiter_ops
|
||||
|
||||
# AITER's decode kernel only implements the 1D/next_n == 1 form,
|
||||
# which is equivalent once the ragged ends are expanded.
|
||||
rocm_aiter_ops.indexer_top_k_decode(
|
||||
logits,
|
||||
next_n,
|
||||
seq_lens,
|
||||
1,
|
||||
self._row_ends(seq_lens, next_n, logits.shape[0]),
|
||||
topk_indices,
|
||||
logits.shape[0],
|
||||
logits.stride(0),
|
||||
logits.stride(1),
|
||||
topk_tokens,
|
||||
)
|
||||
else:
|
||||
assert backend == "per_row", f"unknown topk backend: {backend}"
|
||||
self._per_row(logits, seq_lens, next_n, topk_indices, topk_tokens)
|
||||
|
||||
@staticmethod
|
||||
def _per_row(
|
||||
logits: torch.Tensor,
|
||||
seq_lens: torch.Tensor,
|
||||
next_n: int,
|
||||
topk_indices: torch.Tensor,
|
||||
topk_tokens: int,
|
||||
) -> None:
|
||||
ops.top_k_per_row_decode(
|
||||
logits,
|
||||
next_n,
|
||||
seq_lens,
|
||||
topk_indices,
|
||||
logits.shape[0],
|
||||
logits.stride(0),
|
||||
logits.stride(1),
|
||||
topk_tokens,
|
||||
)
|
||||
|
||||
@@ -8,10 +8,11 @@ import vllm.envs as envs
|
||||
from vllm import _custom_ops # noqa: F401 # registers the torch.ops._C kernels
|
||||
from vllm._aiter_ops import rocm_aiter_ops
|
||||
from vllm.compilation.breakable_cudagraph import eager_break_during_capture
|
||||
from vllm.config import get_current_vllm_config_or_none
|
||||
from vllm.config import CUDAGraphMode, get_current_vllm_config_or_none
|
||||
from vllm.forward_context import get_forward_context
|
||||
from vllm.logger import init_logger
|
||||
from vllm.model_executor.custom_op import CustomOp
|
||||
from vllm.model_executor.layers.indexer_topk import get_indexer_topk
|
||||
from vllm.models.glm5next.amd.ops import kpool_compress as kpool_ops
|
||||
from vllm.models.glm5next.common.sparse_indexer import (
|
||||
RADIX_TOPK_WORKSPACE_SIZE,
|
||||
@@ -24,6 +25,7 @@ from vllm.models.glm5next.common.sparse_indexer import (
|
||||
kv_cache_as_quant_view,
|
||||
)
|
||||
from vllm.platforms import current_platform
|
||||
from vllm.utils.math_utils import cdiv
|
||||
from vllm.utils.torch_utils import (
|
||||
LayerNameType,
|
||||
_encode_layer_name,
|
||||
@@ -37,6 +39,9 @@ from vllm.v1.worker.workspace import current_workspace_manager
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
_GFX950_KPOOL_AITER_MAX_POOLS = 256 * 1024 # (1M ctx)
|
||||
_GFX950_KPOOL_AITER_MIN_POOLS = 16 * 1024
|
||||
|
||||
# kpool write helper: form pools from the current token batch and compress them
|
||||
# into the index K cache via the fused Triton kernel.
|
||||
|
||||
@@ -87,6 +92,51 @@ def _kpool_compress_insert(
|
||||
)
|
||||
|
||||
|
||||
def _kpool_decode_topk_backend(
|
||||
configured: str,
|
||||
*,
|
||||
num_rows: int,
|
||||
max_valid_seq_len: int,
|
||||
select_k: int,
|
||||
index_kpool: int,
|
||||
full_cudagraph: bool,
|
||||
) -> str:
|
||||
"""Select the topk backend for decodes.
|
||||
|
||||
Heuristic based on ctx lengths:
|
||||
- <16k pools: in-tree hip kernel
|
||||
- 16-256k pools: use aiter
|
||||
- >256k pools: in-tree because not measured on >1m ctx
|
||||
|
||||
Since under FULL cudagraphs we cannot access the context length,
|
||||
and the aiter kernel does not always outperform the in-tree kernel,
|
||||
we default to in-tree kernel under FULL cudagraphs. Users can opt in
|
||||
if they know their context length is long enough to benefit from aiter.
|
||||
"""
|
||||
if (
|
||||
configured != "auto"
|
||||
or full_cudagraph
|
||||
or not rocm_aiter_ops.is_indexer_top_k_enabled()
|
||||
):
|
||||
return configured
|
||||
if rocm_aiter_ops.is_indexer_top_k_supported(
|
||||
is_prefill=False,
|
||||
compress_ratio=index_kpool,
|
||||
num_rows=num_rows,
|
||||
max_valid_seq_len=max_valid_seq_len,
|
||||
):
|
||||
return "aiter"
|
||||
if (
|
||||
index_kpool > 1
|
||||
and select_k == 512
|
||||
and _GFX950_KPOOL_AITER_MIN_POOLS
|
||||
<= max_valid_seq_len
|
||||
<= _GFX950_KPOOL_AITER_MAX_POOLS
|
||||
):
|
||||
return "aiter"
|
||||
return configured
|
||||
|
||||
|
||||
@eager_break_during_capture
|
||||
def sparse_attn_indexer_kpool(
|
||||
hidden_states: torch.Tensor,
|
||||
@@ -117,6 +167,7 @@ def sparse_attn_indexer_kpool(
|
||||
# path and when the tail cache is disabled.
|
||||
tail_kv_cache: torch.Tensor | None = None,
|
||||
tail_prefix: str | None = None,
|
||||
topk_backend: str = "auto",
|
||||
) -> torch.Tensor:
|
||||
# careful! this will be None in dummy run
|
||||
attn_metadata = get_forward_context().attn_metadata
|
||||
@@ -580,15 +631,29 @@ def sparse_attn_indexer_kpool(
|
||||
else:
|
||||
topk_dst = topk_indices_buffer[:num_padded_tokens, :topk_tokens]
|
||||
|
||||
torch.ops._C.top_k_per_row_decode(
|
||||
full_cudagraph = (
|
||||
get_forward_context().cudagraph_runtime_mode == CUDAGraphMode.FULL
|
||||
)
|
||||
if full_cudagraph:
|
||||
topk_max_seq_len = max_pool_len * index_kpool
|
||||
else:
|
||||
topk_max_seq_len = attn_metadata_narrowed.max_seq_len
|
||||
|
||||
resolved_backend = _kpool_decode_topk_backend(
|
||||
topk_backend,
|
||||
num_rows=num_rows,
|
||||
max_valid_seq_len=cdiv(topk_max_seq_len, index_kpool),
|
||||
select_k=select_k,
|
||||
index_kpool=index_kpool,
|
||||
full_cudagraph=full_cudagraph,
|
||||
)
|
||||
get_indexer_topk(resolved_backend)(
|
||||
logits,
|
||||
next_n,
|
||||
seq_lens,
|
||||
next_n,
|
||||
topk_dst,
|
||||
num_rows,
|
||||
logits.stride(0),
|
||||
logits.stride(1),
|
||||
select_k,
|
||||
topk_max_seq_len,
|
||||
)
|
||||
|
||||
# Resolve to token-level indices in the output buffer.
|
||||
@@ -664,6 +729,10 @@ class SparseAttnIndexerKpool(CustomOp):
|
||||
self.topk_indices_buffer = topk_indices_buffer
|
||||
self.skip_k_cache_insert = skip_k_cache_insert
|
||||
self.use_fp4_cache = use_fp4_cache
|
||||
cfg = get_current_vllm_config_or_none()
|
||||
self.topk_backend = (
|
||||
cfg.kernel_config.sparse_indexer_topk_backend if cfg is not None else "auto"
|
||||
)
|
||||
|
||||
def forward_hip(
|
||||
self,
|
||||
@@ -726,6 +795,7 @@ class SparseAttnIndexerKpool(CustomOp):
|
||||
positions,
|
||||
self.tail_cache.kv_cache if self.tail_cache is not None else None,
|
||||
self.tail_cache.prefix if self.tail_cache is not None else None,
|
||||
self.topk_backend,
|
||||
)
|
||||
|
||||
def forward_native(
|
||||
|
||||
@@ -32,18 +32,6 @@ logger = init_logger(__name__)
|
||||
FP8_DTYPE = current_platform.fp8_dtype()
|
||||
|
||||
|
||||
@functools.cache
|
||||
def _get_aiter_topk_ops() -> tuple[Callable[..., None], Callable[..., None]] | None:
|
||||
try:
|
||||
from aiter.ops.topk import (
|
||||
top_k_per_row_decode,
|
||||
top_k_per_row_prefill,
|
||||
)
|
||||
except ImportError:
|
||||
return None
|
||||
return top_k_per_row_prefill, top_k_per_row_decode
|
||||
|
||||
|
||||
@functools.cache
|
||||
def _get_aiter_sparse_prefill_opus() -> Callable[..., torch.Tensor] | None:
|
||||
from vllm._aiter_ops import rocm_aiter_ops
|
||||
@@ -58,9 +46,6 @@ def _get_aiter_sparse_prefill_opus() -> Callable[..., torch.Tensor] | None:
|
||||
return pa_sparse_prefill_opus
|
||||
|
||||
|
||||
_GFX950_C4A_AITER_MAX_COMPRESSED_SEQ_LEN = 64 * 1024
|
||||
_GFX950_C4A_NATIVE_MAX_ROWS = 256
|
||||
_GFX950_DSV4_NATIVE_MAX_COLUMNS = 1024 * 1024
|
||||
# Conservative perf gate, not a correctness bound: OPUS is correct for any query
|
||||
# count, but Triton stays faster below this measured crossover.
|
||||
_GFX950_AITER_SPARSE_PREFILL_OPUS_MIN_QUERIES = 1024
|
||||
@@ -71,43 +56,6 @@ def _indexer_k_is_c4a_block_flat(compress_ratio: int) -> bool:
|
||||
return compress_ratio == 4
|
||||
|
||||
|
||||
def _get_aiter_top_k_kernel(
|
||||
*,
|
||||
is_prefill: bool,
|
||||
compress_ratio: int,
|
||||
num_rows: int,
|
||||
max_valid_seq_len: int | None = None,
|
||||
num_columns: int | None = None,
|
||||
topk_tokens: int = 1024,
|
||||
on_gfx950: bool = _ON_GFX950,
|
||||
) -> Callable[..., None] | None:
|
||||
if compress_ratio <= 1 or not on_gfx950:
|
||||
return None
|
||||
|
||||
if not is_prefill:
|
||||
assert max_valid_seq_len is not None
|
||||
if (
|
||||
topk_tokens == 512
|
||||
and 0 < num_rows <= 384
|
||||
and num_columns is not None
|
||||
and num_columns <= _GFX950_DSV4_NATIVE_MAX_COLUMNS
|
||||
):
|
||||
return None
|
||||
# AITER v0.1.19 decode is one-block only. This measured gfx950
|
||||
# FP32/k=1024 compressed-row boundary is independent of the native
|
||||
# split-count boundary in sampler.cu.
|
||||
if (
|
||||
num_rows <= _GFX950_C4A_NATIVE_MAX_ROWS
|
||||
and max_valid_seq_len > _GFX950_C4A_AITER_MAX_COMPRESSED_SEQ_LEN
|
||||
):
|
||||
return None
|
||||
|
||||
topk_ops = _get_aiter_topk_ops()
|
||||
if topk_ops is None:
|
||||
return None
|
||||
return topk_ops[0] if is_prefill else topk_ops[1]
|
||||
|
||||
|
||||
@triton.jit
|
||||
def _localize_aiter_prefill_topk_kernel(
|
||||
indices_ptr,
|
||||
@@ -145,46 +93,20 @@ def _localize_aiter_prefill_topk(
|
||||
|
||||
|
||||
def _launch_aiter_top_k_per_row_prefill(
|
||||
top_k_per_row_prefill: Callable[..., None],
|
||||
logits: torch.Tensor,
|
||||
row_starts: torch.Tensor,
|
||||
row_ends: torch.Tensor,
|
||||
indices: torch.Tensor,
|
||||
topk_tokens: int,
|
||||
) -> None:
|
||||
top_k_per_row_prefill(
|
||||
logits,
|
||||
row_starts,
|
||||
row_ends,
|
||||
indices,
|
||||
None,
|
||||
logits.shape[0],
|
||||
logits.stride(0),
|
||||
logits.stride(1),
|
||||
k=topk_tokens,
|
||||
from vllm._aiter_ops import rocm_aiter_ops
|
||||
|
||||
rocm_aiter_ops.indexer_top_k_prefill(
|
||||
logits, row_starts, row_ends, indices, topk_tokens
|
||||
)
|
||||
_localize_aiter_prefill_topk(indices, row_starts)
|
||||
|
||||
|
||||
def _launch_aiter_top_k_per_row_decode(
|
||||
top_k_per_row_decode: Callable[..., None],
|
||||
logits: torch.Tensor,
|
||||
seq_lens: torch.Tensor,
|
||||
indices: torch.Tensor,
|
||||
topk_tokens: int,
|
||||
) -> None:
|
||||
top_k_per_row_decode(
|
||||
logits,
|
||||
1,
|
||||
seq_lens.reshape(-1),
|
||||
indices,
|
||||
logits.shape[0],
|
||||
logits.stride(0),
|
||||
logits.stride(1),
|
||||
k=topk_tokens,
|
||||
)
|
||||
|
||||
|
||||
@triton.jit
|
||||
def _indexer_k_quant_and_cache_kernel(
|
||||
k_ptr, # [num_tokens, head_dim]
|
||||
@@ -1195,6 +1117,8 @@ def rocm_aiter_sparse_attn_indexer(
|
||||
candidate_block_size: int = 0,
|
||||
candidate_write: bool = False,
|
||||
) -> torch.Tensor:
|
||||
from vllm._aiter_ops import rocm_aiter_ops
|
||||
|
||||
# careful! this will be None in dummy run
|
||||
forward_context = get_forward_context()
|
||||
attn_metadata = forward_context.attn_metadata
|
||||
@@ -1347,14 +1271,12 @@ def rocm_aiter_sparse_attn_indexer(
|
||||
|
||||
num_rows = logits.shape[0]
|
||||
|
||||
aiter_topk_kernel = _get_aiter_top_k_kernel(
|
||||
if rocm_aiter_ops.is_indexer_top_k_supported(
|
||||
is_prefill=True,
|
||||
compress_ratio=compress_ratio,
|
||||
num_rows=num_rows,
|
||||
)
|
||||
if aiter_topk_kernel is not None:
|
||||
):
|
||||
_launch_aiter_top_k_per_row_prefill(
|
||||
aiter_topk_kernel,
|
||||
logits,
|
||||
chunk.cu_seqlen_ks,
|
||||
chunk.cu_seqlen_ke,
|
||||
@@ -1448,19 +1370,20 @@ def rocm_aiter_sparse_attn_indexer(
|
||||
max_compressed_seq_len = max_model_len
|
||||
else:
|
||||
max_compressed_seq_len = layer_attn_metadata.max_seq_len // compress_ratio
|
||||
aiter_topk_kernel = _get_aiter_top_k_kernel(
|
||||
if rocm_aiter_ops.is_indexer_top_k_supported(
|
||||
is_prefill=False,
|
||||
compress_ratio=compress_ratio,
|
||||
num_rows=num_rows,
|
||||
max_valid_seq_len=max_compressed_seq_len,
|
||||
) and not rocm_aiter_ops.dsv4_indexer_prefers_native_top_k(
|
||||
num_rows=num_rows,
|
||||
num_columns=logits.shape[1],
|
||||
topk_tokens=topk_tokens,
|
||||
)
|
||||
if aiter_topk_kernel is not None:
|
||||
_launch_aiter_top_k_per_row_decode(
|
||||
aiter_topk_kernel,
|
||||
):
|
||||
rocm_aiter_ops.indexer_top_k_decode(
|
||||
logits,
|
||||
decode_metadata.seq_lens,
|
||||
1,
|
||||
decode_metadata.seq_lens.reshape(-1),
|
||||
topk_indices,
|
||||
topk_tokens,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user