fix(moe): keep pruned expert count in model.yaml so pruned models survive retraining - #192
Merged
Merged
Conversation
…s pruned architecture Signed-off-by: 林晨 (Leo Cheng) <leo-cheng@vip.qq.com>
Collaborator
|
LGTM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
MoEPruner physically reduces each ES_MOE's expert list and router, but the saved
model.yamlstill describes the original expert count. When a pruned checkpoint is then used for further training (the prune -> LoRA / full fine-tune recovery workflow),Trainer.setup_modelrebuilds the model frommodel.yamlwith ES_MOE's default expert count, andBaseModel.load()'sintersect_dictssilently drops the reduced expert/router weights on shape mismatch. The model re-inflates to the default expert count with randomly initialized experts, so "recovery" ends up training a reconstructed non-pruned model rather than the pruned one.Fix
After surgery, MoEPruner writes each pruned ES_MOE's expert count into its
model.yamlargs ([out_channels, num_experts]; ES_MOE clampstop_k = min(top_k, num_experts)). The pruned architecture now round-trips through a YAML rebuild, so retraining/fine-tuning operates on the actual pruned model.Verification
Added
tests/test_moe_prune_yaml_sync.py: reproduces the re-inflation when the yaml is not synced, and confirms the sync preserves the pruned expert count with all weights round-tripping.