feat(lora): support PEFT named-adapter LoRAs (e.g. Klein 9B)#9252
Open
Pfannkuchensack wants to merge 2 commits into
Open
feat(lora): support PEFT named-adapter LoRAs (e.g. Klein 9B)#9252Pfannkuchensack wants to merge 2 commits into
Pfannkuchensack wants to merge 2 commits into
Conversation
PEFT-format LoRAs with a named adapter encode the adapter name in the weight key (e.g. `foo.lora_A.default.weight` instead of `foo.lora_A.weight`). InvokeAI's format detection and conversion only matched the standard PEFT suffix, so these files were classified as Unknown and silently ignored. Normalize named-adapter keys to the standard PEFT form in both `ModelOnDisk.load_state_dict` (detection pipeline) and `LoRALoader._load_model` (conversion pipeline). The pattern is LoRA-specific, so this is a no-op for non-LoRA state dicts. State dicts with multiple distinct adapter names are left untouched to avoid key collisions. Also widen Flux2-Klein diffusers detection to accept keys without a `transformer.` or `base_model.model.` prefix — some trainers (Modelscope / MuseAI Klein 9B finetunes) save at the top level.
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-format LoRAs with a named adapter encode the adapter name in the weight key (e.g.
foo.lora_A.default.weightinstead offoo.lora_A.weight). InvokeAI's format detection and conversion only matched the standard PEFT suffix, so these files were classified as Unknown and silently ignored.Normalize named-adapter keys to the standard PEFT form in both
ModelOnDisk.load_state_dict(detection pipeline) andLoRALoader._load_model(conversion pipeline). The pattern is LoRA-specific, so this is a no-op for non-LoRA state dicts. State dicts with multiple distinct adapter names are left untouched to avoid key collisions.Also widen Flux2-Klein diffusers detection to accept keys without a
transformer.orbase_model.model.prefix — some trainers (Modelscope / MuseAI Klein 9B finetunes) save at the top level.Related Issues / Discussions
#9021 and #9249
QA Instructions
Tested with a Klein 9B LoRA from Modelscope (
klein-9b-turn2real_v1.5_ep9.safetensors) that uses the PEFT named-adapter format and no key prefix.…lora_A.default.weight/…lora_B.default.weightrather than…lora_A.weight/…lora_B.weight.Unknown(no base, no type, no format).After this PR: the file is recognized with the correct
base,type=LoRA,format=LyCORIS, and (for Flux2) the correctvariant(Klein4B / Klein9B).Automated coverage:
tests/backend/patches/lora_conversions/test_peft_adapter_utils.py— 6 unit tests for the normalization helper (no-op when not needed, stripsdefault, strips custom names, leaves multi-adapter dicts alone, preserves non-LoRA / integer keys).tests/backend/patches/lora_conversions/tests (108) andtests/backend/model_manager/configs/tests (41) still pass.Merge Plan
Standard merge — no schema/migration changes.
Checklist
What's Newcopy (if doing a release after this PR)