Fix MoE target_parameters module_count alignment (#3405, #3701)#499
Fix MoE target_parameters module_count alignment (#3405, #3701)#499GoldenGrapeGentleman wants to merge 2 commits intounslothai:mainfrom
Conversation
MoE ParamWrapper entries (from PEFT target_parameters) have lora_A/B/scaling but may lack a .base_layer module, leaving module_count short of lora_A_count. This caused a misleading 'LoRA count mismatch' diagnostic warning during merge. Fix: after the LoRA collection loop, count MoE expert entries that have lora_A/B but no module, aligning module_count with lora_A/B/scaling counts. Also removes the TODO comment at the resolved location. Tested on: 8x AMD Instinct MI355X (gfx950), ROCm 7.1 - gpt-oss-20b BF16 + MoE expert LoRA (46.2M trainable) - save_pretrained_merged: success, no count mismatch warning
Summary of ChangesHello @GoldenGrapeGentleman, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses and resolves a misleading "LoRA count mismatch" diagnostic warning that occurred when using PEFT Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request provides a clean and effective fix for a LoRA module count mismatch that occurred with MoE models using target_parameters. The added logic correctly identifies uncounted MoE expert modules by checking for LoRA weights on modules without a registered base layer, and appropriately increments the module count. The change is well-targeted to .mlp.experts to avoid side effects. The removal of the corresponding TODO comment is also appropriate. The implementation is straightforward and directly resolves the issue described.
|
Hey @GoldenGrapeGentleman thanks for the contribution. I do remember that there's only one base_layer in the experts module (referring to gate_up_proj iirc?). This does effect transformers v5. Can we handle this specifically for nn.Parameter instead of doing a blanket addition? Also can you test your fix for the following models : Thanks a lot :) |
|
Hi @Datta0 Thanks for your quick response, I will do all you mentioned, maybe after the Chinese Spring Festival. BTW, happy new year to you and unsloth team if anyone is from China(❁´◡`❁) |
|
Happy new year @GoldenGrapeGentleman. Wishing you a great time :) |
Per review feedback, nn.Linear targets always get .base_layer set (module != None), so stats.module is None reliably identifies nn.Parameter (ParamWrapper) targets without path string matching. Avoids incorrectly counting nn.ModuleList(nn.Linear) in transformers v4.
|
Hey @GoldenGrapeGentleman
|
Summary
Resolves the
TODO: handle MoE target_parameters to align countsat line 410 ofsaving_utils.py.Problem
When using PEFT
target_parametersfor MoE expert LoRA (e.g., gpt-oss), thecreate_lora_statisticsfunction reports a misleading diagnostic warning:This happens because MoE
ParamWrapperentries havelora_A/lora_B/scalingcounted, but lack a.base_layermodule, somodule_countis never incremented for them.Fix
After the LoRA collection loop, count MoE expert entries that have
lora_A/lora_Bbut no.module, aligningmodule_countwith the other counts. Only applies to.mlp.expertsentries to avoid affecting non-MoE models.Changes
saving_utils.py: +12 lines / -3 lines (removes TODO comment)Verified on 8× AMD Instinct MI355X (gfx950), ROCm 7.1
save_pretrained_merged: ✅ success, no count mismatch warningmodules=120, lora_A=144warning printedRelated: unslothai/unsloth#3405, unslothai/unsloth#3701
cc @danielhanchen @Datta0