{{ message }}
Fix LoRA adapter support for convolutional layers (fixes #3056)#3064
Open
oliver0006 wants to merge 1 commit into
Open
Fix LoRA adapter support for convolutional layers (fixes #3056)#3064oliver0006 wants to merge 1 commit into
oliver0006 wants to merge 1 commit into
Conversation
The LoRA class claimed to work with nn.Conv layers but assumed nn.Linear semantics (weight shape and linear projections), crashing on any convolutional layer. The adapter projections now mirror the geometry of the pretrained convolution (following the approach of HF peft): the down projection reuses kernel/stride/padding/dilation to map onto rank channels, and the up projection is a pointwise convolution initialized to zero. Grouped convolutions raise a clear error. Linear behavior and checkpoint attribute names are unchanged. Fixes speechbrain#3056 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

What this does
Fixes #3056
The
LoRAadapter class claimed to supportnn.Convlayers but assumednn.Linearsemantics, crashing withRuntimeError: mat1 and mat2 shapes cannot be multipliedon any convolutional layer (e.g. the wav2vec2-style repro in the issue).This PR implements real convolutional support instead of removing the claim, following the approach used by HF
peft:kernel_size,stride,padding,dilation,padding_mode), mapping ontorankchannels — so both branches produce outputs of identical shaperanktoout_channels, zero-initialized (standard LoRA init)groups != 1): clearValueErrorinstead of a cryptic crashnn.Linear(and other weight-matrix modules); checkpoint attribute names (adapter_down_proj/adapter_up_proj) are preserved so existing checkpoints keep loadingTesting
New
tests/unittests/test_adapters.pywith 9 tests verifying the core LoRA properties:base(x) + up(down(x)) * alpha/rankstride=5,padding='same',dilation=2)groups != 1raisesValueErrorAdaptedModel(all_conv=True)repro from the issue, forward + backward, with only adapter params trainableAlso added a Conv1d doctest to the
LoRAdocstring. All 9 tests + 3 doctests pass;ruff check,ruff formatandcodespellpass on the changed files.Co-written by a human (@oliver0006) and Claude AI (Fable 5) working together.
🤖 Generated with Claude Code