Skip to content

Studio: keep lora_alpha in every diffusion LoRA export - #18469

Merged
danielhanchen merged 3 commits into
mainfrom
studio-diffusion-lora-alpha-all
Nov 20, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
studio-diffusion-lora-alpha-all

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Problem

A diffusion LoRA trained with a lora_alpha other than its rank reloads at the wrong strength. diffusers' save_lora_weights only writes the adapter config (rank, alpha) into the safetensors header when it is passed *_lora_adapter_metadata; without it the loader assumes lora_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_alpha defaults to the rank, so a default run is unaffected. A run that sets lora_alpha (the training API accepts it) saves a file that loads scaled by rank / alpha instead of alpha / rank.

Change

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 read lora_alpha 8. On main 7 of these fail; here all pass.

The DiT trainer, conditioning cache and train suites: 410 passed (CPU).

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.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T21:10:19.136643Z 7b8930a Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: f2099af3bf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@NilayYadav NilayYadav self-assigned this Nov 19, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 7b8930a036

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@NilayYadav

Copy link
Copy Markdown
Collaborator

Review + reproduction evidence

Pinned review: 329846f3b. No blocking findings; two optional cleanups noted in the review.

I reproduced the export round trip on the merge base 75bea11 (Linux, CPU, diffusers 0.42.1, peft 0.18.0): a FLUX transformer with a LoRA at r=4, lora_alpha=8, saved through the trainer's own saver and reloaded with load_lora_weights.

  • Before: reloaded lora_alpha = 4, scaling = 1.0, so the adapter applies at half its trained strength.

  • PR head: reloaded lora_alpha = 8, scaling = 2.0, matching training.

  • New test, base vs head: diffusers 0.42.1 7 failed -> 13 passed; diffusers 0.41.0 (the Python 3.10 pin) 7 failed -> 12 passed, 1 skipped (no FLUX.3 pipeline in 0.41.0).

  • Default runs (lora_alpha == rank) load the same scale with or without the header, and files exported before this change load as before.

Conclusion: real and fixed for every DiT family and SDXL. Good to merge once CI on the current head is green.

@danielhanchen
danielhanchen merged commit be0230a into main Nov 20, 2026
@danielhanchen
danielhanchen deleted the studio-diffusion-lora-alpha-all branch November 20, 2026 02:47
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.

3 participants