[Fix] Fix three final_layer LoRA conversion bugs in _convert_sd_scripts_to_ai_toolkit#14001
Merged
Merged
Conversation
…ts_to_ai_toolkit Co-authored-by: christopher5106 <[email protected]> Signed-off-by: lcheng <[email protected]>
|
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. |
DN6
pushed a commit
that referenced
this pull request
Jul 1, 2026
…ts_to_ai_toolkit (#14001) Signed-off-by: lcheng <[email protected]> Co-authored-by: christopher5106 <[email protected]>
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.
Fix three final_layer LoRA conversion bugs in _convert_sd_scripts_to_ai_toolkit
Fixes #13998
Three independent bugs in assign_remaining_weights caused failures when loading FLUX LoRAs that include final_layer weights (common in kohya and ComfyUI/SwarmUI exports).
Case A (KeyError): source.pop(source_key) raised KeyError when a LoRA trained final_layer.linear but not final_layer.adaLN_modulation_1. Fixed by using source.pop(source_key, None) and skipping on None.
Case B (Incompatible keys): Unconsumed final_layer .alpha keys were left in the state dict after assign_remaining_weights, which only consumed lora_down/lora_up. These keys then hit the remaining_keys guard that only tolerates lora_te* prefixes, raising ValueError. Fixed by consuming final_layer .alpha keys after the assignment loop.
Case C (Silent weight corruption): swap_scale_shift was applied to both lora_A and lora_B. The correct transform is swap(B) @ A = swap(B) @ A, meaning only lora_B should be swapped. Applying it to lora_A as well produces swap(B) @ swap(A) which silently corrupts the norm_out LoRA for any FLUX LoRA that trains the final-layer adaLN modulation. Fixed by gating transform on lora_key == "lora_B".