[CPU][Whisper] Support W4A16 quantized Whisper on the CPU WNA16 kernel (#58268)

Signed-off-by: Harshal Adhav <harshal.adhav@amd.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Li, Jiang <jiang1.li@intel.com>
This commit is contained in:
Harshal Adhav
2026-09-30 13:52:53 +08:00
committed by GitHub
co-authored by Cursor Li, Jiang <jiang1.li@intel.com>
parent fcf4750466
commit 5faf81a429
5 changed files with 144 additions and 15 deletions
+45
View File
@@ -1,12 +1,57 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import pytest
import torch
from vllm.platforms import current_platform
if not current_platform.is_cpu():
pytest.skip("skipping CPU-only tests", allow_module_level=True)
from vllm._custom_ops import cpu_gemm_wna16 # noqa: E402
from vllm.model_executor.kernels.linear.mixed_precision.cpu import ( # noqa: E402
_get_isa_hint,
)
# Isolated runs of cpu_gemm_wna16 can hang unless AMX tiles are initialized.
# Guard so non-AMX hosts still take the vec/rvv path.
if torch.cpu._is_amx_tile_supported():
torch.cpu._init_amx()
@pytest.mark.cpu_test
def test_cpu_gemm_wna16_3d_input():
"""cpu_gemm_wna16 flattens 3D [B, T, K] to 2D and reshapes the output back."""
if not hasattr(torch.ops._C, "cpu_gemm_wna16"):
pytest.skip("cpu_gemm_wna16 op is not available")
B, T, K, N = 2, 5, 64, 64
pack_factor = 8
group_size = 32
dtype = torch.bfloat16
q_weight = torch.zeros(N // 16, K * 16 // pack_factor, dtype=torch.int32)
scales = torch.ones(K // group_size, N, dtype=dtype)
x_3d = torch.randn(B, T, K, dtype=dtype)
x_2d = x_3d.reshape(-1, K)
isa_hint = _get_isa_hint(dtype)
kwargs = dict(
q_weight=q_weight,
scales=scales,
zeros=None,
bias=None,
pack_factor=pack_factor,
isa_hint=isa_hint,
)
out_3d = cpu_gemm_wna16(input=x_3d, **kwargs)
out_2d = cpu_gemm_wna16(input=x_2d, **kwargs)
assert out_3d.shape == (B, T, N)
assert out_2d.shape == (B * T, N)
torch.testing.assert_close(out_3d.reshape(-1, N), out_2d)
MODELS = [
"TheBloke/TinyLlama-1.1B-Chat-v1.0-AWQ",
"Qwen/Qwen1.5-0.5B-Chat-GPTQ-Int4",