7分钟
GPU计算
1. xgboost 支持使用gpu 计算,前提是安装时开启了GPU 支持
2. 要想使用GPU 训练,需要指定tree_method 参数为下列的值:
'gpu_exact': 标准的xgboost算法。它会对每个分裂点进行精确的搜索。相对于'gpu_hist',它的训练速度更慢,占用更多内存'gpu_hist':使用xgboost histogram近似算法。它的训练速度更快,占用更少内存
3. 当tree_method 为'gpu_exact','gpu_hist' 时,模型的predict 默认采用GPU 加速。
你可以通过设置predictor 参数来指定predict 时的计算设备:
'cpu_predictor': 使用CPU来执行模型预测'gpu_predictor': 使用GPU来执行模型预测
4. 多GPU 可以通过grow_gpu_hist 参数和 n_gpus 参数配合使用。
- 可以通过
gpu_id参数来选择设备,默认为 0 。如果非0,则GPU的编号规则为mod(gpu_id + i) % n_visible_devices for i in 0~n_gpus-1 - 如果
n_gpus设置为-1,则所有的GPU都被使用。它默认为 1 。
5. 多GPU 不一定比单个GPU 更快,因为PCI总线的带宽限制,数据传输速度可能成为瓶颈。
6. GPU 计算支持的参数:
parameter | gpu_exact | gpu_hist |
|---|---|---|
subsample | ✘ | ✔ |
colsample_bytree | ✘ | ✔ |
colsample_bylevel | ✘ | ✔ |
max_bin | ✘ | ✔ |
gpu_id | ✔ | ✔ |
n_gpus | ✘ | ✔ |
predictor | ✔ | ✔ |
grow_policy | ✘ | ✔ |
monotone_constraints | ✘ | ✔ |
学员评价