Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7895241
feat: first version of bpreshuffle gemm implementation
simondanielsson Aug 10, 2026
749d421
Merge remote-tracking branch 'upstream/main' into orchestrator/aiter-…
simondanielsson Aug 10, 2026
960def5
fix: simplify
simondanielsson Aug 10, 2026
89115b3
fix: remove envvar gate
simondanielsson Aug 10, 2026
579cb71
fix: use aiter's group_fp8_quant(transpose_scale=True) to avoid segfault
simondanielsson Aug 11, 2026
f285864
fix: remove redundant attribute assignment
simondanielsson Aug 11, 2026
af6f0ce
fix: layout of A scales
simondanielsson Aug 12, 2026
80844c4
fix: only select bpreshuffle if tuned
simondanielsson Aug 12, 2026
9d3508e
chore: improve comments
simondanielsson Aug 12, 2026
54f5a11
fix: remove redundant try-except
simondanielsson Aug 12, 2026
9acb005
Merge branch 'vllm-project:main' into feat/bpreshuffle-gemm
simondanielsson Aug 12, 2026
29cd5cb
Merge branch 'main' into feat/bpreshuffle-gemm
simondanielsson Aug 14, 2026
0146384
Merge branch 'main' into feat/bpreshuffle-gemm
simondanielsson Aug 17, 2026
eedab7a
Merge branch 'main' into feat/bpreshuffle-gemm
simondanielsson Aug 18, 2026
5d1610d
chore: generalize _load_gemm_tuned_configs
simondanielsson Aug 20, 2026
7752ecb
Merge branch 'feat/bpreshuffle-gemm' of github.com:simondanielsson/vl…
simondanielsson Aug 20, 2026
e37dbe6
refactor: into AiterPreshuffledFp8BlockScaledMMKernel
simondanielsson Aug 20, 2026
cddfaa6
Merge branch 'main' into feat/bpreshuffle-gemm
simondanielsson Aug 20, 2026
eb9c5b8
Merge branch 'main' into feat/bpreshuffle-gemm
simondanielsson Aug 24, 2026
8a7fa0c
Merge branch 'main' into feat/bpreshuffle-gemm
simondanielsson Aug 28, 2026
a206b14
Merge branch 'main' into feat/bpreshuffle-gemm
simondanielsson Aug 31, 2026
d1e9f01
Merge branch 'main' into feat/bpreshuffle-gemm
simondanielsson Sep 7, 2026
fab8bb3
chore: wrap string literals in parens
simondanielsson Sep 7, 2026
0e39079
Merge branch 'main' into feat/bpreshuffle-gemm
simondanielsson Sep 7, 2026
5ee0170
Merge branch 'main' into feat/bpreshuffle-gemm
tjtanaa Sep 8, 2026
fd1f929
Merge branch 'main' into feat/bpreshuffle-gemm
simondanielsson Sep 9, 2026
dacd2d1
Merge branch 'main' into feat/bpreshuffle-gemm
simondanielsson Sep 10, 2026
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
32 changes: 27 additions & 5 deletions vllm/_aiter_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,18 +171,26 @@ def is_aiter_found_and_supported_on_rdna4() -> bool:

@functools.cache
def _load_gemm_tuned_configs(
q_dtype_w: torch.dtype, csv_path: str
) -> set[tuple[int, int, int]]:
csv_path: str,
filters: tuple[tuple[str, object], ...],
key_cols: tuple[str, ...] = ("N", "K", "M"),
) -> set[tuple[int, ...]]:
try:
df = pd.read_csv(csv_path).drop_duplicates()
df = df[df["q_dtype_w"] == str(q_dtype_w)]
return set(zip(df["N"].astype(int), df["K"].astype(int), df["M"].astype(int)))
for col, val in filters:
if col not in df.columns:
continue
if isinstance(val, int):
df = df[df[col].astype(int) == val]
else:
df = df[df[col].astype(str) == str(val)]
return set(zip(*(df[c].astype(int) for c in key_cols)))
except Exception:
return set()


def _check_kernel_tuned(N: int, K: int, q_dtype_w: torch.dtype, csv_path: str) -> bool:
configs = _load_gemm_tuned_configs(q_dtype_w, csv_path)
configs = _load_gemm_tuned_configs(csv_path, (("q_dtype_w", q_dtype_w),))
l_m = (
[1, 2, 4]
+ list(range(8, 513, 8))
Expand Down Expand Up @@ -3027,6 +3035,20 @@ def is_per_token_w8a8_gemm_tuned(N: int, K: int, q_dtype_w: torch.dtype) -> bool
csv_path = aiter_gemm_a8w8_ops.AITER_CONFIGS.AITER_CONFIG_GEMM_A8W8_FILE
return _check_kernel_tuned(N, K, q_dtype_w, csv_path)

@staticmethod
def is_blockscale_bpreshuffle_tuned(n: int, k: int) -> bool:
"""Whether (N, K) has a tuned aiter blockscale bpreshuffle config."""
if not current_platform.is_rocm():
return False
import aiter.ops.gemm_op_a8w8 as aiter_gemm_a8w8_ops

csv_path = aiter_gemm_a8w8_ops.AITER_CONFIGS.AITER_CONFIG_GEMM_A8W8_BLOCKSCALE_BPRESHUFFLE_FILE
gfx = aiter_gemm_a8w8_ops.get_gfx()
cu_num = aiter_gemm_a8w8_ops.get_cu_num()
return (n, k) in _load_gemm_tuned_configs(
csv_path, (("gfx", gfx), ("cu_num", cu_num)), key_cols=("N", "K")
)

@staticmethod
def shuffle_weight(
tensor: torch.Tensor, layout: tuple[int, int] = (16, 16)
Expand Down
57 changes: 57 additions & 0 deletions vllm/model_executor/kernels/linear/scaled_mm/aiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,15 @@ def __init__(self, config: FP8ScaledMMLinearLayerConfig):
rocm_aiter_ops.is_triton_gemm_w8a8_tuned(n, k) or _on_gfx1250
)

# bpreshuffle GEMM requires an fp8 2D weight with N and K divisible by 128.
# Require tuned config as fallback can trigger faults or numerical errors.
self._is_bpreshuffled = (
rocm_aiter_ops.is_linear_fp8_enabled()
and n % 128 == 0
and k % 128 == 0
and rocm_aiter_ops.is_blockscale_bpreshuffle_tuned(n, k)
)

def process_weights_after_loading(self, layer: torch.nn.Module) -> None:
super().process_weights_after_loading(layer)

Expand All @@ -395,6 +404,28 @@ def process_weights_after_loading(self, layer: torch.nn.Module) -> None:
if ws is not None and ws.dtype == torch.float8_e8m0fnu:
replace_parameter(layer, attr, _upcast_e8m0_to_fp32(ws).contiguous())

if not self._is_bpreshuffled:
Comment thread
simondanielsson marked this conversation as resolved.
Resolved
return

weight = params.weight
if (
weight.dim() != 2
or weight.dtype != current_platform.fp8_dtype()
or weight.shape[0] % 128 != 0
or weight.shape[1] % 128 != 0
):
self._is_bpreshuffled = False
return

shuffled_weight = rocm_aiter_ops.shuffle_weight(
weight.contiguous(), layout=(16, 16)
)
replace_parameter(
layer,
params.WEIGHT,
torch.nn.Parameter(shuffled_weight.data, requires_grad=False),
)

@classmethod
def is_supported(cls, compute_capability=None):
if (
Expand Down Expand Up @@ -433,6 +464,32 @@ def can_implement(cls, config: FP8ScaledMMLinearLayerConfig):
)
return True, None

def apply_weights(
self,
layer: torch.nn.Module,
x: torch.Tensor,
bias: torch.Tensor | None = None,
**kwargs,
) -> torch.Tensor:
if not self._is_bpreshuffled:
return super().apply_weights(layer, x, bias, **kwargs)

params = self._get_layer_params(layer)
Bs = (
params.weight_scale
if params.weight_scale_inv is None
else params.weight_scale_inv
)

x_2d = x.view(-1, x.shape[-1])
A, As = rocm_aiter_ops.group_fp8_quant(x_2d, transpose_scale=True)
output = rocm_aiter_ops.gemm_a8w8_blockscale_bpreshuffle(
A, params.weight, As, Bs, output_dtype=self.config.out_dtype
)
if bias is not None:
output = output + bias
return output.view(*x.shape[:-1], params.weight.shape[0])

def apply_block_scaled_mm(
self,
A: torch.Tensor,
Expand Down
Loading