[CPU] Add CPU FP8 W8A8 linear/MoE support (#49942)

Signed-off-by: yuwenzho <yuwen.zhou@intel.com>
Co-authored-by: Li, Jiang <jiang1.li@intel.com>
This commit is contained in:
Yuwen Zhou
2026-09-18 17:59:42 +08:00
committed by GitHub
co-authored by Li, Jiang <jiang1.li@intel.com>
parent 6df2b1a8c6
commit b346479065
20 changed files with 2924 additions and 46 deletions
+44
View File
@@ -2,6 +2,7 @@
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from enum import IntEnum
from functools import cache
from typing import TYPE_CHECKING, Literal
import torch
@@ -3384,6 +3385,7 @@ class CPUQuantMethod(IntEnum):
FP8_W8A16 = 2
INT4_W4A8 = 3
MXFP4 = 4
FP8_W8A8 = 5
if hasattr(torch.ops._C, "dynamic_4bit_int_moe"):
@@ -3422,6 +3424,7 @@ def fused_experts_cpu(
alpha: float | None = None,
limit: float | None = None,
is_vnni: bool = True,
a1_scale: torch.Tensor | None = None,
) -> None:
torch.ops._C.fused_experts_cpu(
out,
@@ -3435,6 +3438,7 @@ def fused_experts_cpu(
w2_scale,
w1_zero,
w2_zero,
a1_scale,
block_size,
w1_bias,
w2_bias,
@@ -3564,6 +3568,46 @@ def fp8_scaled_mm_cpu(
)
# FP8 W8A8 CPU kernels
@cache
def cpu_has_amx_fp8() -> bool:
"""Whether this CPU has native AMX-FP8 MMA support."""
if not hasattr(torch.ops._C, "cpu_has_amx_fp8"):
return False
return bool(torch.ops._C.cpu_has_amx_fp8())
if hasattr(torch.ops._C, "fp8_scaled_mm_with_quant"):
@register_fake("_C::fp8_scaled_mm_with_quant")
def fp8_scaled_mm_with_quant_fake(
act: torch.Tensor,
act_scales: torch.Tensor | None,
channelwise: bool,
weight: torch.Tensor,
weight_scales: torch.Tensor,
bias: torch.Tensor | None,
output_dtype: torch.dtype,
) -> torch.Tensor:
M = act.reshape(-1, act.size(-1)).size(0)
N = weight.size(0) * weight.size(-1)
return torch.empty((M, N), dtype=output_dtype, device=act.device)
def fp8_scaled_mm_with_quant(
act: torch.Tensor,
act_scales: torch.Tensor | None,
channelwise: bool,
weight: torch.Tensor,
weight_scales: torch.Tensor,
bias: torch.Tensor | None,
output_dtype: torch.dtype,
) -> torch.Tensor:
return torch.ops._C.fp8_scaled_mm_with_quant(
act, act_scales, channelwise, weight, weight_scales, bias, output_dtype
)
def chunk_gated_delta_rule_cpu(
query: torch.Tensor,
key: torch.Tensor,