Repository navigation
[LoRA] convert Z-Image LoRAs that only carry the fused qkv and bare out attention keys - #14875
Conversation
… `out` attention keys A LoRA trained on Z-Image's original module names (musubi-tuner, LyCORIS) has `attention.qkv` and `attention.out` and nothing else. The non-diffusers converter dropped both on the assumption that split `to.q/k/v` and `to_out.0` keys are also present (the Anime-Z layout), which emptied such a LoRA and then raised on its leftover `.alpha` keys. Split the fused key into to_q/to_k/to_v like the single-file converter does and map bare `out` to `to_out.0` when no split keys exist; the Anime-Z case keeps skipping the redundant keys. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Hi @christopher5106, thanks for the PR! It does not appear to link an issue it fixes. If this PR addresses an existing issue, please add a closing keyword (e.g. Please note that PRs without a linked issue are likely to be automatically closed 10 days after this notice. Once the PR links an issue (or gets the |
…rop the private-method test Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
sayakpaul
left a comment
There was a problem hiding this comment.
Thanks for your contribution. I left two questions.
| # limitations under the License. | ||
| import torch | ||
|
|
||
| from diffusers.loaders.lora_conversion_utils import _convert_non_diffusers_z_image_lora_to_diffusers |
There was a problem hiding this comment.
Not needed. We don't test private methods and in general checkpoints, that are beyond our control.
There was a problem hiding this comment.
Removed in 1476f6b. On our side the layout stays covered end to end by a synthetic-LoRA run against the deployed pipeline, so nothing is lost by dropping the unit test here.
| # Combined "qkv" projection. Next to split to.q/k/v keys (Anime-Z) it is | ||
| # redundant; a LoRA trained on Z-Image's original module names carries ONLY | ||
| # the fused key, so split it like the single-file converter does (q, k, v | ||
| # chunks along dim 0, the shared down weight repeated). |
There was a problem hiding this comment.
Could we simplify this statement and provide an example of where this occurs?
There was a problem hiding this comment.
Simplified in 1476f6b. Where it occurs: kohya-style trainers that wrap Z-Image's original module tree, whose attention is a fused qkv linear plus out, emit lora_unet_layers_0_attention_qkv.lora_down.weight / lora_unet_layers_0_attention_out.lora_down.weight and no split q/k/v keys. musubi-tuner's current zimage_model.py splits attention.qkv.weight into to_q/to_k/to_v before wrapping, so its recent checkpoints use the split names, but files from the fused layout circulate: the utensils/mold Z-Image loader documents it as the "Kohya / sd-scripts" layout and maps attention_qkv onto to_q/to_k/to_v and attention_out onto to_out.0 (https://github.com/utensils/mold/blob/main/crates/mold-inference/src/zimage/lora.rs), which is what this hunk does too, with the same chunk order as convert_z_image_fused_attention. The comment now says that in five lines and links that reference.
|
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. |
What does this PR do?
Fixes #14876
A LoRA trained on Z-Image's original module names (musubi-tuner and LyCORIS emit
lora_unet_<block>_attention_qkvandlora_unet_<block>_attention_out, and nothing else for attention) is currently emptied by_convert_non_diffusers_z_image_lora_to_diffusers: the converter drops the fusedqkvkey and the bareoutkey on the assumption that splitto.q/k/vandto_out.0keys are also present (the Anime-Z layout), then raisesValueError: state_dict should be emptyon the leftover.alphakeys.This PR keeps the Anime-Z behaviour (skip the redundant keys when split ones exist) and otherwise:
qkvLoRA intoto_q/to_k/to_v, chunking the up weight along dim 0 likeconvert_z_image_fused_attentiondoes for base weights and repeating the shared down weight;outkey toto_out.0, consuming the alpha thatnormalize_out_keyhad already renamed.Two tests in
tests/lora/test_lora_conversion_z_image.py: the attention-only layout converts to the expected 16 tensors with the right shapes and the k chunk lands unscaled when alpha equals rank; a state dict that carries both fused and split keys still uses the split ones.Found by generating synthetic LoRAs from every layout we see in the wild and running them through a deployed Z-Image pipeline; the fused-only layout was the one that failed.
Before submitting
.lora.down.weight). The underscore-key path (diffusion_model.*.lora_down.weight, ComfyUI exports) still passes a fusedqkvkey through unsplit; left alone because I have not seen such a file, so there is nothing to test it against.outandto_out.0keys,normalize_out_keyrenames the bare alpha toto_out.0.alpha, which can collide with the real one. Pre-existing and unchanged here.Who can review?
@sayakpaul @BenjaminBossan