在Google Colaboratory上使用GPU的XGBoost

3

我正在尝试在Google Colaboratory上使用GPU来运行XGBoost。这是我的笔记本:

import numpy as np
import os
import xgboost as xgb

train_X = np.random.rand(100,5)
train_Y = np.random.choice(2, 100)

test_X = np.random.rand(10,5)
test_Y = np.random.choice(2, 10)

xg_train = xgb.DMatrix(train_X, label=train_Y)
xg_test = xgb.DMatrix(test_X, label=test_Y)

param = {}
# use softmax multi-class classification
param['objective'] = 'multi:softmax'
# scale weight of positive examples
param['eta'] = 0.1
param['max_depth'] = 6
param['silent'] = 1
param['nthread'] = 4
param['num_class'] = 2

param['gpu_id'] = 0
param['max_bin'] = 16
param['tree_method'] = 'gpu_hist'


# watchlist allows us to monitor the evaluation result on all data in the list 
watchlist = [(xg_train, 'train'), (xg_test, 'test')]
num_round = 5

bst = xgb.train(param, xg_train, num_round, watchlist)

当我运行最后一行时:
bst = xgb.train(param, xg_train, num_round, watchlist)

我看到了"Runtime died, Automatically restarting"的提示。

有什么方法可以进行故障排除吗?


1
这里OP提供的代码在Colab上成功运行(2021年2月22日)。 - Ceph
4个回答

5

我已经在Colab上启用了支持GPU的XGBoost。从这里下载Linux版本,然后:

!pip uninstall xgboost
!pip install xgboost-0.81-py2.py3-none-manylinux1_x86_64.whl

...正在为我工作。


这对我没用,而且当我尝试从https://pypi.org/project/xgboost/1.2.0/#files更新轮名称时,它也不起作用。 - timothy.s.lau
这是pip的问题,只需使用!pip install xgboost即可。 - timothy.s.lau

4

目前看起来 !pip install -U xgboost 可行 - 在colab上安装的xgboost版本似乎很旧 (0.9.0 或者其他什么版本)。xgboost 文档 也提供了一个链接到 xgboost 的每晚构建版, 使用以下命令可以安装: !pip install https://s3-us-west-2.amazonaws.com/xgboost-nightly-builds/xgboost-1.4.0_SNAPSHOT%2B4224c08cacceba3f83f90e387c07aa6205a83bfa-py3-none-manylinux2010_x86_64.whl,从colab Jupyter 笔记本单元格中运行。由于他们的安装文件列表有时会更改,如果您想使用这些方法,则可能需要搜索类似于“xgboost文档安装文件”以查找最新的安装文件的位置。


4

Matt Wehman answer works for me. I had some doubts on how to actually place the file xgboost-0.81-py2.py3-none-manylinux1_x86_64.whl inside Colab after download.

The steps are:

  1. Download the XGBoost file from the link provided by Matt onto your local machine
  2. Upload the file onto the Colab server. this can be done either directly from your computer, or saving to your Google Drive and importing from Drive into Colab. You will need to upload the file each time you start the Colab session (which resets after some time of non-use) and loading from Drive is much faster than from your PC.

    To upload using your PC:

    from google.colab import files
    files.upload()
    

    To upload from Google Drive I install and use pyDrive. The process is described here

  3. Once the XGBoost file is in the Colab local directory, you can finally run the code

!pip uninstall xgboost
!pip install xgboost-0.81-py2.py3-none-manylinux1_x86_64.whl


!wget https://s3-us-west-2.amazonaws.com/xgboost-wheels/xgboost-0.81-py2.py3-none-manylinux1_x86_64.whl - Kelvin Ng
这里有一个车轮列表,来自它们的文档:https://s3-us-west-2.amazonaws.com/xgboost-nightly-builds/list.html - wordsforthewise

-3
据我所知,我们无法在Google Colab上导入支持GPU的XGBoost,您确认过吗?

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