You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
error_score=nan issues hidden warnings in model selection utilities when n_jobs>1 #20475
By default many model selection tools such as cross_validate, validation_curves and *SearchCV catch exceptions, raise a warning and score the model with nan. This can be a nice behavior, especially for *SearchCV estimators that can explore invalid hyper-parameter combinations.
However the warnings can be hidden when they are issued on the stderr of loky workers (python subprocesses), for instance in Jupyter interactive environments:
This is a big usability bug. I think we should refactor the model selection tools to raise the warning from the main process instead of the workers. This would make it possible to:
make it possible to display the warning on the main process stderr to avoid hiding those when parallel compution on several Python processes (e.g. with the default loky backend of joblib) or multi-machine (e.g. with the dask or ray cluster backends of joblib).
raise the warning only once (for the first case) to avoid a "wall of warnings"-effect when n_jobs=1
inform the user that can set error_score="raise" in the warning message if they want there code to raise an exception instead of gettting nan-valued scores.
This problem has been causing a lot of confusion to MOOC participants (INRIA/scikit-learn-mooc#377) so it's probably hurting scikit-learn usability significantly.
changed the title [-]`error_score=nan` issue hidden warning in model selection utilities when n_jobs>1[/-][+]`error_score=nan` issues hidden warnings in model selection utilities when n_jobs>1[/+]on Jul 6, 2021
It probably means we need to wrap joblib.Parallel into some kind of ModelEvaluation result object that can wrap both the traditional attributes and any warning message information with traceback info.
Looking a bit more at it, the first thing I am going to do is the simple case: when all the test scores are NaN raise a warning in the main process saying that something is probably wrong with the model configuration and that `error_score='raise' is a good way to debug the error.
I will leave the more complicated cases for later:
find a way to collect the warnings from the subprocesses and raise them in the main process
avoid the "wall of warning" effect, i.e. reduce the number of warnings since they are all the same
All outputs to stdout/stderr should now be captured, including subprocesses and output of compiled libraries (blas, lapack....). In notebook server, some outputs that would previously go to the notebooks logs will now both head to notebook logs and in notebooks outputs. In terminal frontend like Jupyter Console, Emacs or other, this may ends up as duplicated outputs.
This problem seems related to #12939 and overall the problem stems from the usage of warnings library which is not thread-safe. The solution would be to use the logging library and set the correct logging level when running the application.
I would gladly make a Pull request with changes that refactor warnings.warn to a logger.warning from the logging library.
Thanks for your input, I am planning to work on this issue as I mentioned above.
Don't worry though if you are looking to contribute to scikit-learn, there should be plenty of other issues to work on 😉. This part of the doc should help you getting started as well.
Activity
[-]`error_score=nan` issue hidden warning in model selection utilities when n_jobs>1[/-][+]`error_score=nan` issues hidden warnings in model selection utilities when n_jobs>1[/+]lesteve commentedon Jul 6, 2021
I'll try to take a look at this one.
ogrisel commentedon Jul 6, 2021
It probably means we need to wrap
joblib.Parallelinto some kind ofModelEvaluationresult object that can wrap both the traditional attributes and any warning message information with traceback info.lesteve commentedon Jul 9, 2021
Looking a bit more at it, the first thing I am going to do is the simple case: when all the test scores are NaN raise a warning in the main process saying that something is probably wrong with the model configuration and that `error_score='raise' is a good way to debug the error.
I will leave the more complicated cases for later:
lesteve commentedon Jul 9, 2021
Hmmm actually another subtility in this:
ipykernel6 (released quite recently on June 30 2021) fixed the subprocesses stderr not being captured so you do see the warnings inside the Jupyter notebook withipykernel6: https://github.com/ipython/ipykernel/blob/master/CHANGELOG.md#600ipykernel 5.5.5 (no warnings shown)
ipykernel 6.1 (all warnings shown)
senisioi commentedon Jul 19, 2021
This problem seems related to #12939 and overall the problem stems from the usage of warnings library which is not thread-safe. The solution would be to use the logging library and set the correct logging level when running the application.
I would gladly make a Pull request with changes that refactor warnings.warn to a logger.warning from the logging library.
lesteve commentedon Jul 20, 2021
Thanks for your input, I am planning to work on this issue as I mentioned above.
Don't worry though if you are looking to contribute to scikit-learn, there should be plenty of other issues to work on 😉. This part of the doc should help you getting started as well.