【问题标题】:XGBoost with GPU on Google ColaboratoryGoogle Colaboratory 上带有 GPU 的 XGBoost
【发布时间】:2019-01-11 13:30:10
【问题描述】:

我正在尝试在 Google Colaboratory 上将 XGBoost 与 GPU 结合使用。这是我的笔记本:

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)

我得到“运行时已死,自动重新启动”

有任何解决问题的想法吗?

【问题讨论】:

  • 此处OP提供的代码为我在Colab上成功运行(2021年2月22日)。

标签: python gpu xgboost google-colaboratory


【解决方案1】:

目前看来!pip install -U xgboost 可以正常工作 - 似乎 colab 上安装的 xgboost 版本很旧(0.9.0 或其他版本)。 xgboost docs 还具有指向 xgboost 的 nightly builds 的链接,可以像 !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 docs wheel”之类的内容才能找到轮子的最新位置。

【讨论】:

    【解决方案2】:

    Matt Wehman 的回答对我有用。我对下载后如何在 Colab 中实际放置文件 xgboost-0.81-py2.py3-none-manylinux1_x86_64.whl 有一些疑问。

    步骤是:

    1. 从 Matt 提供的链接中将 XGBoost 文件下载到您的本地计算机上
    2. 将文件上传到 Colab 服务器。这可以直接从您的计算机完成,也可以保存到您的 Google Drive 并从 Drive 导入 Colab。每次启动 Colab 会话(一段时间不使用后会重置)时,您都需要上传文件,并且从云端硬盘加载比从 PC 加载要快得多。

      使用您的 PC 上传:

      from google.colab import files
      files.upload()
      

      要从 Google Drive 上传,我安装并使用 pyDrive。流程描述here

    3. XGBoost 文件进入 Colab 本地目录后,您终于可以运行代码了

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

    【讨论】:

    【解决方案3】:

    我已经让 XGBoost 在 Colab 上运行并支持 GPU。从here下载Linux版本,然后

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

    ...为我工作。

    【讨论】:

    【解决方案4】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-08
      • 2019-04-22
      • 1970-01-01
      • 2018-07-21
      • 2018-12-13
      • 1970-01-01
      • 2022-06-29
      相关资源
      最近更新 更多