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

Numba gufuncs slowing down import (due to eager mode compilation) #80

Open
frazane opened this issue Oct 19, 2024 · 3 comments
Open

Numba gufuncs slowing down import (due to eager mode compilation) #80

frazane opened this issue Oct 19, 2024 · 3 comments
Labels
performance Improvements to performance

Comments

@frazane
Copy link
Owner

frazane commented Oct 19, 2024

Importing the library seems to be significantly slowed down by numba, see output of

PYTHONVERBOSE=1 python -c "from scoringrules.core import energy"

This is likely related to how guvectorize works. It has two modes and we're using "eager, decoration-time compilation". In other words, we're compiling functions during import.

Eager, or decoration-time, compilation: If you pass one or more type signatures to the decorator, you will be building a NumPy universal function (ufunc). The rest of this subsection describes building ufuncs using decoration-time compilation.

Lazy, or call-time, compilation: When not given any signatures, the decorator will give you a Numba dynamic universal function (DUFunc) that dynamically compiles a new kernel when called with a previously unsupported input type. A later subsection, “Dynamic universal functions”, describes this mode in more depth.

Potential solutions?

  • Use lazy, call-time compilation
  • Use lazy imports of numba modules
  • Use caching
@frazane frazane added enhancement New feature or request performance Improvements to performance and removed enhancement New feature or request labels Oct 19, 2024
@frazane frazane changed the title Numba is slowing down import Numba gufuncs slowing down import (due to eager mode compilation) Oct 24, 2024
@frazane
Copy link
Owner Author

frazane commented Oct 24, 2024

After some investigation there also seem to be an issue when using np.linalg.norm inside of numba gufuncs. Substituting it with a custom jitted function improves import time considerably (not sure about performance impact).

@frazane
Copy link
Owner Author

frazane commented Oct 24, 2024

Could be related to #68 as we could have fewer numba gufuncs

@frazane
Copy link
Owner Author

frazane commented Dec 11, 2024

Note to self: caching could help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Improvements to performance
Projects
None yet
Development

No branches or pull requests

1 participant