Skip to content

Fix mutable default arguments in quantization config classes#45297

Closed
EhteshamSid wants to merge 1 commit intohuggingface:mainfrom
EhteshamSid:fix/mutable-default-args-quantization-config
Closed

Fix mutable default arguments in quantization config classes#45297
EhteshamSid wants to merge 1 commit intohuggingface:mainfrom
EhteshamSid:fix/mutable-default-args-quantization-config

Conversation

@EhteshamSid
Copy link
Copy Markdown

What does this PR do?

Fixes mutable default argument bugs in four quantization config __init__ methods inside quantization_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:

Class Parameter Old default
HqqConfig skip_modules ["lm_head"]
VptqLayerConfig num_centroids [-1, -1]
VptqLayerConfig num_res_centroids [-1, -1]
VptqLayerConfig vector_lens [-1, -1]
VptqConfig config_for_layers {}
VptqConfig shared_layer_config {}
FourOverSixConfig modules_to_not_convert ["lm_head"]

Each default is replaced with None and 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

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.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 7, 2026

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=45297&sha=254def

@Rocketknight1
Copy link
Copy Markdown
Member

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.

@EhteshamSid
Copy link
Copy Markdown
Author

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.

@Rocketknight1
Copy link
Copy Markdown
Member

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants