Skip to content

Commit f5f91a1

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

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
@@ -501,7 +501,7 @@ def from_dict(cls, qs_dict: dict[str, Any], device: torch.device) -> "QuantState
501501
)
502502
return quant_state
503503

504-
def as_dict(self, packed=False):
504+
def as_dict(self, packed: bool = False) -> dict[str, Any]:
505505
"""
506506
returns dict of tensors and strings to use in serialization via _save_to_state_dict()
507507
param: packed -- returns dict[str, torch.Tensor] for state_dict fit for safetensors saving
@@ -530,7 +530,10 @@ def as_dict(self, packed=False):
530530
# packed format allows serialization of non-tensor components, critical for saving in safetensors format
531531
qs_packed_dict = {k: v for k, v in qs_dict.items() if isinstance(v, torch.Tensor)}
532532
non_tensor_dict = {k: v for k, v in qs_dict.items() if not isinstance(v, torch.Tensor)}
533-
qs_packed_dict["quant_state." + "bitsandbytes__" + self.quant_type] = pack_dict_to_tensor(non_tensor_dict)
533+
key = "quant_state.bitsandbytes__"
534+
if self.quant_type is not None:
535+
key += self.quant_type
536+
qs_packed_dict[key] = pack_dict_to_tensor(non_tensor_dict)
534537
return qs_packed_dict
535538

536539
def to(self, device):

0 commit comments

Comments
 (0)