apex icon indicating copy to clipboard operation
apex copied to clipboard

ImportError: cannot import name 'amp'

Open vr25 opened this issue 5 years ago • 12 comments

Hi,

I can import amp from /apex directory but not from any other location. I installed it using the following command: pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./

but I still get the following error: image

Thanks!

vr25 avatar Nov 22 '19 11:11 vr25

There may still be some python import weirdness going on. Try moving apex out of your training directory hierarchy, to a completely different location.

mcarilli avatar Nov 22 '19 17:11 mcarilli

Hi,

Thanks for your suggestion but it did not work.

from apex import amp works only when present in apex directory. I am wondering how to make it global because pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./ isn't helping either.

Thanks!

vr25 avatar Nov 22 '19 18:11 vr25

@vr25 were you able to find a solution? @vinhngx do you know how to resolve this?

seedlit avatar Dec 06 '19 11:12 seedlit

@vr25 this solved the issue for me.

seedlit avatar Dec 09 '19 06:12 seedlit

Hi @vr25, I had the same problem and my solution is:

  1. Check the version of pytorch with cuda compatibility

    • To check your cuda version: nvcc --version or in usr/local/cuda-[version]
    • If your CUDA is 10.0, please re-check your pytorch with cuda here
    • Then, install/re-install with pip install torch==1.4+cu100 torchvision==0.5.0+cu100 -f https://download.pytorch.org/whl/torch_stable.html
  2. You can now install apex with this as @seedlit has mentioned.

I hope this would help

tanyapohn avatar Jan 29 '20 09:01 tanyapohn

a dirty way would also be to: cp -r apex/apex/ ~/.local/lib/python3.7/site-packages/ and don't forget to source ~/.profile/

ioneliabuzatu avatar May 21 '20 17:05 ioneliabuzatu

Automatic Mixed Precision package is now available within Pytorch (1.6 unstable develope preview). Check this out.

seedlit avatar May 21 '20 18:05 seedlit

Hi @vr25, I had the same problem and my solution is:

  1. Check the version of pytorch with cuda compatibility

    • To check your cuda version: nvcc --version or in usr/local/cuda-[version]
    • If your CUDA is 10.0, please re-check your pytorch with cuda here
    • Then, install/re-install with pip install torch==1.4+cu100 torchvision==0.5.0+cu100 -f https://download.pytorch.org/whl/torch_stable.html
  2. You can now install apex with this as @seedlit has mentioned.

I hope this would help hi i completely follow your setp and it shows install success. when i use "from apex import amp" it does work but i still can't use "from torch.cuda import amp" is shows error message can't import . and here is my server message : cuda version 10.0.130 /graphics: GTX1080 & GTX titan X/pytorch.version.cuda==10.0 do you have any idea on how i could fix this problem? many thanks

zhangshouleibupt avatar Sep 01 '20 09:09 zhangshouleibupt

There may still be some python import weirdness going on. Try moving apex out of your training directory hierarchy, to a completely different location.

On moving the apex folder to /home folder and installing it again using the instructions from here, I was able to use it successfully.

bohare avatar Oct 06 '20 13:10 bohare

a dirty way would also be to: cp -r apex/apex/ ~/.local/lib/python3.7/site-packages/ and don't forget to source ~/.profile/

Thanks, it works

soodeh-nilforoushan avatar Nov 16 '21 18:11 soodeh-nilforoushan

hello,我的问题是使用nvcc --version检测的版本是下面的,报错了ImportError: cannot import name 'amp' from 'torch.cuda',求指导,谢谢! nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2019 NVIDIA Corporation Built on Sun_Jul_28_19:07:16_PDT_2019 Cuda compilation tools, release 10.1, V10.1.243

Mrgorlay avatar Jan 21 '22 12:01 Mrgorlay

@Mrgorlay

Hi @vr25, I had the same problem and my solution is:

  1. Check the version of pytorch with cuda compatibility

    • To check your cuda version: nvcc --version or in usr/local/cuda-[version]
    • If your CUDA is 10.0, please re-check your pytorch with cuda here
    • Then, install/re-install with pip install torch==1.4+cu100 torchvision==0.5.0+cu100 -f https://download.pytorch.org/whl/torch_stable.html
  2. You can now install apex with this as @seedlit has mentioned.

I hope this would help

Cuda 和 PyTorch 版本应该互相支持

你可以尝试安装

# CUDA 10.1
pip install torch==1.8.1+cu101 torchvision==0.9.1+cu101 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

然后,再次安装 Apex

tanyapohn avatar Jan 21 '22 12:01 tanyapohn