ImportError: cannot import name 'get_scheduler' from 'transformers'
Hi, I’m new to Transformer models, just following the tutorials. On Huggingface website, under Course/ 3 Fine tuning a pretrained model/ full training, I just followed your code in course:from transformers import get_schedulernum_epochs = 3num_training_steps = num_epochs * len(train_dataloader)lr_scheduler = get_scheduler(“linear”,optimizer=optimizer,num_warmup_steps=0,num_training_steps=num_training_steps,)print(num_training_steps)But it run into this error:ImportError                               Traceback (most recent call last)in----> 1 from transformers import get_scheduler23 num_epochs = 34 num_training_steps = num_epochs * len(train_dataloader)5 lr_scheduler = get_scheduler(ImportError: cannot import name ‘get_scheduler’ from ‘transformers’ (/Users/myname/opt/anaconda3/lib/python3.8/site-packages/transformers/init.py)I’ve re installed torch, still the same error. How to fix this?
2022-03-12T04:40:35Z
Tryfrom transformers.optimization import get_scheduler
2022-03-14T16:26:44Z
Continuing the discussion fromImportError: cannot import name 'get_scheduler' from 'transformers':mmalandro:from transformers.optimization import get_schedulerThanks very much! However, I tried but it gave me the same error message:from transformers.optimization import get_schedulernum_epochs = 3num_training_steps = num_epochs * len(train_dataloader)lr_scheduler = get_scheduler(“linear”,optimizer=optimizer,num_warmup_steps=0,num_training_steps=num_training_steps,)print(num_training_steps)ImportError                               Traceback (most recent call last)in----> 1 from transformers.optimization import get_scheduler23 num_epochs = 34 num_training_steps = num_epochs * len(train_dataloader)5 lr_scheduler = get_scheduler(ImportError: cannot import name ‘get_scheduler’ from ‘transformers.optimization’
2022-03-14T17:56:28Z
Can you check the version of transformers in your environment? I’m just making a guess because I ran it in colab and it’s importing fine.
2022-03-14T18:18:12Z
My transformers is 3.1.0. Should I change it? I’m running in Jupyter notebook, doest it matter?Thanks a lot!
2022-03-15T13:28:45Z
mmalandro:optimizationI tried to use Colab, same code, all worked! Also some of my previous didn’t work code worked too! Guess has something to do with Jupiter Notebook. Thanks a lot Merve!