Skip to content
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

Error when trying to do torch.save #648

Open
SSamDav opened this issue Feb 12, 2024 · 2 comments
Open

Error when trying to do torch.save #648

SSamDav opened this issue Feb 12, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@SSamDav
Copy link

SSamDav commented Feb 12, 2024

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
@SSamDav SSamDav added the bug Something isn't working label Feb 12, 2024
@SSamDav
Copy link
Author

SSamDav commented Feb 12, 2024

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?

@conglei2XU
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants