From ac6ff53104e54acbbbfba345eeba9cec37287f4e Mon Sep 17 00:00:00 2001 From: jiqing-feng Date: Tue, 29 Apr 2025 12:42:39 +0000 Subject: [PATCH] fix xpu ipex linear in torch2.7 Signed-off-by: jiqing-feng --- bitsandbytes/utils.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bitsandbytes/utils.py b/bitsandbytes/utils.py index e3748685e..7d56c4ac3 100644 --- a/bitsandbytes/utils.py +++ b/bitsandbytes/utils.py @@ -240,10 +240,16 @@ def enable_ipex_fusion(linear, x): ) elif x.device.type == "xpu" and ipex_xpu and _ipex_xpu_version_prereq(2, 5): converted_weight = reverse_4bit_compress_format(linear.weight.data) - new_weight = converted_weight.reshape([quant_state.shape[0], quant_state.shape[1] // 2]) new_scales = quant_state.absmax.view(quant_state.shape[0], quant_state.shape[1] // quant_state.blocksize) new_zeros = None compensation = None + new_weight = converted_weight.reshape([quant_state.shape[0], quant_state.shape[1] // 2]) + # ipex 2.7 requires new_scales is a list of tensors + if _ipex_xpu_version_prereq(2, 7): + new_scales = list(new_scales) + # ipex 2.7 can dequant converted_weight directly. + if linear.training or x.requires_grad == False: + new_weight = converted_weight else: raise ValueError( "Please check the device and ipex version. The device should be cpu or xpu while ipex version should >= 2.5"