From c376833897de8d7b1d4de6151e8c1c430f1386f4 Mon Sep 17 00:00:00 2001 From: fis Date: Wed, 15 Apr 2020 04:39:50 +0800 Subject: [PATCH 1/2] Write binf header. --- src/learner.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/learner.cc b/src/learner.cc index 1c0e91deae88..ff555bccafa3 100644 --- a/src/learner.cc +++ b/src/learner.cc @@ -653,6 +653,9 @@ class LearnerIO : public LearnerConfiguration { // read parameter CHECK_EQ(fi->Read(&mparam_, sizeof(mparam_)), sizeof(mparam_)) << "BoostLearner: wrong model format"; + if (mparam_.base_score + std::numeric_limits::epsilon() == 2.81467e+23) { + mparam_.base_score += std::numeric_limits::epsilon(); + } CHECK(fi->Read(&tparam_.objective)) << "BoostLearner: wrong model format"; CHECK(fi->Read(&tparam_.booster)) << "BoostLearner: wrong model format"; @@ -777,7 +780,13 @@ class LearnerIO : public LearnerConfiguration { } extra_attr.emplace_back("metrics", os.str()); } + if (mparam.base_score == 2.81467e+23) { + // The magic number the collides with "binf"; + mparam.base_score -= std::numeric_limits::epsilon(); + } + std::string header {"binf"}; + fo->Write(header.data(), 4); fo->Write(&mparam, sizeof(LearnerModelParamLegacy)); fo->Write(tparam_.objective); fo->Write(tparam_.booster); From 464e51879d16728e98e1c43fd36556d602996389 Mon Sep 17 00:00:00 2001 From: fis Date: Wed, 15 Apr 2020 05:28:07 +0800 Subject: [PATCH 2/2] No need to work around the new magic. --- src/learner.cc | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/learner.cc b/src/learner.cc index ff555bccafa3..835ea4ad2fe0 100644 --- a/src/learner.cc +++ b/src/learner.cc @@ -653,9 +653,6 @@ class LearnerIO : public LearnerConfiguration { // read parameter CHECK_EQ(fi->Read(&mparam_, sizeof(mparam_)), sizeof(mparam_)) << "BoostLearner: wrong model format"; - if (mparam_.base_score + std::numeric_limits::epsilon() == 2.81467e+23) { - mparam_.base_score += std::numeric_limits::epsilon(); - } CHECK(fi->Read(&tparam_.objective)) << "BoostLearner: wrong model format"; CHECK(fi->Read(&tparam_.booster)) << "BoostLearner: wrong model format"; @@ -780,11 +777,6 @@ class LearnerIO : public LearnerConfiguration { } extra_attr.emplace_back("metrics", os.str()); } - if (mparam.base_score == 2.81467e+23) { - // The magic number the collides with "binf"; - mparam.base_score -= std::numeric_limits::epsilon(); - } - std::string header {"binf"}; fo->Write(header.data(), 4); fo->Write(&mparam, sizeof(LearnerModelParamLegacy));