欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

lightGBM GPU支持的安装、验证方法

发布时间:2023/12/15 40 豆豆
生活随笔 收集整理的这篇文章主要介绍了 lightGBM GPU支持的安装、验证方法 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

以下基于ubuntu 16.04 python 3.6.5安装测试成功

1、安装软件依赖

sudo apt-get install --no-install-recommends git cmake build-essential libboost-dev libboost-system-dev libboost-filesystem-dev

2、安装python库

pip install setuptools wheel numpy scipy scikit-learn -U

3、安装lightGBM-GPU

3.1 pip安装

sudo pip3 install lightgbm --install-option=--gpu --install-option="--opencl-include-dir=/usr/local/cuda/include/" --install-option="--opencl-library=/usr/local/cuda/lib64/libOpenCL.so"

3.1 源码安装

git clone --recursive https://github.com/microsoft/LightGBM ; cd LightGBM mkdir build ; cd build cmake -DUSE_GPU=1 .. # if you have installed NVIDIA CUDA to a customized location, you should specify paths to OpenCL headers and library like the following: # cmake -DUSE_GPU=1 -DOpenCL_LIBRARY=/usr/local/cuda/lib64/libOpenCL.so -DOpenCL_INCLUDE_DIR=/usr/local/cuda/include/ .. make -j$(nproc)

 

cd ../python-package/ python setup.py install

4、测试

编写测试脚本

import lightgbm as lgb import timeparams = {'max_bin': 63, 'num_leaves': 255, 'learning_rate': 0.1, 'tree_learner': 'serial', 'task': 'train', 'is_training_metric': 'false', 'min_data_in_leaf': 1, 'min_sum_hessian_in_leaf': 100, 'ndcg_eval_at': [1,3,5,10], 'sparse_threshold': 1.0, 'nthread': 1, 'device': 'gpu', 'gpu_platform_id': 0, 'gpu_device_id': 0}dtrain = lgb.Dataset('train.libsvm') t0 = time.time() gbm = lgb.train(params, train_set=dtrain, num_boost_round=100,valid_sets=None, valid_names=None,fobj=None, feval=None, init_model=None,feature_name='auto', categorical_feature='auto',early_stopping_rounds=None, evals_result=None,verbose_eval=True,keep_training_booster=False, callbacks=None) t1 = time.time()print('gpu version elapse time: {}'.format(t1-t0))params = {'max_bin': 63, 'num_leaves': 255, 'learning_rate': 0.1, 'tree_learner': 'serial', 'task': 'train', 'is_training_metric': 'false', 'min_data_in_leaf': 1, 'min_sum_hessian_in_leaf': 100, 'ndcg_eval_at': [1,3,5,10], 'sparse_threshold': 1.0, 'nthread': 1, 'device': 'cpu' }t0 = time.time() gbm = lgb.train(params, train_set=dtrain, num_boost_round=100,valid_sets=None, valid_names=None,fobj=None, feval=None, init_model=None,feature_name='auto', categorical_feature='auto',early_stopping_rounds=None, evals_result=None,verbose_eval=True,keep_training_booster=False, callbacks=None) t1 = time.time()print('cpu version elapse time: {}'.format(t1-t0))

 

CPU 32s  vs  CPU 8s

5、遇到问题

 

5.1  terminate called without an active exception


源文件目录:src/treelearner/gpu_tree_learner.h的第26行代码:

#define BOOST_COMPUTE_USE_OFFLINE_CACHE
如果包含这个这个宏 BOOST_COMPUTE_USE_OFFLINE_CACHE,就会导致要寻找缓存目录,因此将其注释,并clean然后重新编译源文件,然后就能安装使用了。

 

5.2 Error: No OpenCL Device Found

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

 

参考:https://www.kaggle.com/kirankunapuli/ieee-fraud-lightgbm-with-gpu

总结

以上是生活随笔为你收集整理的lightGBM GPU支持的安装、验证方法的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。