From df81d0f52f246213a665872d2fe1cc905a3743ad Mon Sep 17 00:00:00 2001 From: kwy404 Date: Sat, 26 Sep 2026 19:11:47 -0300 Subject: [PATCH] fix: match layer names ending with a digit in ignore_layers The "." suffix that keeps "layers.1" from matching "layers.10" was also added to layer names such as "fc1" or "model.decoder.layers.0.fc1", so those entries matched nothing and the layers were quantized anyway. Only add the suffix when modules sit under the name. Signed-off-by: kwy404 --- auto_round/compressors/layer_config_resolver.py | 8 +++++++- test/unit/common/utils/test_set_layer_config.py | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/auto_round/compressors/layer_config_resolver.py b/auto_round/compressors/layer_config_resolver.py index f98129b80c..d24826923f 100644 --- a/auto_round/compressors/layer_config_resolver.py +++ b/auto_round/compressors/layer_config_resolver.py @@ -205,7 +205,13 @@ def normalize_item(item: Union[str, dict, "QuantizationScheme"], layer_name: str ignore_layer_patterns = set() if ignore_layers: ignore_layers = ignore_layers.replace(" ", "").split(",") - ignore_layers = [name + "." if name[-1].isdigit() else name for name in ignore_layers] + # "layers.1" -> "layers.1." so it does not also match "layers.10", but only when modules sit + # under that name; a layer whose own name ends with a digit (e.g. "fc1") is kept as is. + module_names = [n for n, _ in model.named_modules()] + ignore_layers = [ + name + "." if name[-1].isdigit() and any(name + "." in n for n in module_names) else name + for name in ignore_layers + ] ignore_layer_patterns = set(ignore_layers) # 1. ignore_layers -> force 16 diff --git a/test/unit/common/utils/test_set_layer_config.py b/test/unit/common/utils/test_set_layer_config.py index 45fdbfdcb9..6d44d768f7 100644 --- a/test/unit/common/utils/test_set_layer_config.py +++ b/test/unit/common/utils/test_set_layer_config.py @@ -116,6 +116,13 @@ def test_block_level_name_ignores_entire_block(self, model_12layers): assert layer_config["layers.0.fc1"]["bits"] == 16 assert layer_config["layers.0.fc2"]["bits"] == 16 + def test_layer_name_ending_with_digit(self, model_12layers): + """'fc1' and 'layers.0.fc2' end with a digit but name layers, so they must still be ignored.""" + layer_config, _, _ = _call_set_layer_config(model_12layers, ignore_layers="fc1,layers.0.fc2") + assert layer_config["layers.11.fc1"]["bits"] == 16 + assert layer_config["layers.0.fc2"]["bits"] == 16 + assert layer_config["layers.1.fc2"]["bits"] == 4 + class TestUnmatchedLayerConfigWarns: """An unrecognised key in layer_config must trigger a warning, not ValueError."""