question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Weird warnings when using @jit on version 0.50

See original GitHub issue

Reporting a bug

When using Numba version 0.38:

Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> import numba
>>> numba.__version__
'0.38.0'
>>> from numba import jit
>>> @jit
... def _ndiff(x):
...     s = x.size
...     r = np.empty(s, dtype=np.bool) 
...     for i in range(1, s): 
...         r[i] = x[i] - x[i-1] 
...     return r
... 
>>> arr = np.random.choice([0, 1], size=1000000).astype(np.bool)
>>> %timeit _ndiff(arr)
5.32 microseconds

Now the exact same code with version 0.50:

Python 3.8.3 (default, May 19 2020, 18:47:26) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> import numba
>>> numba.__version__
'0.50.0'
>>> from numba import jit
>>> @jit
... def _ndiff(x):
...     s = x.size
...     r = np.empty(s, dtype=np.bool) 
...     for i in range(1, s): 
...         r[i] = x[i] - x[i-1] 
...     return r
... 
>>> arr = np.random.choice([0, 1], size=1000000).astype(np.bool)
>>> %timeit _ndiff(arr)
5.32 microseconds
<stdin>:1: NumbaWarning: 
Compilation is falling back to object mode WITH looplifting enabled because Function "_ndiff" failed type inference due to: No implementation of function Function(<built-in function empty>) found for signature:
 
 >>> empty(int64, dtype=Function(<class 'bool'>))
 
There are 2 candidate implementations:
  - Of which 2 did not match due to:
  Overload in function 'empty': File: <built-in>: Line <N/A>.
    With argument(s): '(int64, dtype=Function(<class 'bool'>))':
   No match.

During: resolving callee type: Function(<built-in function empty>)
During: typing of call at <stdin> (4)


File "<stdin>", line 4:
<source missing, REPL/exec in use?>

<stdin>:1: NumbaWarning: 
Compilation is falling back to object mode WITHOUT looplifting enabled because Function "_ndiff" failed type inference due to: cannot determine Numba type of <class 'numba.core.dispatcher.LiftedLoop'>

File "<stdin>", line 5:
<source missing, REPL/exec in use?>

/home/ubuntu/anaconda3/envs/py38/lib/python3.8/site-packages/numba/core/object_mode_passes.py:177: NumbaWarning: Function "_ndiff" was compiled in object mode without forceobj=True, but has lifted loops.

File "<stdin>", line 3:
<source missing, REPL/exec in use?>

  warnings.warn(errors.NumbaWarning(warn_msg,
/home/ubuntu/anaconda3/envs/py38/lib/python3.8/site-packages/numba/core/object_mode_passes.py:187: NumbaDeprecationWarning: 
Fall-back from the nopython compilation path to the object mode compilation path has been detected, this is deprecated behaviour.

For more information visit http://numba.pydata.org/numba-doc/latest/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit

File "<stdin>", line 3:
<source missing, REPL/exec in use?>

  warnings.warn(errors.NumbaDeprecationWarning(msg,
(again, a few microseconds)

Given the performance of the @jit version in both 0.38 and 0.50, it is ABSOLUTELY AND DEFINITELY not running in object mode. Removing @jit on a 1,000,000-long array makes the Python version take forever, while the version with @jit runs in a few microseconds for the same array size.

Why so many warnings claiming that the function is running in object mode, if this is manifestly not the case?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
stuartarchibaldcommented, Jun 22, 2020

Thanks for the report. The code above won’t compiled with nopython=True because np.bool is not supported as a dtype (np.bool is bool whereas np.bool_ is the dtype). The code runs at about the same speed because under @jit because Numba spots that the loop can be compiled and so compiles it and swaps out the interpreted loop for an compiled one (Compilation is falling back to object mode WITH looplifting enabled...). See also http://numba.pydata.org/numba-doc/latest/user/5minguide.html#what-is-nopython-mode

0reactions
stuartarchibaldcommented, Sep 2, 2020

Closing this issue as no new information has been provided. It is assumed that the above resolved the reported issue, if this is not the case please reopen the issue with new information. Many thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Weird Numba 0.50 behaviour when using @jit - Stack ...
Basically it complains a lot about falling back to object mode because he's not happy with almost everything it finds here. Despite these...
Read more >
Release Notes — Numba 0.50.1 documentation - PyData |
Version 0.50.1 (Jun 24, 2020)¶. This is a bugfix release for 0.50.0, it fixes a critical bug in error reporting and a number...
Read more >
Bug listing with status CONFIRMED as at 2022/12/20 18:46:38
Bug:4315 - "[Future EAPI] add support for version ranges in DEPEND" ... startup warnings interfere with dmcrypt password entry" status:CONFIRMED resolution: ...
Read more >
目录 - Gitee
Next Release: Version 0.50.0, RC=May 28th ... #2866: NotImplementedError/LoweringError when using jit on a function containing an inner function.
Read more >
Performance Improvements in .NET 7
As with previous versions of .NET, performance is a key focus that pervades the entire stack, whether it be features created explicitly for ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found