Skip to content

fix: handle LoKr format keys in Z-image LoRA conversion#13250

Closed
s-zx wants to merge 1 commit intohuggingface:mainfrom
s-zx:fix/13221-zimage-lora-lokr
Closed

fix: handle LoKr format keys in Z-image LoRA conversion#13250
s-zx wants to merge 1 commit intohuggingface:mainfrom
s-zx:fix/13221-zimage-lora-lokr

Conversation

@s-zx
Copy link
Copy Markdown

@s-zx s-zx commented Mar 10, 2026

Summary

The _convert_non_diffusers_z_image_lora_to_diffusers function did not consume LoKr-format keys (.lokr_w1, .lokr_w2, .alpha) from external Z-image LoRA checkpoints (e.g. Kohya/LyCORIS), causing a ValueError when the state_dict was not empty after conversion.

Root Cause

The conversion function handled standard LoRA formats (lora_down/lora_up, lora_A/lora_B, lora.down/up) but lacked handling for LoKr decomposition format used by some trainers.

Fix

Add handling to convert LoKr decomposition to standard lora_A/lora_B format: for linear layers, lokr_w1 @ lokr_w2 maps to lora_B @ lora_A with the same alpha scaling. The conversion applies the standard alpha/rank scaling used by other formats.

Fixes #13221

The _convert_non_diffusers_z_image_lora_to_diffusers function did not consume
LoKr-format keys (.lokr_w1, .lokr_w2, .alpha) from external Z-image LoRA
checkpoints (e.g. Kohya/LyCORIS), causing a ValueError when the state_dict
was not empty after conversion.

Add handling to convert LoKr decomposition to standard lora_A/lora_B format:
for linear layers, lokr_w1 @ lokr_w2 maps to lora_B @ lora_A with the same
alpha scaling used by other formats.

Fixes huggingface#13221
Signed-off-by: s-zx <s-zx@users.noreply.github.com>
@asomoza
Copy link
Copy Markdown
Member

asomoza commented Mar 12, 2026

HI @s-zx, can you show an example image of a lokr that works with this? I mean the original somewhere where it works versus this PR? It would also help to have the actual lokr in the hub

Copy link
Copy Markdown
Member

@sayakpaul sayakpaul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clean! Can be merged provided @asomoza can have a reasonable test with an actual checkpoint.

@asomoza
Copy link
Copy Markdown
Member

asomoza commented Mar 17, 2026

just to add more context, I've tried a lokr before (SDXL) that was properly trained using Kronecker products which is the main reason to use lokr, but this PR doesn't handle that, so I was curious as if this conversion really produces good results.

ComfyUI seems to have the same problem and that's why this node exists: https://github.com/AbstractEyes/comfyui-lycoris

This is not a blocker though, if this conversion works and produces the expected results, it should be fine.

I'll leave the merging decision to @sayakpaul

@bghira
Copy link
Copy Markdown
Contributor

bghira commented Mar 22, 2026

this is incorrectly implemented, w1 and w2 aren't the same as LoRA up and down. the PEFT integration for Diffusers doesn't work with PEFT LoKr models currently (PEFT does on its own though), and this PR is massively incomplete.

better solution for users who need LyCORIS models to load is to use the LyCORIS library;

  • it has high-precision fusion, which PEFT doesn't have
  • it has multi-LyCORIS support
  • actually loads the keys correctly without conversion and uses correct forward impl

@asomoza
Copy link
Copy Markdown
Member

asomoza commented Mar 23, 2026

I'm closing this PR since it didn't have an empirical test we can see and because it's clear that this is not the best method to solve the issue.

There's a discussion in this issue #13261 about lokr loras, once we get a better plan, we can reopen this PR or start a new one.

@asomoza asomoza closed this Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Zimage lora support issue too

4 participants