Skip to content

@dataclass on quant configs breaks __eq__/__repr__/hashing, and to_json_string() raises for most configs #15126

Open

Description

@OnePunchMonk

Describe the bug

Every quantization config subclass in src/diffusers/quantizers/quantization_config.py is decorated with @dataclass, but each has a custom __init__ and declares no dataclass fields beyond the inherited quant_method. @dataclass still generates __eq__/__repr__ from the declared fields it sees, so:

  • GGUFQuantizationConfig(compute_dtype=torch.float16) == GGUFQuantizationConfig(compute_dtype=torch.bfloat16) is True.
  • The configs are unhashable.
  • repr() hides every real parameter for GGUF, BFL, Nunchaku, Quanto, ModelOpt, and AutoRound configs.

Separately, to_json_string() calls self.to_diff_dict(), which only BitsAndBytesConfig defines — every other config raises AttributeError when to_json_string() is called (which is the default use_diff=True path).

Reproduction

import torch
from diffusers.quantizers.quantization_config import GGUFQuantizationConfig, QuantoConfig

a = GGUFQuantizationConfig(compute_dtype=torch.float16)
b = GGUFQuantizationConfig(compute_dtype=torch.bfloat16)
print(a == b)       # True - should be False
print(repr(a))       # "GGUFQuantizationConfig(quant_method=<QuantizationMethod.GGUF: 'gguf'>)" - compute_dtype is missing
hash(a)               # TypeError: unhashable type: 'GGUFQuantizationConfig'

QuantoConfig(weights_dtype="int8").to_json_string()
# AttributeError: 'QuantoConfig' object has no attribute 'to_diff_dict'

Logs

Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: unhashable type: 'GGUFQuantizationConfig'
Traceback (most recent call last):
  File ".../diffusers/src/diffusers/quantizers/quantization_config.py", line 144, in to_json_string
    config_dict = self.to_diff_dict()
                  ^^^^^^^^^^^^^^^^^
AttributeError: 'QuantoConfig' object has no attribute 'to_diff_dict'

System Info

  • diffusers @ main, commit aaf57d0
  • Python 3.12, Linux

Who can help?

(leaving blank — no specific quantization reviewer listed in the template's tag guide)

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