Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Fix] Fix three final_layer LoRA conversion bugs in _convert_sd_scripts_to_ai_toolkit#14001

Merged
sayakpaul merged 1 commit into
huggingface:mainfrom
lcheng321:lcheng321-patch-1
Jun 20, 2026
Merged

[Fix] Fix three final_layer LoRA conversion bugs in _convert_sd_scripts_to_ai_toolkit#14001
sayakpaul merged 1 commit into
huggingface:mainfrom
lcheng321:lcheng321-patch-1

Conversation

@lcheng321

Copy link
Copy Markdown
Contributor

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".

…ts_to_ai_toolkit

Co-authored-by: christopher5106 <[email protected]>
Signed-off-by: lcheng <[email protected]>

@sayakpaul sayakpaul 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.

Thanks a lot!

@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.

@sayakpaul sayakpaul merged commit 2d0110f into huggingface:main Jun 20, 2026
15 checks passed
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fixes-issue lora size/S PR with diff < 50 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FLUX kohya LoRA conversion crashes on final_layer (KeyError on missing adaLN_modulation_1; "Incompatible keys" on final_layer alphas)

3 participants