Skip to content

Commit

Permalink
FIX: Fix 8-bit serialization tests (#30051)
Browse files Browse the repository at this point in the history
* fix 8-bit serialization tests

* add more clarification

* Update src/transformers/quantizers/quantizer_bnb_8bit.py

Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>

---------

Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
  • Loading branch information
2 people authored and Ita Zaporozhets committed May 14, 2024
1 parent 1799b66 commit 8562886
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/transformers/quantizers/quantizer_bnb_8bit.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ def create_quantized_param(
import bitsandbytes as bnb

fp16_statistics_key = param_name.replace("weight", "SCB")
fp16_weights_format_key = param_name.replace("weight", "weight_format")

fp16_statistics = state_dict.get(fp16_statistics_key, None)
fp16_weights_format = state_dict.get(fp16_weights_format_key, None)

module, tensor_name = get_module_from_name(model, param_name)
if tensor_name not in module._parameters:
Expand Down Expand Up @@ -210,6 +213,11 @@ def create_quantized_param(
if unexpected_keys is not None:
unexpected_keys.remove(fp16_statistics_key)

# We just need to pop the `weight_format` keys from the state dict to remove unneeded
# messages. The correct format is correctly retrieved during the first forward pass.
if fp16_weights_format is not None and unexpected_keys is not None:
unexpected_keys.remove(fp16_weights_format_key)

def _process_model_after_weight_loading(self, model: "PreTrainedModel", **kwargs):
model.is_loaded_in_8bit = True
model.is_8bit_serializable = self.is_serializable
Expand Down

0 comments on commit 8562886

Please sign in to comment.