-
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
[python] preserve None in _choose_param_value() #5289
Changes from all commits
5154daf
f29662a
53876bd
6616078
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -408,21 +408,27 @@ def _choose_param_value(main_param_name: str, params: Dict[str, Any], default_va | |
# avoid side effects on passed-in parameters | ||
params = deepcopy(params) | ||
|
||
# find a value, and remove other aliases with .pop() | ||
# prefer the value of 'main_param_name' if it exists, otherwise search the aliases | ||
found_value = None | ||
aliases = _ConfigAliases.get(main_param_name) - {main_param_name} | ||
|
||
# if main_param_name was provided, keep that value and remove all aliases | ||
if main_param_name in params.keys(): | ||
found_value = params[main_param_name] | ||
for param in aliases: | ||
params.pop(param, None) | ||
return params | ||
|
||
for param in _ConfigAliases.get(main_param_name): | ||
val = params.pop(param, None) | ||
if found_value is None and val is not None: | ||
found_value = val | ||
# if main param name was not found, search for an alias | ||
for param in aliases: | ||
if param in params.keys(): | ||
params[main_param_name] = params[param] | ||
break | ||
|
||
if found_value is not None: | ||
params[main_param_name] = found_value | ||
else: | ||
params[main_param_name] = default_value | ||
if main_param_name in params.keys(): | ||
for param in aliases: | ||
params.pop(param, None) | ||
return params | ||
Comment on lines
+425
to
+428
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this the same as lines 414-417? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If That's different from lines 414-417, which is like "a value was provided via the main parameter name". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I see. Maybe after not finding the
I'm approving since this is just a suggestion. Thanks for the explanation! |
||
|
||
# neither of main_param_name, aliases were found | ||
params[main_param_name] = default_value | ||
|
||
return params | ||
|
||
|
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.
This is probably for a different PR but shouldn't we try to match the behavior of the C++ side with respect to aliases and try to sort them using the same criteria than here?
LightGBM/include/LightGBM/config.h
Lines 1141 to 1144 in fc0c8fd
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.
oh wow, I actually did not know the C++ side did that!
Yes probably would be a good idea to consider that in a future PR. I could see "a different alias got chosen because the order of resolution changed" being a really subtle reproducibility problem that costs users some time, but would want to weigh that against the performance burden of adding more sorting size-checking code to the parameter-resolving stuff.
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.
@StrikerRUS @jmoralez I just created #5304 to track the work of making alias-resolution consistent and reproducible.
Please add any other details there that you think I might have missed.