From 601c8f9a64bde279ebb9b5956a9068f8de5df753 Mon Sep 17 00:00:00 2001 From: Wing Lian Date: Mon, 29 Dec 2025 15:14:24 -0500 Subject: [PATCH 1/2] add guard for self.weight.quant_state attribute --- bitsandbytes/nn/modules.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bitsandbytes/nn/modules.py b/bitsandbytes/nn/modules.py index d3332acfe..caa797813 100644 --- a/bitsandbytes/nn/modules.py +++ b/bitsandbytes/nn/modules.py @@ -515,7 +515,10 @@ def _save_to_state_dict(self, destination, prefix, keep_vars): save weight and bias, then fill state_dict with components of quant_state """ - if getattr(self.weight.quant_state, "packing_format_for_cpu", False): + if ( + getattr(self.weight, "quant_state", None) is not None + and getattr(self.weight.quant_state, "packing_format_for_cpu", False) + ): self.weight.data, self.weight.quant_state = _convert_weight_packed_for_cpu_inverse( self.weight.data, self.weight.quant_state ) From c440c6f59826c8bd2f0aa1f860d6d09f39179105 Mon Sep 17 00:00:00 2001 From: Matthew Douglas <38992547+matthewdouglas@users.noreply.github.com> Date: Wed, 7 Jan 2026 10:41:16 -0500 Subject: [PATCH 2/2] Lint fix --- bitsandbytes/nn/modules.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bitsandbytes/nn/modules.py b/bitsandbytes/nn/modules.py index caa797813..9c0a647cb 100644 --- a/bitsandbytes/nn/modules.py +++ b/bitsandbytes/nn/modules.py @@ -515,9 +515,8 @@ def _save_to_state_dict(self, destination, prefix, keep_vars): save weight and bias, then fill state_dict with components of quant_state """ - if ( - getattr(self.weight, "quant_state", None) is not None - and getattr(self.weight.quant_state, "packing_format_for_cpu", False) + if getattr(self.weight, "quant_state", None) is not None and getattr( + self.weight.quant_state, "packing_format_for_cpu", False ): self.weight.data, self.weight.quant_state = _convert_weight_packed_for_cpu_inverse( self.weight.data, self.weight.quant_state