fix: handle LoKr format keys in Z-image LoRA conversion#13250
fix: handle LoKr format keys in Z-image LoRA conversion#13250s-zx wants to merge 1 commit intohuggingface:mainfrom
Conversation
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>
|
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 |
|
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 |
|
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;
|
|
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. |
Summary
The
_convert_non_diffusers_z_image_lora_to_diffusersfunction did not consume LoKr-format keys (.lokr_w1,.lokr_w2,.alpha) from external Z-image LoRA checkpoints (e.g. Kohya/LyCORIS), causing aValueErrorwhen 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_w2maps tolora_B @ lora_Awith the same alpha scaling. The conversion applies the standard alpha/rank scaling used by other formats.Fixes #13221