Transformers: ImportError: cannot import name 'AutoModel' from 'transformers'

Created on 6 May 2020  路  4Comments  路  Source: huggingface/transformers

馃悰 Bug

(Not sure that it is a bug, but it is too easy to reproduce I think)

Information

I couldn't run python -c 'from transformers import AutoModel', instead getting the error on the titile.

To reproduce

Steps to reproduce the behavior:

  1. $ sudo docker run -it --rm python:3.6 bash
  2. # pip install tensorflow==2.0 transformers==2.8.0
  3. # python -c 'from transformers import AutoModel'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: cannot import name 'AutoModel'

Initially I got this error with transformers-cli download :

# transformers-cli download t5-large
Traceback (most recent call last):
  File "/usr/local/bin/transformers-cli", line 32, in <module>
    service.run()
  File "/usr/local/lib/python3.6/site-packages/transformers/commands/download.py", line 29, in run
    from transformers import AutoModel, AutoTokenizer
ImportError: cannot import name 'AutoModel'

Expected behavior

no import error.

Environment info

  • transformers version: 2.8.0
  • Platform: Linux-4.15.0-99-generic-x86_64-with-debian-10.3
  • Python version: 3.6.10
  • PyTorch version (GPU?): not installed (NA)
  • Tensorflow version (GPU?): 2.0.0 (False)
  • Using GPU in script?: no
  • Using distributed or parallel set-up in script?: no

Also tested on 3.6@Ubuntu 18.04, 3.8@Docker(python:3.8).
The Docker backend is Ubuntu 18.04.

Thank you.

Most helpful comment

AutoModel is the equivalent of TFAutoModel but for PyTorch model classes. If you don't have pytorch installed this is expected.

Use TFAutoModel instead =)

All 4 comments

Got the same result with 2.9.0, i.e. with # pip install tensorflow==2.0 transformers==2.9.0

AutoModel is the equivalent of TFAutoModel but for PyTorch model classes. If you don't have pytorch installed this is expected.

Use TFAutoModel instead =)

Thank you!

@julien-c
But there still is a problem with transformers-cli.
Now, people who want to use transformers-cli download are required to install PyTorch even when they use Tensorflow only.

edit:
It could be the problem specific to t5-large. I'll try it later.

Was this page helpful?
0 / 5 - 0 ratings