-
Notifications
You must be signed in to change notification settings - Fork 10
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 python bindings #110
Add python bindings #110
Conversation
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.
- It may be worthwhile to setup the basic python packaging stuff now (i.e. a
setup.py
). I don't know if we'll ever want to make this available as a python package directly, but we might. And I'm not sure how compatible your directory layout here will be if we do that. You can look at NEML for asetup.py
that works with cmake. - What is the actual minimum torch and python version required? If we really need python3.11 that could be annoying, as it's not standard on Ubuntu yet.
- The tests error on python3.10 with a legitimate syntax error. Probably should fix that unless 3.11 is really needed.
- We should have the python test action loop over python versions in our valid range. Maybe the same thing with torch, but I'm okay with just forcing people to 2.1 if that's what's needed.
I'll try to add a pyproject.toml
I dropped the 3.11 requirement and fixed the unpacking syntax error.
I agree, if github does not have any limit on the number of checks... |
lol I forgot ubuntu 22.04 does not have python 3.6 in the main universe. Should we switch to conda or just drop python 3.6 support? I'm fine with either solution. |
This is ready again. |
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.
- Add check that the python source has been blacked (
black --check
). - I have a fun bug where I installed the package, uninstalled it, and then tried to install it again. It will not build. The problem is with linking to torch. Delete the build folder and trying again fixed the issue. Uhh, maybe try it on Linux and see what happens?
- It would be nice to be able to construct both
BatchTensor
and the derived classes ofFixedDimTensor
from torch tensors and numpy arrays. I think you just need to implement thetorch.tensor
variant and then rely on the torch tensor constructor to handle the rest of the conversions. They must have a "ensure_tensor" or similar method like numpy. ForBatchTensor
the user would supply the tensor and anint
indicating the separation between the batch and base dims. ForFixedDimTensor
we should be able to infer all the dimensions (and throw if necessary) without help. - I don't think you test the
torch.tensor
view into our classes. A few simple tests would be nice (values are the same, if you change the tensor view you change the underlying neml2 tensor data, devices are the same).
I searched online but couldn't find any way of locating the pytorch package without first finding python. I would argue that what I have right now is fine, because if python is not found, it will merrily fall back to plan B (downloading a cpu libtorch). So strictly speaking, we are not introducing python as a dependency (if we are not going to compile python bindings). |
Also note that I renamed the github workflow recipe "Formatting Check" to "C++ Formatting Check" (because we now have a "Python Formatting Check"). So you will need to modify the list of expected checks. |
A few "new" things to review:
I let the wheels use a special rpath to avoid bundling all the libtorch dependencies into our wheel. We probably want to discuss about this. |
I haven't added the "upload to pypi" step yet. We may want to play with the wheels on more machines before uploading to pypi... |
At a higher level, we should probably think about how to auto-update python wheels to stay up-to-date with pytorch updates. I am also not entirely satisfied with the hard-coded torch versions scattered across the repository. |
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.
- See comment on minimum cmake version.
- We should probably include "build and test" for python bindings in the github actions.
- I suggest have a
load_model
helper that combinesload_input
andget_model
. - Perhaps add a parameter partial type test to
test_model.py
as that's going to be important shortly.
I will make a new PR to actually upload the pypi package after we merge this.
Good work, nearly done!
… need a trampoline class
I opened a future issue after merging this PR: #130 |
Python Binding Test Results (macos-latest63 tests 39 ✅ 2s ⏱️ Results for commit c2a467d. |
And also #131 |
Python Binding Test Results (ubuntu-latest)63 tests 39 ✅ 2s ⏱️ Results for commit 6a60dd0. |
Python Binding Test Results (macos-latest)63 tests 39 ✅ 1m 20s ⏱️ Results for commit 6a60dd0. |
Coverage after merging pybind into main will be
Coverage Report
|
Add python bindings
CMake configure