简体   繁体   English

Google Colaboratory 上带有 GPU 的 XGBoost

[英]XGBoost with GPU on Google Colaboratory

I am trying to use XGBoost with GPU on Google Colaboratory.我正在尝试在 Google Colaboratory 上使用带有 GPU 的 XGBoost。 Here is my notebook:这是我的笔记本:

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)

When I run last line:当我运行最后一行时:

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

I get "Runtime died, Automatically restarting"我得到“运行时死亡,自动重新启动”

Any ideas how to troubleshoot?任何想法如何排除故障?

I have got XGBoost running on Colab with GPU support.我已经在具有 GPU 支持的 Colab 上运行了 XGBoost。 Download the Linux version from here , and then这里下载 Linux 版本,然后

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

...is working for me. ...正在为我工​​作。

Matt Wehman answer works for me. Matt Wehman 的回答对我有用。 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.我对如何在下载后实际将文件 xgboost-0.81-py2.py3-none-manylinux1_x86_64.whl 放入 Colab 有一些疑问。

The steps are:步骤是:

  1. Download the XGBoost file from the link provided by Matt onto your local machine从 Matt 提供的链接将 XGBoost 文件下载到您的本地机器上
  2. Upload the file onto the Colab server.将文件上传到 Colab 服务器。 this can be done either directly from your computer, or saving to your Google Drive and importing from Drive into Colab.这可以直接从您的计算机完成,也可以保存到您的 Google Drive 并从 Drive 导入到 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.每次启动 Colab 会话(在一段时间未使用后重置)时,您都需要上传文件,并且从云端硬盘加载比从 PC 加载要快得多。

    To upload using your PC:要使用您的 PC 上传:

     from google.colab import files files.upload()

    To upload from Google Drive I install and use pyDrive.要从 Google Drive 上传,我安装并使用 pyDrive。 The process is described here该过程描述为here

  3. Once the XGBoost file is in the Colab local directory, you can finally run the code一旦 XGBoost 文件位于 Colab 本地目录中,您就可以最终运行代码

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

At the moment it looks like !pip install -U xgboost works - seems like the version of xgboost installed on colab was old (0.9.0 or something).目前看起来!pip install -U xgboost有效 - 似乎安装在 colab 上的 xgboost 版本很旧(0.9.0 或其他)。 The xgboost docs also have a link to the nightly builds for xgboost which can be installed like !pip install https://s3-us-west-2.amazonaws.com/xgboost-nightly-builds/xgboost-1.4.0_SNAPSHOT%2B4224c08cacceba3f83f90e387c07aa6205a83bfa-py3-none-manylinux2010_x86_64.whl from a colab jupyter notebook cell. 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 notebook cell。 Since it looks like their list of wheels changes sometimes, you might have to search for something like 'xgboost docs wheels' to find the latest location of the wheels if you want to use those.由于看起来他们的轮子列表有时会发生变化,因此如果您想使用它们,您可能需要搜索诸如“xgboost docs Wheels”之类的内容来查找轮子的最新位置。

据我所知,我们无法在 Google Colab 上导入支持 GPU 的 XGBoost,您检查过了吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM