-
-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Granite4 Quantization Bug Fix #28398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
0d11efc
375c61e
38a677b
c7f5534
0c5b1ce
e0cb248
4825e50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,7 +49,7 @@ | |
| make_layers, | ||
| maybe_prefix, | ||
| ) | ||
|
|
||
| import re | ||
|
|
||
| class GraniteMoeHybridMambaDecoderLayer(nn.Module): | ||
| def __init__( | ||
|
|
@@ -652,11 +652,62 @@ def get_mamba_state_shape_from_config( | |
| conv_kernel=hf_config.mamba_d_conv, | ||
| ) | ||
|
|
||
| def maybe_update_quant_config( | ||
| self, quant_config: QuantizationConfig | ||
| ) -> QuantizationConfig: | ||
| """ | ||
| Update quant config so that ignored module and target module names | ||
| match the vLLM model names. | ||
| Granite model specific: mamba -> mixer remapping. | ||
| """ | ||
| remapping_rules = [ | ||
| # Granite model: mamba -> mixer remapping | ||
| ( | ||
| r"model\.layers\.(\d+)\.mamba\.in_proj", | ||
| r"model.layers.\1.mixer.in_proj", | ||
| ), | ||
| ( | ||
| r"model\.layers\.(\d+)\.mamba\.out_proj", | ||
| r"model.layers.\1.mixer.out_proj", | ||
| ), | ||
| ] | ||
| # Update ignore list | ||
| if hasattr(quant_config, "ignore"): | ||
| updated_ignore = [] | ||
| for name in quant_config.ignore: | ||
| updated_name = name | ||
| for pattern, repl in remapping_rules: | ||
| if re.fullmatch(pattern, name): | ||
| updated_name = re.sub(pattern, repl, name) | ||
| updated_ignore.append(updated_name) | ||
| quant_config.ignore = updated_ignore | ||
| # Update target list | ||
| if hasattr(quant_config, "config_groups"): | ||
| config_groups = quant_config.config_groups | ||
| for group_name in config_groups: | ||
| if "targets" in config_groups[group_name]: | ||
| targets = [] | ||
| for name in config_groups[group_name]["targets"]: | ||
| updated_name = name | ||
| for pattern, repl in remapping_rules: | ||
| if re.fullmatch(pattern, name): | ||
| updated_name = re.sub(pattern, repl, name) | ||
| targets.append(updated_name) | ||
| config_groups[group_name]["targets"] = targets | ||
| quant_config.config_groups = config_groups | ||
| return quant_config | ||
|
||
|
|
||
| def __init__(self, *, vllm_config: VllmConfig, prefix: str = ""): | ||
| super().__init__() | ||
|
|
||
| config = vllm_config.model_config.hf_config | ||
| self.vllm_config = vllm_config | ||
|
|
||
| if hasattr(vllm_config, "quant_config"): | ||
| vllm_config.quant_config = self.maybe_update_quant_config( | ||
| vllm_config.quant_config | ||
| ) | ||
|
|
||
| self.model_config = vllm_config.model_config | ||
| lora_config = vllm_config.lora_config | ||
| scheduler_config = vllm_config.scheduler_config | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
config_groupsassignment behind target checkThe
config_groups[group_name]["targets"] = targetsassignment is aligned with thefor group_nameloop rather than the precedingif "targets" in config_groups[group_name]block. When a quantization config contains a group that lacks a"targets"key (which is common for groups that only tweak global parameters), the code still executes this assignment and references the local variabletargetsthat was never initialised, raising anUnboundLocalErrorduring model construction. The assignment should live inside theifblock so groups without targets are skipped.Useful? React with 👍 / 👎.