AttributeError: module 'typing' has no attribute '_ClassVar'
Author: HatterTheMad
Pull request: no

## 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.5.1
- Platform: Linux
- Python version: 3.8
- PyTorch version (GPU?): 1.7.0+cpu
- Using GPU in script?:  No
- Using distributed or parallel set-up in script?: Yes

### Who can help @sgugger .... @LysandreJik  ... mb?

## Information

Model I am using: Distilbert

The problem arises when using:
Just this:

``` python
from transformers import AutoTokenizer, AutoModelForQuestionAnswering
```

The tasks I am working on is:
* [ ] my own task or dataset: 
I am using default Distilbert for my flask API

## To reproduce

Steps to reproduce the behavior:
That's a big part of the question. It works just fine on my local machine, but gives this error when run on my AWS server.


``` python
from flask import Flask, request, jsonify
from flask import Flask
from flask_restful import Api, Resource
from transformers import AutoTokenizer, AutoModelForQuestionAnswering
from transformers.pipelines import pipeline

tokenizer = AutoTokenizer.from_pretrained('./Dis_Save/')
model = AutoModelForQuestionAnswering.from_pretrained('./Dis_Save/')
nlp_qa = pipeline('question-answering', tokenizer=tokenizer,model=model)

app = Flask(__name__)

@app.route('/api/QandA', methods=['GET', 'POST'])

def QandA():
    content = request.json
    print(content['userMessages'])
    X = nlp_qa(context=content['userMessages'], question=content['question'])
    return(jsonify({"answer":X["answer"], "score":X["score"]}))

if __name__ == "__main__":
	app.run(debug=True)
```

#This is all the code that I have. Here is the full error that I get:

```
  File "access/main.py", line 4, in <module>
    from transformers import AutoTokenizer, AutoModelForQuestionAnswering
  File "/home/ubuntu/access/transformers/__init__.py", line 22, in <module>
    from .integrations import (  # isort:skip
  File "/home/ubuntu/access/transformers/integrations.py", line 82, in <module>
    from .trainer_callback import TrainerCallback  # noqa: E402
  File "/home/ubuntu/access/transformers/trainer_callback.py", line 27, in <module>
    from .training_args import TrainingArguments
  File "/home/ubuntu/access/transformers/training_args.py", line 36, in <module>
    class TrainingArguments:
  File "/home/ubuntu/access/dataclasses.py", line 958, in dataclass
    return wrap(_cls)
  File "/home/ubuntu/access/dataclasses.py", line 950, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash, frozen)
  File "/home/ubuntu/access/dataclasses.py", line 800, in _process_class
    cls_fields = [_get_field(cls, name, type)
  File "/home/ubuntu/access/dataclasses.py", line 800, in <listcomp>
    cls_fields = [_get_field(cls, name, type)
  File "/home/ubuntu/access/dataclasses.py", line 659, in _get_field
    if (_is_classvar(a_type, typing)
  File "/home/ubuntu/access/dataclasses.py", line 550, in _is_classvar
    return type(a_type) is typing._ClassVar
AttributeError: module 'typing' has no attribute '_ClassVar'
```

Comments:
This is weird! Looking at the stacktrace, I have a few questions:

- Are you running a file in `access/main.py`?
- If yes, is there a `dataclasses.py` file in that `access` folder?

It seems far-fetched but if that's the case, it might be possible that this file is interfering with the `dataclasses` module.

It seems related to an incompatibility of python > 3.6 with package dataclasses, as explained here:

        https://github.com/google/flax/pull/270

Yes, but we only install `dataclasses` on Python versions that are inferior to 3.7: https://github.com/huggingface/transformers/blob/master/setup.py#L137

I encountered the same problem with the following setup:

- transformers version: 3.5.1
- Platform: Linux
- Python version: 3.8
- PyTorch version (GPU?): 1.7.0+cpu
- Using GPU in script?: No
- Using distributed or parallel set-up in script?: No

Local execution works fine, but when running the code on Google App Engine (Standard Environment), it fails with error `AttributeError: module 'typing' has no attribute '_ClassVar'`. There is no file called `dataclasses.py` anywhere in the project,

Stacktrace:
```
File "/srv/application/stance_pred/bert_inference.py", line 8, in <module>      from transformers import DistilBertForSequenceClassification, DistilBertTokenizer, DistilBertConfig
File "/layers/google.python.pip/pip/transformers/__init__.py", line 22, in <module>      from .integrations import (  # isort:skip
File "/layers/google.python.pip/pip/transformers/integrations.py", line 82, in <module>      from .trainer_callback import TrainerCallback  # noqa: E402
File "/layers/google.python.pip/pip/transformers/trainer_callback.py", line 27, in <module>      from .training_args import TrainingArguments
File "/layers/google.python.pip/pip/transformers/training_args.py", line 36, in <module>      class TrainingArguments:
File "/layers/google.python.pip/pip/dataclasses.py", line 958, in dataclass      return wrap(_cls)
File "/layers/google.python.pip/pip/dataclasses.py", line 950, in wrap      return _process_class(cls, init, repr, eq, order, unsafe_hash, frozen)
File "/layers/google.python.pip/pip/dataclasses.py", line 800, in _process_class      cls_fields = [_get_field(cls, name, type)
File "/layers/google.python.pip/pip/dataclasses.py", line 800, in <listcomp>      cls_fields = [_get_field(cls, name, type)
File "/layers/google.python.pip/pip/dataclasses.py", line 659, in _get_field      if (_is_classvar(a_type, typing)
File "/layers/google.python.pip/pip/dataclasses.py", line 550, in _is_classvar      return type(a_type) is typing._ClassVar  AttributeError: module 'typing' has no attribute '_ClassVar'
```

Any solution?

Could one of you post the result of `pip list` in the environment where that is failing? Or even better paste the result of `pip freeze`, alongside a few lines of code that reproduce the issue.

Thank you!

I solved this problem by removing `dataclasses*`

I have solved this problem by downgrading to Python version: 3.6

Thanks @attardi 

note that `fairseq` 0.10.1 requires `dataclasses` even for py>3.7 where it's built-in and HF Trainer breaks when `dataclasses` are installed for these versions. So if some project pulls in `fairseq`  which will force the install of `dataclasses` HF Trainer will break. Probably need to ask `fairseq` to fix their dependencies.

Until then @thesby's solution is the easiest one.

```
pip uninstall dataclasses -y
```

I don't know why, but for me changing the version of Python worked (from 3.9.12 to 3.9.5.)

> note that `fairseq` 0.10.1 requires `dataclasses` even for py>3.7 where it's built-in and HF Trainer breaks when `dataclasses` are installed for these versions. So if some project pulls in `fairseq` which will force the install of `dataclasses` HF Trainer will break. Probably need to ask `fairseq` to fix their dependencies.
> 
> Until then @thesby's solution is the easiest one.
> 
> ```
> pip uninstall dataclasses -y
> ```

In my case `pip` command itself was broken so I had to do by hand:

```
rm -rf lib/dataclasses-0.6.dist-info
rm lib/dataclasses.py
```

in the location where `dataclasses` has been installed!

Dependency to `dataclasses` in setup.py should be python 3.6 only:

```diff
-'dataclasses'
+'dataclasses; python_version < "3.7"'
```

or use `if sys.version_info >= (3, 7):` check to dynamically configure `_deps` in https://github.com/huggingface/transformers/blob/main/setup.py#L98.

I met the same error without having dataclasses installed in my environment (python 3.9). I installed dataclasses and uninstalled it again - from this point on the error disappeared. 

Remove dataclasses, this package seems not maintained anymore!