Unverified Commit 57fc00f3 authored by Wing Lian's avatar Wing Lian Committed by GitHub
Browse files

fix for itemsize => element_size() for torch backwards compat (#30133)



* fix for itemsize => element_size() for torch backwards compat

* improve handling of element counting

* Update src/transformers/modeling_utils.py

* fixup

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

---------
Co-authored-by: default avatarYounes Belkada <49240599+younesbelkada@users.noreply.github.com>
Co-authored-by: default avatarYounes Belkada <younesbelkada@gmail.com>
Co-authored-by: default avataramyeroberts <22614925+amyeroberts@users.noreply.github.com>
parent 77b59dce
...@@ -1160,12 +1160,13 @@ class ModuleUtilsMixin: ...@@ -1160,12 +1160,13 @@ class ModuleUtilsMixin:
# For 4bit models, we need to multiply the number of parameters by 2 as half of the parameters are # For 4bit models, we need to multiply the number of parameters by 2 as half of the parameters are
# used for the 4bit quantization (uint8 tensors are stored) # used for the 4bit quantization (uint8 tensors are stored)
if is_loaded_in_4bit and isinstance(param, bnb.nn.Params4bit): if is_loaded_in_4bit and isinstance(param, bnb.nn.Params4bit):
quant_storage = self.hf_quantizer.quantization_config.bnb_4bit_quant_storage if hasattr(param, "element_size"):
# For compatibility with older PT version - see: https://github.com/huggingface/peft/pull/1635 num_bytes = param.element_size()
nb_params = ( elif hasattr(param, "quant_storage"):
quant_storage.itemsize if hasattr(quant_storage, "itemsize") else quant_storage.element_size() num_bytes = param.quant_storage.itemsize
) else:
total_numel.append(param.numel() * 2 * nb_params) num_bytes = 1
total_numel.append(param.numel() * 2 * num_bytes)
else: else:
total_numel.append(param.numel()) total_numel.append(param.numel())
......
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