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

Add Numba implementation of Blockwise #1015

Merged
merged 3 commits into from
Dec 3, 2024

Conversation

ricardoV94
Copy link
Member

@ricardoV94 ricardoV94 commented Oct 4, 2024

It uses the machinery developed for RVs and Elemwise. The hard part has to do with multiple number of inputs and numba fussiness.

It also improves Blockwise shape inference based on the infer_shape of the core ops

The small cholesky benchmark I added here test runs 10x faster after this PR on my local machine.

Related Issue

@ricardoV94 ricardoV94 marked this pull request as ready for review October 6, 2024 13:44
Copy link

codecov bot commented Oct 7, 2024

Codecov Report

Attention: Patch coverage is 94.18605% with 5 lines in your changes missing coverage. Please review.

Project coverage is 82.10%. Comparing base (ef97287) to head (661408a).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
pytensor/link/numba/dispatch/blockwise.py 90.00% 4 Missing ⚠️
pytensor/link/numba/dispatch/random.py 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1015      +/-   ##
==========================================
+ Coverage   82.09%   82.10%   +0.01%     
==========================================
  Files         183      185       +2     
  Lines       48010    48089      +79     
  Branches     8653     8659       +6     
==========================================
+ Hits        39412    39485      +73     
- Misses       6435     6439       +4     
- Partials     2163     2165       +2     
Files with missing lines Coverage Δ
pytensor/link/numba/dispatch/__init__.py 100.00% <100.00%> (ø)
pytensor/tensor/blockwise.py 85.50% <100.00%> (+1.29%) ⬆️
pytensor/tensor/random/rewriting/numba.py 100.00% <ø> (ø)
pytensor/tensor/rewriting/numba.py 100.00% <100.00%> (ø)
pytensor/link/numba/dispatch/random.py 58.97% <0.00%> (ø)
pytensor/link/numba/dispatch/blockwise.py 90.00% <90.00%> (ø)

... and 1 file with indirect coverage changes

@ricardoV94
Copy link
Member Author

Getting a failure in the CI that I don't reproduce locally: FAILED tests/link/numba/test_blockwise.py::test_blockwise[Det-True] - TypeError: cannot pickle 'PyCapsule' object

Any idea @jessegrabowski @aseyboldt @lucianopaz (sorry for tag spam)

@aseyboldt
Copy link
Member

Maybe locally you end up using a different multiprocessing context? It could be that the pytests run in fork mode and locally it runs in forkserver for some reason?

@ricardoV94
Copy link
Member Author

May be also a numba/scipy version difference

@ricardoV94
Copy link
Member Author

Oh the failure is on the python3.10 CI, it passes on python3.12. numba and scipy versions are equivalent.

@ricardoV94
Copy link
Member Author

The problems seems to be the to_tuple dynamically generated function

Copy link
Member

@jessegrabowski jessegrabowski left a comment

Choose a reason for hiding this comment

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

looks great

pytensor/link/numba/dispatch/blockwise.py Outdated Show resolved Hide resolved
pytensor/tensor/blockwise.py Outdated Show resolved Hide resolved
pytensor/tensor/rewriting/numba.py Show resolved Hide resolved
This can only be done when the output of infer_shape of the core_op depends only on the input shapes, and not their values.
@ricardoV94 ricardoV94 merged commit 07bd48d into pymc-devs:main Dec 3, 2024
61 of 62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vectorize follow-up
4 participants