Fix mutable default arguments in quantization config classes#45297
Fix mutable default arguments in quantization config classes#45297EhteshamSid wants to merge 1 commit intohuggingface:mainfrom
Conversation
Mutable default arguments (list/dict literals) are shared across all calls when the default is used, which can cause silent state leakage between instantiations. Replaced with None sentinel defaults and initialized to fresh instances in the function body. Affected classes: HqqConfig, VptqLayerConfig, VptqConfig, FourOverSixConfig - params skip_modules, num_centroids, num_res_centroids, vector_lens, config_for_layers, shared_layer_config, modules_to_not_convert.
|
View the CircleCI Test Summary for this PR: https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=45297&sha=254def |
|
Are there any cases where these args actually get mutated? If not, we'd prefer not to handle this right now. Due to the agent flood, we're trying to cut down on PRs that don't add features or fix real bugs; we'll delegate this kind of repo cleanup to internal agents later. |
|
I checked the codebase - these defaults aren't mutated anywhere after assignment, so there's no actual runtime bug. Happy to close this if you'd prefer to handle cleanup internally. |
|
Yes, we'll leave it for now! Thank you for the PR, though - we'd definitely have accepted this a few months ago, but right now we're really trying to control the volume of submissions to make it possible for our reviewers to function. Code agents have changed a lot about how open source works! |
What does this PR do?
Fixes mutable default argument bugs in four quantization config
__init__methods insidequantization_config.py.In Python, mutable objects used as default argument values (e.g.
=[],={}) are created once at function definition time and shared across all calls that rely on the default. This means if any caller mutates the object, every subsequent call without an explicit argument sees the modified value - a subtle and hard-to-trace bug.Affected classes and parameters:
HqqConfigskip_modules["lm_head"]VptqLayerConfignum_centroids[-1, -1]VptqLayerConfignum_res_centroids[-1, -1]VptqLayerConfigvector_lens[-1, -1]VptqConfigconfig_for_layers{}VptqConfigshared_layer_config{}FourOverSixConfigmodules_to_not_convert["lm_head"]Each default is replaced with
Noneand a guard at the top of__init__assigns a fresh instance, so every call gets its own object. Runtime behavior is unchanged for callers that do not pass the argument explicitly.Before submitting