Repository navigation
Studio: keep lora_alpha in every diffusion LoRA export - #18469
Conversation
FLUX.1, Qwen-Image, Z-Image, Krea 2, FLUX.2-dev, FLUX.2-klein, LTX-2 and SDXL saved without the adapter metadata, so diffusers reloaded an adapter trained at lora_alpha != rank at alpha == rank. They now write it, as Qwen-Image-2.1, FLUX.3, MOSS and Wan already did.
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
| adapter_metadata | ||
| and "transformer_lora_adapter_metadata" in inspect.signature(save).parameters | ||
| ): | ||
| kwargs["transformer_lora_adapter_metadata"] = dict(adapter_metadata) |
There was a problem hiding this comment.
Writing the whole training-side LoraConfig makes these exports unloadable in a previously working Diffusers environment, even when alpha equals rank. Diffusers passes the header straight into LoraConfig(**metadata). PEFT 0.18.1 writes alora_invocation_tokens: null for an ordinary LoRA, and PEFT 0.17.1 rejects that keyword. The SDXL saver has the same issue with unet.peft_config["default"].to_dict().
I trained tiny FLUX.1 and SDXL adapters on an RTX 3090 with rank 4 and alpha 4 or 8, then called pipe.load_lora_weights(...) on a fresh model for each file. On Diffusers 0.36.0 / PEFT 0.17.1, all four merge-base exports loaded, with the known half-strength update at alpha 8. All four PR exports raised TypeError: LoraConfig.__init__() got an unexpected keyword argument 'alora_invocation_tokens'. On Studio's pinned Diffusers 0.42.1 / PEFT 0.18.1, the PR correctly restored the trained outputs in all four cases.
Could the two savers write the portable fields used by these trainers? I kept r, lora_alpha, target_modules, rank_pattern, alpha_pattern, lora_dropout, and init_lora_weights in the header and left every weight tensor identical. All four files then loaded in both environments with zero difference from the trained denoiser outputs. The default-alpha case makes a good regression test because it already round-trips on the merge base.
…red LoRA save helper [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Review + reproduction evidencePinned review: I reproduced the export round trip on the merge base
Conclusion: real and fixed for every DiT family and SDXL. Good to merge once CI on the current head is green. |
Problem
A diffusion LoRA trained with a
lora_alphaother than its rank reloads at the wrong strength. diffusers'save_lora_weightsonly writes the adapter config (rank, alpha) into the safetensors header when it is passed*_lora_adapter_metadata; without it the loader assumeslora_alpha == rank. Qwen-Image-2.1, FLUX.3, MOSS, Wan and (since #18386) LTX-2.5 already pass it. FLUX.1, Qwen-Image, Z-Image, Krea 2, FLUX.2-dev, FLUX.2-klein and the SDXL UNet trainer still saved without it, and LTX-2 had its own inline copy of the logic.lora_alphadefaults to the rank, so a default run is unaffected. A run that setslora_alpha(the training API accepts it) saves a file that loads scaled byrank / alphainstead ofalpha / rank.Change
_save_transformer_lora, passes the trained adapter'sLoraConfigastransformer_lora_adapter_metadatawhen this diffusers'save_lora_weightstakes it (older diffusers keep the old call).save_takes_metadata = Trueand save through the helper; LTX-2's inline copy from Studio diffusion training: LTX-2.5 LoRA training (captions through the Gemma 4 worker, dev DiT, baked into the distilled Video page model) #18386 is replaced by it.unet_lora_adapter_metadatathe same way.Tests
studio/backend/tests/test_diffusion_lora_alpha_metadata.py: every DiT family in_SPECS(skipped where the installed diffusers has no pipeline for it) and SDXL save an r=4, alpha=8 adapter and the header must readlora_alpha8. On main 7 of these fail; here all pass.The DiT trainer, conditioning cache and train suites: 410 passed (CPU).