fix(moe): preserve pruned experts' kernel sizes in model.yaml so retraining reloads their weights - #194
Merged
Conversation
…aining reloads their weights Signed-off-by: 林晨 (Leo Cheng) <leo-cheng@vip.qq.com>
Contributor
Author
|
The three failing checks ( This change is isolated to MoE pruning YAML sync ( |
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 keeps the highest-utilization experts, which in a trained model have heterogeneous depthwise kernel sizes (e.g. a layer keeps experts with kernels [5, 9]). PR #192 encoded the reduced
num_expertsintomodel.yaml, but not the kept experts' kernel sizes.Consequently
YOLO(pruned.pt).train()(the prune -> LoRA / full fine-tune recovery workflow) rebuilds eachES_MOEfrom YAML with the default kernels[3, 5, ...][:num_experts], which mismatch the kept experts' actual kernels.intersect_dictsthen drops those depthwise weights on the shape mismatch and re-initializes the experts randomly, so retraining starts from a degraded model.On a VisDrone YOLO-Master-EsMoE-N pruned to 2 experts/layer this is reproducible: direct-inference val is mAP50 0.4269, but the first retrain epoch starts at mAP50 ~0.002 (random experts). After the fix the same retrain starts from a correctly loaded model.
Fix
ES_MOEgains an optionalexpert_kernel_sizesargument (defaults toNone, so behavior is unchanged when unset).MoEPruner._sync_yaml_num_expertsnow writes the fullES_MOEpositional arg list, including each kept expert's kernel size, intomodel.yaml. The YAML rebuild then reconstructs the exact kept experts and their weights surviveintersect_dicts.Tests
tests/test_moe_prune_yaml_sync.pygainstest_sync_preserves_expert_kernels, which builds a stand-in pruned model with non-default kernels, syncs, rebuilds, and asserts the kernels and weights are preserved. All three tests pass. The change is backward compatible.