Skip to content

Fix PEFT load report listing other adapters' weights as missing - #51199

Merged
hmellor merged 2 commits into
huggingface:mainfrom
lucamotz:fix-peft-second-adapter-missing-keys
Nov 25, 2026
Merged

hmellor merged 2 commits into
huggingface:mainfrom
lucamotz:fix-peft-second-adapter-missing-keys

Conversation

@lucamotz

@lucamotz lucamotz commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

🤗 Transformers CI

What does this PR do?

Since #43261, is_adapter_key in load_adapter matches any key that contains the adapter name or the PEFT type ("lora"), so loading a second LoRA adapter reports the LoRA weights of every already-loaded adapter as MISSING ("newly initialized") and sizes the warmup for them, although they are untouched. It now matches only keys that have the adapter name as a dot-separated component, which also stops adapter_1 from matching adapter_10's keys.

Reproducer (on main it fails with 20 lora_{A,B}.first.weight keys; the documented per-task load_adapter flow of jinaai/jina-embeddings-v3-hf lists 294 when loading a second task):

from transformers import AutoModelForCausalLM

model = AutoModelForCausalLM.from_pretrained("hf-internal-testing/tiny-random-OPTForCausalLM")
model.load_adapter("peft-internal-testing/tiny-OPTForCausalLM-lora", adapter_name="first")
info = model.load_adapter("peft-internal-testing/tiny-OPTForCausalLM-lora", adapter_name="second")
assert not info.missing_keys, sorted(info.missing_keys)

For merging: #45682 re-declares the old is_adapter_key after _load_pretrained_model; whichever of the two merges second should drop that copy, otherwise the false MISSING report comes back, because git does not flag that block (the new test fails on it).

Validation: test_peft_load_second_adapter_no_missing_keys fails on main and passes here; otherwise tests/peft_integration gives the same results as on main.

I used Claude Code for parts of this implementation.

Tests
  • CPU: tests/peft_integration 31 passed, 16 skipped (3 accelerator, 13 slow).
  • CUDA (GB10 sm_121, torch 2.14 + CUDA 13.0), RUN_SLOW=1 tests/peft_integration: main 39 passed / 5 failed, this PR 40 / 4. The only difference is the new test; the four rank-changing hotswap tests (*_lower_rank_works, *_higher_rank_works) fail on both.
Real checkpoints
  • jinaai/jina-embeddings-v5-text-nano as EuroBertModel (config switched to eurobert), its four task adapters loaded in turn: main reports 168 / 336 / 504 false MISSING on loads 2–4, this PR 0. On both, every adapter's weights and embeddings are bit-identical to a model with only that adapter loaded (fp32 and bf16, GB10).

Who can review?

Anyone in the community is free to review the PR once the tests have passed.

@lucamotz
lucamotz marked this pull request as ready for review November 25, 2026 07:42
@lucamotz

Copy link
Copy Markdown
Contributor Author

fyi @hmellor

@hmellor hmellor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

cc @BenjaminBossan

@hmellor
hmellor enabled auto-merge November 25, 2026 11:50
hmellor added a commit to BenjaminBossan/transformers that referenced this pull request Nov 25, 2026
Matching on the PEFT type (e.g. "lora") made the load report list every
other loaded adapter's weights as missing. Match the adapter name as a
dot-separated key component instead, as in huggingface#51199, and drop the
duplicate is_adapter_key definition.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
@hmellor
hmellor disabled auto-merge November 25, 2026 11:54
@hmellor
hmellor enabled auto-merge November 25, 2026 11:54
@hmellor
hmellor added this pull request to the merge queue Nov 25, 2026
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

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.

Merged via the queue into huggingface:main with commit 805525a Nov 25, 2026
132 checks passed
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.

3 participants