ImportError: cannot import name 'DPRReader' from 'transformers'
Author: hiteshsom
Pull request: no
Labels: name: wontfix

Hi, I am trying to run below code, it can be found at this [link](https://huggingface.co/transformers/model_doc/dpr.html#dprreader)
```
from transformers import DPRReader, DPRReaderTokenizer
tokenizer = DPRReaderTokenizer.from_pretrained('facebook/dpr-reader-single-nq-base')
model = DPRReader.from_pretrained('facebook/dpr-reader-single-nq-base')
encoded_inputs = tokenizer(
        questions=["What is love ?"],
        titles=["Haddaway"],
        texts=["'What Is Love' is a song recorded by the artist Haddaway"],
        return_tensors='pt'
    )
outputs = model(**encoded_inputs)
start_logits = outputs.stat_logits
end_logits = outputs.end_logits
relevance_logits = outputs.relevance_logits
```
But got error

## Environment info
<!-- You can run the command `transformers-cli env` and copy-and-paste its output below.
     Don't forget to fill out the missing fields in that output! -->
     
- `transformers` version: 3.0.2
- Platform: Windows (GCP Instance)
- Python version: 3.8.6
- PyTorch version (GPU?): '1.7.0+cpu'
- Tensorflow version (GPU?): Not installed
- Using GPU in script?: No
- Using distributed or parallel set-up in script?: No

### Who can help
<!-- Your issue will be replied to more quickly if you can figure out the right person to tag with @
 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.
 
 albert, bert, GPT2, XLM: @LysandreJik 
 tokenizers: @mfuntowicz
 Trainer: @sgugger
 Speed and Memory Benchmarks: @patrickvonplaten
 Model Cards: @julien-c
 TextGeneration: @TevenLeScao 
 examples/distillation: @VictorSanh
 nlp datasets: [different repo](https://github.com/huggingface/nlp)
 rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)
 Text Generation: @patrickvonplaten @TevenLeScao
 Blenderbot: @patrickvonplaten
 Bart: @patrickvonplaten
 Marian: @patrickvonplaten
 Pegasus: @patrickvonplaten
 mBART: @patrickvonplaten
 T5: @patrickvonplaten
 Longformer/Reformer: @patrickvonplaten
 TransfoXL/XLNet: @TevenLeScao
 RAG: @patrickvonplaten, @lhoestq
 FSMT: @stas00
 examples/seq2seq: @patil-suraj
 examples/bert-loses-patience: @JetRunner
 tensorflow: @jplu
 examples/token-classification: @stefan-it
 documentation: @sgugger
 -->

## Information

Model I am using (Bert, XLNet ...):

The problem arises when using:
* [x] the official example scripts: (give details below)
* [ ] my own modified scripts: (give details below)

The tasks I am working on is:
* [ ] an official GLUE/SQUaD task: (give the name)
* [x] my own task or dataset: (give details below)
I am just trying to run DPR model. 

## To reproduce

Steps to reproduce the behavior:

1. Execute this in your python
```
from transformers import DPRReader, DPRReaderTokenizer
tokenizer = DPRReaderTokenizer.from_pretrained('facebook/dpr-reader-single-nq-base')
model = DPRReader.from_pretrained('facebook/dpr-reader-single-nq-base')
encoded_inputs = tokenizer(
        questions=["What is love ?"],
        titles=["Haddaway"],
        texts=["'What Is Love' is a song recorded by the artist Haddaway"],
        return_tensors='pt'
    )
outputs = model(**encoded_inputs)
start_logits = outputs.stat_logits
end_logits = outputs.end_logits
relevance_logits = outputs.relevance_logits
```

<!-- If you have code snippets, error messages, stack traces please provide them here as well.
     Important! Use code tags to correctly format your code. See https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks#syntax-highlighting
     Do not use screenshots, as they are hard to read and (more importantly) don't allow others to copy-and-paste your code.-->
The error traceback is below:
```
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-2f646c4dd41f> in <module>
----> 1 from transformers import DPRReader, DPRReaderTokenizer
      2 tokenizer = DPRReaderTokenizer.from_pretrained('facebook/dpr-reader-single-nq-base')
      3 model = DPRReader.from_pretrained('facebook/dpr-reader-single-nq-base')
      4 encoded_inputs = tokenizer(
      5         questions=["What is love ?"],

ImportError: cannot import name 'DPRReader' from 'transformers' (C:\<some_path>\env\lib\site-packages\transformers\__init__.py)

```

## Expected behavior

<!-- A clear and concise description of what you would expect to happen. -->
I haven't executed this but I would hope nothing in output as all the results are stored in variables.

Comments:
The DPR model is part of the 3.1.0 release. Please update your transformers library (4.0.1 is the current release btw :)).

https://github.com/huggingface/transformers/releases/tag/v3.1.0

Hi @cronoik , Thanks for answering. I tried this 
```
pip install transformers==4.0.1
```
but got this error
```
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
sentence-transformers 0.3.9 requires transformers<3.6.0,>=3.1.0, but you have transformers 4.0.1 which is incompatible.
dpr 0.1.0 requires transformers<3.1.0,>=3.0.0, but you have transformers 4.0.1 which is incompatible.
```

So then I installed version 3.1.0 as follows:

```
pip install transformers==3.1.0
```
But still getting dependency error.


```
Collecting transformers==3.1.0
  Using cached transformers-3.1.0-py3-none-any.whl (884 kB)
Requirement already satisfied: requests in c:\users\hiteshsom\documents\env\lib\site-packages (from transformers==3.1.0) (2.25.0)
Requirement already satisfied: sacremoses in c:\users\hiteshsom\documents\env\lib\site-packages (from transformers==3.1.0) (0.0.43)
Requirement already satisfied: tqdm>=4.27 in c:\users\hiteshsom\documents\env\lib\site-packages (from transformers==3.1.0) (4.48.0)
Requirement already satisfied: numpy in c:\users\hiteshsom\documents\env\lib\site-packages (from transformers==3.1.0) (1.18.5)
Requirement already satisfied: filelock in c:\users\hiteshsom\documents\env\lib\site-packages (from transformers==3.1.0) (3.0.12)
Requirement already satisfied: packaging in c:\users\hiteshsom\documents\env\lib\site-packages (from transformers==3.1.0) (20.4)
Requirement already satisfied: sentencepiece!=0.1.92 in c:\users\hiteshsom\documents\env\lib\site-packages (from transformers==3.1.0) (0.1.94)
Requirement already satisfied: regex!=2019.12.17 in c:\users\hiteshsom\documents\env\lib\site-packages (from transformers==3.1.0) (2020.11.13)
Requirement already satisfied: six in c:\users\hiteshsom\documents\env\lib\site-packages (from packaging->transformers==3.1.0) (1.15.0)
Requirement already satisfied: pyparsing>=2.0.2 in c:\users\hiteshsom\documents\env\lib\site-packages (from packaging->transformers==3.1.0) (2.4.7)
Requirement already satisfied: chardet<4,>=3.0.2 in c:\users\hiteshsom\documents\env\lib\site-packages (from requests->transformers==3.1.0) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\hiteshsom\documents\env\lib\site-packages (from requests->transformers==3.1.0) (2020.11.8)
Requirement already satisfied: idna<3,>=2.5 in c:\users\hiteshsom\documents\env\lib\site-packages (from requests->transformers==3.1.0) (2.10)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\users\hiteshsom\documents\env\lib\site-packages (from requests->transformers==3.1.0) (1.25.10)
Requirement already satisfied: regex!=2019.12.17 in c:\users\hiteshsom\documents\env\lib\site-packages (from transformers==3.1.0) (2020.11.13)
Requirement already satisfied: six in c:\users\hiteshsom\documents\env\lib\site-packages (from packaging->transformers==3.1.0) (1.15.0)
Requirement already satisfied: click in c:\users\hiteshsom\documents\env\lib\site-packages (from sacremoses->transformers==3.1.0) (7.1.2)
Requirement already satisfied: joblib in c:\users\hiteshsom\documents\env\lib\site-packages (from sacremoses->transformers==3.1.0) (0.17.0)
Requirement already satisfied: tqdm>=4.27 in c:\users\hiteshsom\documents\env\lib\site-packages (from transformers==3.1.0) (4.48.0)
Collecting tokenizers==0.8.1.rc2
  Using cached tokenizers-0.8.1rc2-cp38-cp38-win_amd64.whl (1.9 MB)
Installing collected packages: tokenizers, transformers
  Attempting uninstall: tokenizers
    Found existing installation: tokenizers 0.9.4
    Uninstalling tokenizers-0.9.4:
      Successfully uninstalled tokenizers-0.9.4
  Attempting uninstall: transformers
    Found existing installation: transformers 4.0.1
    Uninstalling transformers-4.0.1:
      Successfully uninstalled transformers-4.0.1
Successfully installed tokenizers-0.8.1rc2 transformers-3.1.0

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
dpr 0.1.0 requires transformers<3.1.0,>=3.0.0, but you have transformers 3.1.0 which is incompatible.
```

Well, you have a package (`dpr`) installed that requires transformers<3.1.0,>=3.0.0. You can now do what you always do in such a dependency conflict situation:

1. Ask yourself if you need this package, if not uninstall it.
2. Create a virtual environment and install the transformers library there.
3. Force pip to install the package anyway but keep in mind that this might break the `dpr` package.

Do the one that suits your needs the most.


Hi, I installed `transformers==3.0.0` which I think installed `dpr` but gave dependency error on `sentence transformers` and then I installed `transformers==3.1.0` which only gives dependency error in `dpr` and now when I do  `pip freeze` and I get both the packages. 

After this I ran the example script and it gave this output
```
HBox(children=(FloatProgress(value=0.0, description='Downloading', max=231508.0, style=ProgressStyle(descripti…


HBox(children=(FloatProgress(value=0.0, description='Downloading', max=484.0, style=ProgressStyle(description_…


HBox(children=(FloatProgress(value=0.0, description='Downloading', max=437998572.0, style=ProgressStyle(descri…


Some weights of DPRReader were not initialized from the model checkpoint at facebook/dpr-reader-single-nq-base and are newly initialized: ['span_predictor.encoder.bert_model.embeddings.position_ids']
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-2f646c4dd41f> in <module>
      9     )
     10 outputs = model(**encoded_inputs)
---> 11 start_logits = outputs.stat_logits
     12 end_logits = outputs.end_logits
     13 relevance_logits = outputs.relevance_logits

AttributeError: 'tuple' object has no attribute 'stat_logits'
```

Its still an error but attribute error and  not Import error so may be we can close this issue.

That is because the class output objects were introduced in a later transformer version. For 3.1.0 the variable `outputs` is still a tuple and you need to check the documentation of DPRReader to figure out which element of the tuple is `stat_logits`, `end_logits` and `relevance_logits`.

But I have just checked the installed packages in a virtual environment with 3.1.0 and 4.0.0 and both had no package called `dpr` installed. You probably got it from somewhere else and can remove it.

`dpr` may come by installing `transformers` version `3.0.0`

> 
> 
> That is because the class output objects were introduced in a later transformer version. For 3.1.0 the variable `outputs` is still a tuple and you need to check the documentation of DPRReader to figure out which element of the tuple is `stat_logits`, `end_logits` and `relevance_logits`.



Thanks for this. I will check documentation



This issue has been automatically marked as stale and been closed because it has not had recent activity. Thank you for your contributions.

If you think this still needs to be addressed please comment on this thread.