在 Google Colab notebook 上安装 RAPIDS 库

Install RAPIDS library on Googe Colab notebook

我想知道是否可以在 Google Colaboratory notebook 中安装 RAPIDS 库(完全在 GPU 上执行机器学习任务)?

我做了一些研究,但我一直无法找到这样做的方法...

看起来各种子部分还不能通过 pip 安装,所以将它们安装到 colab 上的唯一方法是在 colab 上构建它们,这可能比您有兴趣投资于此更费力:) https://github.com/rapidsai/cudf/issues/285 是要注意 rapidsai/cudf 的问题(大概其他 rapidsai/ libs 也会效仿)。

现在可以使用新的 T4 实例 https://medium.com/rapids-ai/run-rapids-on-google-colab-for-free-1617ac6323a8

要同时启用 cuGraph,您可以将 wget 命令替换为:

!conda 安装-c nvidia/label/cuda10.0 -c rapidsai/label/cuda10.0 -c pytorch \ -c numba -c conda-forge -c numba -c 默认值\ 提升 cudf=0.6 cuml=0.6 python=3.6 cugraph=0.6 -y

最新解决方案;

!wget -nc https://github.com/rapidsai/notebooks-extended/raw/master/utils/rapids-colab.sh
!bash rapids-colab.sh

import sys, os

sys.path.append('/usr/local/lib/python3.6/site-packages/')
os.environ['NUMBAPRO_NVVM'] = '/usr/local/cuda/nvvm/lib64/libnvvm.so'
os.environ['NUMBAPRO_LIBDEVICE'] = '/usr/local/cuda/nvvm/libdevice/'

是几天前推送的,请参阅问题 #104 or #110, or the full rapids-colab.sh script 了解更多信息。

注意:灌注目前需要一个 Tesla T4 实例,可以通过以下方式进行检查;

# check gpu type
!nvidia-smi

import pynvml

pynvml.nvmlInit()
handle = pynvml.nvmlDeviceGetHandleByIndex(0)
device_name = pynvml.nvmlDeviceGetName(handle)

# your dolphin is broken, please reset & try again
if device_name != b'Tesla T4':
  raise Exception("""Unfortunately this instance does not have a T4 GPU.
    
    Please make sure you've configured Colab to request a GPU instance type.
    
    Sometimes Colab allocates a Tesla K80 instead of a T4. Resetting the instance.

    If you get a K80 GPU, try Runtime -> Reset all runtimes...""")
  
# got a T4, good to go 
else:
  print('Woo! You got the right kind of GPU!')

2019 年 12 月更新

RAPIDS v0.11+ 的新进程

因为

  • RAPIDS v0.11 具有依赖项 (pyarrow) 先前的安装脚本未涵盖,
  • notebooks-contrib 存储库,其中包含 RAPIDS 演示笔记本(例如 colab_notebooks) 和 Colab 安装脚本,现在遵循 RAPIDS 标准版本特定的分支结构*
  • 一些 Colab 用户仍然喜欢 v0.10,

我们尊敬的 notebooks-contrib 霸主 taureandyernv 已经更新了现在的脚本:

If running v0.11 or higher, updates pyarrow library to 0.15.x.

这是 Colab 中 v0.11 运行 的代码单元:

# Install RAPIDS
!wget -nc https://raw.githubusercontent.com/rapidsai/notebooks-contrib/890b04ed8687da6e3a100c81f449ff6f7b559956/utils/rapids-colab.sh
!bash rapids-colab.sh

import sys, os

dist_package_index = sys.path.index("/usr/local/lib/python3.6/dist-packages")
sys.path = sys.path[:dist_package_index] + ["/usr/local/lib/python3.6/site-packages"] + sys.path[dist_package_index:]
sys.path
if os.path.exists('update_pyarrow.py'): ## This file only exists if you're using RAPIDS version 0.11 or higher
  exec(open("update_pyarrow.py").read(), globals())

有关设置 Colab 和实施此脚本的演练,请参阅 How to Install RAPIDS in Google Colab

-* 例如branch-0.11 for v0.11 and branch-0.12 v0.12,默认设置为当前版本