馃毃 Give mixed-rank LoRAs without alpha keys their intended scale - #14409
Open
apolinario wants to merge 1 commit into
Open
馃毃 Give mixed-rank LoRAs without alpha keys their intended scale#14409apolinario wants to merge 1 commit into
apolinario wants to merge 1 commit into
Conversation
Collaborator
Author
|
(unsure if we need this test) |
BenjaminBossan
approved these changes
Aug 7, 2026
BenjaminBossan
left a comment
Member
There was a problem hiding this comment.
Thanks for the fix.
From the PEFT point of view, this looks correct. One edge case I'm not sure about is if rank_dict contains exactly one unique value: I assume in that case, we would never reach this function and it's okay. If we can, however, reach this function, then it's uncovered.
I don't know enough about the Diffusers ecosystem to judge whether this change could break existing checkpoints, but it's reasonable to assume that no alpha implies the intended scale is 1.0.
As for the test, it probably doesn't add a lot, I'd say is best if a maintainer takes a look.
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.
get_peft_kwargstakeslora_alphafrom the first entry of the rank dict and never revisits it, and with no alpha keysalpha_patternstays empty. For an adapter with mixed ranks and no alpha keys that means every module whose rank differs from the first key's rank gets an arbitrary scale: PEFT falls back to the globallora_alpha(peft/tuners/lora/model.py,alpha_pattern.get(key, config.lora_alpha)), so the direction of the error depends on state dict key order.Real case:
larryvrh/MiniMax-H3-Turbo-Loraships 518 tensors, ranks 64 (attention/FFN) and 16 (AdaLN), zero alpha keys, and statesW_eff = W + lora_B @ lora_A, alpha = rank. The AdaLN key sorts first, solora_alpha = 16, r = 64and all rank 64 modules load at 0.25x. Its pre converted mirror (InstantX/MiniMax-H3-Turbo-Lora-Diffusers) documents a manualnetwork_alphasworkaround for exactly this.The fix mirrors the ranks into the alphas when the checkpoint brings no alpha information, which is the diffusers/PEFT convention (alpha == rank, scale 1.0) and what
load_lora_adapteralready does for SAI control LoRAs a few lines below. It is gated on the absence of alpha data: mixed rank adapters with a declared alpha keep it (a uniform declared alpha must not fall back to per module ranks), uniform rank adapters are a no-op, and the metadata serialization path is unaffected because it bypasses this function entirely.馃毃 Behavior change for existing mixed rank, no alpha LoRAs: they previously loaded at an order dependent wrong scale and now load at the intended scale 1.0.
Kohya conversion precedent for the invariant:
lora_conversion_utils.pyfoldsalpha / rankinto the weights withdefault_alpha = rank, i.e. it also assumes scale 1.0 when alpha is absent.Tests cover the mixed rank no alpha case (including key order independence), uniform rank, uniform declared alpha, and per module alphas.