Skip to content

PEFT 0.22 compatibility: tensor parallel adapter save, regex LoRA target scope, classifier DDP default - #18499

Merged
danielhanchen merged 2 commits into
mainfrom
ci/peft-022-regex-scope-ddp
Nov 19, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
ci/peft-022-regex-scope-ddp

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

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_false and ..._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_pretrained drops every sharded LoRA factor (tp_native.py, pp_native.py)

_peft_state_dict asks 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 by save_tp_adapter was 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_dict in pp_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_modules loses 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_modules to 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's gate_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-linear are untouched.

3. DDP find_unused_parameters default for sequence classification (_ddp_defaults.py)

PEFT 0.22 adds DistilBERT's pre_classifier to the default SEQ_CLS modules_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 to find_unused_parameters=True, which crashes reentrant checkpointing ("ready only once"). pre_classifier runs every forward too, so it joins the list.

Testing

PEFT 0.21.2 PEFT 0.22.0
main passes 5 tensor parallel parity cells, the regex scope test and 2 DDP default tests fail (the CI failures)
this branch 336 passed, 9 skipped 336 passed, 9 skipped

The 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.py and tests/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 on main under PEFT 0.22.0.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T16:36:04.775637Z ad9e0a5 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: ad9e0a55dc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@danielhanchen
danielhanchen merged commit 5ceb720 into main Nov 19, 2026
@danielhanchen
danielhanchen deleted the ci/peft-022-regex-scope-ddp branch November 19, 2026 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant