adapters
adapters copied to clipboard
Error when trying to do torch.save
When running this code
import adapters
import torch
from transformers import AutoConfig, AutoModelForSequenceClassification
source_model = "FacebookAI/xlm-roberta-base"
num_labels = 100
config = AutoConfig.from_pretrained(
source_model, num_labels=num_labels
)
model = AutoModelForSequenceClassification.from_pretrained(
source_model, config=config
)
adapters.init(model)
torch.save(model, "test.pth")
I got the following error:
Can't pickle <class 'abc.XLMRobertaForSequenceClassification'>: attribute lookup XLMRobertaForSequenceClassification on abc failed
I'm using the following setup:
adapters==0.1.1
torch==1.13.1
transformers==4.35.2
It seems the problem is because the code creates a class in "execution time" using
model_class = type(
model_class_name,
(EmbeddingAdaptersWrapperMixin, ModelWithHeadsAdaptersMixin, model.__class__),
{},
)
There is any way I could do torch.save and preserving the class?
I found that the model-saving operations was achieved by model.save_adapter(). In your case, after adding adapters into models, It may not support torch save anymore.