Skip to content

Commit

Permalink
Fix AutoModel can't load gptq model due to module prefix mismatch vs …
Browse files Browse the repository at this point in the history
…AutoModelForCausalLM (#2146)

* fix the issue of AutoModel failing to load the gptq model.

* clear

* update comments

---------

Co-authored-by: Qubitium-ModelCloud <[email protected]>
  • Loading branch information
LRL-ModelCloud and Qubitium authored Jan 6, 2025
1 parent d21256c commit 40a518b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions optimum/gptq/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
"model.decoder.layers",
"gpt_neox.layers",
"model.layers",
# modules loaded by AutoModel vs AutoModelForCausalLM have different prefixes
"h",
"decoder.layers",
"layers",
]

GPTQ_CONFIG = "quantize_config.json"
2 changes: 1 addition & 1 deletion optimum/gptq/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def get_block_name_with_pattern(model: nn.Module):
modules_names = [n for n, _ in model.named_modules()]
for pattern_candidate in BLOCK_PATTERNS:
pattern_candidate = pattern_candidate
if any(pattern_candidate in name for name in modules_names):
if any(name.startswith(pattern_candidate) for name in modules_names):
return pattern_candidate
raise ValueError("Block pattern could not be match. Pass `block_name_to_quantize` argument in `quantize_model`")

Expand Down

0 comments on commit 40a518b

Please sign in to comment.