Limit tree depth for GPU hist. (#6045)

This commit is contained in:
Jiaming Yuan 2020-08-22 19:34:52 +08:00 committed by GitHub
parent b9ebbffc57
commit a144daf034
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 3 deletions

View File

@ -40,7 +40,7 @@ class EarlyStopException(Exception):
"""
def __init__(self, best_iteration):
super(EarlyStopException, self).__init__()
super().__init__()
self.best_iteration = best_iteration

View File

@ -1025,7 +1025,7 @@ class XGBRFClassifier(XGBClassifier):
**kwargs)
def get_xgb_params(self):
params = super(XGBRFClassifier, self).get_xgb_params()
params = super().get_xgb_params()
params['num_parallel_tree'] = self.n_estimators
return params
@ -1057,7 +1057,7 @@ class XGBRFRegressor(XGBRegressor):
reg_lambda=reg_lambda, **kwargs)
def get_xgb_params(self):
params = super(XGBRFRegressor, self).get_xgb_params()
params = super().get_xgb_params()
params['num_parallel_tree'] = self.n_estimators
return params

View File

@ -239,6 +239,10 @@ struct TrainParam : public XGBoostParameter<TrainParam> {
if (this->max_leaves > 0) {
n_nodes = this->max_leaves * 2 - 1;
} else {
// bst_node_t will overflow.
CHECK_LE(this->max_depth, 31)
<< "max_depth can not be greater than 31 as that might generate 2 ** "
"32 - 1 nodes.";
n_nodes = (1 << (this->max_depth + 1)) - 1;
}
CHECK_NE(n_nodes, 0);

View File

@ -505,5 +505,17 @@ TEST(GpuHist, ConfigIO) {
ASSERT_EQ(j_updater, j_updater_roundtrip);
}
TEST(GpuHist, MaxDepth) {
GenericParameter generic_param(CreateEmptyGenericParam(0));
size_t constexpr kRows = 16;
size_t constexpr kCols = 4;
auto p_mat = RandomDataGenerator{kRows, kCols, 0}.GenerateDMatrix();
auto learner = std::unique_ptr<Learner>(Learner::Create({p_mat}));
learner->SetParam("max_depth", "32");
learner->Configure();
ASSERT_THROW({learner->UpdateOneIter(0, p_mat);}, dmlc::Error);
}
} // namespace tree
} // namespace xgboost