Repository navigation
Warn when LoRA skips the dense and shared expert layers of MoE models on transformers v5 with peft 0.19 to 0.21.2 - #7771
Open
albertvillanova wants to merge 2 commits into
Open
albertvillanova wants to merge 2 commits into
albertvillanova wants to merge 2 commits into
Conversation
…ormers v5 with peft<0.19
… on transformers v5 with peft 0.19 to 0.21.2
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
albertvillanova
changed the base branch from
guard-moe-lora-routed-experts-peft
to
main
October 16, 2026 11:21
This branch has not been deployed
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.
This PR makes the trainers warn when a LoRA config would silently not train the dense and shared expert layers of an MoE model, which happens with transformers v5 and peft 0.19 to 0.21.2.
Closes #7767.
Motivation
With transformers v5 and peft 0.19 to 0.21.2, the latest release,
target_moduleslike["gate_proj", "up_proj", "down_proj"]or"all-linear"only train the routed experts of MoE models that have a dense first layer or shared experts (GLM-4-MoE, DeepSeek-V3, ...): the dense and shared expert layers get no LoRA, with no warning. It is fixed on peft main, but these versions remain in TRL's supported range. See #7767 for the root cause.Solution
Before creating the PEFT model, the trainers log a warning when all of these hold:
LoraConfig, with transformers>=5.0.0 and peft>=0.19.0,<0.21.3.dev0 (peft main, which has the fix, is 0.21.3.dev0).experts.)nn.Linearlayers named like expert projections (gate_proj,up_proj,down_proj,w1,w2,w3), i.e. the dense or shared expert layerstarget_moduleswould reach them (a string such as"all-linear", or a leaf name in that set)It is a warning rather than an error: the routed experts are still trained, and no
target_modulesspelling avoids the issue with these versions, so an error would block training these models on the latest PEFT release.Tests will be added in a follow-up PR, together with those for the #7769 guard. Verified locally with SFT on transformers 5.19.0:
all-linearOn transformers 4.56.2 with peft 0.21.2, nothing is logged.
Changes
get_peft_modelin the SFT, DPO, KTO, GRPO, RLOO, Reward and Distillation trainers, with the same block in eachNote
Low Risk
Logging-only change before PEFT wrapping; no training logic or defaults are modified.
Overview
Adds a pre-
get_peft_modelwarning in SFT, DPO, KTO, GRPO, RLOO, Reward, and Distillation trainers when LoRA on transformers v5 with peft 0.19.0–0.21.2 would only adapt routed MoE experts and leave dense/shared MLP projections (gate_proj,up_proj,down_proj, etc.) without adapters—matching the silent gap fixed on peft main (≥0.21.3.dev0).The check mirrors the existing #7765 guard (same MoE +
target_modulesheuristics) but useslogger.warninginstead of raising, so training can continue on the latest supported peft release while users are pointed to upgrade peft or install from main (#7767).Reviewed by Cursor Bugbot for commit 7273cb2. Bugbot is set up for automated code reviews on this repo. Configure here.