-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[c++] enhance error handling for forced splits file loading #6832
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
Open
KYash03
wants to merge
6
commits into
microsoft:master
Choose a base branch
from
KYash03:fix/forcedsplits-file-error
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+30
−11
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
133cc75
[gbdt] enhance error handling for forced splits file loading
KYash03 c1ace38
Merge branch 'microsoft:master' into fix/forcedsplits-file-error
KYash03 f69dc2e
Merge branch 'master' into fix/forcedsplits-file-error
shiyu1994 19a3ffb
Merge branch 'master' into fix/forcedsplits-file-error
shiyu1994 e2ae1f2
Merge branch 'master' into fix/forcedsplits-file-error
StrikerRUS 2cb1942
Merge branch 'master' into fix/forcedsplits-file-error
shiyu1994 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think this should be a fatal error at training time... if I'm training a model and expecting specific splits to be used, I'd prefer a big loud error to a training run wasting time and compute resources only to produce a model that accidentally does not look like what I'd wanted.
HOWEVER... I think
GBDT::Init()
and/orGBDT::ResetConfig()
will also be called when you load a model at scoring time, and at scoring time we wouldn't want to get a fatal error because of a missing or malformed file which is only supposed to affect training.I'm not certain how to resolve that. Can you please investigate that and propose something?
It would probably be helpful to add tests for these different conditions. You can do this in Python for this purpose. Or if you don't have time / interest, I can push some tests here and then you could work on making them pass?
So to be clear, the behavior I want to see is:
forcedsplits_filename
file does not exist or is not readable --> ERRORforcedsplits_filename
is not valid JSON --> ERRORforcedsplits_filename
file does not exist or is not readable --> no log output, no errorsforcedsplits_filename
is not valid JSON --> no log output, no errorsUh oh!
There was an error while loading. Please reload this page.
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.
We could add a flag to the GBDT class to indicate the current mode.
This is what I was thinking:
Regarding the tests, I'd be happy to write them!
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.
Thanks very much. It is not that simple.
For example, there are many workflows where training and prediction are done in the same process, using the same Booster. So a single property
is_training_
is not going to work.There are also multiple APIs for training.
LightGBM/src/boosting/gbdt.cpp
Line 237 in 3fad53b
LightGBM/src/boosting/gbdt.cpp
Line 344 in 3fad53b
And we'd also want to be careful to not introduce this type of checking on every boosting round, as that would hurt performance.
Maybe @shiyu1994 could help us figure out where to put a check like this.
Also referencing this related PR to help: #5653
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.
What if we consider force split is forbidden in inference time? I think that also tells the user that force splitting is impossible when the model has already been trained.
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.
Introducing a flag to check for whether the model is to be used for inference or training is quite complicated. That's why I think the current solution is acceptable.
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.
@jameslamb What do you think about keeping the current changes in this PR, given the reasons above?
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.
Sorry for the delay.
I think just raising a warning is an acceptable compromise... it gives users a hint to follow, and by not being a fatal error it shouldn't cause problems at inference time.
This will mean that if you train a model with forced splits, save it to a file, then load it in another environment where that file referenced by
forcedsplits_filename
does not exist, you'll now get a warning about this. That might be annoying for people but I think it's worth it for the benefits mentioned above.So for this PR... I support this, but @KYash03 please added tests for the conditions I mentioned in https://github.com/microsoft/LightGBM/pull/6832/files#r1957536985 (but with the "file does not exist or is not readable" case always resulting in this warning message in logs).
@shiyu1994 @StrikerRUS in the future, do you think we should move towards forced splits being considered "data" instead of a parameter? That way, it wouldn't get persisted in the model file (just as
init_score
andweight
are not persisted in the model file). That'd be a clean way to achieve behavior like "forced splits are only used at training time", I think. If you agree with that as a better long-term state, I can write up a feature request describing it.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.
Hey, I think it's good idea!