[Quantisation] account for nested tensors from quantisers#44228
Open
JonoLF wants to merge 2 commits intohuggingface:mainfrom
Open
[Quantisation] account for nested tensors from quantisers#44228JonoLF wants to merge 2 commits intohuggingface:mainfrom
JonoLF wants to merge 2 commits intohuggingface:mainfrom
Conversation
052c8e5 to
d3485ea
Compare
de3920f to
a2909bd
Compare
SunMarc
reviewed
Feb 27, 2026
Member
SunMarc
left a comment
There was a problem hiding this comment.
Can you add a test for that in quanto ? I think i've added some tests in other quantizers to make sure that the mem calculation is right and it was using get_total_byte_count.
a2909bd to
6986cde
Compare
Contributor
|
View the CircleCI Test Summary for this PR: https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=44228&sha=6986cd |
This was referenced Apr 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
When using a quantisation config with a colpali-engine model like so:
Using 5.3.0.dev0, the following error would occur:
model = BiQwen2_5.from_pretrained( ~~~~~~~~~~~~~~~~~~~~~~~~~^ model_name, ^^^^^^^^^^^ ...<3 lines>... quantization_config=quantisation_config, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ).eval() ^ File ".../.venv/lib/python3.13/site-packages/colpali_engine/models/qwen2_5/biqwen2_5/modeling_biqwen2_5.py", line 27, in from_pretrained return super().from_pretrained(*args, **kwargs, key_mapping=key_mapping) ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../.venv/lib/python3.13/site-packages/transformers/modeling_utils.py", line 4127, in from_pretrained loading_info = model.load_adapter( _adapter_model_path, ...<2 lines>... adapter_kwargs=adapter_kwargs, ) File ".../.venv/lib/python3.13/site-packages/transformers/integrations/peft.py", line 575, in load_adapter loading_info, _ = self._load_pretrained_model( ~~~~~~~~~~~~~~~~~~~~~~~~~~~^ model=self, ^^^^^^^^^^^ ...<2 lines>... load_config=load_config, ^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File ".../.venv/lib/python3.13/site-packages/transformers/modeling_utils.py", line 4175, in _load_pretrained_model caching_allocator_warmup(model, expanded_device_map, load_config.hf_quantizer) ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../.venv/lib/python3.13/site-packages/transformers/modeling_utils.py", line 4731, in caching_allocator_warmup total_byte_count = get_total_byte_count(model, accelerator_device_map, hf_quantizer) File ".../.venv/lib/python3.13/site-packages/transformers/modeling_utils.py", line 4688, in get_total_byte_count param = model.get_parameter_or_buffer(param_name) File ".../.venv/lib/python3.13/site-packages/transformers/modeling_utils.py", line 4592, in get_parameter_or_buffer module, param_name = get_module_from_name(self, target) ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^ File ".../.venv/lib/python3.13/site-packages/transformers/quantizers/quantizers_utils.py", line 21, in get_module_from_name module = module.get_submodule(module_name) File ".../.venv/lib/python3.13/site-packages/torch/nn/modules/module.py", line 732, in get_submodule raise AttributeError("`" + item + "` is not an nn.Module") AttributeError: `weight` is not an nn.ModuleUpon inspection,
get_module_from_name, was assuming that the parameter name was only the string after the last '.' in thetensor_name, and when it got a tensor name like so:tensor_name='visual.blocks.0.attn.qkv.weight._data._data'the check for a module would fail, as it would assume that
_datais the param name, and everything else is the module.What this fix does, is correctly identify that the parameter is
weight._data._databy checking if each possible module name is an instance of a torch module.Since we know get a potentially listed param name, in
get_parameter_or_bufferwe then recurse through the param name to get the leaf param to be returned.pytest tests/utils/test_modeling_utils.pypassed, I'm not entirely sure what else to test.I'm assuming that this was introduced by either the quantisation process, or is a facet of the colpali model, but again, I'm not entirely sure.
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@SunMarc @MekkCyber