Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions bitsandbytes/nn/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,9 @@ def to(self, *args, **kwargs):
if device is not None and device.type != "meta" and self.data.device.type == "cpu":
if device.type != "cpu" or self.data.dtype != torch.int8:
return self._quantize(device)
elif self.data.dtype == torch.int8 and device.type in ("cpu", "xpu") and (ipex_cpu or ipex_xpu):
self.CB = self.data
elif self.data.dtype == torch.int8:
if device.type == "cpu" or (device.type == "xpu" and ipex_xpu):
self.CB = self.data

new_param = Int8Params(
super().to(device=device, dtype=dtype, non_blocking=non_blocking),
Expand Down
9 changes: 5 additions & 4 deletions tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,10 @@ def test_dynamic_blockwise_quantization(self, device, dtype, nested, blocksize,
abserr = sum(diffs) / len(diffs)
relerr = sum(reldiffs) / len(reldiffs)
if signed:
threshold_abserr = 0.0036 if device in ("cpu", "xpu") and (F.ipex_cpu or F.ipex_xpu) else 0.0035
assert abserr < 0.0036
assert relerr < 0.015
else:
assert abserr < 0.00175 if device in ("cpu", "xpu") and (F.ipex_cpu or F.ipex_xpu) else 0.0023
assert abserr < 0.00175 if (device in "cpu") or (device in "xpu" and F.ipex_xpu) else 0.0023
assert relerr < 0.012
assert A2.dtype == dtype

Expand Down Expand Up @@ -172,8 +171,10 @@ def test_blockwise_cpu_large(self, hidden, blocksize):
@pytest.mark.parametrize("bits", range(2, 9), ids=id_formatter("bits"))
@pytest.mark.parametrize("method", ["linear", "fp8", "dynamic"])
def test_few_bit_quant(self, device, bits, method):
if bits != 8 and (device == "cpu" or (device == "xpu" and F.ipex_xpu)):
pytest.skip("CPU/XPU implementation only supports 8 bits")
if device in "cpu" and bits != 8:
pytest.skip("CPU implementation only supports 8 bits")
if device in "xpu" and bits != 8 and F.ipex_xpu:
pytest.skip("XPU ipex implementation only supports 8 bits")

abserrs = []
relerrs = []
Expand Down