Transformers: Import Error: cannot import name 'warmup_linear'

Created on 24 Jun 2019  路  8Comments  路  Source: huggingface/transformers

I get the following error:

  File "/Users/gregory/PROJECTS/MyML/MLClassification/TrainAndTest/Models/controller.py", line 11, in <module>
    from Models.bert import BertModel
  File "/Users/gregory/PROJECTS/MyML/MLClassification/TrainAndTest/Models/bert.py", line 9, in <module>
    from pytorch_pretrained_bert.optimization import BertAdam, warmup_linear
ImportError: cannot import name 'warmup_linear'

This problem was already noted in comments to the following issue:
https://github.com/huggingface/pytorch-pretrained-BERT/issues/499
The response said that it was fixed with PR #506, and suggested to clone this Git repository and install the package from it.
However @goyalsaransh97 already mentioned that the problem persists for him (or her).

So it does for me too.

BTW, please notice, the code works fine on machine where all packages were installed about an year ago.

Most helpful comment

The version 0.4.0 doesn't give this issue.
pip install pytorch_pretrained_bert==0.4.0

All 8 comments

I probably was wrong and the issue was supposed to be fixed with PR #518... Anyway, the latest was merged a while ago and did not help.

You have to wait for the next release or use the master branch

@thomwolf ,

You have to wait for the next release or use the master branch

I cloned the git repo directly from here:

git clone https://github.com/huggingface/pytorch-pretrained-BERT.git

I think it takes master branch by default, isn't it?

Explicit "git checkout master" changes nothing.

The latest master branch gives the same issue. Version 0.5.1 works as of now without this issue

The version 0.4.0 doesn't give this issue.
pip install pytorch_pretrained_bert==0.4.0

The version 0.4.0 doesn't give this issue.
pip install pytorch_pretrained_bert==0.4.0

Downgrading to 0.4.0 solved my problem.

This issue has popped up again in 0.6.2 for me. Downgrading to 0.6.1 solved it

pip install pytorch-pretrained-bert==0.6.1
Was this page helpful?
0 / 5 - 0 ratings

Related issues

HansBambel picture HansBambel  路  3Comments

0x01h picture 0x01h  路  3Comments

yspaik picture yspaik  路  3Comments

iedmrc picture iedmrc  路  3Comments

adigoryl picture adigoryl  路  3Comments