From a9313802ea5c01063f36941e7e6f70e312ee38f8 Mon Sep 17 00:00:00 2001 From: Jiaming Yuan Date: Sun, 5 Apr 2020 03:52:54 +0800 Subject: [PATCH] Fix dump model. (#5485) --- include/xgboost/learner.h | 2 +- src/c_api/c_api.cc | 1 - src/learner.cc | 5 ++--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/include/xgboost/learner.h b/include/xgboost/learner.h index 933c8aded..5985a5c12 100644 --- a/include/xgboost/learner.h +++ b/include/xgboost/learner.h @@ -199,7 +199,7 @@ class Learner : public Model, public Configurable, public rabit::Serializable { */ virtual std::vector DumpModel(const FeatureMap& fmap, bool with_stats, - std::string format) const = 0; + std::string format) = 0; virtual XGBAPIThreadLocalEntry& GetThreadLocal() const = 0; /*! diff --git a/src/c_api/c_api.cc b/src/c_api/c_api.cc index d31deb83d..2ea2d6375 100644 --- a/src/c_api/c_api.cc +++ b/src/c_api/c_api.cc @@ -663,7 +663,6 @@ inline void XGBoostDumpModelImpl(BoosterHandle handle, const FeatureMap &fmap, auto *bst = static_cast(handle); std::vector& str_vecs = bst->GetThreadLocal().ret_vec_str; std::vector& charp_vecs = bst->GetThreadLocal().ret_vec_charp; - bst->Configure(); str_vecs = bst->DumpModel(fmap, with_stats != 0, format); charp_vecs.resize(str_vecs.size()); for (size_t i = 0; i < str_vecs.size(); ++i) { diff --git a/src/learner.cc b/src/learner.cc index c11fe1176..4f93c4d7b 100644 --- a/src/learner.cc +++ b/src/learner.cc @@ -897,9 +897,8 @@ class LearnerImpl : public LearnerIO { std::vector DumpModel(const FeatureMap& fmap, bool with_stats, - std::string format) const override { - CHECK(!this->need_configuration_) - << "The model hasn't been built yet. Are you using raw Booster interface?"; + std::string format) override { + this->Configure(); return gbm_->DumpModel(fmap, with_stats, format); }