-
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
suppress alias warnings with verbosity<0 (fixes #4518) #5253
Conversation
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 doing this! Like I mentioned in #4518 (comment), I totally support this change. But I'd like to hear @StrikerRUS's perspective on this one as well before this is merged.
Until then, please see a few small suggestions below.
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.
Changes look good to me, thanks! Since Config
is so central to the codebase, I'd like one other maintainer to review and approve before we merge this.
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 PR!
I'm sorry, config initialization routine is still not clear enough for me. However, I left some comments that may help to spot uncovered by this PR cases.
src/io/config.cpp
Outdated
GetInt(params, "verbose", &verbosity); | ||
GetInt(params, "verbosity", &verbosity); |
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.
If params have both verbose
and verbosity
keys I think we should still emit the following warning for this case
LightGBM/include/LightGBM/config.h
Lines 1145 to 1147 in 1cc9f9d
Log::Warning("%s is set with %s=%s, %s=%s will be ignored. Current value: %s=%s", | |
alias->second.c_str(), alias_set->second.c_str(), params->at(alias_set->second).c_str(), | |
pair.first.c_str(), pair.second.c_str(), alias->second.c_str(), params->at(alias_set->second).c_str()); |
to inform user that
verbosity
has higher precedence over verbose
.
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 done in the KeyAliasTransform
function after setting the verbosity and de-duplicating.
src/io/config.cpp
Outdated
@@ -42,6 +42,19 @@ std::unordered_map<std::string, std::string> Config::Str2Map(const char* paramet | |||
for (auto arg : args) { | |||
KV2Map(¶ms, Common::Trim(arg).c_str()); |
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.
Looks like the following warnings in KV2Map()
function are still cannot be suppressed by passing verbosity
param because // define verbosity and set logging level
happens later in the code
Lines 28 to 35 in 1cc9f9d
} else { | |
Log::Warning("%s is set=%s, %s=%s will be ignored. Current value: %s=%s", | |
key.c_str(), value_search->second.c_str(), key.c_str(), value.c_str(), | |
key.c_str(), value_search->second.c_str()); | |
} | |
} | |
} else { | |
Log::Warning("Unknown parameter %s", kv); |
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.
These warnings come from duplicated parameters, not aliases. I can try to address them as well in this PR if its in the scope.
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 believe it's related.
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.
Second thought on this, maybe we should leave the duplicates warning? I think it helps the user more than being annoying, since you can remove the warnings by removing the duplicate argument or you can confirm that the argument passed through the CLI is overriding the one on the config file.
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 agree with you. I believe each warning is helpful, but unfortunately LightGBM users want to completely silence their program (according to the issues they create in the repo).
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.
Addressed by having an unordered_map of vectors where we store all parameters for as many times as they're defined, set the verbosity taking the first values of verbose
and verbosity
and then de-duplicating with the KeepFirstValues
function, where warning level logs are printed but after the verbosity has been set, so these can be disabled as well.
I've changed the approach, now:
This of course uses more memory now but I couldn't think of a better way to handle the possible duplicate parameters. I'm open to adapt this to a better idea. |
There are some issues right now with this because it prints the warnings several times and there seems to be a weird interaction with the dataset both in the python and R-packages where if you don't re-construct the dataset, verbosity -1 doesn't remove the alias warnings. I have to look into that. The CLI works fine though 😄 |
Seems like the duplicate warnings about aliases is on master as well. I'll open an issue. |
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!
Could you please resolve merge conflicts? |
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 a lot for this PR!
I don't have any other additional comments except a one below about the function naming.
But I think I'm not qualified to formally approve these mostly cpp changes.
✔️
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.
Looks good to me, except a minor naming
Can we merge this PR? |
did this happen? I couldn't find an issue like that from search and don't see one linked here.
Based on what I see in the diff for unit tests, I think this can be merged. It does seem like the warnings described in #3641 (comment) (which led to #4518) can now be suppressed with But I'll defer to @jmoralez . To be honest, there have been significant changes since I first approved and it's difficult for me to understand the current state of this PR a bit. For example, the conversation in #5253 (comment) is unresolved. |
Yes, I opened #5332. The duplicate parameter warnings were also addressed in this PR. The My opinion is that this is ready to be merged, but of course I'm biased haha. |
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.
Yes, I opened #5332.
ah ok, thanks for pointing that out! I just got unlucky with the search terms I chose 😅
If that issue had mentioned this PR with #5253
or if a comment had been posted on this PR saying "created #5332
", it would have been easier for me to find.
The duplicate parameter warnings were also addressed in this PR
Sorry, I'm still confused...do you mean specifically that as of this PR being merged, we could also close #5332?
If so, please:
- add "fixes alias warnings can print several times #5332" to the description
- add one more test confirming that the duplicate warnings are no longer raised
No, I meant that this was originally only going to remove warnings for parameter aliases, i.e. you set The duplicate prints (#5332) is not solved yet. |
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 and sorry for taking so long to come back and re-review! I understand now what his PR does and doesn't fix.
Let's merge this...it's only changing internal details, so easy to revise any of these design decisions in the future if we decide a different pattern is preferable for changing other logging-related stuff.
Awesome contribution, @jmoralez ! People have been asking for this for a long time 😬
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. |
Sets the logging level before resolving the parameter aliases so that the warnings related to them can be suppressed using the verbosity parameter.
Fixes #4518.