如何在Google Colab上使用Chainer从CPU切换到GPU?

3
我按照Chainer文档的说明进行操作,但在运行代码时出现了错误:
RuntimeErrorTraceback (most recent call last)
<ipython-input-9-ffb21f9880f0> in <module>()
      ...
      6 model = Classifier(CompetitionNetwork(n_units = 64))
----> 7 model.to_gpu()
      ...
RuntimeError: CUDA environment is not correctly set up
(see https://github.com/chainer/chainer#installation).No module named cupy

然后我尝试了许多不同的方式来安装Cupy,其中之一是

!apt -y install libcusparse8.0 libnvrtc8.0 libnvtoolsext1
!ln -snf /usr/lib/x86_64-linux-gnu/libnvrtc-builtins.so.8.0 /usr/lib/x86_64-linux-gnu/libnvrtc-builtins.so
!pip install cupy-cuda80 chainer

在导入Cupy并运行我的代码后,仍然出现相同的错误。
RuntimeError: CUDA environment is not correctly set up (see
https://github.com/chainer/chainer#installation).No module named cupy

接下来,我尝试使用以下方式安装cuda:

!wget https://developer.nvidia.com/compute/cuda/9.2/Prod/local_installers/cuda-repo-ubuntu1604-9-2-local_9.2.88-1_amd64 -O cuda-repo-ubuntu1604-9-2-local_9.2.88-1_amd64.deb

!dpkg -i cuda-repo-ubuntu1604-9-2-local_9.2.88-1_amd64.deb

!apt-key add /var/cuda-repo-<version>/7fa2af80.pub

!apt-get update

!apt-get install cuda

这花费了很长时间,看起来似乎可以工作,但最终仍然出现了相同的错误。

在Google Colab的GPU上使用Chainer似乎非常困难,除非我做错了什么。用Tensorflow要容易得多。有没有人有使用Chainer在谷歌的GPU上的经验?


您可以按照以下步骤在Colab中获取GPU或TPU:- Runtime->更改Runtime - megh_sat
3个回答

1

这个可行!我从例子中意识到只有使用Python 3才能在GPU上运行,但仍然很棒,谢谢! - Lynn Le
您也可以在启用了GPU的Colab上使用Python 2运行Chainer。 - kmaehashi

1
如果您在Google Colab环境中遇到了问题,
  1. First try restarting the Runtime by selecting "Restart runtime..." from Runtime menu.
  2. If it does not solve the issue, run the following code to destroy & re-create the container (note: you will lose files created on the container), so that you can start over from clean state. You may need to wait for a minute after running the command and refresh the browser to reload the notebook.

    !kill -9 -1
    
你的安装Chainer/CuPy的步骤是正确的。 https://github.com/kmaehashi/chainer-colab 你不需要手动安装CUDA Toolkit;Colab容器默认提供它。

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接