-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
[MRG] BUILD: warn instead of raise when openmp unsupported #15174
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
[MRG] BUILD: warn instead of raise when openmp unsupported #15174
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.
First pass:
@thomasjpfan or @NicolasHug could you test on your mac that the warning is printed as expected when you build on an environment which does not support OpenMP (without setting SKLEARN_NO_OPENMP). |
The failing coverage is because we don't test that the warning is printed. It would require a special CI job on macOS with no OpenMP support. Not sure it's worth it. |
I'm triggered (kidding, I'm on linux though :p) |
I had this image in my head that the US team was on the macos side of the force. I hope you'll find the strength to forgive me :) |
Without setting SKLEARN_NO_OPENMP I get:
|
Sorry Thomas my request wasn't precise enough. I added a warning in the init of sklearn when sklearn has been built without openmp unintentionally. I meant could you test if this warning is printed ? And if you have time, if it's not printed when you build with SKLEARN_NO_OPENMP ? |
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 looks pretty good from the code side. I'm not sure the logic would be easy for a reader to understand readily, but I think it's okay. I've not tested
@jeremiedbb To clarify, is this PR suppose to build when |
is this PR suppose to build when SKLEARN_NO_OPENMP is unset and openmp is
not available
AFAIK yes, that's the primary point: make it easy to set up a
development environment.
|
I am not able to build with |
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, thanks @jeremiedbb . Do we still need the new CI?
|
||
msg = ("This test fails because scikit-learn has been built without OpenMP" | ||
" support. You can skip this test by setting the environment " | ||
"variable SKLEARN_SKIP_OPENMP_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.
This is however not recommended since...
from sklearn.utils._openmp_helpers import _openmp_supported | ||
|
||
|
||
def test_openmp_supported(): |
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.
Maybe this should be in sklearn/tests directly?
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 thought so at first but didn't found where. What do you have in mind ? in test_common ? in a new 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.
New file is good for me
# Check that sklearn is built with OpenMP supported. | ||
# This test can be disabled by setting the environment variable | ||
# ``SKLEARN_SKIP_OPENMP_TEST``. | ||
if os.getenv("SKLEARN_SKIP_OPENMP_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.
Should this just be the old SKLEARN_NO_OPENMP variable? Maybe we can just re-use 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.
besides the fact that I find it more explicit, I think it might add some confusion since SKLEARN_NO_OPENMP existed at some point but was used at build time whereas this one if used at runtime.
I think it's useful see this comment |
sklearn/utils/_show_versions.py
Outdated
def show_versions(): | ||
"Print useful debugging information" | ||
"""Print useful debugging information""" | ||
|
||
sys_info = _get_sys_info() | ||
deps_info = _get_deps_info() | ||
|
||
print('\nSystem:') | ||
print('\nSystem') | ||
print('------') | ||
for k, stat in sys_info.items(): | ||
print("{k:>10}: {stat}".format(k=k, stat=stat)) | ||
|
||
print('\nPython deps:') | ||
print('\nPython deps') | ||
print('-----------') | ||
for k, stat in deps_info.items(): | ||
print("{k:>10}: {stat}".format(k=k, stat=stat)) | ||
|
||
print("\n{k:>10}: {stat}".format(k="Built with OpenMP", | ||
stat=_openmp_supported())) |
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.
as discussed with @ogrisel irl, I added an entry in show_versions to show OpenMP status.
It will displayed as Built with OpenMP: True/False
.
Later it could be improved to display the OpenMP runtime linked (requires threadpoolctl)
I also allowed myself a little cosmetic change in this function. replaced
Python deps:
pip: 18.1
setuptools: 41.4.0
sklearn: 0.22.dev0
...
by
Python deps
-----------
pip: 18.1
setuptools: 41.4.0
sklearn: 0.22.dev0
...
which I find nicer.
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.
Python deps => Python dependencies
But wasn't this tested already since we allowed the SKLEARN_NO_OPENMP variable? |
there's no SKLEARN_NO_OPENMP with this PR |
There is in master |
yes but this PR removes it |
I understand why we don't need the var, that's not my point. My question is about the new CI. You claim it's still necessary because:
|
|
Wny don't we just repurpose those 2 jobs?? |
Both are linux jobs (note that they were not made to test no openmp, they existed before). On linux we can't build without openmp now. So we need a macOS job for that. |
Thanks, that's the part I was missing |
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.
LGTM, thanks @jeremiedbb
(I think @ogrisel's approval is about the previous version so this would still need another +1)
sklearn/tests/test_build.py
Outdated
if os.getenv("SKLEARN_SKIP_OPENMP_TEST"): | ||
pytest.skip("test explicitly disabled (SKLEARN_SKIP_OPENMP_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.
So concretely we have a whole new CI job only for these 2 lines.
Kinda sad but OK.
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.
not really because we want to test that all functions pass the tests when building without openmp (hgbt, sparse_manhattan, t-sne, ...)
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 am overall +1 with this PR but I find the phrasing "openmp support" very confusing. scikit-learn does not "support OpenMP". It's the compilers that support OpenMP or not based on their configuration.
I would rather rephrase variables such as SKLEARN_OPENMP_SUPPORTED
to SKLEARN_OPENMP_PARALLELISM_ENABLED
and so on.
Here are a few nitpicks (and others along those lines):
Done. |
Merged! Thanks @jeremiedbb! |
Changed the behavior to warn during the build that OpenMP is not supported, continuing the build without OpenMP. It should ease the sprints a little bit :)
(Edited)
after some discussions the behavior is now the following:
check that a test program not involving OpenMP can be compiled. Allows fast fail (cythonizing takes time) and allows to distinguish from openmp related build errors (see Building scikit-learn with gcc 9.2 in a conda env fails #15129)
then check that a test program involving OpenMP can be compiled.
a new test is added which asserts that sklearn has been built with OpenMP enabled. It can be skipped with an env var.
a new entry in show version is added:
built with OpenMP: True/False
This PR also add a new CI job to test sklearn build without openmp on macOS.