Skip to content
Merged
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
2 changes: 1 addition & 1 deletion bitsandbytes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
if torch.cuda.is_available():
from .backends.cuda import ops as cuda_ops

if torch.xpu.is_available():
if hasattr(torch, "xpu") and torch.xpu.is_available():
from .backends.xpu import ops as xpu_ops


Expand Down
8 changes: 6 additions & 2 deletions bitsandbytes/backends/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
1.0,
],
dtype=torch.float32,
device="xpu" if torch.xpu.is_available() else "cpu", # Only cpu/xpu use this table for now.
device="xpu"
if hasattr(torch, "xpu") and torch.xpu.is_available()
else "cpu", # Only cpu/xpu use this table for now.
)
_FP4_QUANT_TABLE = torch.tensor(
[
Expand All @@ -52,6 +54,8 @@
-0.2500,
],
dtype=torch.float32,
device="xpu" if torch.xpu.is_available() else "cpu", # Only cpu/xpu use this table for now.
device="xpu"
if hasattr(torch, "xpu") and torch.xpu.is_available()
else "cpu", # Only cpu/xpu use this table for now.
)
CODE = {"nf4": _NF4_QUANT_TABLE, "fp4": _FP4_QUANT_TABLE}
3 changes: 3 additions & 0 deletions tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,9 @@ def test_gemv_4bit(self, device, dim, dtype, storage_type, quant_storage, double
@pytest.mark.parametrize("dtype", [torch.float16, torch.bfloat16, torch.float32], ids=describe_dtype)
@pytest.mark.parametrize("double_quant", [False], ids=["DQ_True"])
def test_gemv_eye_4bit(self, device, storage_type, dtype, double_quant):
if device == "cpu" and dtype == torch.bfloat16 and torch.__version__ < (2, 3):
pytest.skip("eye doe not support bfloat16 on CPU in torch < 2.3")

dims = 10
torch.random.manual_seed(np.random.randint(0, 412424242))
dims = get_test_dims(0, 8192, n=dims)
Expand Down
5 changes: 2 additions & 3 deletions tests/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,8 @@ def test_quantize_4bit(self, device, dtype, storage_dtype, quant_type, blocksize
assert absmax.device == A.device
assert absmax.dtype == torch.float32

# TODO: Enable it
if device in ("cpu", "xpu") and storage_dtype == torch.bfloat16:
pytest.skip("CPU bf16 storage_dtype will fail on torch op check")
if storage_dtype != torch.uint8:
pytest.xfail("opcheck fails for storage_dtype != torch.uint8")

opcheck(torch.ops.bitsandbytes.quantize_4bit, (A, blocksize, quant_type, storage_dtype))

Expand Down