lightgbm安装问题

931 阅读2分钟

本文已参与「新人创作礼」活动,一起开启掘金创作之路。

lightgbm

github

doc

这里文档的安装指南是CLI版本,不需要。具体安装link进这个:

python-package

中文文档

概述

安装

install:

conda 安装,垃圾

[20220812更]:github_使用conda安装,不支持GPU。

conda install -c conda-forge lightgbm

strongly recommend installation from the conda-forge channel and not from the default one due to many reasons.

[LightGBM] [Fatal] GPU Tree Learner was not enabled in this build.
Please recompile with CMake option -DUSE_GPU=1
GPU False !!!

使用pip安装,可行

  • Exception: Please install CMake and all required dependencies first

    • 安装页面

      • 有三条依赖环境:

        1. Build from Sources section

          1. 对应不同系统的要求都有
        2. For Windows users, CMake (version 3.8 or higher) is strongly required.
          
        3. Boost and OpenCL are needed:...
          
          1. Installation Guide【安装OpenCL、libboost、CMake】
    • ubuntu安装lib过程

      #下列【新】软件包将被安装:
      # nvidia-opencl-dev ocl-icd-opencl-dev
      sudo apt install nvidia-opencl-dev
      sudo apt install ocl-icd-libopencl1 ocl-icd-opencl-dev
      sudo apt install libboost-dev libboost-system-dev libboost-filesystem-dev
      # in conda env 
      conda install cmake
      
  • install

    pip install lightgbm --install-option=--gpu
    

gpu test:

github.com/microsoft/L…

测试代码一:

import lightgbm
import numpy as np
​
​
def check_gpu_support():
    data = np.random.rand(50, 2)
    label = np.random.randint(2, size=50)
    print(label)
    train_data = lightgbm.Dataset(data, label=label)
    params = {'num_iterations': 1, 'device': 'gpu'}
    try:
        gbm = lightgbm.train(params, train_set=train_data)
        print("GPU True !!!")
    except Exception as e:
        print("GPU False !!!")
​
​
if __name__ == '__main__':
    check_gpu_support()

测试代码二:

import lightgbm as lgb
import time
import numpy as np
​
# 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,
#           'device': 'gpu',
#           'gpu_platform_id': 0,
#           'gpu_device_id': 0}
#
dtrain = lgb.Dataset(data=np.array([[2, 23, 34, 54, 1], [21, 23, 4, 64, 1], [27, 53, 3, 4, 0]]))
# t0 = time.time()
# gbm = lgb.train(params, train_set=dtrain, num_boost_round=10,
#                 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,
          'device': 'cpu'
          }
​
t0 = time.time()
gbm = lgb.train(params, train_set=dtrain, num_boost_round=10,
                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))

关于gpu版本和cuda版本

github-issue_gpu文档不清楚

cuda版本:使用device_type="cuda"代替device_type="gpu"

最新回答:

CUDA version is a re-written in CUDA language GPU version for systems where OpenCL is not available.

总结:

gpu版本:我用的python的,所以是python语言

cuda版本:用的cuda语言写的

\