fix(lora): correctly detect flattened layer keys in LayerPatcher#9295
Open
Pfannkuchensack wants to merge 1 commit into
Open
fix(lora): correctly detect flattened layer keys in LayerPatcher#9295Pfannkuchensack wants to merge 1 commit into
Pfannkuchensack wants to merge 1 commit into
Conversation
The patcher decided whether a patch's layer keys were flattened (legacy underscore-joined) or real dotted module paths by inspecting only the first key. For FLUX.2 Klein diffusers LoRAs whose first converted layer is a dotless top-level module (e.g. `context_embedder`), the whole patch was misclassified as flattened, causing `assert "." not in layer_key` to fail on subsequent dotted keys and crashing LoRA application. Inspect all keys instead: a flattened key never contains a dot, so the patch is flattened only if no key contains one. Add a regression test covering the mixed dotless/dotted key ordering.
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
The patcher decided whether a patch's layer keys were flattened (legacy underscore-joined) or real dotted module paths by inspecting only the first key. For FLUX.2 Klein diffusers LoRAs whose first converted layer is a dotless top-level module (e.g.
context_embedder), the whole patch was misclassified as flattened, causingassert "." not in layer_keyto fail on subsequent dotted keys and crashing LoRA application.Inspect all keys instead: a flattened key never contains a dot, so the patch is flattened only if no key contains one. Add a regression test covering the mixed dotless/dotted key ordering.
Related Issues / Discussions
https://discord.com/channels/1020123559063990373/1149510134058471514/1517709403858669708
QA Instructions
A FLUX.2 Klein diffusers-format LoRA whose first converted layer targets a dotless top-level module (e.g.
transformer.context_embedder,transformer.x_embedder,transformer.proj_out) previously crashed on load with:File ".../invokeai/backend/patches/layer_patcher.py", line 289, in _get_submodule
assert "." not in layer_key
To verify:
uv run --extra cuda --extra test python -m pytest tests/backend/patches/test_layer_patcher.py -q
All tests pass (including the new
test_apply_smart_model_patches_mixed_dotted_and_dotless_keysregression test, which fails on the old single-first-key heuristic).Merge Plan
Standard merge — isolated, low-risk change to LoRA patching logic. No DB/schema changes.
Checklist
What's Newcopy (if doing a release after this PR)