Build ROCm LightGBM from source

Build ROCm LightGBM from source#

2025-12-15

2 min read time

Applies to Linux

Prerequisites#

Before proceeding, ensure that you have installed a supported ROCm version, operating system, and Python environment that are compatible with the ROCm Finance libraries. Verify that your system includes a supported AMD Instinct GPU. For guidance, see ROCm finance installation prerequisites.

For a consistent and streamlined setup experience, it’s recommended to use a ROCm development environment Docker container. See Install ROCm Finance for instructions.

Build from source#

  1. Clone the ROCm/LightGBM source code from GitHub.

    git clone --recurse-submodules https://github.com/ROCm/lightgbm/
    
  2. Create and activate a Python virtual environment.

    python -m venv lightgbm_build
    source lightgbm_build/bin/activate
    
  3. Configure the build directory and CMake – make sure you’re using CMake version 3.8 or greater.

    export CMAKE_PREFIX_PATH=/opt/rocm
    export CMAKE_CXX_COMPILER=hipcc
    cmake -DUSE_ROCM=1 -B build -S . -D CMAKE_PREFIX_PATH=/opt/rocm
    
  4. Build the executable binary.

    cd build
    make -j
    

    You should see the LightGBM executable built and placed just outside the build directory.

    cd ..
    
  5. Build the exectuable binary with unit tests.

    export CMAKE_PREFIX_PATH=/opt/rocm
    export CMAKE_CXX_COMPILER=hipcc
    cmake -DUSE_ROCM=1 -DBUILD_CPP_TEST=ON -B build -S . CMAKE_PREFIX_PATH=/opt/rocm
    cd build
    cmake --target testlightgbm -j
    

    To run the unit tests, use:

    cd ..
    ./testlightgbm
    
  6. Build and install the Python module.

    export CMAKE_PREFIX_PATH=/opt/rocm
    pip install --upgrade pip
    pip install --upgrade --force-reinstall numpy pandas scikit-learn scipy setuptools matplotlib cloudpickle pytest psutil joblib pyarrow dask cffi
    ./build-python.sh bdist_wheel --rocm
    pip install dist/amd_lightgbm*.whl
    
  7. Verify the installation.

    pip show -v amd_lightgbm
    
    Example output
     Name: amd_lightgbm
     Version: 4.6.0.99
     Summary: ROCm Port of LightGBM Python-package
    ... [output truncated]