-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Using torchvision C++ API without installing python #2692
Comments
I managed to build the so with the hack: https://github.com/pytorch/vision/blob/master/torchvision/csrc/cuda/vision_cuda.h#L2 change this line to include torch/torch.h. Same with CPU. Also disable the unncessary pybind API call.
However I don't feel like this is the right way to do. Is there any side effect if I disabled all python access? |
@mthrok has been looking into something like that for torchaudio and torchtext, maybe his findings could apply for torchvision as well? We might need to move away from |
I am working on gathering requirements and specing out cmake build for torchtext and torchaudio, which includes both Python extension module and C++ library. I thought torchvision has already have cmake build so did not look into it but if it's something beneficial to torchvision, I can include that one too. So as to build C++ library, the source code cannot use things that are related to Python. This includes PyBind11 and The way I am thinking of cmake build is some thing like the following;
Here is an example how Python extension can be build with |
We already solved the vision/torchvision/csrc/vision.cpp Line 2 in 15848ed
<Python.h> for some magical reasons such as vision/torchvision/csrc/vision.cpp Lines 19 to 35 in 15848ed
Due to those two points, our CMake file currently depends on Python Line 33 in 15848ed
|
Yeah, I think if they can separate registration (binding) and implementation, then things could work nicely. from the doc I am working (internal only) |
At a glance it looks like you can remove Python2 portion at least. |
@mthrok do you have any plan to fix this? Or can I presume it is okay to temporaily applied the fix I mentioned and will have no side effects? |
Could it be a CMake option like USE_PYTHON? When it is disabled, we skip including |
I do not have a plan to fix this yet. My work is still proposal phase, and torchvision is more complicated than torchtext or torchaudio. However if @fmassa's comment
is correct, then I think changing Searching |
That's what I am working on, but in the case of torchvision, |
Good catch. This is actually an artifact of testing that should be changed -- we wrapped the C++ models in Python so that we could compare the outputs of the model. But torchvision library itself only uses |
@stu1130 This is still currently in progress. There are a few PRs that try to minimize the use of |
Hi! Thanks very much for this project! We built a port of torchvision for the R language: https://github.com/mlverse/torchvision and now we want to work on supporting the C++ operations. For that, it would be great if we didn't require users to install Python in order to use our package. Would you consider a PR avoiding the Python requirement in the builds? I can successfully build without Python by simply removing the So my approach would be to have a CMake variable, like vision/torchvision/csrc/vision.cpp Lines 3 to 5 in 68f511e
And other calls like: vision/torchvision/csrc/io/image/image.cpp Lines 1 to 5 in 68f511e
Does that look reasonable? I am no CMake expert, but that seems to be feasible without introducing any breaking change and leaving the default behavior as is. |
Hi @dfalbel , Thanks for the proposal! We can accept such a proposal in the CMakeLists (we can actually by default set This is something that we would like to get fixed for a while now, see #3965 But ideally, we would just remove In any case, we should remove the |
❓ Questions and Help
I have followed the document and built the libtorchvsion.dylib but when I ran
otool -L libtorchvsion.dylib
it showedIs there a way to get rid of
libpython3.8.dylib
, I think it is required for using python custom operators and we will only use C++.The text was updated successfully, but these errors were encountered: