首先题外话,个人感觉kaggle更好用点(对于mxnet来说),可以看一下我的这篇博客
使用Kaggle安装MxNet大无语事件流程记录【成功解决】
1.查看cuda版本
!nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Sep_21_10:33:58_PDT_2022
Cuda compilation tools, release 11.8, V11.8.89
Build cuda_11.8.r11.8/compiler.31833905_0
2.想尝试直接安装对应的GPU版本的mxnet,发现没有这个版本
!pip install mxnet-cu118
Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/
ERROR: Could not find a version that satisfies the requirement mxnet-cu118 (from versions: none)
ERROR: No matching distribution found for mxnet-cu118
3.尝试搜索了各种方法,包括重新安装cuda,安装各个版本的包,都不管用,最后都指向了一条错误,so后边有的是7有的是10
OSError: libcudnn.so.7: cannot open shared object file: No such file or directory
4.但是安装11.2版本的错误是这个
libcuda.so.1: cannot open shared object file: No such file or directory
5.然后问chatgpt,他可能比较蠢让我先安装了个cpu版本,然后再卸载再安装gpu版本
!pip install mxnet
此时验证版本
import mxnet
mxnet.__version__
1.9.1
但是仍然无法使用gpu
import mxnet as mx
# 检查是否有可用的GPU设备
if mx.context.num_gpus() > 0:
print("GPU可用")
else:
print("没有可用的GPU设备")
# 创建一个使用GPU的NDArray
x = mx.nd.ones((3, 3), ctx=mx.gpu())
print(x)
MXNetError: Traceback (most recent call last):
File "../src/imperative/imperative.cc", line 81
MXNetError: Operator _ones is not implemented for GPU.
6.继续安装gpu版本,这里我没有卸载cpu版本,后来证明卸载了确实不能用
!pip install mxnet-cu112
注意,这里我再第二次验证的时候发现,如果先装cpu再验证代码再装gpu可能会让你重启runtime,但是重启完就好了,我第一次装的时候直接把cpu,gpu一股脑装了才验证的
7.最终验证
ps:我查了一下那个libcudnn错误在文件里还是没有这个,所以我也很无语最后为什么可以了,有大佬懂的可以评论区指教一下