-
Notifications
You must be signed in to change notification settings - Fork 129
Make scan to be a cython extension #77
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
Conversation
Will this be doing compilation all the time or is it cached? |
It will compile once on installation and it requires one of
I like the Cython first approach more, less maintainance + a lot of libraries require Cython anyway. The Cython install time dependency can be stated in pyproject.toml/setup.cfg so user never takes care of installing Cython before he installs pytensor |
With hddm we supported both. If Cython was installed, we would cythonize to c, if not, the shipped c-extensions would be used: https://github.com/hddm-devs/hddm/blob/master/setup.py#L4 |
pyproject.toml allows to specify buld time dependencies so if you pip install without having some packages like numpy or Cython it will install them for you to run setup.py in an isolated mode. After installation they will not appear in the userspace. So you can only have Cython to compile the extension and be always sure it will be available |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #77 +/- ##
==========================================
- Coverage 74.46% 74.45% -0.01%
==========================================
Files 179 179
Lines 49282 49235 -47
Branches 10432 10426 -6
==========================================
- Hits 36696 36660 -36
+ Misses 10282 10275 -7
+ Partials 2304 2300 -4
|
Did you maybe forget to git add |
@aseyboldt the scan Op as it is written in the package accepts storage for outputs and a void function f() |
It was already there, I think I better delete some generated C code instead and reorganize imports quite a bit |
@ferrine can we get a clean git history for this one? Seems too important to just merge squash everything. |
08b99d1
to
8629a40
Compare
@ricardoV94 I've cleaned the history and removed the code on that we are not going to depend:
|
The last major question I think is important is: "Who compiles scan now given it was compiled by user before?" Available options
|
I still don't get it yet. Previously this was compiled at runtime, right? So the c compiler would see the function in the loop and could optimize the loop with that in mind. But if this is precompiled, it can no longer specialize at all. That doesn't sound like what we want to me, or am I missing something? |
My understanding is that the general Scan Cython code is frozen within a release. Only the inner function is compiled at runtime. I'll let @ferrine confirm that though. |
Scan is not a COp unlike other C provided functions Scan is a monolyth to call a It will compile inner function for you https://github.com/pymc-devs/pytensor/blob/main/pytensor/scan/op.py#L1433 and will use the compiled extension if it has it: It will pass the inner graph fn to cython fn |
What's the benefit from this PR? We save on shipping the C code? Anything else? |
I think this PR will make the code base slightly more structured which we would want it to be in the long term. Even if we remove Scan C code in the future there is a setup to support Cython extensions. If we prefer scan over generated numba code, we wrap it, if we prefer to drop Scan it is also fine. |
I'm still somewhat hung up on precompilation before distribution. This complicates distribution, because pytensor is no longer a pure python package then. We have to build the extension module for different architectures and operating systems, and can't easily use more recent machine code instructions. Why would we want to do this in the first place?
This is true currently, but we want to get rid of that "users have to compile code anyway". Building a few Cython extensions is more managable than all the other compiler shenanigans we have to deal with, so if there really is a long-term need for our own extension modules, I think we can manage, but I really don't see the need. |
@ricardoV94 @aseyboldt Will Scan code be removed at some point? |
Only when we remove the C backend. I would imagine it will stay for a minimum of one year more. |
Been thinking it over a bit..
I think you are right, and if so I think this cython extension is probably a good think after all. I guess I've been a bit too optimistic about how fast we can remove the c backend... So sorry @ferrine, I think you are right :-) |
If we are not going to promote C backend that much I think it is easier to have linux only wheels and let other users just compile a thing they had compiled before the change. This will make our ci smaller. |
8629a40
to
f771cf8
Compare
Got merge conflicts resolved |
Can we merge this? |
8092b11
to
8326ebf
Compare
Your first commit title seems to have a typo? "refresgithub actions" And the last two commits should go together I think. Otherwise I'll trust you because I am not familiar with these internals. Pinging @maresb in case he can spot anything. |
8326ebf
to
f1547a0
Compare
typed_list passed unexpectedly
f1547a0
to
45aba5a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose you copied the changes to versioneer.py
and we don't need to review these?
"pytensor/assert_op.py", | ||
"pytensor/graph/opt.py", | ||
"pytensor/graph/opt_utils.py", | ||
"pytensor/graph/optdb.py", | ||
"pytensor/graph/kanren.py", | ||
"pytensor/graph/unify.py", | ||
"pytensor/link/jax/jax_linker.py", | ||
"pytensor/link/jax/jax_dispatch.py", | ||
"pytensor/graph/toolbox.py", | ||
"pytensor/scalar/basic_scipy.py", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of these get deleted in your other PR, right?
We should remember to update this after rebasing the other PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, one of these PRs goes first
Sorry, I'm just seeing this now. What did you want me to have a look at? Something in the |
If you could check the |
|
☝️ fixed in #134 ✔️ Thanks for the merge! |
I did rebase an merge since there were some major blocks of changes |
That should be the action in most of the PRs ;) |
Thank you for opening a PR!
Address #78 to make scan be a Cython extension
Before
After
Here are a few important guidelines and requirements to check before your PR can be merged:
pre-commit
is installed and set up.Don't worry, your PR doesn't need to be in perfect order to submit it. As development progresses and/or reviewers request changes, you can always rewrite the history of your feature/PR branches.
If your PR is an ongoing effort and you would like to involve us in the process, simply make it a draft PR.