-
Notifications
You must be signed in to change notification settings - Fork 403
Support AutoQuant in Megatron-Core #1512
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 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 |
|---|---|---|
|
|
@@ -291,13 +291,10 @@ def get_score(self, recipe: QuantRecipe) -> float: | |
| total_score += importance.cpu().item() | ||
| continue | ||
|
|
||
| if parallel_state.expert_model_parallel_group.is_initialized(): | ||
| # TODO: Support expert model parallelism for score estimation | ||
| warnings.warn("AutoQuantize does not support expert model parallelism yet.") | ||
| importance = importance.cpu() | ||
| importance = DistributedProcessGroup.get_dist_syncd_obj( | ||
| importance, | ||
| [parallel_state.tensor_parallel_group, parallel_state.data_parallel_group], | ||
| [parallel_state.tensor_parallel_group, parallel_state.data_parallel_group, parallel_state.expert_model_parallel_group], | ||
| sum, | ||
| ) | ||
| total_score += importance.item() | ||
|
|
@@ -318,13 +315,9 @@ def get_cost(self, recipe: QuantRecipe) -> float: | |
| cost += weight_size * recipe.compression | ||
| continue | ||
|
|
||
| if parallel_state.expert_model_parallel_group.is_initialized(): | ||
| # TODO: Support expert model parallelism | ||
| warnings.warn("AutoQuantize does not support expert model parallelism yet.") | ||
|
|
||
| weight_size = DistributedProcessGroup.get_dist_syncd_obj( | ||
| weight_size, | ||
| [parallel_state.tensor_parallel_group], | ||
| [parallel_state.tensor_parallel_group, parallel_state.expert_model_parallel_group], | ||
|
Comment on lines
318
to
+320
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. Keep the search budget on the same scale as the new EP-synced costs. Line 320 makes expert-module costs global across Suggested fix- total_weight_size = self._get_total_weight_size(self.model.modules())
+ total_weight_size = sum(
+ candidate_stat["costs"][-1] for candidate_stat in self.candidate_stats.values()
+ )
max_weight_size = total_weight_size * compression🤖 Prompt for AI Agents |
||
| sum, | ||
| ) | ||
|
|
||
|
|
@@ -362,6 +355,8 @@ class _AutoQuantizeBaseSearcher(BaseSearcher, ABC): | |
| # gate_proj, up_proj, down_proj for Qwen3 like MoE models | ||
| r"^(.*?\.mlp\.experts)\.\d+\.(gate_proj|up_proj|down_proj)$", | ||
| r"^(.*?\.mixer\.experts)\.\d+\.(up_proj|down_proj)$", # NemotronH MoE experts | ||
| # NemotronH MoE experts in MCore naming (linear_fc1=gate+up fused, linear_fc2=down) | ||
| r"^(.*?\.mlp\.experts\.local_experts)\.\d+\.(linear_fc1|linear_fc2)$", | ||
| r"^(.*?)\.(gate_proj|up_proj)$", # gate_proj, up_proj for llama like models | ||
| r"^(.*?)\.(\d+\.(w1|w2|w3))$", # mixtral experts | ||
| r"^(.*?)\.((w1_linear|w2_linear|w3_linear)\.\d+)$", # dbrx experts | ||
|
|
||
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.
Canonicalize the winning recipe across expert-parallel ranks too.
These changes make candidate stats identical across EP shards, but
run_search()still normalizes the solver output only over DP/TP. The comment at Lines 750-752 already calls out tie-driven divergence, so the same grouped MoE hparam can still end up with different recipes on different expert-parallel ranks.Suggested fix
best_format = DistributedProcessGroup.get_dist_syncd_obj( best_hparam_recipe_info["format"], - [_ps.data_parallel_group, _ps.tensor_parallel_group], + [ + _ps.data_parallel_group, + _ps.tensor_parallel_group, + _ps.expert_model_parallel_group, + ], lambda a: a[0], )Also applies to: 318-320
🤖 Prompt for AI Agents