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

[RAG] official facebook example code for RAG is not working anymore. #11704

Closed
giobin opened this issue May 12, 2021 · 0 comments · Fixed by #11705
Closed

[RAG] official facebook example code for RAG is not working anymore. #11704

giobin opened this issue May 12, 2021 · 0 comments · Fixed by #11705

Comments

@giobin
Copy link

giobin commented May 12, 2021

Environment info

  • transformers version: 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:

  1. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant