Skip to content

Commit 9b7b373

Browse files
committed
Fix QuantState.from_dict
Signed-off-by: cyy <[email protected]>
1 parent a47a40e commit 9b7b373

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

bitsandbytes/functional.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -464,12 +464,13 @@ def from_dict(cls, qs_dict: dict[str, Any], device: torch.device) -> "QuantState
464464

465465
# unpacking tensor with non-tensor components
466466
qs_key = [k for k, v in qs_dict.items() if "quant_state" in k and isinstance(v, torch.Tensor)]
467-
if not len(qs_key) and "quant_type" not in qs_dict:
468-
raise ValueError("Expected packed or unpacked quant_state items, found neither")
469-
elif len(qs_key) != 1 or qs_key[0].split(".")[-1] not in cls.valid_qs_type_keys:
470-
raise ValueError(
471-
f"There should be exactly one `quant_state` item with ending from {cls.valid_qs_type_keys}.\nDetected {qs_key}.",
472-
)
467+
if "quant_type" not in qs_dict:
468+
if not qs_key:
469+
raise ValueError("Expected packed or unpacked quant_state items, found neither")
470+
elif len(qs_key) != 1 or qs_key[0].split(".")[-1] not in cls.valid_qs_type_keys:
471+
raise ValueError(
472+
f"There should be exactly one `quant_state` item with ending from {cls.valid_qs_type_keys}.\nDetected {qs_key}.",
473+
)
473474

474475
# unpacking minor and non-tensor quant state items if necessary
475476
if len(qs_key) == 1:

0 commit comments

Comments
 (0)