-
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
include parameters from reference dataset on subset (fixes #5402) #5416
Conversation
Should we also add Lines 789 to 790 in 5ef46f9
Also, Lines 757 to 758 in 5ef46f9
|
Line 1554 in 6b695c2
and those attributes are set there Lines 845 to 846 in 5ef46f9
Lines 857 to 858 in 5ef46f9
|
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 for this! Please see my suggestion about making the test stricter.
@@ -243,6 +243,13 @@ def test_chunked_dataset_linear(): | |||
valid_data.construct() | |||
|
|||
|
|||
def test_save_dataset_subset_and_load_from_file(tmp_path): | |||
data = np.random.rand(100, 2) | |||
ds = lgb.Dataset(data) |
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.
Could you please try overriding the defaults (e.g. setting max_bin: 7
or something) and check that those non-default values survive the round trip to disk?
I think that would increase our confidence that this is working as expected. Otherwise, I think a bug of the form "all parameter values are lost when writing to binary Dataset file" could make it through this test.
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 that will raise an error like the one in #4904, but I'll try it and confirm here.
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 I see. I expected a PR called "include parameters" to test that parameters on either side of an operation had the same values.
I think maybe I got confused by the presence of writing and reading a binary file, and thought the issue was specific to storing a Dataset
to disk. Is it like "when taking a subset, not all parameters are copied from the reference Dataset to the subset...and this can show up as an error loading the Dataset from file"?
If it is, then it would be great to be able to reach into the Dataset (on the C++ side, not the Python object) and check that attributes like max_bin_
are the same and a non-default value before writing to a file. But I'm not sure how to do that without introducing a new c_api
entrypoint.
So if adding the test I suggested does hit the error from #4904, then I think this test in its current state is ok. It is still an improvement that fixes a bug.
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 built the dataset with non default parameters and check that loading it with the same ones succeeds in 6a2fd1f.
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 nice! Thank you for that and for the explanation.
I tried running this PR's test code on latest master
, and can see based on the error message that those non-default parameter values are being respected.
import lightgbm as lgb
import numpy as np
data = np.random.rand(100, 2)
params = {'max_bin': 50, 'min_data_in_bin': 10}
ds = lgb.Dataset(data, params=params).construct()
ds.subset([1, 2, 3, 5, 8]).save_binary('subset.bin')
lgb.Dataset('subset.bin', params=params).construct()
[LightGBM] [Fatal] Dataset was constructed with parameter max_bin=32649. It cannot be changed to 50 when loading from binary file.
I'm not sure where that 32649
is coming from, but I think that's not an issue caused by this 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.
Thanks for this!
I ran the test code on latest master
(865c126) and confirmed that this test fails with the error
[LightGBM] [Fatal] Dataset was constructed with parameter max_bin=32649. It cannot be changed to 50 when loading from binary file.
The fix here looks correct to me.
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.
Thank you!
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. |
Fixes #5402