Skip to content

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

Closed

Description

@anh-nguyenn

Describe the bug

BaseQuantizeConfig.to_dict() publishes out["dynamic"] = self.dynamic and then mutates each dynamic layer dict in place: it removes the "adapter" key and replaces "bits" with its serialized form. Serializing a config therefore changes the live config object and drops per-layer adapter overrides.

To Reproduce

from gptqmodel import QuantizeConfig
from gptqmodel.adapter.adapter import Lora

qconfig = QuantizeConfig(
    bits=4,
    group_size=128,
    adapter=Lora(rank=8),
    dynamic={
        "model.layers.0.self_attn.q_proj": {
            "bits": 8,
            "adapter": {"rank": 16},
        }
    },
)

print("before:", qconfig.dynamic)
print("rank patterns before:", qconfig.extract_adapter_rank_patterns())
payload = qconfig.to_dict()
print("payload dynamic:", payload["dynamic"])
print("after:", qconfig.dynamic)
print("rank patterns after:", qconfig.extract_adapter_rank_patterns())

Actual:

before: {'model.layers.0.self_attn.q_proj': {'bits': 8, 'adapter': {'rank': 16}}}
rank patterns before: {'model.layers.0.self_attn.q_proj': 16}
payload dynamic: {'model.layers.0.self_attn.q_proj': {'bits': 8}}
after: {'model.layers.0.self_attn.q_proj': {'bits': 8}}
rank patterns after: {}

Expected: to_dict() is a read-only serialization operation. The returned payload should contain the serialized dynamic entry (without the in-memory-only adapter override), while qconfig.dynamic keeps the adapter override and qconfig.extract_adapter_rank_patterns() still returns {'model.layers.0.self_attn.q_proj': 16} afterwards.

Expected behavior

to_dict() must not mutate self.dynamic; it should build a detached serialized copy of each dynamic layer entry.

Environment

  • Python 3.12.3
  • torch 2.8.0+cu128
  • GPT-QModel main @ cc0c7ba

The reproduction is CPU-only; no model download or GPU is required.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions