Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Integer Overflow #2357 #2400

Merged
merged 6 commits into from
Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/Parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Core Parameters

- in ``dart``, it also affects on normalization weights of dropped trees

- ``num_leaves`` :raw-html:`<a id="num_leaves" title="Permalink to this parameter" href="#num_leaves">&#x1F517;&#xFE0E;</a>`, default = ``31``, type = int, aliases: ``num_leaf``, ``max_leaves``, ``max_leaf``, constraints: ``num_leaves > 1``
- ``num_leaves`` :raw-html:`<a id="num_leaves" title="Permalink to this parameter" href="#num_leaves">&#x1F517;&#xFE0E;</a>`, default = ``31``, type = int, aliases: ``num_leaf``, ``max_leaves``, ``max_leaf``, constraints: ``1 < num_leaves <= 131072``

- max number of leaves in one tree

Expand Down
1 change: 1 addition & 0 deletions include/LightGBM/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 6 additions & 2 deletions src/io/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,16 @@ void Config::CheckParamConflict() {
}
// Check max_depth and num_leaves
if (max_depth > 0) {
int full_num_leaves = static_cast<int>(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<int>(full_num_leaves);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/io/config_auto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ void Config::GetMembersFromString(const std::unordered_map<std::string, std::str

GetInt(params, "num_leaves", &num_leaves);
CHECK(num_leaves >1);
CHECK(num_leaves <=131072);

GetInt(params, "num_threads", &num_threads);

Expand Down