From b209b8f7b683f65afef659088e71c34ad745de47 Mon Sep 17 00:00:00 2001 From: Yina Chen <33650826+cyita@users.noreply.github.com> Date: Thu, 7 Sep 2023 23:56:36 +0800 Subject: [PATCH] [LLM] Fix arc qtype != q4_0 generate issue (#8920) * Fix arc precision!=q4_0 generate issue * meet comments --- .../llm/src/bigdl/llm/transformers/low_bit_linear.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/python/llm/src/bigdl/llm/transformers/low_bit_linear.py b/python/llm/src/bigdl/llm/transformers/low_bit_linear.py index 241f6109..2a040bf0 100644 --- a/python/llm/src/bigdl/llm/transformers/low_bit_linear.py +++ b/python/llm/src/bigdl/llm/transformers/low_bit_linear.py @@ -98,7 +98,10 @@ def ggml_q_format_convet_cpu2xpu(tensor: torch.Tensor, num_elem: int, qtype: int src = ctypes.c_void_p(tensor.data.data_ptr()) - dst_tensor = torch.empty_like(tensor) + if qtype == ggml_tensor_qtype["sym_int4"]: + dst_tensor = torch.empty_like(tensor) + else: + return tensor dst = ctypes.c_void_p(dst_tensor.data.data_ptr()) ggml.ggml_q_format_convet_cpu2xpu(src, dst, num_elem, qtype) return dst_tensor @@ -114,7 +117,10 @@ def ggml_q_format_convet_xpu2cpu(tensor: torch.Tensor, num_elem: int, qtype: int src = ctypes.c_void_p(tensor.data.data_ptr()) - dst_tensor = torch.empty_like(tensor) + if qtype == ggml_tensor_qtype["sym_int4"]: + dst_tensor = torch.empty_like(tensor) + else: + return tensor dst = ctypes.c_void_p(dst_tensor.data.data_ptr()) ggml.ggml_q_format_convet_xpu2cpu(src, dst, num_elem, qtype) return dst_tensor