Support mixed-rank LoRA adapter metadata - #3004
Open
bghira wants to merge 1 commit into
Open
Conversation
Inspect init_lora checkpoints before constructing PEFT configs so mixed-rank checkpoints can populate rank_pattern and alpha_pattern instead of being forced through the global rank. Infer missing alpha values from per-module ranks when a checkpoint has mixed ranks but no explicit alpha tensors, and preserve explicit alpha tensors when present. Apply the same inference path for validation adapters and direct LoRA weight loading. Route vendored pipelines through SimpleTuner's get_peft_kwargs wrapper so Diffusers loader changes do not drop layerwise rank or alpha metadata.
bghira
marked this pull request as ready for review
August 6, 2026 19:44
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for mixed-rank LoRA checkpoints by inferring per-module alpha/rank patterns and wiring those into PEFT/diffusers loading paths.
Changes:
- Add utilities to detect mixed ranks, collect alpha/rank metadata, and synthesize missing alphas.
- Update adapter/pipeline/model codepaths to apply inferred alpha/rank patterns during LoRA init/load.
- Add regression + unit tests covering mixed-rank detection and alpha inference behavior.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_lora_loading_regression.py | Adds regression test validating mixed-rank init_lora produces PEFT rank/alpha patterns. |
| tests/test_lora_format.py | Adds unit tests for format detection and mixed-rank alpha/rank inference helpers. |
| simpletuner/helpers/training/lora_format.py | Introduces rank/alpha collection + inference helpers and a get_peft_kwargs wrapper. |
| simpletuner/helpers/training/adapter.py | Updates LoRA weight loading to set scaling via alpha and synthesize alphas for mixed ranks. |
| simpletuner/helpers/models/sd3/pipeline.py | Switches to local get_peft_kwargs wrapper import. |
| simpletuner/helpers/models/longcat_video/pipeline.py | Removes get_peft_kwargs from import list. |
| simpletuner/helpers/models/krea2/lora_pipeline.py | Switches to local get_peft_kwargs wrapper import. |
| simpletuner/helpers/models/ideogram/pipeline.py | Switches to local get_peft_kwargs wrapper import. |
| simpletuner/helpers/models/hidream/pipeline.py | Switches to local get_peft_kwargs wrapper import. |
| simpletuner/helpers/models/flux/pipeline_controlnet.py | Removes get_peft_kwargs from import list. |
| simpletuner/helpers/models/flux/pipeline.py | Imports local get_peft_kwargs wrapper via lora_format. |
| simpletuner/helpers/models/common.py | Uses init_lora checkpoint metadata to set PEFT rank/alpha patterns; normalizes inferred alphas. |
| simpletuner/helpers/models/chroma/pipeline.py | Switches to local get_peft_kwargs wrapper import. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
172
to
+176
| elif ".alpha" in k or ".lora_alpha" in k: | ||
| explicit_alpha_keys = True | ||
| kk = k.replace(".lora_alpha", "").replace(".alpha", "") | ||
| if kk in lora_layers: | ||
| lora_layers[kk].lora_alpha[loraKey] = v | ||
| _set_lora_alpha(lora_layers[kk], loraKey, v) |
Comment on lines
155
to
+160
| for k, v in state_dict.items(): | ||
| if "lora_A" in k: | ||
| kk = k.replace(".lora_A.weight", "") | ||
| if kk in lora_layers: | ||
| lora_layers[kk].lora_A[loraKey].weight.copy_(v) | ||
| loaded_ranks[kk] = int(v.shape[0]) |
Comment on lines
+61
to
+62
| def _most_common(values: list[Any]) -> Any: | ||
| return Counter(values).most_common(1)[0][0] |
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.
Summary
Adds mixed-rank LoRA metadata handling so init_lora and validation adapter loading can preserve per-layer rank and alpha values instead of forcing everything through the global rank.
Details
Validation
.venv/bin/python -m unittest -v -f tests.test_lora_format tests.test_lora_loading_regression