Skip to content

Commit 7feebad

Browse files
xinhe3XuehaoSun
authored andcommitted
support ComposableConfig setattr
Signed-off-by: Xin He <[email protected]>
1 parent 34a2c8f commit 7feebad

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

neural_compressor/common/base_config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,13 @@ def __add__(self, other: BaseConfig) -> BaseConfig:
692692
self.config_list.append(other)
693693
return self
694694

695+
def __setattr__(self, name, value):
696+
"""Override the setattr function to propagate updates."""
697+
ABC.__setattr__(self, name, value)
698+
for config in self.config_list:
699+
if hasattr(config, name):
700+
setattr(config, name, value)
701+
695702
def to_dict(self, params_list=[], operator2str=None):
696703
"""Converts the configuration object to a dictionary.
697704

neural_compressor/torch/quantization/quantize.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ def preprocess_quant_config(model, quant_config, mode="prepare", example_inputs=
9191
else:
9292
model_info = quant_config.get_model_info(model=model)
9393

94-
if hasattr(quant_config, "model_path") and quant_config.model_path == "" and hasattr(model, "name_or_path"):
94+
if (
95+
(hasattr(quant_config, "model_path") and quant_config.model_path == "")
96+
or isinstance(quant_config, ComposableConfig)
97+
) and hasattr(model, "name_or_path"):
9598
quant_config.model_path = model.name_or_path
9699
configs_mapping = quant_config.to_config_mapping(model_info=model_info)
97100
logger.debug(configs_mapping)

0 commit comments

Comments
 (0)