ImportError: cannot import name 'amp' from 'torch.cuda'

See original GitHub issue

Description When running from simpletransformers.classification import MultiLabelClassificationModel I am met with ImportError: cannot import name 'amp' from 'torch.cuda'

Details Running on Anaconda Jupyter Notebook. My imported modules:

import pandas as pd
import numpy as np
import sklearn
from sklearn.model_selection import *
import transformers
import simpletransformers
import torch
import apex

Importing modules are all good. Installed apex using conda install -c conda-forge nvidia-apex and pytorch using conda install pytorch torchvision cpuonly -c pytorch

Tried to troubleshoot with solutions in this thread: https://github.com/NVIDIA/apex/issues/621 but nothing has worked so far,

Full Error

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-3-de513398c64a> in <module>
----> 1 from simpletransformers.classification import MultiLabelClassificationModel

~\AppData\Local\Continuum\anaconda3\lib\site-packages\simpletransformers\classification\__init__.py in <module>
----> 1 from simpletransformers.classification.classification_model import ClassificationModel
      2 from simpletransformers.classification.multi_label_classification_model import MultiLabelClassificationModel
      3 from simpletransformers.classification.multi_modal_classification_model import MultiModalClassificationModel
      4 from simpletransformers.config.model_args import ClassificationArgs
      5 from simpletransformers.config.model_args import MultiLabelClassificationArgs

~\AppData\Local\Continuum\anaconda3\lib\site-packages\simpletransformers\classification\classification_model.py in <module>
     43 from simpletransformers.custom_models.models import ElectraForSequenceClassification
     44 from tensorboardX import SummaryWriter
---> 45 from torch.cuda import amp
     46 from torch.utils.data import DataLoader, RandomSampler, SequentialSampler, TensorDataset
     47 from torch.utils.data.distributed import DistributedSampler

ImportError: cannot import name 'amp' from 'torch.cuda' (C:\Users\...\AppData\Local\Continuum\anaconda3\lib\site-packages\torch\cuda\__init__.py)

Thank you so much for your help!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
pulkitmehtaworkcommented, Aug 22, 2020

you have to pass that as an argument while training the model e.g. model.train_model(train_df,args={‘fp16’: False,‘num_train_epochs’:3,‘overwrite_output_dir’:True})

3reactions
ThilinaRajapaksecommented, Aug 5, 2020

Set fp16 to False.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Module 'torch.cuda' has no attribute 'amp' with torch 1.6.0
It returns aother error, when I activate conda env again. It returns: ImportError: cannot import name 'default_generator'.
Read more >
【DEBUG日记】cannot import name 'amp'_一加一h的博客
Traceback (most recent call last): File "train.py", line 15, in <module> from torch.cuda import amp ImportError: cannot import name 'amp'.
Read more >
no module named 'torch.cuda.amp' - You.com | The Search ...
I am training a model using google colab and i got this error when i am trying to import autocast code used to...
Read more >
"cannot import name 'autocast' from 'torch'" : r/StableDiffusion
It's because you've installed PyTorch with pip at the system level before. You need to set a Conda environment variable to not look...
Read more >
ImportError: cannot import name 'amp' from 'apex' (unknown ...
I was facing the same issue. After installing apex, the folder site-packages/apex is under a folder called apex-0.1-py3.8.egg.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found