fix(lora): validate LoRA dimensions against model at load time (#922)#925
Open
livepeer-tessa wants to merge 1 commit intomainfrom
Open
fix(lora): validate LoRA dimensions against model at load time (#922)#925livepeer-tessa wants to merge 1 commit intomainfrom
livepeer-tessa wants to merge 1 commit intomainfrom
Conversation
Add dimension validation in parse_lora_weights() so a LoRA trained for a
different model size (e.g. Wan2.1-5B, in_features=5120) is rejected with a
user-friendly ValueError when loaded into the 1.3B model (in_features=1536),
rather than loading silently and crashing 150+ times at inference.
Before: mat1/mat2 shape mismatch RuntimeError deep in peft/torch at inference
After: ValueError at load time naming the layer, expected vs actual dims, and
a plain-language hint about model architecture mismatch
Also adds test_lora_dimension_validation.py covering:
- compatible LoRA loads without error
- 5B LoRA on 1.3B model raises ValueError
- error message is user-friendly (names layer + dimensions)
- out_features mismatch is also caught
- 5B LoRA on 5B model is fine
Signed-off-by: Tessa (livepeer-tessa) <tessa@livepeer.org>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Contributor
🚀 fal.ai Preview Deployment
Livepeer Runner
Testing Livepeer Mode |
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.
Problem
Closes #922.
When a LoRA trained for Wan2.1-5B (
in_features=5120) is loaded into the Wan2.1-1.3B model (in_features=1536),peft_lora.pysuccessfully loads the adapter (layer names match) but then fails at inference with:This produced 156 identical errors in session
067a55be(14:41–14:55 UTC today) while consuming GPU resources the entire time — with no user-visible error message.Root Cause
parse_lora_weights()matched LoRA layer names to model parameters without checking that the weight shapes were compatible. The mismatch (lora_A.shape[1] != model_weight.shape[1]) only surfaced later during thetorch.mmcall insidepeft/tuners/lora/layer.py.Fix
Add dimension validation inside
parse_lora_weights()immediately after a match is found. If the LoRA'sin_featuresorout_featuresdon't match the model layer's weight shape, raise aValueErrorwith a user-readable message naming the layer, the LoRA dimensions, the model dimensions, and a plain-language hint about model architecture mismatch.Before:
After:
The
ValueErrorpropagates throughPeftLoRAStrategy.load_adapters_from_list(caught →RuntimeError: LoRA loading failed) and throughPermanentMergeLoRAStrategythe same way.Tests
5 new unit tests in
tests/test_lora_dimension_validation.py:ValueErrorAll 5 pass locally.