fix: biencoder PEFT adapter key remapping for merge_lora#1478
Open
fix: biencoder PEFT adapter key remapping for merge_lora#1478
Conversation
The biencoder wraps the base model as `lm_q`, so PEFT adapter weights and target modules were saved with `lm_q.` prefix. However, the standalone base model (LlamaBidirectionalModel extends LlamaModel) uses bare module names like `layers.0.self_attn.q_proj` — no `model.` prefix. This caused merge_lora.py to fail because PEFT could not match the target modules or weight keys against the base model. Changes: - state_dict_adapter: fix PEFT key path in to_hf to strip `lm_q.` without adding `model.` (base_model.model.lm_q.X → base_model.model.X) - state_dict_adapter: fix from_hf to handle new PEFT key format (base_model.model.X → base_model.model.lm_q.X) - addons: strip `lm_q.` prefix from target modules for biencoder so adapter_config.json is compatible with the standalone HF base model Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
3 tasks
Collaborator
Author
|
/ok to test b6c94c1 |
Collaborator
Author
|
/ok to test 019acfc |
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
BiencoderStateDictAdapterso thatmerge_lora.pyworks against the standalone base model (LlamaBidirectionalModel)lm_q, so adapter weights/target modules were saved with incorrect prefixes (lm_q.→model.instead oflm_q.→ bare)LlamaBidirectionalModelextendsLlamaModel(notLlamaForCausalLM), so its modules arelayers.*notmodel.layers.*Changes
state_dict_adapter.py: Fix PEFT key path into_hf(base_model.model.lm_q.X→base_model.model.X, was incorrectly producingbase_model.model.model.X). Fixfrom_hfto handle the corrected format.addons.py: Striplm_q.prefix from target modules in_extract_target_modulesfor biencoder, soadapter_config.jsonhas module names matching the standalone HF base model.Test plan
to_hf→from_hf)test_addons.pyandtest_state_dict_adapter.pytests pass (31 total)merge_lora.pyagainstnvidia/llama-nemotron-embed-1b-v2🤖 Generated with Claude Code