Skip to content

Commit 40a518b

Browse files
Fix AutoModel can't load gptq model due to module prefix mismatch vs AutoModelForCausalLM (#2146)
* fix the issue of AutoModel failing to load the gptq model. * clear * update comments --------- Co-authored-by: Qubitium-ModelCloud <qubitium@modelcloud.ai>
1 parent d21256c commit 40a518b

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

optimum/gptq/constants.py

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
"model.decoder.layers",
1919
"gpt_neox.layers",
2020
"model.layers",
21+
# modules loaded by AutoModel vs AutoModelForCausalLM have different prefixes
22+
"h",
23+
"decoder.layers",
24+
"layers",
2125
]
2226

2327
GPTQ_CONFIG = "quantize_config.json"

optimum/gptq/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def get_block_name_with_pattern(model: nn.Module):
7272
modules_names = [n for n, _ in model.named_modules()]
7373
for pattern_candidate in BLOCK_PATTERNS:
7474
pattern_candidate = pattern_candidate
75-
if any(pattern_candidate in name for name in modules_names):
75+
if any(name.startswith(pattern_candidate) for name in modules_names):
7676
return pattern_candidate
7777
raise ValueError("Block pattern could not be match. Pass `block_name_to_quantize` argument in `quantize_model`")
7878

0 commit comments

Comments
 (0)