diff --git a/docs/Parameters.rst b/docs/Parameters.rst
index 23a034a16be..ad6011adb14 100644
--- a/docs/Parameters.rst
+++ b/docs/Parameters.rst
@@ -135,7 +135,7 @@ Core Parameters
- in ``dart``, it also affects on normalization weights of dropped trees
-- ``num_leaves`` :raw-html:`🔗︎`, default = ``31``, type = int, aliases: ``num_leaf``, ``max_leaves``, ``max_leaf``, constraints: ``num_leaves > 1``
+- ``num_leaves`` :raw-html:`🔗︎`, default = ``31``, type = int, aliases: ``num_leaf``, ``max_leaves``, ``max_leaf``, constraints: ``1 < num_leaves <= 131072``
- max number of leaves in one tree
diff --git a/include/LightGBM/config.h b/include/LightGBM/config.h
index 8460cd9048b..f3943b76ff4 100644
--- a/include/LightGBM/config.h
+++ b/include/LightGBM/config.h
@@ -166,6 +166,7 @@ struct Config {
// default = 31
// alias = num_leaf, max_leaves, max_leaf
// check = >1
+ // check = <=131072
// desc = max number of leaves in one tree
int num_leaves = kDefaultNumLeaves;
diff --git a/src/io/config.cpp b/src/io/config.cpp
index 8ef537bdf80..2019b0464c9 100644
--- a/src/io/config.cpp
+++ b/src/io/config.cpp
@@ -320,12 +320,16 @@ void Config::CheckParamConflict() {
}
// Check max_depth and num_leaves
if (max_depth > 0) {
- int full_num_leaves = static_cast(std::pow(2, max_depth));
+ double full_num_leaves = std::pow(2, max_depth);
if (full_num_leaves > num_leaves
&& num_leaves == kDefaultNumLeaves) {
Log::Warning("Accuracy may be bad since you didn't set num_leaves and 2^max_depth > num_leaves");
}
- num_leaves = std::min(num_leaves, 2 << max_depth);
+
+ if (full_num_leaves < num_leaves) {
+ // Fits in an int, and is more restrictive than the current num_leaves
+ num_leaves = static_cast(full_num_leaves);
+ }
}
}
diff --git a/src/io/config_auto.cpp b/src/io/config_auto.cpp
index c0239ada666..8498ef2394f 100644
--- a/src/io/config_auto.cpp
+++ b/src/io/config_auto.cpp
@@ -301,6 +301,7 @@ void Config::GetMembersFromString(const std::unordered_map1);
+ CHECK(num_leaves <=131072);
GetInt(params, "num_threads", &num_threads);