Skip to content

Commit 2adcb7a

Browse files
authored
Add function to reverse 4bit weights for HPU (#1757)
* Add function to reverse 4bit weights for HPU * Fix lint error
1 parent b2a8a15 commit 2adcb7a

File tree

1 file changed

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

1 file changed

+9
-2
lines changed

bitsandbytes/backends/hpu/ops.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@
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

119

10+
# convert btw standard 4-bit compression format and ipex compression format
11+
# needed for backward compatibility with older versions of gaudi sw
12+
def _reverse_4bit_compress_format(weight: torch.Tensor):
13+
out_1 = (weight & 0xF0) >> 4
14+
out_2 = (weight & 0xF) << 4
15+
out = out_1 | out_2
16+
return out
17+
18+
1219
@register_kernel("bitsandbytes::dequantize_4bit", "hpu")
1320
def _(
1421
A: torch.Tensor,

0 commit comments

Comments
 (0)