Skip to content

Fix Kohya UNet LoRA key conversion for conv_in/conv_out/time_embedding#14006

Draft
dxqb wants to merge 1 commit into
huggingface:mainfrom
dxqb:fix-unet-lora-conv-time-embedding
Draft

Fix Kohya UNet LoRA key conversion for conv_in/conv_out/time_embedding#14006
dxqb wants to merge 1 commit into
huggingface:mainfrom
dxqb:fix-unet-lora-conv-time-embedding

Conversation

@dxqb

@dxqb dxqb commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #14005.

What does this PR do?

_convert_unet_lora_key() converts Kohya-format UNet LoRA keys to Diffusers-compatible names by replacing every _ with . and then patching specific substrings back (input.blocksdown_blocks, proj.inproj_in, conv.shortcutconv_shortcut, etc.). It was missing patches for three top-level UNet submodules:

  • conv.inconv_in
  • conv.outconv_out
  • time.embed.0 / time.embed.2time_embedding.linear_1 / time_embedding.linear_2

So a Kohya key like lora_unet_conv_in... came out as conv.in... instead of conv_in..., didn't match any parameter on the actual model, and got reported as an unexpected key by the PEFT adapter loader instead of being applied.

This adds the missing patches. Verified locally that _convert_unet_lora_key now produces the correct names for conv_in, conv_out, time_embedding.linear_1, and time_embedding.linear_2, and that unrelated keys (e.g. emb_layers inside resnet blocks) are unaffected.

Who can review?

@yiyixuxu

_convert_unet_lora_key() had no mapping for these three top-level UNet
submodules, so Kohya-format keys touching them (e.g. lora_unet_conv_in,
lora_unet_time_embed_0/2) came out as conv.in/conv.out/time.embed.0/2
instead of conv_in/conv_out/time_embedding.linear_1/2, and were
reported as unexpected keys instead of being applied.
@github-actions github-actions Bot added lora size/S PR with diff < 50 LOC fixes-issue labels Jun 20, 2026
@dxqb

dxqb commented Jun 20, 2026

Copy link
Copy Markdown
Contributor Author

needs a test, I'll mark the PR as ready as soon as that passes

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.

_convert_unet_lora_key misses conv_in/conv_out/time_embedding mapping for Kohya UNet LoRAs

1 participant