我正在运行Ubuntu 18.04 深度学习 AMI (DLAMI)在 AWS 上,并尝试在p2.xlarge
EC2 实例上运行它,但 CUDA 在我的 Python 解释器中不可用。我假设 CUDA 可以开箱即用,因为它是一个 AMI,据说是为与 torch/CUDA 一起使用而设计的。
pytorch_latest_p37
我正在尝试在预装 DLAMI 的 conda 环境中运行我的代码。它使用 Python3.7,并附带使用 CUDA 11.0 构建的 PyTorch 1.7.1:
ubuntu@ip-111-21-33-212:~$ source activate pytorch_latest_p37
nvidia-smi
和的输出nvcc
似乎都表明 CUDA 已安装:
(pytorch_latest_p37) ubuntu@ip-111-21-33-212:~$ nvidia-smi
Sun Jul 18 07:51:09 2021
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 450.119.03 Driver Version: 450.119.03 CUDA Version: 11.0 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 Tesla K80 On | 00000000:00:1E.0 Off | 0 |
| N/A 32C P8 30W / 149W | 0MiB / 11441MiB | 0% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+
(pytorch_latest_p37) ubuntu@ip-111-21-33-212:~$ nvcc --version nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Mon_Oct_12_20:09:46_PDT_2020
Cuda compilation tools, release 11.1, V11.1.105
Build cuda_11.1.TC455_06.29190527_0
但在 ipython 中torch.cuda.is_available()
返回时false
,我收到错误消息,指出 torch 未使用 CUDA 支持进行编译:
(pytorch_latest_p37) ubuntu@ip-111-21-33-212:~$ ipython
Python 3.9.5 (default, Jun 4 2021, 12:28:51)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.22.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import torch
In [2]: torch.cuda.is_available()
Out[2]: False
In [3]: torch.zeros(1).cuda()
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-2-0904fac96cba> in <module>
----> 1 torch.zeros(1).cuda()
~/anaconda3/envs/pytorch_latest_p37/lib/python3.9/site-packages/torch/cuda/__init__.py in _lazy_init()
164 "Cannot re-initialize CUDA in forked subprocess. " + msg)
165 if not hasattr(torch._C, '_cuda_getDeviceCount'):
--> 166 raise AssertionError("Torch not compiled with CUDA enabled")
167 if _cudart is None:
168 raise AssertionError(
AssertionError: Torch not compiled with CUDA enabled
这里发生了什么?我需要做什么才能让 CUDA 在 P2/P3 实例上运行?
谢谢!