Skip to content
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

Use importlib to load numba extensions #5209

Merged
merged 26 commits into from Feb 7, 2022

Conversation

svrakitin
Copy link
Contributor

Closes #4927

@esc
Copy link
Member

esc commented Feb 7, 2020

@svrakitin thanks for submitting this and congrats on submitting your first PR to Numba. I have queued it for review now.

@stuartarchibald stuartarchibald added the Pending BuildFarm For PRs that have been reviewed but pending a push through our buildfarm label Feb 7, 2020
@stuartarchibald stuartarchibald added this to the Numba 0.49 RC milestone Feb 7, 2020
Copy link
Member

@esc esc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGMT just two small remarks.

buildscripts/condarecipe.local/meta.yaml Outdated Show resolved Hide resolved
buildscripts/condarecipe.local/meta.yaml Outdated Show resolved Hide resolved
@svrakitin
Copy link
Contributor Author

This one adds importlib_metadata as dependency for python versions < 3.8.

@svrakitin svrakitin requested a review from esc February 7, 2020 15:26
try:
from importlib import metadata as importlib_metadata
except ImportError:
import importlib_metadata
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if this fails? I'm wondering if there ought to be an explicit Python>=3.8 branch which just imports it and then another which tries and fails gracefully if the package is missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will only fail on Python < 3.8 if importlib_metadata is missing (it is listed as requirement).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We tend to assume nothing about how Numba was built, it's entirely possible someone just grabbed the source and some limited set of bootstrap packages available for their unusual architecture and built it (this actually happens in practice, we see these people on the issue tracker when strange things happen!). As a result, we tend to err on the side of trying to be as helpful as possible and catch things like this and say something about it being needed.

Further, this will need adding to the dependencies section in the docs: https://github.com/numba/numba/blob/13ece9b97e6f01f750e870347f231282325f60c3/docs/source/user/installing.rst#dependency-list

@stuartarchibald
Copy link
Contributor

Note to reviewers: Someone needs to go and manually test this for Python 3.7 and 3.8 against numba-scipy to make sure it works fine in practice.

Copy link
Member

@esc esc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the new dependency should still be added to http://numba.pydata.org/numba-doc/latest/user/installing.html#dependency-list and also potentially setup.py. Looks good beyond that.

@esc
Copy link
Member

esc commented Feb 10, 2020

BTW: how hard is this dependency?

@svrakitin
Copy link
Contributor Author

@esc It is non-optional run time dependency.

@esc
Copy link
Member

esc commented Feb 11, 2020

@esc It is non-optional run time dependency.

In that case, I believe it should be added to setup.py too. The only other two dependencies that are listed there are llvmlite and numpy.

@esc
Copy link
Member

esc commented Feb 11, 2020

Actually setuptools is in there too.

@esc esc added 4 - Waiting on reviewer Waiting for reviewer to respond to author and removed 3 - Ready for Review labels Feb 11, 2020
@esc
Copy link
Member

esc commented Feb 11, 2020

@svrakitin thanks for submitting the fixes, I have now marked it as waiting for reviewer input. @stuartarchibald @sklam what say you?

esc
esc previously approved these changes Feb 11, 2020
Copy link
Contributor

@stuartarchibald stuartarchibald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. There's a couple of tiny things to resolve (we should use conda packages ahead of pip!).

Otherwise, this PR seems technically fine and gets approval from me. More generally the core developers will need to agree on accepting importlib_metadata as a hard dependency but I do not anticipate this being a problem.

@esc any chance you could please test run this with numba-scipy to make sure it works ok in practice, thanks.

@@ -32,6 +32,7 @@ call activate %CONDA_ENV%
if %PYTHON% LSS 3.4 (%CONDA_INSTALL% enum34)
if %PYTHON% LSS 3.4 (%PIP_INSTALL% singledispatch)
if %PYTHON% LSS 3.3 (%CONDA_INSTALL% -c numba funcsigs)
if %PYTHON% LSS 3.8 (%PIP_INSTALL% importlib-metadata)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps get this from the Anaconda distro?!

@@ -80,6 +80,8 @@ $CONDA_INSTALL -c numba llvmlite
# Install enum34 and singledispatch for Python < 3.4
if [ $PYTHON \< "3.4" ]; then $CONDA_INSTALL enum34; fi
if [ $PYTHON \< "3.4" ]; then $PIP_INSTALL singledispatch; fi
# Install importlib-metadata for Python < 3.8
if [ $PYTHON \< "3.8" ]; then $PIP_INSTALL importlib-metadata; fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps get this from the Anaconda distro?!

Copy link
Contributor

@stuartarchibald stuartarchibald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fixes. Code changes approved. This now needs manual and build farm testing.

@stuartarchibald stuartarchibald removed the 4 - Waiting on reviewer Waiting for reviewer to respond to author label Feb 12, 2020
@gmarkall gmarkall added the 4 - Waiting on reviewer Waiting for reviewer to respond to author label Jan 25, 2022
@@ -98,6 +98,8 @@ fi
# Install latest llvmlite build
$CONDA_INSTALL -c numba/label/dev llvmlite

# Install importlib-metadata for Python < 3.8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Install importlib-metadata for Python < 3.8
# Install importlib-metadata for Python < 3.9

Copy link
Contributor

@stuartarchibald stuartarchibald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating and testing this @gmarkall . Few minor things to look at else I think this is ready for testing on the farm. Thanks again!

Comment on lines 49 to 50
# On channel https://anaconda.org/numba/
- importlib_metadata # [py<39]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# On channel https://anaconda.org/numba/
- importlib_metadata # [py<39]
- importlib_metadata # [py<39]
# On channel https://anaconda.org/numba/

looks like this comment is now on the incorrect line.

Comment on lines 37 to 39
# On channel https://anaconda.org/numba/
- llvmlite >=0.39.0dev0,<0.39
- importlib_metadata # [py<39]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# On channel https://anaconda.org/numba/
- llvmlite >=0.39.0dev0,<0.39
- importlib_metadata # [py<39]
- importlib_metadata # [py<39]
# On channel https://anaconda.org/numba/
- llvmlite >=0.39.0dev0,<0.39

Comment on lines -68 to +64
self.assertEqual(counters['init'], 1)
# was our init function called?
mod.init_func.assert_called_once()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a similar change can also be made to test_entrypoint_tolerance as part of this clean up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar change made - note this also involves configuring the mock with a side effect for init_func().

@stuartarchibald stuartarchibald added the Effort - long Long size effort needed label Jan 25, 2022
@gmarkall
Copy link
Member

@stuartarchibald Many thanks for the reviews - the most recent comments should now be addressed.

@stuartarchibald
Copy link
Contributor

stuartarchibald commented Jan 26, 2022

@stuartarchibald Many thanks for the reviews - the most recent comments should now be addressed.

Thanks @gmarkall, the updates look good. If you are happy to:

Then I'm happy to approve this patch. Many thanks!

Copy link
Member

@gmarkall gmarkall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved re 724990f which is authored by @stuartarchibald.

@gmarkall
Copy link
Member

gpuci run tests.

@stuartarchibald
Copy link
Contributor

Approved re 724990f which is authored by @stuartarchibald.

Thanks @gmarkall

@stuartarchibald stuartarchibald added 4 - Waiting on CI Review etc done, waiting for CI to finish Pending BuildFarm For PRs that have been reviewed but pending a push through our buildfarm and removed 4 - Waiting on reviewer Waiting for reviewer to respond to author labels Jan 26, 2022
Copy link
Contributor

@stuartarchibald stuartarchibald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the effort on this! Looks good.

@stuartarchibald
Copy link
Contributor

Buildfarm ID: numba_smoketest_cpu_yaml_74.

@stuartarchibald
Copy link
Contributor

Buildfarm ID: numba_smoketest_cpu_yaml_74.

Passed.

@stuartarchibald stuartarchibald added 5 - Ready to merge Review and testing done, is ready to merge BuildFarm Passed For PRs that have been through the buildfarm and passed and removed Pending BuildFarm For PRs that have been reviewed but pending a push through our buildfarm 4 - Waiting on CI Review etc done, waiting for CI to finish labels Feb 7, 2022
@sklam sklam merged commit fa5c9e1 into numba:main Feb 7, 2022
@svrakitin svrakitin deleted the fix/4927-slow-import branch February 7, 2022 23:54
@gmarkall
Copy link
Member

gmarkall commented Feb 8, 2022

@svrakitin Many thanks for your efforts here! 🎉

@svrakitin
Copy link
Contributor Author

@gmarkall Hah, thanks for getting this to the end. :)

@flying-sheep
Copy link

Actually setuptools is in there too.

Good catch @esc, it should have been removed from there in this PR.

Follow-up PR to close the deal: #8366

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 - Ready to merge Review and testing done, is ready to merge BuildFarm Passed For PRs that have been through the buildfarm and passed Effort - long Long size effort needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Importing numba is slow
9 participants