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

NumPy 1.21 support #7483

Merged
merged 8 commits into from Nov 22, 2021
Merged

NumPy 1.21 support #7483

merged 8 commits into from Nov 22, 2021

Conversation

stuartarchibald
Copy link
Contributor

@stuartarchibald stuartarchibald commented Oct 14, 2021

This PR:

This is a start to support NumPy 1.21 use of FASTCALL methods
in ufuncs.  There are probably better ways to achieve this support.

NumPy further uses `tp_vectorcall_offset` on newer versions.  This
PR does not add support for this (meaning that a DUfunc will be
unnecessarily slow on NumPy >=1.21 when kwargs are used).
@gmarkall
Copy link
Member

Will this close #7176?

@stuartarchibald
Copy link
Contributor Author

Will this close #7176?

Not sure yet. I've got this patch running all tests locally to see if there's any more failures (there's usually a few floating point issues with a NumPy upgrade but we might be lucky!).

@stuartarchibald
Copy link
Contributor Author

Testing locally on linux x86_64:

Run 1:

..Fatal Python error: Aborted

Current thread 0x00007f4c4cf88740 (most recent call first):
  File "<path>/numba/numba/tests/support.py", line 785 in tearDown
  File "<pypath>lib/python3.9/unittest/case.py", line 553 in _callTearDown
  File "<pypath>lib/python3.9/unittest/case.py", line 595 in run
  File "<pypath>lib/python3.9/unittest/case.py", line 651 in __call__
  File "<path>/numba/numba/testing/main.py", line 664 in __call__
  File "<pypath>lib/python3.9/multiprocessing/pool.py", line 125 in worker
  File "<pypath>lib/python3.9/multiprocessing/process.py", line 108 in run
  File "<pypath>lib/python3.9/multiprocessing/process.py", line 315 in _bootstrap
  File "<pypath>lib/python3.9/multiprocessing/popen_fork.py", line 71 in _launch
  File "<pypath>lib/python3.9/multiprocessing/popen_fork.py", line 19 in __init__
  File "<pypath>lib/python3.9/multiprocessing/context.py", line 277 in _Popen
  File "<pypath>lib/python3.9/multiprocessing/process.py", line 121 in start
  File "<pypath>lib/python3.9/multiprocessing/pool.py", line 326 in _repopulate_pool_static
  File "<pypath>lib/python3.9/multiprocessing/pool.py", line 303 in _repopulate_pool
  File "<pypath>lib/python3.9/multiprocessing/pool.py", line 212 in __init__
  File "<pypath>lib/python3.9/multiprocessing/context.py", line 119 in Pool
  File "<path>/numba/numba/testing/main.py", line 741 in _run_inner
  File "<pypath>lib/python3.9/unittest/runner.py", line 176 in run
  File "<path>/numba/numba/testing/main.py", line 795 in run
  File "<pypath>lib/python3.9/unittest/main.py", line 271 in runTests
  File "<path>/numba/numba/testing/main.py", line 325 in run_tests_real
  File "<path>/numba/numba/testing/main.py", line 340 in runTests
  File "<pypath>lib/python3.9/unittest/main.py", line 101 in __init__
  File "<path>/numba/numba/testing/main.py", line 168 in __init__
  File "<path>/numba/numba/testing/__init__.py", line 54 in run_tests
  File "<path>/numba/numba/testing/_runtests.py", line 25 in _main
  File "<path>/numba/numba/runtests.py", line 9 in <module>
  File "<pypath>lib/python3.9/runpy.py", line 87 in _run_code
  File "<pypath>lib/python3.9/runpy.py", line 213 in run_module
  File "<path>/numba/./runtests.py", line 16 in <module>
....Traceback (most recent call last):
  File "<path>/numba/./runtests.py", line 16, in <module>
    runpy.run_module('numba.runtests', run_name='__main__')
  File "<pypath>lib/python3.9/runpy.py", line 213, in run_module
    return _run_code(code, {}, init_globals, run_name, mod_spec)
  File "<pypath>lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "<path>/numba/numba/runtests.py", line 9, in <module>
    sys.exit(0 if _main(sys.argv) else 1)
  File "<path>/numba/numba/testing/_runtests.py", line 25, in _main
    return run_tests(argv, defaultTest='numba.tests',
  File "<path>/numba/numba/testing/__init__.py", line 54, in run_tests
    prog = NumbaTestProgram(argv=argv,
  File "<path>/numba/numba/testing/main.py", line 168, in __init__
    super(NumbaTestProgram, self).__init__(*args, **kwargs)
  File "<pypath>lib/python3.9/unittest/main.py", line 101, in __init__
    self.runTests()
  File "<path>/numba/numba/testing/main.py", line 340, in runTests
    run_tests_real()
  File "<path>/numba/numba/testing/main.py", line 325, in run_tests_real
    super(NumbaTestProgram, self).runTests()
  File "<pypath>lib/python3.9/unittest/main.py", line 271, in runTests
    self.result = testRunner.run(self.test)
  File "<path>/numba/numba/testing/main.py", line 795, in run
    return super(ParallelTestRunner, self).run(self._run_inner)
  File "<pypath>lib/python3.9/unittest/runner.py", line 176, in run
    test(result)
  File "<path>/numba/numba/testing/main.py", line 743, in _run_inner
    self._run_parallel_tests(result, pool, child_runner, tests)
  File "<path>/numba/numba/testing/main.py", line 779, in _run_parallel_tests
    raise e
  File "<path>/numba/numba/testing/main.py", line 770, in _run_parallel_tests
    child_result = it.__next__(self.timeout)
  File "<pypath>lib/python3.9/multiprocessing/pool.py", line 865, in next
    raise TimeoutError from None
multiprocessing.context.TimeoutError: Tests didn't finish before timeout (or crashed):
- 'numba.tests.test_ctypes.TestCTypesUseCases.test_storing_voidptr_to_int_array'

Run 2:

======================================================================
ERROR: test_ufunc_attributes (numba.tests.npyufunc.test_ufunc.TestUFuncs)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "<path>/numba/numba/tests/npyufunc/test_ufunc.py", line 74, in test_ufunc_attributes
    self._test_ufunc_attributes(v, a[0], b[0])
  File "<path>/numba/numba/tests/npyufunc/test_ufunc.py", line 58, in _test_ufunc_attributes
    self.assertPreciseEqual(ufunc_reduce(ufunc, a), np.sum(a), msg=info)
  File "<path>/numba/numba/tests/npyufunc/test_ufunc.py", line 35, in ufunc_reduce
    arg = ufunc.reduce(arg)
TypeError: reduce() got an unexpected keyword argument '<class 'tuple'>'

----------------------------------------------------------------------
Ran 10848 tests in 1983.202s

FAILED (errors=1, skipped=729, expected failures=14)

@stuartarchibald
Copy link
Contributor Author

Run 3:

Fatal Python error: Aborted

Current thread 0x00007f9c41256740 (most recent call first):
  File "<path>/numba/numba/tests/support.py", line 785 in tearDown
  File "<pypath>/lib/python3.9/unittest/case.py", line 553 in _callTearDown
  File "<pypath>/lib/python3.9/unittest/case.py", line 595 in run
  File "<pypath>/lib/python3.9/unittest/case.py", line 651 in __call__
  File "<path>/numba/numba/testing/main.py", line 664 in __call__
  File "<pypath>/lib/python3.9/multiprocessing/pool.py", line 125 in worker
  File "<pypath>/lib/python3.9/multiprocessing/process.py", line 108 in run
  File "<pypath>/lib/python3.9/multiprocessing/process.py", line 315 in _bootstrap
  File "<pypath>/lib/python3.9/multiprocessing/popen_fork.py", line 71 in _launch
  File "<pypath>/lib/python3.9/multiprocessing/popen_fork.py", line 19 in __init__
  File "<pypath>/lib/python3.9/multiprocessing/context.py", line 277 in _Popen
  File "<pypath>/lib/python3.9/multiprocessing/process.py", line 121 in start
  File "<pypath>/lib/python3.9/multiprocessing/pool.py", line 326 in _repopulate_pool_static
  File "<pypath>/lib/python3.9/multiprocessing/pool.py", line 303 in _repopulate_pool
  File "<pypath>/lib/python3.9/multiprocessing/pool.py", line 212 in __init__
  File "<pypath>/lib/python3.9/multiprocessing/context.py", line 119 in Pool
  File "<path>/numba/numba/testing/main.py", line 741 in _run_inner
  File "<pypath>/lib/python3.9/unittest/runner.py", line 176 in run
  File "<path>/numba/numba/testing/main.py", line 795 in run
  File "<pypath>/lib/python3.9/unittest/main.py", line 271 in runTests
  File "<path>/numba/numba/testing/main.py", line 325 in run_tests_real
  File "<path>/numba/numba/testing/main.py", line 340 in runTests
  File "<pypath>/lib/python3.9/unittest/main.py", line 101 in __init__
  File "<path>/numba/numba/testing/main.py", line 168 in __init__
  File "<path>/numba/numba/testing/__init__.py", line 54 in run_tests
  File "<path>/numba/numba/testing/_runtests.py", line 25 in _main
  File "<path>/numba/numba/runtests.py", line 9 in <module>
  File "<pypath>/lib/python3.9/runpy.py", line 87 in _run_code
  File "<pypath>/lib/python3.9/runpy.py", line 213 in run_module
  File "<path>/numba/./runtests.py", line 16 in <module>
<path>/numba/numba/core/ir_utils.py:2141: NumbaPendingDeprecationWarning: 
Encountered the use of a type that is scheduled for deprecation: type 'reflected list' found for argument 'x' of function 'TestListComprehension.test_bulk_use_cases.<locals>.list25'.

For more information visit https://numba.pydata.org/numba-doc/latest/reference/deprecation.html#deprecation-of-reflection-for-list-and-set-types

File "numba/tests/test_comprehension.py", line 189:

        def list25(x):
        ^

  warnings.warn(NumbaPendingDeprecationWarning(msg, loc=loc))
....Traceback (most recent call last):
  File "<path>/numba/./runtests.py", line 16, in <module>
    runpy.run_module('numba.runtests', run_name='__main__')
  File "<pypath>/lib/python3.9/runpy.py", line 213, in run_module
    return _run_code(code, {}, init_globals, run_name, mod_spec)
  File "<pypath>/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "<path>/numba/numba/runtests.py", line 9, in <module>
    sys.exit(0 if _main(sys.argv) else 1)
  File "<path>/numba/numba/testing/_runtests.py", line 25, in _main
    return run_tests(argv, defaultTest='numba.tests',
  File "<path>/numba/numba/testing/__init__.py", line 54, in run_tests
    prog = NumbaTestProgram(argv=argv,
  File "<path>/numba/numba/testing/main.py", line 168, in __init__
    super(NumbaTestProgram, self).__init__(*args, **kwargs)
  File "<pypath>/lib/python3.9/unittest/main.py", line 101, in __init__
    self.runTests()
  File "<path>/numba/numba/testing/main.py", line 340, in runTests
    run_tests_real()
  File "<path>/numba/numba/testing/main.py", line 325, in run_tests_real
    super(NumbaTestProgram, self).runTests()
  File "<pypath>/lib/python3.9/unittest/main.py", line 271, in runTests
    self.result = testRunner.run(self.test)
  File "<path>/numba/numba/testing/main.py", line 795, in run
    return super(ParallelTestRunner, self).run(self._run_inner)
  File "<pypath>/lib/python3.9/unittest/runner.py", line 176, in run
    test(result)
  File "<path>/numba/numba/testing/main.py", line 743, in _run_inner
    self._run_parallel_tests(result, pool, child_runner, tests)
  File "<path>/numba/numba/testing/main.py", line 779, in _run_parallel_tests
    raise e
  File "<path>/numba/numba/testing/main.py", line 770, in _run_parallel_tests
    child_result = it.__next__(self.timeout)
  File "<pypath>/lib/python3.9/multiprocessing/pool.py", line 865, in next
    raise TimeoutError from None
multiprocessing.context.TimeoutError: Tests didn't finish before timeout (or crashed):
- 'numba.tests.test_ctypes.TestCTypesUseCases.test_storing_voidptr_to_int_array'

@gmarkall
Copy link
Member

Results on my linux-64 system:

======================================================================
ERROR: test_ufunc_attributes (numba.tests.npyufunc.test_ufunc.TestUFuncs)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/gmarkall/numbadev/numba/numba/tests/npyufunc/test_ufunc.py", line 74, in test_ufunc_attributes
    self._test_ufunc_attributes(v, a[0], b[0])
  File "/home/gmarkall/numbadev/numba/numba/tests/npyufunc/test_ufunc.py", line 58, in _test_ufunc_attributes
    self.assertPreciseEqual(ufunc_reduce(ufunc, a), np.sum(a), msg=info)
  File "/home/gmarkall/numbadev/numba/numba/tests/npyufunc/test_ufunc.py", line 35, in ufunc_reduce
    arg = ufunc.reduce(arg)
TypeError: reduce() got an unexpected keyword argument '<class 'tuple'>'

======================================================================
FAIL: test_check_objmode_cache_ndarray (numba.tests.test_extending.TestCachingOverloadObjmode)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/gmarkall/numbadev/numba/numba/tests/test_extending.py", line 1860, in test_check_objmode_cache_ndarray
    self.assertEqual(res['exitcode'], 0)
AssertionError: 1 != 0

----------------------------------------------------------------------
Ran 10848 tests in 1442.926s

I didn't have scipy installed so some BLAS tests have not run. Also I saw messages about not having enough cores for some tests (I have 6 physical, 12 HT). Going to install SciPy and do another run.

@stuartarchibald
Copy link
Contributor Author

@gmarkall thanks for trying. I'm surprised there's tests that need more than 6 cores, maybe it's a bug in a test/some logic, if you get a moment and can identify the culprit that'd be very helpful, thanks!

@gmarkall
Copy link
Member

This time with SciPy installed:

======================================================================
ERROR: test_ufunc_attributes (numba.tests.npyufunc.test_ufunc.TestUFuncs)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/gmarkall/numbadev/numba/numba/tests/npyufunc/test_ufunc.py", line 74, in test_ufunc_attributes
    self._test_ufunc_attributes(v, a[0], b[0])
  File "/home/gmarkall/numbadev/numba/numba/tests/npyufunc/test_ufunc.py", line 58, in _test_ufunc_attributes
    self.assertPreciseEqual(ufunc_reduce(ufunc, a), np.sum(a), msg=info)
  File "/home/gmarkall/numbadev/numba/numba/tests/npyufunc/test_ufunc.py", line 35, in ufunc_reduce
    arg = ufunc.reduce(arg)
TypeError: reduce() got an unexpected keyword argument '<class 'tuple'>'

----------------------------------------------------------------------
Ran 10848 tests in 1530.389s

FAILED (errors=1, skipped=633, expected failures=14)

@gmarkall
Copy link
Member

@gmarkall thanks for trying. I'm surprised there's tests that need more than 6 cores, maybe it's a bug in a test/some logic, if you get a moment and can identify the culprit that'd be very helpful, thanks!

An example:

test_threadmask_across_fork_workqueue_1_threads (numba.tests.test_num_threads.TestNumThreadsBackends) ... skipped 'Not enough CPU cores'

which comes from:

@unittest.skipIf(config.NUMBA_NUM_THREADS < 2, "Not enough CPU cores")

somehow config.NUMBA_NUM_THREADS is getting set to 1 or less in a subprocess.

@seberg
Copy link
Contributor

seberg commented Oct 14, 2021

Is this easy to run locally? I am confused why TypeError: reduce() got an unexpected keyword argument '<class 'tuple'>' appears here but CI is happy. It is not that FASTCALL and normal calling convention are mixed up for some reason?

@stuartarchibald
Copy link
Contributor Author

Is this easy to run locally? I am confused why TypeError: reduce() got an unexpected keyword argument '<class 'tuple'>' appears here but CI is happy. It is not that FASTCALL and normal calling convention are mixed up for some reason?

@seberg Thanks for taking a look. It should just be building Numba from this branch and then from the Numba repo root:

./runtests.py numba.tests.npyufunc.test_ufunc.TestUFuncs.test_ufunc_attributes

I presume you've got a local build working already so as to create the original 1.21 PR?

RE:

CI is happy.

Numba's public CI is a bit unusual: https://numba.readthedocs.io/en/stable/developer/contributing.html#continuous-integration-testing, there's a possibility that it just wasn't hit by the right combination of tests/packages/systems/pythons.

@seberg
Copy link
Contributor

seberg commented Oct 14, 2021

No, to be honest, I trusted the CI to run it... I will try to have a look later today probably.

@stuartarchibald
Copy link
Contributor Author

Thanks @seberg! Development builds (of e.g. llvmlite) are in the conda channel numba/label/dev.

@seberg
Copy link
Contributor

seberg commented Oct 14, 2021

Trivial error, my strcmp call is obvious nonsense and has inverted behaviour.

numba/np/ufunc/_internal.c Outdated Show resolved Hide resolved
@stuartarchibald
Copy link
Contributor Author

First local test run against 4df2640 passed.

@stuartarchibald
Copy link
Contributor Author

Second local test run against 4df2640 passed.

@sklam
Copy link
Member

sklam commented Oct 21, 2021

I think all that is left here is a build farm run?

@esc
Copy link
Member

esc commented Nov 22, 2021

Build numba_smoketest_cpu_yaml_65 has started

Copy link
Member

@sklam sklam left a comment

Choose a reason for hiding this comment

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

The changes on NaT looks good as well.

Once NumPy stabilizes on the behavior for NaT comparison, we can come back to update the test. But for now, the changes here is avoiding tests that contains NaT in median.

@sklam sklam added 4 - Waiting on reviewer Waiting for reviewer to respond to author and removed 3 - Ready for Review labels Nov 22, 2021
@sklam
Copy link
Member

sklam commented Nov 22, 2021

Note: once this passes on the farm, it can be merged.

@sklam sklam added 4 - Waiting on CI Review etc done, waiting for CI to finish and removed 4 - Waiting on reviewer Waiting for reviewer to respond to author labels Nov 22, 2021
@esc
Copy link
Member

esc commented Nov 22, 2021

Screen Shot 2021-11-22 at 23 41 45

Everything not Python 3.10 passed. So we will merge this tonight.

@esc
Copy link
Member

esc commented Nov 22, 2021

@sklam @seberg @stuartarchibald @gmarkall thank you all!

@esc
Copy link
Member

esc commented Nov 22, 2021

Everything not Python 3.10 passed. So we will merge this tonight.

With the exception of the ppcle64 build, due to missing Numpy 1.21 -- as I just double checked -- @sklam still good to go?

@sklam sklam added 5 - Ready to merge Review and testing done, is ready to merge 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 Nov 22, 2021
@sklam sklam merged commit fc280ec into numba:master Nov 22, 2021
@seberg
Copy link
Contributor

seberg commented Nov 23, 2021

One thing to note, is that on Python 3.8+, NumPy also uses tp_vectorcall, since I had first thought this might be backported too, I wanted to be a bit minimal and did not include that.

If keywords are being used, numba will have some extra overhad for e.g. ufunc(x, out=y), implementing fastcall could be nice.

@christian-cahig
Copy link

Hi, is this supported in Numba 0.54.1?

@seibert
Copy link
Contributor

seibert commented Dec 8, 2021

This will be released in Numba 0.55.0, coming soon. (Edit: I should say, a release candidate will be coming soon. Due to the magnitude of changes in 0.55, we're going to give people a long RC period to test it before a final release in January 2022.)

@kyoungseoun-chung
Copy link

As far as I know, it doesn't.

I think you should install numba by cloning the repository, otherwise, we need to wait for the new version release...

@seberg
Copy link
Contributor

seberg commented Dec 8, 2021

I expect the patch applies cleanly to 0.54.x, although I guess that won't help much...

@seibert
Copy link
Contributor

seibert commented Dec 8, 2021

If you are using conda, we also automatically build packages whenever a PR is merged, which you can install:

conda install -c numba/label/dev numba=0.55.0dev0

(Edit: Note that while these packages have to pass our full test suite, they don't have any of the community testing that comes with an official release. So be careful. :) )

@christian-cahig
Copy link

If you are using conda, we also automatically build packages whenever a PR is merged, which you can install:

conda install -c numba/label/dev numba=0.55.0dev0

(Edit: Note that while these packages have to pass our full test suite, they don't have any of the community testing that comes with an official release. So be careful. :) )

Thanks, @seibert!

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants