* Fix #3342 and h2oai/h2o4gpu#625: Save predictor parameters in model file This allows pickled models to retain predictor attributes, such as 'predictor' (whether to use CPU or GPU) and 'n_gpu' (number of GPUs to use). Related: h2oai/h2o4gpu#625 Closes #3342. TODO. Write a test. * Fix lint * Do not load GPU predictor into CPU-only XGBoost * Add a test for pickling GPU predictors * Make sample data big enough to pass multi GPU test * Update test_gpu_predictor.cu
49 lines
1.6 KiB
C++
49 lines
1.6 KiB
C++
// Copyright by Contributors
|
|
#include <gtest/gtest.h>
|
|
#include <vector>
|
|
#include "helpers.h"
|
|
#include "xgboost/learner.h"
|
|
|
|
namespace xgboost {
|
|
|
|
TEST(learner, Test) {
|
|
typedef std::pair<std::string, std::string> arg;
|
|
auto args = {arg("tree_method", "exact")};
|
|
auto mat_ptr = CreateDMatrix(10, 10, 0);
|
|
std::vector<std::shared_ptr<xgboost::DMatrix>> mat = {*mat_ptr};
|
|
auto learner = std::unique_ptr<Learner>(Learner::Create(mat));
|
|
learner->Configure(args);
|
|
|
|
delete mat_ptr;
|
|
}
|
|
|
|
TEST(learner, SelectTreeMethod) {
|
|
using arg = std::pair<std::string, std::string>;
|
|
auto mat_ptr = CreateDMatrix(10, 10, 0);
|
|
std::vector<std::shared_ptr<xgboost::DMatrix>> mat = {*mat_ptr};
|
|
auto learner = std::unique_ptr<Learner>(Learner::Create(mat));
|
|
|
|
// Test if `tree_method` can be set
|
|
learner->Configure({arg("tree_method", "approx")});
|
|
ASSERT_EQ(learner->GetConfigurationArguments().at("updater"),
|
|
"grow_histmaker,prune");
|
|
learner->Configure({arg("tree_method", "exact")});
|
|
ASSERT_EQ(learner->GetConfigurationArguments().at("updater"),
|
|
"grow_colmaker,prune");
|
|
learner->Configure({arg("tree_method", "hist")});
|
|
ASSERT_EQ(learner->GetConfigurationArguments().at("updater"),
|
|
"grow_fast_histmaker");
|
|
#ifdef XGBOOST_USE_CUDA
|
|
learner->Configure({arg("tree_method", "gpu_exact")});
|
|
ASSERT_EQ(learner->GetConfigurationArguments().at("updater"),
|
|
"grow_gpu,prune");
|
|
learner->Configure({arg("tree_method", "gpu_hist")});
|
|
ASSERT_EQ(learner->GetConfigurationArguments().at("updater"),
|
|
"grow_gpu_hist");
|
|
#endif
|
|
|
|
delete mat_ptr;
|
|
}
|
|
|
|
} // namespace xgboost
|