Skip to content

Add option to build the library using the python's torch installation #3004

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bmanga
Copy link
Contributor

@bmanga bmanga commented Nov 14, 2020

This adds an option to use python's torch installation, which is usually easier to obtain (and very likely to be available).

I'm undecided as to whether we should be adding this logic also to the Config file (so users can also use the option when using the library), but that can be added later.

@facebook-github-bot
Copy link

Hi @bmanga!

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file.

In order for us to review and merge your code, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@vfdev-5
Copy link
Collaborator

vfdev-5 commented Nov 16, 2020

@bmanga thanks for the PR ! Yes, this can simplify the setup, however I'm not sure the following

which is usually easier to obtain (and very likely to be available)

In my opinion, if the use-case requires torchvision C++ frontend, it is unlikely to have pytorch installed as python library... probably due to limited resources like on embedded systems. What do you think ?

@bmanga
Copy link
Contributor Author

bmanga commented Nov 16, 2020

@vfdev-5

In my opinion, if the use-case requires torchvision C++ frontend, it is unlikely to have pytorch installed as python library... probably due to limited resources like on embedded systems. What do you think ?

The code added is just for building the library, it's not added to the Config file and so not (yet) exposed to the users of the library.
I don't think C++ torchvision can be deployed in environments so constrained as to not have a python installation, and if that is the case I would think that most likely the library is cross-compiled (on a system where python is available).

But this PR is mostly for development purposes. I would think that the most likely scenario where the c++ torchvision lib is used is to add the ops required to run torchscript models. And these models are probably created using the python frontend, which means that torch is available in python.
Even if that is not the case, I find it easier to install the latest torch via pip rather than going to fetch the archive from somewhere and add the path to CMAKE_PREFIX_PATH.

Of course, all of this is completely optional :)

@fmassa
Copy link
Member

fmassa commented Nov 16, 2020

Hi @bmanga

Thanks for the PR!

Just chiming in to bring a few extra points:

I don't think C++ torchvision can be deployed in environments so constrained as to not have a python installation

With #2897 (and after we refactor a few things), torchvision will be able to run on android devices.
For now, it has a separate CMakeLists, but maybe in the future it would be able to let it use our own CMakeLists.txt from main torchvision.

Additionally, in #3011 I mention that it would be great to remove all Python includes from the torchvision C++ dependency, but for now for some reason Windows requires it, but we should find a way of fixing this.

@bmanga
Copy link
Contributor Author

bmanga commented Nov 16, 2020

Hi @fmassa :)

With #2897 (and after we refactor a few things), torchvision will be able to run on android devices.

I would say that falls under the second part of my argument: You won't build torchvision on android, just deploy there.

Additionally, in #3011 I mention that it would be great to remove all Python includes from the torchvision C++ dependency, but for now for some reason Windows requires it, but we should find a way of fixing this.

I would love to see that 😁, but this PR doesn't introduce a dependency of the binary on python. It's just a build dependency.
It's essentially meant to exploit pip as a package manager for C++.

I am not strongly pushing for this, I just think it's a nice convenience over using

export TORCH_PATH=$(dirname $(python -c "import torch; print(torch.__file__)"))
cmake .. -DTorch_DIR=$TORCH_PATH/share/cmake/Torch [...]

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

1 similar comment
@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants