-
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
Does PEFT support CodeBERT? #1865
Comments
I took a look at your example but since you're using custom models and datasets, I cannot reproduce it. Instead, I tried to simplify the example as much as I could, resulting in the code below. It uses the codebert model from MS and some dummy data: import torch
from torch.optim import AdamW
from peft import (
get_peft_model,
PeftType,
PrefixTuningConfig,
)
from transformers import RobertaForSequenceClassification
model_name_or_path = "microsoft/codebert-base" # BB
model = RobertaForSequenceClassification.from_pretrained(model_name_or_path, return_dict=True, num_labels=2) # BB
batch_size = 1
gradient_accumulation_steps = 4
num_epochs = 5
lr = 3e-2
max_input_length = 512
peft_config = PrefixTuningConfig(
task_type='SEQ_CLS',
num_virtual_tokens=1 # to be changed
)
model = get_peft_model(model, peft_config)
model.print_trainable_parameters()
optimizer = AdamW(model.parameters(), lr=lr)
model.train()
for epoch in range(num_epochs):
outputs = model(torch.arange(10).view(-1, 1), torch.ones(10).view(-1, 1), labels=torch.zeros(20).view(10, 2))
loss = outputs.loss
loss.backward()
optimizer.step()
optimizer.zero_grad()
print(epoch, loss.item())
print("finished successfully") When I run it locally, it passes. Therefore, it's unclear to me what goes wrong with your script. If possible, I would advise to run this code on CPU with a debugger turned on and check what exactly is going wrong, as it looks like you're indexing outside of the tensor dimensions. If you do that, you should also be able to provide the full stack trace of the error, which could also help investigating. |
@BenjaminBossan |
Yes, it should totally work for 5 labels. Did you try it and encounter an error? |
@BenjaminBossan |
Well, predicting 5 classes is harder than 2, so it's hard to tell if there is something wrong or if the output is expected. Could you please show me the |
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread. |
System Info
linux
Who can help?
@pacman100 @younesbelkada @BenjaminBossan
When I used prefix tuning to fine-tune codebert for sequence classification, it showed the following errors:
I used RobertaForSequenceClassification to load codebert. Did the error occure for the reason that PEFT does not support codebert?
Information
Tasks
examples
folderReproduction
Expected behavior
finetune the codebert model
The text was updated successfully, but these errors were encountered: