From adc72d50f77940d303044d683d062e9b1c2d3bb2 Mon Sep 17 00:00:00 2001 From: ailuntz Date: Tue, 10 Mar 2026 16:04:36 +0800 Subject: [PATCH] Replace asserts with errors --- bitsandbytes/autograd/_functions.py | 3 ++- bitsandbytes/functional.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/bitsandbytes/autograd/_functions.py b/bitsandbytes/autograd/_functions.py index b34f4a943..0258768e2 100644 --- a/bitsandbytes/autograd/_functions.py +++ b/bitsandbytes/autograd/_functions.py @@ -378,7 +378,8 @@ def matmul_4bit( out: Optional[torch.Tensor] = None, bias: Optional[torch.Tensor] = None, ): - assert quant_state is not None + if quant_state is None: + raise ValueError("quant_state cannot be None") # Change dtype to input dtype on CPU if A.device.type == "cpu": quant_state.dtype = A.dtype diff --git a/bitsandbytes/functional.py b/bitsandbytes/functional.py index 6ce846277..22109c3d2 100644 --- a/bitsandbytes/functional.py +++ b/bitsandbytes/functional.py @@ -707,7 +707,8 @@ def dequantize_blockwise( The dequantized tensor. The datatype is indicated by `quant_state.dtype` and defaults to `torch.float32`. """ - assert quant_state is not None or absmax is not None + if quant_state is None and absmax is None: + raise ValueError("Either quant_state or absmax must be provided") if code is None and quant_state is None: if "dynamic" not in name2qmap: name2qmap["dynamic"] = create_dynamic_map().to(A.device)