Repository navigation
PEFT 0.22 compatibility: tensor parallel adapter save, regex LoRA target scope, classifier DDP default - #18499
Merged
Merged
Conversation
…ssifier as a classifier head
…arded LoRA factors are saved
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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.
Summary
PEFT 0.22.0 was released today, and CI installs the latest PEFT, so every PR now fails several shards (seen on #18486, #18487 and others):
Repo tests (CPU, gloo),gloo-tp,gloo-tp-env: tensor parallel parity tests, e.g.test_qwen4exp_parallel_matches_one_process[tp2],test_deepseek_v41_parallel_matches_one_process[tp4],test_tp2_matches_one_process[llama]. The saved adapter is missing keys, or is empty.Repo tests (CPU, rest):test_peft_moe_linear_targets.py::test_regex_keeps_its_scope.Repo tests (CPU, rest-2):test_ddp_find_unused_default.py::test_sequence_classification_head_defaults_to_falseand..._trainable_embeddings_default_to_false.All of them pass with PEFT 0.21.2 and fail with 0.22.0 on
main, locally. These are not test problems: each one is a real behaviour change for users on PEFT 0.22.Root causes and fixes
1. Tensor parallel
save_pretraineddrops every sharded LoRA factor (tp_native.py,pp_native.py)_peft_state_dictasks PEFT which entries to save by passing the model's state dict and matching PEFT's selection back by tensor identity, then gathers the selected DTensors itself (_full, which also puts fused tensor parallel layouts back in their 1-GPU order).PEFT 0.22 now gathers selected DTensors inside
get_peft_model_state_dict(_gather_state_dict_for_save), returning new plain tensors. None of them match by identity, so every sharded factor was silently left out. Only replicated tensors survived, and the adapter written bysave_tp_adapterwas partial or empty.Fix: PEFT now selects over each DTensor's local shard (
to_local()), which it does not gather, and each selection maps back to its key. The gather and fused-layout handling stay in Unsloth as before. The pipeline parallel adapter gather (adapter_state_dictinpp_native.py) had the same exposure for FSDP2 / tensor parallel stages: PEFT's own gather would skip the fused-layout lookup. It gets the same change. On PEFT 0.21 both paths behave exactly as before.2. A regex
target_modulesloses its scope on MoE models (import_fixes.py)PEFT 0.22 rewrote the v5 MoE target conversion so that dense Linears that share an expert name keep LoRA (what #12281 patched in for older PEFT). It converts a regex
target_modulesto the bare leaf names it resolves to, so a regex scoped to one layer's projections, e.g.model\Wlayers\W1\Wmlp\Wshared_experts\W(gate_proj|up_proj|down_proj), now puts LoRA on every layer'sgate_proj/up_proj/down_proj. PEFT's own code carries a TODO noting it "may match too broadly if only specific layers are targeted".Fix: after conversion, a bare leaf target that names only Linears, some of which the regex did not match, goes back to exactly the module names the regex matched. Parameter targets and
all-linearare untouched.3. DDP
find_unused_parametersdefault for sequence classification (_ddp_defaults.py)PEFT 0.22 adds DistilBERT's
pre_classifierto the default SEQ_CLSmodules_to_save(classifier,score,pre_classifier). Unsloth's list of classifier heads that run every forward was("score", "classifier"), so a plain classifier LoRA no longer counted as safe and DDP fell back tofind_unused_parameters=True, which crashes reentrant checkpointing ("ready only once").pre_classifierruns every forward too, so it joins the list.Testing
mainThe 336 cover the tensor and pipeline parallel gloo set (
test_qwen4exp_parallel_gloo.py,test_parallel_deepseek_v41_gloo.py,test_tp_native_oracle.py,test_tp_kv_replicated_gloo.py,test_pp_fsdp2_gloo.py,test_pp_native_gloo.py,test_pp_env_gloo.py,test_pp_schedules_gloo.py,test_frozen_table_tp_gloo.py,test_frozen_table_pp_gloo.py),test_ddp_find_unused_default.py,test_peft_moe_linear_targets.pyandtests/version_compat/test_peft_conversion_symbol_backfill.py. The existing parity tests are the guard: each compares the saved adapter and the LoRA targets with a single-process reference, and they fail onmainunder PEFT 0.22.0.