Limit tree depth for GPU hist. (#6045)
This commit is contained in:
parent
b9ebbffc57
commit
a144daf034
@ -40,7 +40,7 @@ class EarlyStopException(Exception):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, best_iteration):
|
def __init__(self, best_iteration):
|
||||||
super(EarlyStopException, self).__init__()
|
super().__init__()
|
||||||
self.best_iteration = best_iteration
|
self.best_iteration = best_iteration
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1025,7 +1025,7 @@ class XGBRFClassifier(XGBClassifier):
|
|||||||
**kwargs)
|
**kwargs)
|
||||||
|
|
||||||
def get_xgb_params(self):
|
def get_xgb_params(self):
|
||||||
params = super(XGBRFClassifier, self).get_xgb_params()
|
params = super().get_xgb_params()
|
||||||
params['num_parallel_tree'] = self.n_estimators
|
params['num_parallel_tree'] = self.n_estimators
|
||||||
return params
|
return params
|
||||||
|
|
||||||
@ -1057,7 +1057,7 @@ class XGBRFRegressor(XGBRegressor):
|
|||||||
reg_lambda=reg_lambda, **kwargs)
|
reg_lambda=reg_lambda, **kwargs)
|
||||||
|
|
||||||
def get_xgb_params(self):
|
def get_xgb_params(self):
|
||||||
params = super(XGBRFRegressor, self).get_xgb_params()
|
params = super().get_xgb_params()
|
||||||
params['num_parallel_tree'] = self.n_estimators
|
params['num_parallel_tree'] = self.n_estimators
|
||||||
return params
|
return params
|
||||||
|
|
||||||
|
|||||||
@ -239,6 +239,10 @@ struct TrainParam : public XGBoostParameter<TrainParam> {
|
|||||||
if (this->max_leaves > 0) {
|
if (this->max_leaves > 0) {
|
||||||
n_nodes = this->max_leaves * 2 - 1;
|
n_nodes = this->max_leaves * 2 - 1;
|
||||||
} else {
|
} 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;
|
n_nodes = (1 << (this->max_depth + 1)) - 1;
|
||||||
}
|
}
|
||||||
CHECK_NE(n_nodes, 0);
|
CHECK_NE(n_nodes, 0);
|
||||||
|
|||||||
@ -505,5 +505,17 @@ TEST(GpuHist, ConfigIO) {
|
|||||||
ASSERT_EQ(j_updater, j_updater_roundtrip);
|
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 tree
|
||||||
} // namespace xgboost
|
} // namespace xgboost
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user