frazane / scoringrules

Scoring rules for probabilistic forecast evaluation and optimization.
https://frazane.github.io/scoringrules/
Apache License 2.0
39 stars 6 forks source link

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

Open frazane opened 5 days ago

frazane commented 5 days ago

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?

frazane commented 1 day ago

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 commented 1 day ago

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