-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
[python] save all param values into model file #2589
Conversation
python-package/lightgbm/basic.py
Outdated
params_to_update = copy.deepcopy(self.params) | ||
params_to_update.update(dict(kwargs, | ||
predict_raw_score=raw_score, | ||
predict_leaf_index=pred_leaf, | ||
predict_contrib=pred_contrib, | ||
num_iteration_predict=num_iteration)) | ||
self.reset_parameter(params_to_update) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guolinke This seems to be quite computationally expensive part and it doesn't work in case params contain any "core" parameters, e.g.
[LightGBM] [Fatal] Cannot change metric during training
[LightGBM] [Fatal] Cannot change num_class during training
[LightGBM] [Fatal] Cannot change boosting during training
Maybe we can put predict parameters into config directly at cpp side during prediction itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, use reset parameter is not a good idea. BTW, do we need to save predict parameters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean remove predict params from model file completely? I think it makes sense, because they are not needed to restore a model and seems to be more "logging" stuff (or at least something different than params used to train model). I think we can introduce naming schema like predict_*
for them and filter later to not write params in model file which start with predict_
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, it makes senses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, then I'll remove my attempts to record prediction time params from here. Can you please help with cpp part to not store them at all (here or in a separate PR)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool idea!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, seems that we already have [doc-only]
directive:
LightGBM/helpers/parameter_generator.py
Lines 301 to 302 in dc65e0a
if "[doc-only]" in y: | |
continue |
BTW, why are for example boosting
and objective
already doc-only
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As they are not automatically generated. We manually write their code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can add a tag, e.g. [no-save], to these parameters, and skip them in to_string.
I've added [no-save]
tag in the latest commit and applied it to predict
and convert_model
tasks' params.
Maybe we can apply it to "output" training values as well? I mean, params like
LightGBM/include/LightGBM/config.h
Lines 488 to 491 in 102893a
// alias = model_output, model_out | |
// desc = filename of output model in training | |
// desc = **Note**: can be used only in CLI version | |
std::string output_model = "LightGBM_model.txt"; |
LightGBM/include/LightGBM/config.h
Lines 564 to 567 in 102893a
// alias = is_save_binary, is_save_binary_file | |
// desc = if ``true``, LightGBM will save the dataset (including validation data) to a binary file. This speed ups the data loading for the next time | |
// desc = **Note**: can be used only in CLI version; for language-specific packages you can use the correspondent function | |
bool save_binary = false; |
LightGBM/include/LightGBM/config.h
Lines 784 to 787 in 102893a
// check = >0 | |
// alias = output_freq | |
// desc = frequency for metric output | |
int metric_freq = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guolinke WDYT about the list of candidate params for the tag?
a2302a3
to
0275dc0
Compare
@guolinke Just out of curiosity, what is the reason to keep text and JSON representations different? |
@jameslamb @Laurae2 Would you mind fixing R-package right here or prefer create a separate PR later? |
@guolinke One more problem is that it seems params for
|
@StrikerRUS yes, it is a problem. Currently, we only copy the params in lgb.train/... to the Dataset, but the copy to Booster from Dataset. |
which part you refer to? |
Do you have any thoughts how to fix it?..
I mean, some fields that presented in text format are not included into JSON format and vice versa. For example, parameters, feature importances.
|
maybe in Booster Construct: LightGBM/python-package/lightgbm/basic.py Lines 1713 to 1716 in bbc45fe
we can construct dataset first, and then copy its params to booster, then construct booster. BTW, maybe this line in Dataset Construct is needed: https://github.com/microsoft/LightGBM/pull/2594/files#diff-732a5a5220860efcac575e9e956bbaeaR855 For the field mismatch, I think it is caused by multiple contributors, we can unify them. |
OK, I see. Let's work on that within #2208 after merging this PR and #2594.
OK, I think it'll be good refactoring to have and it will help a lot of third-party libraries that work with LightGBM model's dumps. I'll create a separate issue for this. |
@StrikerRUS actually, I think the parameter write back should be in #2594, otherwise, the reset config checking for dataset may fail.. |
Blocked by #2594. |
@guolinke
|
Thanks @StrikerRUS , I agree with you, some of the parameters don't need to save.
|
@guolinke I added some more params in the latest commit, please check. Maybe we need to ignore more params, e.g. |
@StrikerRUS I think |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fix for Python part of #2208.