main
py 51 lines 1.81 KB
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3 """Launch-config selection for the ReplaySSM Mamba2 output_only decode kernel.
4
5 Mirrors ``mamba_ssm.py``: a hard-coded heuristic per kernel, plus an
6 ``override`` context manager for benchmarks/tests/config sweeps. Hardware is
7 auto-detected (Blackwell vs not) so call sites need not thread it through.
8 """
9
10 import functools
11
12 from vllm.platforms import current_platform
13 from vllm.triton_utils import triton
14
15
16 @functools.cache
17 def _is_blackwell() -> bool:
18 try:
19 return current_platform.is_device_capability_family(100)
20 except Exception:
21 return False
22
23
24 # Per-kernel overrides keyed by the kernel name passed to get_replayssm_config.
25 _overrides: dict[str, tuple] = {}
26
27
28 def _dstate_tile(dstate: int, tile: int) -> int:
29 return max(16, min(tile, triton.next_power_of_2(dstate)))
30
31
32 def _mamba2_output_only(dstate, L, is_blackwell):
33 # (block_size_m, num_warps, nf_dstate_tile, fl_dstate_tile, num_stages);
34 # decoupled dstate tiling, serving-batch optimum, dtype-independent per device.
35 if is_blackwell:
36 return 64, 1, _dstate_tile(dstate, 32), _dstate_tile(dstate, 64), 2
37 return 16, 1, _dstate_tile(dstate, 64), _dstate_tile(dstate, 128), 2
38
39
40 def get_replayssm_config(kernel: str, **shape) -> tuple:
41 """Return the launch config for ``kernel`` (override > tuned default).
42
43 kernel: "mamba2_output_only". ``shape`` carries the keying dims (dstate;
44 ``L`` for the buffer length, default 16); hardware is auto-detected.
45 """
46 if kernel in _overrides:
47 return _overrides[kernel]
48 bw = _is_blackwell()
49 if kernel == "mamba2_output_only":
50 return _mamba2_output_only(shape["dstate"], shape.get("L", 16), bw)
51 raise ValueError(f"unknown ReplaySSM kernel config key: {kernel}")