-
Notifications
You must be signed in to change notification settings - Fork 31.2k
Closed
Description
Environment info
transformersversion: 4.6.0.dev0- Platform: Linux-3.10.0-1127.10.1.el7.x86_64-x86_64-with-debian-buster-sid
- Python version: 3.6.13
- PyTorch version (GPU?): 1.8.1+cu102 (True)
- Tensorflow version (GPU?): 2.4.1 (False)
- Using GPU in script?: no
- Using distributed or parallel set-up in script?: no
Who can help
rag: @patrickvonplaten, @lhoestq
Models:
RAG model
Information
Model I am using RAG
The problem arises when using the official example scripts from https://huggingface.co/facebook/rag-sequence-nq, which I copied here:
from transformers import RagTokenizer, RagRetriever, RagSequenceForGeneration
tokenizer = RagTokenizer.from_pretrained("facebook/rag-sequence-nq")
retriever = RagRetriever.from_pretrained("facebook/rag-sequence-nq", index_name="exact", use_dummy_dataset=True)
model = RagSequenceForGeneration.from_pretrained("facebook/rag-sequence-nq", retriever=retriever)
input_dict = tokenizer.prepare_seq2seq_batch("how many countries are in europe", return_tensors="pt")
generated = model.generate(input_ids=input_dict["input_ids"])
print(tokenizer.batch_decode(generated, skip_special_tokens=True)[0])
The tasks I am working on is:
I am trying to ran the sample code from above. Note that this same error occurs also when finetuning rag with the official code in transformers/examples/research_projects/rag/finetune_rag.sh
To reproduce
Steps to reproduce the behavior:
- run the sample code above
The error is:
Traceback (most recent call last):
File "prova_rag.py", line 5, in <module>
model = RagSequenceForGeneration.from_pretrained("facebook/rag-sequence-nq", retriever=retriever, _fast_init=False)
File "/nlu/users/giovanni_bonetta/transformers/src/transformers/modeling_utils.py", line 1208, in from_pretrained
model, state_dict, pretrained_model_name_or_path
File "/nlu/users/giovanni_bonetta/transformers/src/transformers/modeling_utils.py", line 1278, in _load_state_dict_into_model
model._init_weights(module)
File "/nlu/users/giovanni_bonetta/miniconda2/envs/hf_venv/lib/python3.6/site-packages/torch/nn/modules/module.py", line 948, in __getattr__
type(self).__name__, name))
AttributeError: 'RagSequenceForGeneration' object has no attribute '_init_weights'
Looking at last commits i suppose that the error was introduced in "Pytorch - Lazy initialization of models #11471" a couple of weeks ago, where the line model._init_weights(module) was introduced.
Expected behavior
It should initialize the model without errors.
patrickvonplaten
Metadata
Metadata
Assignees
Labels
No labels