ImportError: cannot import name 'AutoModelForMaskedLM' from 'transformers' (unknown location)
Author: hailong23-jin
Pull request: no

### System Info

Environment:

```
python 3.8
transformers==4.4.2
ubuntu 20.04
cuda 11.3

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Mon_May__3_19:15:13_PDT_2021
Cuda compilation tools, release 11.3, V11.3.109
Build cuda_11.3.r11.3/compiler.29920130_0

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 525.60.11    Driver Version: 525.60.11    CUDA Version: 12.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  Off  | 00000000:01:00.0  On |                  Off |
| 36%   57C    P2   252W / 450W |  18490MiB / 24564MiB |     91%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1021      G   /usr/lib/xorg/Xorg                 35MiB |
|    0   N/A  N/A      1775      G   /usr/lib/xorg/Xorg                 72MiB |
|    0   N/A  N/A      1924      G   /usr/bin/gnome-shell              185MiB |
|    0   N/A  N/A     14033      C   python                          18176MiB |
+-----------------------------------------------------------------------------+
```


`pip install transformers==4.4.2`
```
Python 3.8.5 (default, Sep  4 2020, 07:30:14) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from transformers import AutoModelForMaskedLM
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'AutoModelForMaskedLM' from 'transformers' (unknown location)
>>> 
```

Is this a bug? When I install the latest version `pip install transformers==4.25.1 `, it shows:

```
Python 3.8.5 (default, Sep  4 2020, 07:30:14) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from transformers import AutoModelForMaskedLM
2022-12-16 19:08:29.243002: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/cuda/lib:/usr/local/cuda/lib64:/usr/local/lib/
2022-12-16 19:08:29.243021: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
```
why the latest version need cuda 10.1 ?


### Who can help?

_No response_

### Information

- [ ] The official example scripts
- [ ] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

step 1: `pip install transformers==4.4.2`

step 2: open the terminal

step 3: python

step 4: from transformers import AutoModelForMaskedLM

### Expected behavior

I want to know how to deal with this problem, I can not use the `transformers` package and its functions.

Comments:
Hi @medlen 
Thanks for raising the issue! 
Your installation might be broken, as I managed to import `AutoModelForMaskedLM` with `transformers==4.4.2` using the same hardware specs as you:
```
>>> import transformers
>>> transformers.__version__
'4.4.2'
>>> from transformers import AutoModelForMaskedLM
>>>
```
Can you double check your `transformers` version and let us know?

Thanks for your quick reply. This is my `transformers` version :

`pip show transformers`

```
Name: transformers
Version: 4.4.2
Summary: State-of-the-art Natural Language Processing for TensorFlow 2.0 and PyTorch
Home-page: https://github.com/huggingface/transformers
Author: Thomas Wolf, Lysandre Debut, Victor Sanh, Julien Chaumond, Sam Shleifer, Patrick von Platen, Sylvain Gugger, Google AI Language Team Authors, Open AI team Authors, Facebook AI Authors, Carnegie Mellon University Authors
Author-email: thomas@huggingface.co
License: Apache
Location: /home/jinhl/anaconda3/envs/py38/lib/python3.8/site-packages
Requires: tokenizers, packaging, filelock, tqdm, numpy, regex, sacremoses, requests
Required-by: simpletransformers
```

```
Python 3.8.5 (default, Sep  4 2020, 07:30:14) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import transformers
>>> transformers.__version__
'4.4.2'
>>> from transformers import AutoModelForMaskedLM
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'AutoModelForMaskedLM' from 'transformers' (unknown location)
>>> 
```

Additionally, my GPU device is GeForce 4090.

Are you using conda or python venv? 
can you run `which python` and `which pip`?

I am using conda.  These are their locations:

```
which conda 
/home/jinhl/anaconda3/condabin/conda
which pip
/home/jinhl/anaconda3/envs/py38/bin/pip
which python
/home/jinhl/anaconda3/envs/py38/bin/python
```

There is maybe something wrong with my python environment. 
I create a new conda environment with python=3.8, and  install `transformers==4.4.2`. 
Repeating the above steps.
It raise a new version invalid error:

```
>>> import transformers
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jinhl/PythonWorkspace/transformers/__init__.py", line 43, in <module>
    from . import dependency_versions_check
  File "/home/jinhl/PythonWorkspace/transformers/dependency_versions_check.py", line 40, in <module>
    require_version_core(deps[pkg])
  File "/home/jinhl/PythonWorkspace/transformers/utils/versions.py", line 94, in require_version_core
    return require_version(requirement, hint)
  File "/home/jinhl/PythonWorkspace/transformers/utils/versions.py", line 85, in require_version
    if want_ver is not None and not ops[op](version.parse(got_ver), version.parse(want_ver)):
  File "/home/jinhl/anaconda3/envs/py38-test/lib/python3.8/site-packages/packaging/version.py", line 52, in parse
    return Version(version)
  File "/home/jinhl/anaconda3/envs/py38-test/lib/python3.8/site-packages/packaging/version.py", line 197, in __init__
    raise InvalidVersion(f"Invalid version: '{version}'")
packaging.version.InvalidVersion: Invalid version: '0.10.1,<0.11'
>>> 
```

after my test, this is because tokenizers version invalid. 

in: https://github.com/huggingface/transformers/blob/v4.4.2/src/transformers/utils/versions.py#L85 
```
if want_ver is not None and not ops[op](version.parse(got_ver), version.parse(want_ver)):
        raise pkg_resources.VersionConflict(
            f"{requirement} is required for a normal functioning of this module, but found {pkg}=={got_ver}.{hint}"
        )
```
for `tokenizers` , `got_ver=0.10.3`  `want_ver=0.10.1,<0.11`, the later  cause the error. I am not sure it is a special case for my machine or a bug.

After I comment out the version check code,  `AutoModelForMaskedLM ` can be correctly imported.



+1

+1

+1


You can keep posting `+1`s without any useful information, it will definitely help us fix the issue.

I encountered the same error: `packaging.version.InvalidVersion: Invalid version: '0.10.1,<0.11'`

This error seems to be caused by a problem in handling multiple requirements, which has been resolved by a change in [this PR](https://github.com/huggingface/transformers/pull/11110). Therefore, the problem can be resolved by changing the version of `transfomers` to 4.6 or higher.

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.