-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request for adding the lora implementation for Conv1d rather than transormers.utils.Conv1d #2241
Comments
Thanks for opening this feature request. We cannot drop support for transormers |
Thanks, would you please provide any hints for me to implement it? e.g., do you think it is ok if I directly replace every transformers.conv1d with torch.conv1d? Thanks a lot. |
First of all, let me preface by saying that I'm not sure if we can just use torch peft/src/peft/tuners/lora/layer.py Lines 1262 to 1269 in 3f9ce55
This is the logic where we check the base layer type and decide that we want to apply a Theoretically, we can just replace the elif isinstance(target_base_layer, (Conv1D, nn.Conv1d)): to match torch However, we should not replace transformers |
Hi, I tried you recommendation method, but I received a new error:
Since my conv1d has kernel size large than 1, it is not trival to make the transformation. I will try other softwares to see if it works. |
If you provide the code to reproduce the error, I can take a look. |
Hi, thanks a lot. I am trying to implement the lora mode of Enformer: https://github.com/lucidrains/enformer-pytorch Here is my code to have the lora mode:
LoRA works well for linear, toq,tok, tov, but the conv represents the nn.Conv1d mode, and I faced this error. The conv layer has kernel size as 5. |
I could make a bit more progress: import torch
from peft import LoraConfig, get_peft_model
from enformer_pytorch import Enformer
model = Enformer.from_pretrained("EleutherAI/enformer-official-rough", device_map=0)
model = get_peft_model(model, LoraConfig(target_modules=["linear", "to_q", "to_k", "to_v", "conv"]))
seq = torch.randint(0, 5, (1, 196_608)).to(0) # for ACGTN, in that order (-1 for padding)
output = model(seq) The only changes I had to make were to this line: - elif isinstance(target_base_layer, Conv1D):
+ elif isinstance(target_base_layer, (Conv1D, nn.Conv1d)): and this line: - elif isinstance(base_layer, nn.Conv2d):
+ elif isinstance(base_layer, (nn.Conv2d, nn.Conv1d)): However, the forward pass will fail because of mismatched shapes. I think the |
Feature request
Hi, I found that Lora does not support the model with torch.nn.Conv1d as convolution layers, which limits the use-case for models pre-trained with this class (for example, Enformer). I wonder if it is possible to add an implementation based on this class.
Motivation
To finetune enformer.
Your contribution
If you need I can open a PR.
The text was updated successfully, but these errors were encountered: