Skip to content

LightGBM

LightGBM is a fast, distributed, high-performance framework based on decision tree algorithms for ranking, classification and many other machine learning Task.

Install

LightGBM is supported via CLI, Python, R. The installation of Python packages and CLI is provided below, and the option to support GPU is added when compiling.

Compile and install the Python package:

# install boost dependencies
apt-get update
apt-get install libboost-dev libboost-system-dev libboost-filesystem-dev -y

# Install GPU-enabled Python packages
pip install lightgbm --install-option=--gpu --install-option="--opencl-include-dir=/usr/local/cuda/include/" --install-option="--opencl-library= /usr/local/cuda/lib64/libOpenCL.so"

mkdir -p /etc/OpenCL/vendors
echo "libnvidia-opencl.so.1" > /etc/OpenCL/vendors/nvidia.icd

Compile and install from the command line:

# install boost dependencies
apt-get update
apt-get install libboost-dev libboost-system-dev libboost-filesystem-dev -y

# Clone LightGBM code
git clone "https://mirror.ghproxy.com/https://github.com/microsoft/LightGBM.git"
cd LightGBM
# switch version branch
git checkout v3.2.1
# Replace the warehouse address of some submodules with the acceleration address, and clone
sed -i "s/ \(https:\/\/github.com\)/ https:\/\/mirror.ghproxy.com\/\1/" .gitmodules
git submodule update --init
cd external_libs/fast_double_parser
sed -i "s/ \(https:\/\/github.com\)/ https:\/\/mirror.ghproxy.com\/\1/" .gitmodules
git submodule update --init
cd ../..

# Compile and install the command line that supports GPU options
mkdir build
cd build
cmake -DUSE_GPU=1 -DOpenCL_LIBRARY=/usr/local/cuda/lib64/libOpenCL.so -DOpenCL_INCLUDE_DIR=/usr/local/cuda/include/ ..
make -j4

mkdir -p /etc/OpenCL/vendors
echo "libnvidia-opencl.so.1" > /etc/OpenCL/vendors/nvidia.icd

# Execute command line tests
cd..
./lightgbm

# You can also install Python packages at the same time using source code
cd python-package
python setup.py install --gpu --opencl-include-dir=/usr/local/cuda/include/ --opencl-library=/usr/local/cuda/lib64/libOpenCL.so --no-cache