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

AttributeError: 'BartConfig' object has no attribute '_to_dict_new' #351

Closed
LRY1994 opened this issue May 22, 2022 · 3 comments · Fixed by #406
Closed

AttributeError: 'BartConfig' object has no attribute '_to_dict_new' #351

LRY1994 opened this issue May 22, 2022 · 3 comments · Fixed by #406
Labels
bug Something isn't working

Comments

@LRY1994
Copy link

LRY1994 commented May 22, 2022

Environment info

  • adapter-transformers version:3.0.0
  • Platform: Unbuntu
  • Python version: 3.8
  • PyTorch version (GPU?): 1.11.0
  • Using GPU in script?: yes
  • Using distributed or parallel set-up in script?: no

Information

Model I am using : BartForConditionalGeneration

Language I am using the model on: English

Adapter setup I am using (if any): no

The problem arises when using:

  • torch.save(self.model, self.args.best_model_dir + "model.bin")
  • model = torch.load(self.args.best_model_dir + "model.bin")
  • Traceback (most recent call last):
    File "/home/simon/桌面/closed-book-prompt-qa/src/test.py", line 3, in
    model = torch.load( "src/temp/model_1653153641/model.bin")
    File "/home/simon/anaconda3/envs/qa/lib/python3.8/site-packages/torch/serialization.py", line 712, in load
    return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
    File "/home/simon/anaconda3/envs/qa/lib/python3.8/site-packages/torch/serialization.py", line 1046, in _load
    result = unpickler.load()
    File "/home/simon/anaconda3/envs/qa/lib/python3.8/site-packages/transformers/configuration_utils.py", line 253, in getattribute
    return super().getattribute(key)
    AttributeError: 'BartConfig' object has no attribute '_to_dict_new'

Expected behavior

successfully loaded for my downstream task

@LRY1994 LRY1994 added the bug Something isn't working label May 22, 2022
@LRY1994
Copy link
Author

LRY1994 commented May 22, 2022

when I downgrade to version 2.3.0 , it works .

@calpt
Copy link
Member

calpt commented May 23, 2022

Hey @LRY1994, this behavior is indeed introduced by a change in v3.x of the library. The recommended way of saving & loading model checkpoints using (adapter-)transformers is via the save_pretrained()/ from_pretrained() methods:

model.save_pretrained(self.args.best_model_dir)
...
model = BartForConditionalGeneration.from_pretrained(self.args.best_model_dir)

We'll look into solving the issues using torch.save()/load() you described.

@calpt
Copy link
Member

calpt commented Aug 24, 2022

This issue should be fixed with #406 and the next adapter-transformers release (v3.1.0).

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

Successfully merging a pull request may close this issue.

2 participants