Skip to content

Commit b5dab2f

Browse files
BenjaminBossanBernardZach
authored andcommitted
FIX: Broken repr of TorchAoConfig (huggingface#34560)
FIX Broken repr of TorchAoConfig The __repr__ method references a non-existent self.kwargs. This is now fixed. There does not appear to be a uniform way of defining __repr__ for quantization configs. I copied the method as implemented for HQQ: https://github.com/huggingface/transformers/blob/e2ac16b28a0b8b900e136750309ca40c49d975c5/src/transformers/utils/quantization_config.py#L285-L287
1 parent ebecbb9 commit b5dab2f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/transformers/utils/quantization_config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,8 @@ def get_apply_tensor_subclass(self):
13091309
return _STR_TO_METHOD[self.quant_type](**self.quant_type_kwargs)
13101310

13111311
def __repr__(self):
1312-
return f"{self.quant_type}({', '.join(str(k) + '=' + str(v) for k, v in self.kwargs.items())})"
1312+
config_dict = self.to_dict()
1313+
return f"{self.__class__.__name__} {json.dumps(config_dict, indent=2, sort_keys=True)}\n"
13131314

13141315

13151316
@dataclass

tests/quantization/torchao_integration/test_torchao.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ def test_post_init_check(self):
7474
with self.assertRaisesRegex(ValueError, "Unexpected keyword arg"):
7575
_ = TorchAoConfig("int4_weight_only", group_size1=32)
7676

77+
def test_repr(self):
78+
"""
79+
Check that there is no error in the repr
80+
"""
81+
quantization_config = TorchAoConfig("int4_weight_only", modules_to_not_convert=["conv"], group_size=8)
82+
repr(quantization_config)
83+
7784

7885
@require_torch_gpu
7986
@require_torchao

0 commit comments

Comments
 (0)