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

0.57.0rc1 NumbaDeprecationWarning: @guvectorize even with nopython keyword argument #8903

Closed
oyamad opened this issue Apr 16, 2023 · 3 comments · Fixed by #8909
Closed

0.57.0rc1 NumbaDeprecationWarning: @guvectorize even with nopython keyword argument #8903

oyamad opened this issue Apr 16, 2023 · 3 comments · Fixed by #8909
Labels
bug - incorrect behavior Bugs: incorrect behavior good first issue A good issue for a first time contributor

Comments

@oyamad
Copy link

oyamad commented Apr 16, 2023

The following code (note the nopython=True argument)

from numba import guvectorize, int64

@guvectorize([(int64[:], int64, int64[:])], '(n),()->(n)', nopython=True)
def g(x, y, res):
    for i in range(x.shape[0]):
        res[i] = x[i] + y

raises NumbaDeprecationWarning:

/Applications/anaconda3/envs/py311/lib/python3.11/site-packages/numba/np/ufunc/ufuncbuilder.py:328: NumbaDeprecationWarning: The 'nopython' keyword argument was not supplied to the 'numba.jit' decorator. The implicit default value for this argument is currently False, but it will be changed to True in Numba 0.59.0. See https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit for details. self.nb_func = jit(_target='npyufunc', cache=cache)(py_func)

This does not occur with @vectorize:

from numba import vectorize, float64

@vectorize([float64(float64, float64)], nopython=True)
def f(x, y):
    return x + y
>>> numba.__version__
'0.57.0rc1'
@guilhermeleobas
Copy link
Contributor

Hi @oyamad, thanks for the report. I can confirm this "bug" in Numba.

In the snippet of code below, the call to jit is missing **targetoptions expansion.

self.nb_func = jit(_target='npyufunc', cache=cache)(py_func)

Numba doesn't report the warning on vectorize because of the **targetoptions expansion, which contains nopython=True

self.nb_func = jit(_target='npyufunc',
cache=cache,
**targetoptions)(py_func)

Let me know if you'd like to send a patch fixing this issue.

@guilhermeleobas guilhermeleobas added good first issue A good issue for a first time contributor bug - incorrect behavior Bugs: incorrect behavior labels Apr 17, 2023
oyamad added a commit to oyamad/numba that referenced this issue Apr 18, 2023
@guilhermeleobas
Copy link
Contributor

Hi @oyamad, really appreciate you putting some effort towards fixing this issue.

We discuss this topic at today's Numba meeting and we have decided that it would be best to suppress the NumbaDeprecationWarning. Altering the call to jit could potentially result in unexpected behavior, especially if different flags are passed to the (gu)vectorize decorator.

@oyamad
Copy link
Author

oyamad commented Apr 19, 2023

@guilhermeleobas Sure, so, in the description in https://numba.readthedocs.io/en/stable/reference/jit-compilation.html#numba.guvectorize, the keyword arguments nopython, forceobj, and locals for guvectorize (have been and) continue to be kept ignored? I guess that should be documented?

stuartarchibald added a commit to stuartarchibald/numba that referenced this issue Apr 19, 2023
…ze`.

This adds localised suppressions for `NumbaDeprecationWarning`s that
would have been raised from the code path for `@{gu,}vectorize` due to
Numba's internal use of `@jit()` with the `nopython` kwarg not present.

This is considered acceptable due to the following: Deprecation warnings
from Numba's internal use of its own API should not be visible to users.
Unfortunately there's no trivial programmatic way to work around the
internal use of `@jit`-with-no-kwargs in this case as numerous code
paths go through the same operations and user code may well be relying on
"object mode" fall-back. What this patch does it makes it so that users will
not see `NumbaDeprecationWarning`s for this internal use. However, if a
user defines a `@{gu,}vectorize` function that ends up using the fall-back
to the object mode pipeline during compilation, Numba will continue to raise
numerous loud warnings about this happening which should provide a hint as
to the problem and how to fix it.

Numerous tests have been added to check combinations of kwargs/use of
default kwargs being passed through to `@{gu,}vectorize`. These tests
make sure that there are no additional `NumbaDeprecationWarning`s
raised to do with Numba's internal use of `@jit()` in `@{gu,}vectorize`
where the `nopython` kwarg is not supplied.

Closes numba#8903
sklam added a commit that referenced this issue Apr 24, 2023
Fix #8903. `NumbaDeprecationWarning`s raised from `@{gu,}vectorize`.
sklam added a commit to sklam/numba that referenced this issue Apr 25, 2023
Fix numba#8903. `NumbaDeprecationWarning`s raised from `@{gu,}vectorize`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug - incorrect behavior Bugs: incorrect behavior good first issue A good issue for a first time contributor
Projects
None yet
2 participants