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

question: compiling tch-rs with static torch lib #647

Open
antimora opened this issue Mar 15, 2023 · 4 comments
Open

question: compiling tch-rs with static torch lib #647

antimora opened this issue Mar 15, 2023 · 4 comments

Comments

@antimora
Copy link

tch-rs uses the torch's shared library. Is it possible to build tch-rs with static library? I have a use case where I want to bundle torch (WASM and iOS). It would

@antimora antimora changed the title Compiling tch-rs with static torch lib question: compiling tch-rs with static torch lib Mar 18, 2023
@LaurentMazare
Copy link
Owner

This would indeed be a nice thing to support, a first limitation is getting a statically linked version of libtorch, using this I feel that it wouldn't be very difficult to tweak the build script (and would also probably remove some hacks required by the shared library setup).
Interestingly https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-static-with-deps-2.0.0%2Bcpu.zip does exist (I just replaced the shared in the original URL with static) but this doesn't seem to contain the libtorch.a file that I would have expected and instead have the shared object version.

@LaurentMazare
Copy link
Owner

I've looked at this into more details and put up #712 that has some support for static linking. It works fine on linux cpu version - I'm not sure it would help on wasm though as the libtorch library is in c++ but maybe there is some emscripten magic that can be applied there.

@finnkauski
Copy link

@antimora did you end up trying to compile it statically and run it on WASM?

@antimora
Copy link
Author

@finnkauski no, I didn't. I am using Burn framework and now it supports WebGPU and Candle CPU backend which compilable to WASM . Here is an example I created https://github.com/tracel-ai/burn/tree/main/examples/image-classification-web

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

No branches or pull requests

3 participants