Closed
Description
Using the master branch, if I create 2 boosters from file using the C API, I get broken scores from all but the first created booster:
BoosterHandle bh1, bh2;
LGBM_BoosterCreateFromModelfile("./LightGBM_model.txt", &num_iterations, &bh1); // comment this & you get good results
LGBM_BoosterCreateFromModelfile("./LightGBM_model.txt", &num_iterations, &bh2);
// Score is only correct if I predict with bh1, or predict with bh2 but don't initialize bh1 before initializing bh2:
predict(bh2, values , NUM_FEATURES, num_iterations, &out_len, &ref_scores[0]); // score changes depending on bh2 being the first Booster created or not.
Meaning, only the first booster created works properly.
I'm on Ubuntu 18.04, x86_64.
Thank you
Activity
shiyu1994 commentedon Feb 19, 2021
@AlbertoEAF It seems that the
predict
function is not from the C API ? I failed to reproduce the problem withLGBM_BoosterPredictForFile
. Loading two models withLGBM_BoosterCreateFromModelfile
and then predict withLGBM_BoosterPredictForFile
, the two boosters produce consistent results. So could you provide more details aboutpredict
function ? Or provide a complete reproducible example ? Thanks.AlbertoEAF commentedon Feb 19, 2021
Yes @shiyu1994 it's from this test code: https://gist.github.com/AlbertoEAF/5972db15a27c294bab65b97e1bc4c315 :)
If you modify that gist like the snippet above this happens.
shiyu1994 commentedon Feb 20, 2021
Sorry @AlbertoEAF , I still cannot reproduce the error. At least, for the attached
LightGBM_model.txt
file and the following code snippet, using the first and the second booster handle produce exactly the same result.Could you please provide the
LightGBM_model.txt
file which produces the error? Thanks!LightGBM_model.txt
shiyu1994 commentedon Feb 24, 2021
@AlbertoEAF Could you please recheck this issue and provide a reproducible case? We need to fix this before next release. Thank you! :)
guolinke commentedon Feb 27, 2021
gentle ping @AlbertoEAF , for this issue blocks the release of 3.2.0.
AlbertoEAF commentedon Mar 1, 2021
Hi there :),
Unfortunately I cannot provide that model file as it is sensitive, neither do I have much time on my hands to try to produce a simpler example this week. I can try it in the weekend though since it's urgent.
AlbertoEAF commentedon Mar 6, 2021
Hello @shiyu1994 and @guolinke I managed to reproduce it. I created a new branch https://github.com/feedzai/LightGBM/tree/test-double-model-load which you can use (has the model and the profile code).
To test:
you should get the following outputs, when they should be the same for both boosterHandles 1 & 2:
and if you comment the creation of boosterHandle1 and its predictions, boosterHandle2 starts spitting the results of boosterHandle1 in the screenshot above.
shiyu1994 commentedon Mar 8, 2021
@AlbertoEAF Thanks for your effort. It seems that the file
profiling/profile_single_row_predict.cpp
is missing from the branch. Can you please upload it ?AlbertoEAF commentedon Mar 8, 2021
Done! Sorry for that @shiyu1994 :)
shiyu1994 commentedon Mar 9, 2021
@AlbertoEAF I think I found the problem. Is your model file produced by an earlier version of LightGBM (earlier than the merge of
linear_tree
in #3299)? If so, the fieldis_linear=
is missing from the model file. And when loaded by the latest version of LightGBM, theis_linear_
member of tree will be undefined, which causes undefined prediction behavior.To fix this, let's set the
is_linear_
filed tofalse
when it is absent from the model file, for backward compatibility.I'll open a PR for this.
set is_linear_ to false when it is absent from the model file (fix mi…
17 remaining items