Skip to content

Commit d53c8f6

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

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

bitsandbytes/functional.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ def from_dict(cls, qs_dict: dict[str, Any], device: torch.device) -> "QuantState
503503
)
504504
return quant_state
505505

506-
def as_dict(self, packed=False):
506+
def as_dict(self, packed: bool = False) -> dict[str, Any]:
507507
"""
508508
returns dict of tensors and strings to use in serialization via _save_to_state_dict()
509509
param: packed -- returns dict[str, torch.Tensor] for state_dict fit for safetensors saving
@@ -532,7 +532,10 @@ def as_dict(self, packed=False):
532532
# packed format allows serialization of non-tensor components, critical for saving in safetensors format
533533
qs_packed_dict = {k: v for k, v in qs_dict.items() if isinstance(v, torch.Tensor)}
534534
non_tensor_dict = {k: v for k, v in qs_dict.items() if not isinstance(v, torch.Tensor)}
535-
qs_packed_dict["quant_state." + "bitsandbytes__" + self.quant_type] = pack_dict_to_tensor(non_tensor_dict)
535+
key = "quant_state.bitsandbytes__"
536+
if self.quant_type is not None:
537+
key += self.quant_type
538+
qs_packed_dict[key] = pack_dict_to_tensor(non_tensor_dict)
536539
return qs_packed_dict
537540

538541
def to(self, device):

0 commit comments

Comments
 (0)