De-duplicate GPU parameters. (#4454)

* Only define `gpu_id` and `n_gpus` in `LearnerTrainParam`
* Pass LearnerTrainParam through XGBoost vid factory method.
* Disable all GPU usage when GPU related parameters are not specified (fixes XGBoost choosing GPU over aggressively).
* Test learner train param io.
* Fix gpu pickling.
This commit is contained in:
Jiaming Yuan
2019-05-29 11:55:57 +08:00
committed by GitHub
parent a3fedbeaa8
commit c589eff941
69 changed files with 927 additions and 562 deletions

View File

@@ -7,9 +7,10 @@
TEST(Linear, shotgun) {
auto mat = xgboost::CreateDMatrix(10, 10, 0);
auto lparam = xgboost::CreateEmptyGenericParam(0, 0);
{
auto updater = std::unique_ptr<xgboost::LinearUpdater>(
xgboost::LinearUpdater::Create("shotgun"));
xgboost::LinearUpdater::Create("shotgun", &lparam));
updater->Init({{"eta", "1."}});
xgboost::HostDeviceVector<xgboost::GradientPair> gpair(
(*mat)->Info().num_row_, xgboost::GradientPair(-5, 1.0));
@@ -24,7 +25,7 @@ TEST(Linear, shotgun) {
}
{
auto updater = std::unique_ptr<xgboost::LinearUpdater>(
xgboost::LinearUpdater::Create("shotgun"));
xgboost::LinearUpdater::Create("shotgun", &lparam));
EXPECT_ANY_THROW(updater->Init({{"feature_selector", "random"}}));
}
delete mat;
@@ -32,8 +33,9 @@ TEST(Linear, shotgun) {
TEST(Linear, coordinate) {
auto mat = xgboost::CreateDMatrix(10, 10, 0);
auto lparam = xgboost::CreateEmptyGenericParam(0, 0);
auto updater = std::unique_ptr<xgboost::LinearUpdater>(
xgboost::LinearUpdater::Create("coord_descent"));
xgboost::LinearUpdater::Create("coord_descent", &lparam));
updater->Init({{"eta", "1."}});
xgboost::HostDeviceVector<xgboost::GradientPair> gpair(
(*mat)->Info().num_row_, xgboost::GradientPair(-5, 1.0));

View File

@@ -6,11 +6,12 @@
namespace xgboost {
TEST(Linear, GPUCoordinate) {
dh::safe_cuda(cudaSetDevice(0));
auto mat = xgboost::CreateDMatrix(10, 10, 0);
auto lparam = CreateEmptyGenericParam(0, 1);
lparam.n_gpus = 1;
auto updater = std::unique_ptr<xgboost::LinearUpdater>(
xgboost::LinearUpdater::Create("gpu_coord_descent"));
updater->Init({{"eta", "1."}, {"n_gpus", "1"}});
xgboost::LinearUpdater::Create("gpu_coord_descent", &lparam));
updater->Init({{"eta", "1."}});
xgboost::HostDeviceVector<xgboost::GradientPair> gpair(
(*mat)->Info().num_row_, xgboost::GradientPair(-5, 1.0));
xgboost::gbm::GBLinearModel model;
@@ -26,12 +27,13 @@ TEST(Linear, GPUCoordinate) {
#if defined(XGBOOST_USE_NCCL)
TEST(Linear, MGPU_GPUCoordinate) {
dh::safe_cuda(cudaSetDevice(0));
{
auto mat = xgboost::CreateDMatrix(10, 10, 0);
auto lparam = CreateEmptyGenericParam(0, -1);
lparam.n_gpus = -1;
auto updater = std::unique_ptr<xgboost::LinearUpdater>(
xgboost::LinearUpdater::Create("gpu_coord_descent"));
updater->Init({{"eta", "1."}, {"n_gpus", "-1"}});
xgboost::LinearUpdater::Create("gpu_coord_descent", &lparam));
updater->Init({{"eta", "1."}});
xgboost::HostDeviceVector<xgboost::GradientPair> gpair(
(*mat)->Info().num_row_, xgboost::GradientPair(-5, 1.0));
xgboost::gbm::GBLinearModel model;
@@ -44,15 +46,13 @@ TEST(Linear, MGPU_GPUCoordinate) {
delete mat;
}
dh::safe_cuda(cudaSetDevice(0));
{
auto lparam = CreateEmptyGenericParam(1, -1);
lparam.n_gpus = -1;
auto mat = xgboost::CreateDMatrix(10, 10, 0);
auto updater = std::unique_ptr<xgboost::LinearUpdater>(
xgboost::LinearUpdater::Create("gpu_coord_descent"));
updater->Init({
{"eta", "1."},
{"n_gpus", "-1"},
{"gpu_id", "1"}});
xgboost::LinearUpdater::Create("gpu_coord_descent", &lparam));
updater->Init({{"eta", "1."}});
xgboost::HostDeviceVector<xgboost::GradientPair> gpair(
(*mat)->Info().num_row_, xgboost::GradientPair(-5, 1.0));
xgboost::gbm::GBLinearModel model;