Skip to content
This repository was archived by the owner on Jun 4, 2025. It is now read-only.

Commit d8f7073

Browse files
author
Sara Adkins
committed
add to_diff_dict
1 parent f53d7b9 commit d8f7073

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/transformers/utils/quantization_config.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,27 @@ def to_dict(self) -> Dict[str, Any]:
11541154
"sparsity_config": sparsity_config,
11551155
}
11561156

1157+
def to_diff_dict(self) -> Dict[str, Any]:
1158+
"""
1159+
Removes all attributes from config which correspond to the default config attributes for better readability and
1160+
serializes to a Python dictionary.
1161+
Returns:
1162+
`Dict[str, Any]`: Dictionary of all the attributes that make up this configuration instance,
1163+
"""
1164+
config_dict = self.to_dict()
1165+
1166+
# get the default config dict
1167+
default_config_dict = CompressedTensorsConfig().to_dict()
1168+
1169+
serializable_config_dict = {}
1170+
1171+
# only serialize values that differ from the default config
1172+
for key, value in config_dict.items():
1173+
if value != default_config_dict[key]:
1174+
serializable_config_dict[key] = value
1175+
1176+
return serializable_config_dict
1177+
11571178

11581179
class FbgemmFp8Config(QuantizationConfigMixin):
11591180
"""

0 commit comments

Comments
 (0)