[CPU] Conv1d optimised kernel for aarch64 (#54093)

Signed-off-by: Anna Mayne <anna.mayne@arm.com>
Co-authored-by: Li, Jiang <jiang1.li@intel.com>
This commit is contained in:
almayne
2026-09-30 20:23:42 +08:00
committed by GitHub
co-authored by Li, Jiang <jiang1.li@intel.com>
parent df5668e5c9
commit 93dd80f636
9 changed files with 460 additions and 205 deletions
@@ -6,10 +6,61 @@ import pytest
import torch
from vllm.model_executor.layers import utils
from vllm.platforms import current_platform
from vllm.platforms import CpuArchEnum, current_platform
from vllm.utils.torch_utils import set_default_torch_dtype
def test_dispatch_prepacks_arm_bf16_causal_conv(monkeypatch):
monkeypatch.setattr(
current_platform, "get_cpu_architecture", lambda: CpuArchEnum.ARM
)
monkeypatch.setattr(torch.cpu, "get_capabilities", lambda: {"bf16": True})
monkeypatch.setattr(torch.cpu, "_is_avx512_bf16_supported", lambda: False)
packed = torch.randn(32, 4, dtype=torch.bfloat16)
pack_inputs = []
def pack(weight):
pack_inputs.append(weight.clone())
return packed
monkeypatch.setattr(utils.ops, "causal_conv1d_weight_pack", pack)
original = torch.randn(32, 1, 4, dtype=torch.bfloat16)
layer = torch.nn.Module()
layer.weight = torch.nn.Parameter(original.clone(), requires_grad=False)
utils.dispatch_cpu_unquantized_gemm(layer, remove_weight=False)
assert len(pack_inputs) == 1
# Check causal_conv1d_weight_pack received the expected weights
torch.testing.assert_close(pack_inputs[0], original.view(32, 4))
# Check we have correctly stashed the unpacked weights
torch.testing.assert_close(layer._cpu_unpacked_conv_weight, original.view(32, 4))
# Check we have correctly stored the packed weights
assert layer.weight.data_ptr() == packed.data_ptr()
def test_dispatch_does_not_pack_3d_expert_weight(monkeypatch):
monkeypatch.setattr(
current_platform, "get_cpu_architecture", lambda: CpuArchEnum.ARM
)
monkeypatch.setattr(torch.cpu, "get_capabilities", lambda: {"bf16": True})
monkeypatch.setattr(torch.cpu, "_is_avx512_bf16_supported", lambda: False)
pack_calls = []
monkeypatch.setattr(
utils.ops,
"causal_conv1d_weight_pack",
lambda weight: pack_calls.append(weight),
)
layer = torch.nn.Module()
layer.weight = torch.nn.Parameter(
torch.randn(8, 32, 4, dtype=torch.bfloat16), requires_grad=False
)
utils.dispatch_cpu_unquantized_gemm(layer, remove_weight=False)
assert pack_calls == []
@pytest.fixture(scope="module")
def _mock_zentorch_linear_unary():
"""Register a mock zentorch_linear_unary op when zentorch is not installed.