From 394ff86965a64f0a337d2a8860eae0d2d70607e6 Mon Sep 17 00:00:00 2001 From: Yan Ma Date: Sun, 12 Apr 2026 10:46:28 +0800 Subject: [PATCH] [XPU][CT] support per-channel quantization in xpu fp8 linear method (#38316) Signed-off-by: Yan Ma --- vllm/model_executor/kernels/linear/__init__.py | 2 +- vllm/model_executor/kernels/linear/scaled_mm/xpu.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/vllm/model_executor/kernels/linear/__init__.py b/vllm/model_executor/kernels/linear/__init__.py index c7b159c923..b032f863d5 100644 --- a/vllm/model_executor/kernels/linear/__init__.py +++ b/vllm/model_executor/kernels/linear/__init__.py @@ -204,7 +204,7 @@ _POSSIBLE_WFP8A16_KERNELS: dict[PlatformEnum, list[type[FP8ScaledMMLinearKernel] # To be added ], PlatformEnum.XPU: [ - # To be added + XPUFP8ScaledMMLinearKernel, ], } diff --git a/vllm/model_executor/kernels/linear/scaled_mm/xpu.py b/vllm/model_executor/kernels/linear/scaled_mm/xpu.py index b16ee16997..6d75a420e7 100644 --- a/vllm/model_executor/kernels/linear/scaled_mm/xpu.py +++ b/vllm/model_executor/kernels/linear/scaled_mm/xpu.py @@ -9,6 +9,11 @@ from vllm.model_executor.kernels.linear import ( # noqa: E501 FP8ScaledMMLinearKernel, FP8ScaledMMLinearLayerConfig, ) +from vllm.model_executor.layers.quantization.utils.quant_utils import ( + kFp8StaticChannelSym, + kFp8StaticTensorSym, +) +from vllm.model_executor.utils import replace_parameter from vllm.platforms import current_platform @@ -23,6 +28,11 @@ class XPUFP8ScaledMMLinearKernel(FP8ScaledMMLinearKernel): @classmethod def can_implement(cls, c: FP8ScaledMMLinearLayerConfig) -> tuple[bool, str | None]: + if c.weight_quant_key not in {kFp8StaticChannelSym, kFp8StaticTensorSym}: + return ( + False, + "XPUFP8ScaledMM only support per-channel and per-tensor quantization", + ) if c.weight_quant_key.dtype not in {torch.float8_e5m2, torch.float8_e4m3fn}: return False, "XPUFP8ScaledMM only support FP8 weight dtype" return True, None @@ -35,6 +45,9 @@ class XPUFP8ScaledMMLinearKernel(FP8ScaledMMLinearKernel): self.config = c self.layer_param_names = layer_param_names + def process_weights_after_loading(self, layer: torch.nn.Module) -> None: + replace_parameter(layer, "weight", layer.weight.data.t()) + def apply_weights( self, layer: torch.nn.Module,