Skip to content

Commit a2085bf

Browse files
authored
[backport] Fix loading GPU pickle with a CPU-only xgboost distribution. (dmlc#8632) (dmlc#8641)
We can handle loading the pickle on a CPU-only machine if the XGBoost is built with CUDA enabled (Linux and Windows PyPI package), but not if the distribution is CPU-only (macOS PyPI package).
1 parent 067b704 commit a2085bf

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/gbm/gbtree.cc

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "xgboost/logging.h"
2929
#include "xgboost/objective.h"
3030
#include "xgboost/predictor.h"
31+
#include "xgboost/string_view.h"
3132
#include "xgboost/tree_updater.h"
3233

3334
namespace xgboost {
@@ -395,23 +396,36 @@ void GBTree::LoadConfig(Json const& in) {
395396
tparam_.process_type = TreeProcessType::kDefault;
396397
int32_t const n_gpus = xgboost::common::AllVisibleGPUs();
397398
if (n_gpus == 0 && tparam_.predictor == PredictorType::kGPUPredictor) {
398-
LOG(WARNING)
399-
<< "Loading from a raw memory buffer on CPU only machine. "
400-
"Changing predictor to auto.";
399+
LOG(WARNING) << "Loading from a raw memory buffer on CPU only machine. "
400+
"Changing predictor to auto.";
401401
tparam_.UpdateAllowUnknown(Args{{"predictor", "auto"}});
402402
}
403+
404+
auto msg = StringView{
405+
R"(
406+
Loading from a raw memory buffer (like pickle in Python, RDS in R) on a CPU-only
407+
machine. Consider using `save_model/load_model` instead. See:
408+
409+
https://xgboost.readthedocs.io/en/latest/tutorials/saving_model.html
410+
411+
for more details about differences between saving model and serializing.)"};
412+
403413
if (n_gpus == 0 && tparam_.tree_method == TreeMethod::kGPUHist) {
404414
tparam_.UpdateAllowUnknown(Args{{"tree_method", "hist"}});
405-
LOG(WARNING)
406-
<< "Loading from a raw memory buffer on CPU only machine. "
407-
"Changing tree_method to hist.";
415+
LOG(WARNING) << msg << " Changing `tree_method` to `hist`.";
408416
}
409417

410418
auto const& j_updaters = get<Object const>(in["updater"]);
411419
updaters_.clear();
420+
412421
for (auto const& kv : j_updaters) {
413-
std::unique_ptr<TreeUpdater> up(
414-
TreeUpdater::Create(kv.first, ctx_, model_.learner_model_param->task));
422+
auto name = kv.first;
423+
if (n_gpus == 0 && name == "grow_gpu_hist") {
424+
name = "grow_quantile_histmaker";
425+
LOG(WARNING) << "Changing updater from `grow_gpu_hist` to `grow_quantile_histmaker`.";
426+
}
427+
std::unique_ptr<TreeUpdater> up{
428+
TreeUpdater::Create(name, ctx_, model_.learner_model_param->task)};
415429
up->LoadConfig(kv.second);
416430
updaters_.push_back(std::move(up));
417431
}

0 commit comments

Comments
 (0)