Skip to content

Commit 717d6c8

Browse files
committed
Add conversion between module_to_not_convert and ignore.
Signed-off-by: Muti Chung <mtchung037@gmail.com>
1 parent a147a51 commit 717d6c8

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/llmcompressor/modifiers/awq/convert_autoawq.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,20 @@ def convert_and_save(
203203
is_symmetric = not autoawq_config.get("zero_point")
204204
group_size = cast(int, autoawq_config.get("group_size"))
205205

206-
# TODO: check syntax of modules_to_not_convert
207-
ignore = autoawq_config.get("modules_to_not_convert")
208-
if ignore is None:
209-
ignore = ["lm_head"]
206+
# Convert AutoAWQ's substring-based ignore list to llm-compressor's regex format
207+
# Usage in AutoAWQ:
208+
# ```python
209+
# if any(key in name for key in modules_to_not_convert): ...
210+
# ```
211+
# See https://github.com/casper-hansen/AutoAWQ/blob/88e4c76b20755db275574e6a03c83c84ba3bece5/awq/utils/module.py#L62
212+
modules_to_not_convert = autoawq_config.get("modules_to_not_convert", None)
213+
ignore = []
214+
if modules_to_not_convert is not None:
215+
# Convert each substring pattern to a regex pattern that matches it anywhere
216+
for module in modules_to_not_convert:
217+
ignore.append(f"re:.*{re.escape(module)}.*")
218+
219+
ignore.append("lm_head") # AutoAWQ ignores lm_head by default
210220

211221
# 1. Load the model weights directly.
212222
state_dict = load_state_dict_from_model_dir(model_path)

0 commit comments

Comments
 (0)