Ghostintheshell
Ghostintheshell

Reputation: 153

How to install LightGBM with GPU support at Google's Colaboratory

I tried to follow the instruction from the documentation

   !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

It threw me following error message

/bin/sh: 1: sudo: not found
/bin/sh: 1: sudo: not found
/bin/sh: 1: sudo: not found

Then I following instruction from "Install LightGBM within anaconda3 with GPU support"

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

It threw me following error message

Cloning into 'LightGBM'...
remote: Counting objects: 9752, done.
remote: Compressing objects: 100% (29/29), done.
remote: Total 9752 (delta 6), reused 12 (delta 5), pack-reused 9718
Receiving objects: 100% (9752/9752), 7.68 MiB | 24.05 MiB/s, done.
Resolving deltas: 100% (6835/6835), done.
Submodule 'include/boost/compute' (https://github.com/boostorg/compute) registered for path 'compute'
Cloning into '/content/LightGBM/compute'...
remote: Counting objects: 21405, done.        
remote: Compressing objects: 100% (32/32), done.        
remote: Total 21405 (delta 20), reused 35 (delta 13), pack-reused 21354        
Receiving objects: 100% (21405/21405), 8.45 MiB | 21.85 MiB/s, done.
Resolving deltas: 100% (17364/17364), done.
Submodule path 'compute': checked out '6de7f6448796f67958dde8de4569fb1ae649ee91'
/bin/sh: 1: sudo: not found

Now I am baffled.

Upvotes: 2

Views: 3318

Answers (4)

Nelly
Nelly

Reputation: 1

Try this:

%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)

Then download the setup.py file from the python-package directory with the following lines:

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

Edit the file by adding the following code at line 267:

os.chdir('/content/LightGBM') 

Upload the setup.py file into colab and use the following code to place it back into it's folder:

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

Lastly, run:

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

That should do it.

Upvotes: 0

I had some issues with other solutions proposed. This worked for me:

  1. set GPU under 'Runtime'->'Change runtime type'

  2. Then, execute:

!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. Finally, import lightgbm, set 'device': 'gpu' in the parameters and you are ready to train your model!

Upvotes: 2

zsfVishnu
zsfVishnu

Reputation: 450

I had the same issue as you, and after trying out some minor changes what worked for me was changing the !cd to %cd , and remove sudo

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

but make sure you followed the installation steps correctly

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

Also CMake should be installed, just !pip install it

Upvotes: 2

Bob Smith
Bob Smith

Reputation: 38579

Adapting the public install instructions 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

Here's an example notebook.

Upvotes: 1

Related Questions