Guard against index error in prediction. (#6982)

* Remove `best_ntree_limit` from documents.
This commit is contained in:
Jiaming Yuan
2021-05-25 23:24:59 +08:00
committed by GitHub
parent c6d87e5e18
commit 86e60e3ba8
5 changed files with 24 additions and 8 deletions

View File

@@ -501,6 +501,7 @@ void GBTree::PredictBatch(DMatrix* p_fmat,
uint32_t tree_begin, tree_end;
std::tie(tree_begin, tree_end) =
detail::LayerToTree(model_, tparam_, layer_begin, layer_end);
CHECK_LE(tree_end, model_.trees.size()) << "Invalid number of trees.";
if (tree_end > tree_begin) {
predictor->PredictBatch(p_fmat, out_preds, model_, tree_begin, tree_end);
}