[MT-TREE] Support prediction cache and model slicing. (#8968)

- Fix prediction range.
- Support prediction cache in mt-hist.
- Support model slicing.
- Make the booster a Python iterable by defining `__iter__`.
- Cleanup removed/deprecated parameters.
- A new field in the output model `iteration_indptr` for pointing to the ranges of trees for each iteration.
This commit is contained in:
Jiaming Yuan
2023-03-27 23:10:54 +08:00
committed by GitHub
parent c2b3a13e70
commit acc110c251
30 changed files with 502 additions and 343 deletions

View File

@@ -1,5 +1,5 @@
/*!
* Copyright 2017-2022 XGBoost contributors
/**
* Copyright 2017-2023, XGBoost contributors
*/
#include <gtest/gtest.h>
#include <xgboost/c_api.h>
@@ -155,7 +155,7 @@ TEST(GPUPredictor, ShapStump) {
std::vector<std::unique_ptr<RegTree>> trees;
trees.push_back(std::unique_ptr<RegTree>(new RegTree));
model.CommitModel(std::move(trees), 0);
model.CommitModelGroup(std::move(trees), 0);
auto gpu_lparam = CreateEmptyGenericParam(0);
std::unique_ptr<Predictor> gpu_predictor = std::unique_ptr<Predictor>(
@@ -183,7 +183,7 @@ TEST(GPUPredictor, Shap) {
std::vector<std::unique_ptr<RegTree>> trees;
trees.push_back(std::unique_ptr<RegTree>(new RegTree));
trees[0]->ExpandNode(0, 0, 0.5, true, 1.0, -1.0, 1.0, 0.0, 5.0, 2.0, 3.0);
model.CommitModel(std::move(trees), 0);
model.CommitModelGroup(std::move(trees), 0);
auto gpu_lparam = CreateEmptyGenericParam(0);
auto cpu_lparam = CreateEmptyGenericParam(-1);

View File

@@ -209,7 +209,7 @@ void GBTreeModelForTest(gbm::GBTreeModel *model, uint32_t split_ind,
p_tree->ExpandCategorical(0, split_ind, split_cats, true, 1.5f,
left_weight, right_weight,
3.0f, 2.2f, 7.0f, 9.0f);
model->CommitModel(std::move(trees), 0);
model->CommitModelGroup(std::move(trees), 0);
}
void TestCategoricalPrediction(std::string name) {
@@ -445,7 +445,7 @@ void TestVectorLeafPrediction(Context const *ctx) {
ASSERT_TRUE(mparam.IsVectorLeaf());
gbm::GBTreeModel model{&mparam, ctx};
model.CommitModel(std::move(trees), 0);
model.CommitModelGroup(std::move(trees), 0);
auto run_test = [&](float expected, HostDeviceVector<float> *p_data) {
{

View File

@@ -14,6 +14,23 @@
#include "../helpers.h"
namespace xgboost {
inline gbm::GBTreeModel CreateTestModel(LearnerModelParam const* param, Context const* ctx,
size_t n_classes = 1) {
gbm::GBTreeModel model(param, ctx);
for (size_t i = 0; i < n_classes; ++i) {
std::vector<std::unique_ptr<RegTree>> trees;
trees.push_back(std::unique_ptr<RegTree>(new RegTree));
if (i == 0) {
(*trees.back())[0].SetLeaf(1.5f);
(*trees.back()).Stat(0).sum_hess = 1.0f;
}
model.CommitModelGroup(std::move(trees), i);
}
return model;
}
template <typename Page>
void TestPredictionFromGradientIndex(std::string name, size_t rows, size_t cols,
std::shared_ptr<DMatrix> p_hist) {