Skip to content

fix(config): avoid mutating dynamic overrides in to_dict - #3442

Merged
Qubitium merged 1 commit into
ModelCloud:mainfrom
anh-nguyenn:fix/quant-config-to-dict-mutation
Oct 26, 2026
Merged

Qubitium merged 1 commit into
ModelCloud:mainfrom
anh-nguyenn:fix/quant-config-to-dict-mutation

Conversation

@anh-nguyenn

Copy link
Copy Markdown
Contributor

Fixes #3440

Summary

BaseQuantizeConfig.to_dict() published out["dynamic"] = self.dynamic and then removed "adapter" and rewrote "bits" in each dynamic layer dict in place. Serializing a config therefore mutated the live config and dropped per-layer adapter rank overrides, which breaks extract_adapter_rank_patterns() and any later save/load step that relies on them.

What Changed

  • Deep-copy self.dynamic before building the serialized payload, so the in-memory config keeps its adapter overrides.
  • Keep the serialized payload behavior unchanged: adapter overrides are omitted from the emitted dynamic entries and bits are serialized normally.
  • Add a regression test asserting that to_dict() leaves qconfig.dynamic and extract_adapter_rank_patterns() intact.

Tests

Before the fix (test run against main config implementation):

python -m pytest -q tests/test_adapter_config.py::TestExtensionConfig::test_to_dict_does_not_mutate_dynamic_adapter_overrides --timeout=120
# 1 failed
# AssertionError: qconfig.dynamic == {'...': {'bits': 8}} != {'...': {'bits': 8, 'adapter': {'rank': 16}}}

After the fix:

python -m pytest -q tests/test_adapter_config.py tests/test_serialization.py -k "TestExtensionConfig or legacy or meta_only or gptaq_config_none or awq_scale_search" --timeout=180
# 9 passed, 3 deselected in 4.29s

python -m ruff check --config format/ruff.toml gptqmodel/quantization/config.py tests/test_adapter_config.py
# All checks passed!

GPU validation: not applicable. This is a pure config-serialization fix and the regression test is CPU-only.

AI assistance

This PR was prepared with AI assistance (opencode) and reviewed against the repository conventions. There is no AI co-author trailer.

Labels

This account does not have label permissions. Please add the bug label (and any required triage labels) when reviewing.

to_dict() reused self.dynamic for the serialized payload and then removed adapter keys and serialized bits in place. This dropped per-layer adapter rank overrides from the live config. Serialize a deep copy instead.

Signed-off-by: Anh Nguyen (Jerry) <[email protected]>

@Qubitium Qubitium left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anh-nguyenn Thank you! LGTM

@Qubitium
Qubitium merged commit 7f29eeb into ModelCloud:main Oct 26, 2026
1 check passed
@anh-nguyenn
anh-nguyenn deleted the fix/quant-config-to-dict-mutation branch October 26, 2026 23:02
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.

[BUG] QuantizeConfig.to_dict() mutates config.dynamic and drops adapter overrides

2 participants