如何在Google的Colaboratory中安装支持GPU的LightGBM

时间:2018-04-03 05:04:23

标签: google-colaboratory lightgbm

我试图按照文档中的说明进行操作

def outer_function(msg):
    message = msg 
    print(message) #P1
def inner_function():
    print(message) #P2
    return inner_function()

它告诉我以下错误消息

   !sudo apt-get update
   !sudo apt-get install --no-install-recommends nvidia-375
   !sudo apt-get install --no-install-recommends nvidia-opencl-icd-375 nvidia- 
    opencl-dev opencl-headers

然后我按照" Install LightGBM within anaconda3 with GPU support"

的指示进行操作
/bin/sh: 1: sudo: not found
/bin/sh: 1: sudo: not found
/bin/sh: 1: sudo: not found

它告诉我以下错误消息

!git clone --recursive https://github.com/Microsoft/LightGBM.git
!cd LightGBM/python-package
!sudo python3 setup.py install --gpu

现在我感到很困惑。

4 个答案:

答案 0 :(得分:1)

调整公开安装说明WFM - https://github.com/Microsoft/LightGBM/blob/master/docs/Installation-Guide.rst#linux

!git clone --recursive https://github.com/Microsoft/LightGBM ; cd LightGBM
import os
os.chdir('LightGBM')
!mkdir build
os.chdir('build')
!apt-get install cmake
!cmake ..
!make -j4

此处an example notebook

答案 1 :(得分:1)

我和你有同样的问题,在尝试了一些微小的改动之后,对我有用的是改变了!cd到%cd,并删除了sudo

!git clone --recursive https://github.com/Microsoft/LightGBM.git
%cd LightGBM/python-package
!python3 setup.py install --gpu

但请确保您正确遵循安装步骤

!git clone --recursive https://github.com/Microsoft/LightGBM
%cd LightGBM
!mkdir build
!cd build
!cmake ./LightGBM
!make -j4

还应该安装CMake,只需安装它吧

答案 2 :(得分:0)

我对提出的其他解决方案有一些疑问。 这对我有用:

  1. 在“运行时”->“更改运行时类型”下设置GPU

  2. 然后执行:

!git clone --recursive https://github.com/Microsoft/LightGBM
%cd /content/LightGBM
!mkdir build
!cmake -DUSE_GPU=1
!make -j$(nproc)
!sudo apt-get -y install python-pip
!sudo -H pip install setuptools pandas numpy scipy scikit-learn -U
%cd /content/LightGBM/python-package
!sudo python setup.py install --precompile
  1. 最后,import lightgbm,在参数中设置'device': 'gpu',您就可以训练模型了!

答案 3 :(得分:0)

尝试一下:

%cd /content
!rm -r /usr/local/lib/python3.6/dist-packages/lightgbm
!rm -r /content/LightGBM
!git clone --recursive https://github.com/Microsoft/LightGBM
%cd LightGBM
!mkdir build
%cd build
!cmake -DUSE_GPU=1 -DOpenCL_LIBRARY=/usr/local/cuda/lib64/libOpenCL.so.1.1 -DOpenCL_INCLUDE_DIR=/usr/local/cuda/include/ ..
!make -j$(nproc)

然后使用以下几行从python-package目录下载setup.py文件:

from google.colab import files
files.download('/content/LightGBM/python-package/setup.py')

通过在第267行添加以下代码来编辑文件:

os.chdir('/content/LightGBM') 

将setup.py文件上传到colab,并使用以下代码将其放回文件夹中:

import shutil
shutil.move("/content/setup.py", "/content/LightGBM/python-package/setup.py") 

最后,运行:

%cd /content
%cd LightGBM/python-package
!python3 setup.py install --precompile

应该这样做。