question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error while saving Longformer pre-trained model

See original GitHub issue

Thanks for the transformers library!

Information

I am trying to finetune a pre-trained model of type LongformerForQuestionAnswer on a custom QA dataset using a custom script morphed from run_squad.py. The pre-trained model is allenai/longformer-large-4096-finetuned-triviaqa

While saving the pretrained model, I run into the following error:

Traceback (most recent call last):
  File "examples/question-answering/run_nq.py", line 809, in <module>
    main()
  File "examples/question-answering/run_nq.py", line 752, in main
    global_step, tr_loss = train(args, train_dataset, model, tokenizer)
  File "examples/question-answering/run_nq.py", line 248, in train
    tokenizer.save_pretrained(output_dir)
  File "/home/danishp/git/explain-qa/src/third_party/transformers/src/transformers/tokenization_utils_base.py", line 1368, in save_pretrained
    write_dict[key] = value.__getstate__()
AttributeError: 'AddedToken' object has no attribute '__getstate__'

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
gabrercommented, Jul 13, 2020

Actually, I never pip-installed the tranformers library, I am just running the cloned github code from a few days ago (this is because I had to edit some parts of the code for my use case).

However, when I pip installed these versions, surprisingly, I don’t see this error. As you suggest, it is possible that some tokenizer changes that were intended for version 3.0.0 crept in.

In the cloned code that I am using, if I change the following line to:

https://github.com/huggingface/transformers/blob/ef0e9d806c51059b07b98cb0279a20d3ba3cbc1d/src/transformers/tokenization_utils_base.py#L1368

write_dict[key] = value.content # instead of __getstate__()

The problem is fixed.

Just had the same issue with version 3.0.2 while fine-tuning the Robert-base model. Guess, it would have been the same with other BERT-base models. Changing this line solved the issue.

2reactions
danishpruthicommented, Jul 2, 2020

Actually, I never pip-installed the tranformers library, I am just running the cloned github code from a few days ago (this is because I had to edit some parts of the code for my use case).

However, when I pip installed these versions, surprisingly, I don’t see this error. As you suggest, it is possible that some tokenizer changes that were intended for version 3.0.0 crept in.

In the cloned code that I am using, if I change the following line to:

https://github.com/huggingface/transformers/blob/ef0e9d806c51059b07b98cb0279a20d3ba3cbc1d/src/transformers/tokenization_utils_base.py#L1368

write_dict[key] = value.content # instead of __getstate__()

The problem is fixed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Longformer
Transformer-based models are unable to process long sequences due to their self-attention operation, which scales quadratically with the sequence length. To ...
Read more >
Cannot load longformer model in tensorflow after fine ...
I fine-tuned a longformer model in Tensorflow 2.8.2 on Google Colab ... But now I am getting this error when trying to save...
Read more >
Importing Hugging Face models into Spark NLP
In this article we are going to show two examples of how to import Hugging Face embeddings models into Spark NLP, and another...
Read more >
Source code for extractive - TransformerSum - Read the Docs
MODEL_CLASSES = ( tuple( "Note: Only showing custom models because old ... Only load the pre-trained weights when # beginning to fit for...
Read more >
arXiv:2004.05150v2 [cs.CL] 2 Dec 2020
ness of Longformer in long document modeling. Then, to evaluate Longformer's ability ... pretrained models, we pretrain it with the masked.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found