Transformers: ImportError: cannot import name 'MODEL_WITH_LM_HEAD_MAPPING'

Created on 2 Jun 2020  路  2Comments  路  Source: huggingface/transformers

ImportError: cannot import name 'MODEL_WITH_LM_HEAD_MAPPING' from 'transformers' (C:\Users\\anaconda3\envs\tensorflow\lib\site-packagestransformers__init__.py)

Model I am using (Bert, XLNet ...): GPT2

Language I am using the model on (English, Chinese ...): English

The problem arises when using:
[x] the official example scripts: (give details below)
a necessary package does not exist for import

The tasks I am working on is:
[x] my own task or dataset: (give details below)
I am trying to finetune the GPT2 library to work with recipes

To reproduce

Steps to reproduce the behavior:

  1. create conda virtualenv
  2. install latest version of Tensorflow GPU
  3. install transformers library
  4. navigate to the 'language-modeling' folder
  5. run 'python run_language_modeling.py' in conda virtualenv

LOG:

python run_language_modeling.py
2020-06-01 23:53:43.603759: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
Traceback (most recent call last):
  File "run_language_modeling.py", line 29, in <module>
    from transformers import (
ImportError: cannot import name 'MODEL_WITH_LM_HEAD_MAPPING' from 'transformers' (C:\Users\<name>\anaconda3\envs\tensorflow\lib\site-packages\transformers\__init__.py)

Expected behavior

There should be an error with not receiving variables or no output at all. If you were to insert data it would train an instance of GPT2 and save it to the output directory

Environment info

  • transformers version: 2.10.0
  • Platform: Windows-10-10.0.18362-SP0
  • Python version: 3.7.7
  • PyTorch version (GPU?): not installed (NA)
  • Tensorflow version (GPU): 2.1.0 (True)
  • Using GPU in script?: Yes
  • Using distributed or parallel set-up in script?: No

It would be nice to figure out what the issue is. I am aware that there are 3 questions similar to this, but they all use torch while I am using tensorflow. All of the solutions I have tried (reinstalling tensorflow, reinstalling transformers, updating packages, reformatting code, etc.) have not worked. Thanks.

Most helpful comment

MODEL_WITH_LM_HEAD_MAPPING is a mapping containing all the Pytorch models that have an LM head. Since you don't have PyTorch installed, you can't import them.

With TensorFlow you're probably looking for TF_MODEL_WITH_LM_HEAD_MAPPING.

Please note that the run_language_modeling.py script is currently PyTorch only. A TensorFlow version will be available in the future.

All 2 comments

This might help: #3444

MODEL_WITH_LM_HEAD_MAPPING is a mapping containing all the Pytorch models that have an LM head. Since you don't have PyTorch installed, you can't import them.

With TensorFlow you're probably looking for TF_MODEL_WITH_LM_HEAD_MAPPING.

Please note that the run_language_modeling.py script is currently PyTorch only. A TensorFlow version will be available in the future.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

siddsach picture siddsach  路  3Comments

0x01h picture 0x01h  路  3Comments

rsanjaykamath picture rsanjaykamath  路  3Comments

fabiocapsouza picture fabiocapsouza  路  3Comments

fyubang picture fyubang  路  3Comments