-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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 evalution of linear trees with a single leaf. #3987
Fix evalution of linear trees with a single leaf. #3987
Conversation
…datasets. Prior to this change, the line "score_t threshold = tmp_gradients[top_k - 1];" would generate an exception, since tmp_gradients would be empty when the cnt input value to the function is zero.
…data set given as of array of pointers to rows (as opposed to existing method LGBM_BoosterPredictForMat which requires data given as contiguous array)
Note that trees without linear models at the leaf always handle num_leaves = 1 as a special case and directly output the leaf value. Linear trees were missing this special case handling, and hence would have the following issues: * Calling Tree::Predict or Tree::PredictByMap would cause an access violation exception attempting to access the first value of the empty split_feature_ array in GetLeaf. * PredictionFunLinear would either cause an access violation or go into an infinite loop when attempting to do the equivalent of GetLeaf. Note also that PredictionFun does not need the same changes as PredictionFunLinear, since both are only called by Tree::AddPredictionToScore, which has a special case for (!is_linear_ && num_leaves_ <= 1) that precludes calling PredictionFun.
cc @btrotta |
@mjmckp Thanks for finding and fixing this! I reproduced the error you describe with the following script, which causes LightGBM to crash:
Your fix looks good to me! |
Thanks for the fix @mjmckp ! |
This pull request has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this. |
Note that trees without linear models at the leaf always handle
num_leaves = 1
as a special case and directly output the leaf value. Linear trees were missing this special case handling, and hence would have the following issues:Tree::Predict
orTree::PredictByMap
would cause an access violation exception attempting to access the first value of the emptysplit_feature_
array inGetLeaf
.PredictionFunLinear
would either cause an access violation or go into an infinite loop when attempting to do the equivalent ofGetLeaf
.Note also that
PredictionFun
does not need the same changes asPredictionFunLinear
, since both are only called byTree::AddPredictionToScore
, which has a special case for(!is_linear_ && num_leaves_ <= 1)
that precludes callingPredictionFun
.