diff --git a/modules/intel/ipex/__init__.py b/modules/intel/ipex/__init__.py index d165f050e..6e1f5047a 100644 --- a/modules/intel/ipex/__init__.py +++ b/modules/intel/ipex/__init__.py @@ -126,13 +126,15 @@ def ipex_init(): # pylint: disable=too-many-statements torch.cuda.List = torch.xpu.List if torch_version < 2.9: - # torch._int_mm via onednn is supposed to land on pytorch with torch 2.8 or 2.9 - # ipex 2.7+ has experimental torch._int_mm support but uses the cpu with torch.compile and also runs as slow as onednn.qlinear - if (not has_ipex or torch_version <= 2.7) and hasattr(torch.ops, "onednn") and hasattr(torch.ops.onednn, "qlinear_pointwise"): - def onednn_mm(x: torch.Tensor, y: torch.Tensor, output_dtype=torch.float32): - # supports int8, fp32, fp16, and bf16 matmul with accumulation using a different float dtype + # torch._int_mm via onednn quantized matmul is supported with torch 2.9 + # ipex 2.7+ has the same torch._int_mm support as torch 2.9 but doesn't support torch.compile + # torch._int_mm directly uses onednn quantized matmul + # onednn qlinear is a wrapper around onednn quantized matmul + if hasattr(torch.ops, "onednn") and hasattr(torch.ops.onednn, "qlinear_pointwise"): + def onednn_mm(x: torch.Tensor, y: torch.Tensor): + # supports int8, fp32, fp16, and bf16 matmul with accumulation using a different dtype # int8 matmul with onednn is slower than 16 bit with dim_size < 4096 - return torch.ops.onednn.qlinear_pointwise(x, 1.0, 0, y, torch.ones(1, device=y.device), torch.zeros(1, device=y.device), None, 1.0, 0, output_dtype, "none", [], "none") + return torch.ops.onednn.qlinear_pointwise.default(x, 1.0, 0, y, torch.ones(1, device=y.device), torch.zeros(1, device=y.device), None, 1.0, 0, torch.float32, "none", [], "none") torch._int_mm = onednn_mm try: # torch.compile fix