Unverified Commit b86d0f4e authored by Younes Belkada's avatar Younes Belkada Committed by GitHub
Browse files

FIX: Fix 8-bit serialization tests (#30051)



* fix 8-bit serialization tests

* add more clarification

* Update src/transformers/quantizers/quantizer_bnb_8bit.py
Co-authored-by: default avataramyeroberts <22614925+amyeroberts@users.noreply.github.com>

---------
Co-authored-by: default avataramyeroberts <22614925+amyeroberts@users.noreply.github.com>
parent ddf5f258
...@@ -171,7 +171,10 @@ class Bnb8BitHfQuantizer(HfQuantizer): ...@@ -171,7 +171,10 @@ class Bnb8BitHfQuantizer(HfQuantizer):
import bitsandbytes as bnb import bitsandbytes as bnb
fp16_statistics_key = param_name.replace("weight", "SCB") 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_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) module, tensor_name = get_module_from_name(model, param_name)
if tensor_name not in module._parameters: if tensor_name not in module._parameters:
...@@ -210,6 +213,11 @@ class Bnb8BitHfQuantizer(HfQuantizer): ...@@ -210,6 +213,11 @@ class Bnb8BitHfQuantizer(HfQuantizer):
if unexpected_keys is not None: if unexpected_keys is not None:
unexpected_keys.remove(fp16_statistics_key) 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): def _process_model_after_weight_loading(self, model: "PreTrainedModel", **kwargs):
model.is_loaded_in_8bit = True model.is_loaded_in_8bit = True
model.is_8bit_serializable = self.is_serializable model.is_8bit_serializable = self.is_serializable
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment