-
Notifications
You must be signed in to change notification settings - Fork 544
[bugfix] Fixed the bug in retrieving the quantization method for mlp.experts (e.g., DeepSeek_v3.2_exp w8a8) #4035
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: v0.11.0-dev
Are you sure you want to change the base?
Changes from all commits
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 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -52,6 +52,16 @@ def get_linear_quant_type(quant_description: Dict[str, Any], prefix: str, | |||||||||||||||||
| f"Not all shards of {prefix} are quantized with same quant type." | ||||||||||||||||||
| f"Shard {proj_name} uses {shard_quant_type}, but another shard" | ||||||||||||||||||
| f"use {quant_type}. Please check quantization config.") | ||||||||||||||||||
| elif "experts" in prefix: | ||||||||||||||||||
| # For the experts' prefix (e.g., "model.layers.3.mlp.experts") | ||||||||||||||||||
| # Assume all experts within the same MLP use the same quantization method | ||||||||||||||||||
| experts_quant_description = set( | ||||||||||||||||||
| quant_description[layer] | ||||||||||||||||||
| for layer in quant_description if prefix in layer | ||||||||||||||||||
| ) | ||||||||||||||||||
|
Comment on lines
+58
to
+61
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Suggested change
|
||||||||||||||||||
| if not len(experts_quant_description) == 1: | ||||||||||||||||||
| raise RuntimeError(f"{prefix} has different quantization type: {experts_quant_description}.") | ||||||||||||||||||
| quant_type = experts_quant_description.pop() | ||||||||||||||||||
| else: | ||||||||||||||||||
| quant_type = quant_description[prefix + '.weight'] | ||||||||||||||||||
| return quant_type | ||||||||||||||||||
|
|
||||||||||||||||||
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.
This logic can be improved for correctness and robustness:
prefix in layeris less precise thanlayer.startswith(prefix + '.')for hierarchical module names. It could lead to incorrect matches if another module name contains the expert prefix as a substring.prefix,experts_quant_descriptionwill be an empty list.any()on an empty list returnsFalse, causingis_skippedto beFalse. This will likely lead to aRuntimeErrorlater inget_linear_quant_type. It's safer to treat this case as skipped (unquantized).Here is a suggested improvement that addresses these points.