diff --git a/src/transformers/quantizers/auto.py b/src/transformers/quantizers/auto.py index 549c4fe1329..6b8d71b7c73 100644 --- a/src/transformers/quantizers/auto.py +++ b/src/transformers/quantizers/auto.py @@ -129,10 +129,13 @@ class AutoHfQuantizer: """ handles situations where both quantization_config from args and quantization_config from model config are present. """ - warning_msg = ( - "You passed `quantization_config` or equivalent parameters to `from_pretrained` but the model you're loading" - " already has a `quantization_config` attribute. The `quantization_config` from the model will be prevail." - ) + if quantization_config_from_args is not None: + warning_msg = ( + "You passed `quantization_config` or equivalent parameters to `from_pretrained` but the model you're loading" + " already has a `quantization_config` attribute. The `quantization_config` from the model will be used." + ) + else: + warning_msg = "" if isinstance(quantization_config, dict): quantization_config = AutoQuantizationConfig.from_dict(quantization_config) @@ -144,5 +147,7 @@ class AutoHfQuantizer: setattr(quantization_config, attr, val) warning_msg += f"However, loading attributes (e.g. {list(loading_attr_dict.keys())}) will be overwritten with the one you passed to `from_pretrained`. The rest will be ignored." - warnings.warn(warning_msg) + if warning_msg != "": + warnings.warn(warning_msg) + return quantization_config