ubuntu20.04安装lightgbm的gpu版本

本文详细介绍了如何在Python环境下安装LightGBM的GPU版本,包括CMake、OpenCL、libboost等依赖的安装步骤,并区分了CUDA和GPU版本的区别,以及提供测试代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

lightgbm_gpu install

github

doc

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

python-package

概述

安装

install:

  • 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】
    • 安装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:

https://github.com/microsoft/LightGBM/issues/3939

测试代码一:

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语言写的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值