From 73723b707fe4b5ba99271ef3cbd3d3ad20d36000 Mon Sep 17 00:00:00 2001 From: stefankoncarevic Date: Tue, 1 Sep 2026 21:48:45 +0200 Subject: [PATCH] [ROCm][MoE] Fix gfx950 block scale swizzle for AITER Triton MXFP4 W4A16 (#54773) Signed-off-by: Stefan Koncarevic --- .../fused_moe/experts/aiter_mxfp4_w4a16_moe.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/vllm/model_executor/layers/fused_moe/experts/aiter_mxfp4_w4a16_moe.py b/vllm/model_executor/layers/fused_moe/experts/aiter_mxfp4_w4a16_moe.py index 3a0bdf428b..e14e54922a 100644 --- a/vllm/model_executor/layers/fused_moe/experts/aiter_mxfp4_w4a16_moe.py +++ b/vllm/model_executor/layers/fused_moe/experts/aiter_mxfp4_w4a16_moe.py @@ -152,6 +152,9 @@ def aiter_triton_kernel_w4a16_moe_forward( score_mode: str | None = None, ): assert quant_config is not None and rocm_aiter_ops.is_enabled() + from vllm.model_executor.layers.quantization.utils.mxfp4_utils import ( + should_use_cdna4_mx_scale_swizzle, + ) from vllm.platforms.rocm import on_gfx1250 try: @@ -245,6 +248,11 @@ def aiter_triton_kernel_w4a16_moe_forward( # SILU: silu(gate) * up — same kernel, just no "+1" residual in swiglu. swiglu_add_residual = activation != MoEActivation.SILU + # Weight loading already swizzled the block scales on gfx950, so the kernel + # has to be told; the load-time swizzle and this gate must agree or the + # kernel indexes a swizzled buffer as if it were linear. + swz = "CDNA4_SCALE" if should_use_cdna4_mx_scale_swizzle() else None + intermediate = moe_gemm_a16w4( hidden_states, w1_data, @@ -256,7 +264,7 @@ def aiter_triton_kernel_w4a16_moe_forward( routing_data, gather_indx=gather_idx, gammas=gammas if apply_router_weight_on_input else None, - swizzle_mx_scale=None, + swizzle_mx_scale=swz, apply_swiglu=True, alpha=swiglu_alpha, limit=swiglu_limit, @@ -276,7 +284,7 @@ def aiter_triton_kernel_w4a16_moe_forward( routing_data, scatter_indx=scatter_idx, gammas=None if apply_router_weight_on_input else gammas, - swizzle_mx_scale=None, + swizzle_mx_scale=swz, unpadded_N=unpadded_N_w2, unpadded_K=unpadded_K_w2, )