[LoRA] convert Z-Image LoRAs that only carry the fused qkv and bare out attention keys - #14875
Open
christopher5106 wants to merge 1 commit into
Open
christopher5106 wants to merge 1 commit into
christopher5106 wants to merge 1 commit into
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>
Contributor
|
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 |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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