From 3f3f7563a19b7eda13070359b4a49e2c404f30d7 Mon Sep 17 00:00:00 2001 From: Jiaming Yuan Date: Thu, 21 Sep 2023 05:52:33 +0800 Subject: [PATCH] Load configuration before loading model. Initialize the context before loading model. --- src/gbm/gbtree.cc | 4 +--- src/learner.cc | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/gbm/gbtree.cc b/src/gbm/gbtree.cc index b0327da15711..fd740677bdd2 100644 --- a/src/gbm/gbtree.cc +++ b/src/gbm/gbtree.cc @@ -405,9 +405,7 @@ void GBTree::SaveConfig(Json* p_out) const { // e.g. updating a model, then saving and loading it would result in an empty // model out["gbtree_train_param"]["process_type"] = String("default"); - // Duplicated from SaveModel so that user can get `num_parallel_tree` without parsing - // the model. We might remove this once we can deprecate `best_ntree_limit` so that the - // language binding doesn't need to know about the forest size. + // We save it for parameter validation. It's not loaded in `LoadConfig`. out["gbtree_model_param"] = ToJson(model_.param); out["updater"] = Array{}; diff --git a/src/learner.cc b/src/learner.cc index d2b297dca3ba..8d54aa782090 100644 --- a/src/learner.cc +++ b/src/learner.cc @@ -1170,8 +1170,8 @@ class LearnerIO : public LearnerConfiguration { // We should migrate to use `xgb.load.raw` instead. this->LoadModel(memory_snapshot); } else { - this->LoadModel(memory_snapshot["Model"]); this->LoadConfig(memory_snapshot["Config"]); + this->LoadModel(memory_snapshot["Model"]); } } else { std::string header;