Skip to content

Commit 45e0b25

Browse files
committed
Add function to reverse 4bit weights for HPU
1 parent c9bce2b commit 45e0b25

File tree

1 file changed

+7
-2
lines changed
  • bitsandbytes/backends/hpu

1 file changed

+7
-2
lines changed

bitsandbytes/backends/hpu/ops.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33

44
import torch
55

6-
from bitsandbytes.utils import _reverse_4bit_compress_format
7-
86
from ..._ops import register_kernel
97
from ..utils import GAUDI_SW_VER
108

9+
# convert btw standard 4-bit compression format and ipex compression format
10+
# needed for backward compatibility with older versions of gaudi sw
11+
def _reverse_4bit_compress_format(weight: torch.Tensor):
12+
out_1 = (weight & 0xF0) >> 4
13+
out_2 = (weight & 0xF) << 4
14+
out = out_1 | out_2
15+
return out
1116

1217
@register_kernel("bitsandbytes::dequantize_4bit", "hpu")
1318
def _(

0 commit comments

Comments
 (0)