LaurentMazare / tch-rs

Rust bindings for the C++ api of PyTorch.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rebuild for torch-sys is triggered everytime

doofin opened this issue · comments

Hi, I have exported LD_LIBRARY_PATH and LIBTORCH as required and have a working tch-rs with cuda . However everytime I tried to run tests, torch-sys is rebuild ("Compiling torch-sys v0.10.0") which takes long time.

However,It works fine on my other pc without setting env vars for LIBTORCH with only cpu

maybe relevant to this PR : #184

Thanks for reporting this, I have to say that I observed some similar behavior where rebuilding is triggered more often than what seems necessary and it's a bit of a pain as it's quite slow to build. It might be worth digging into this, I'm not really sure where this would come from, LIBTORCH is marked as cargo:rerun-if-env-changed so that should only trigger if the value of the environment variable actually changes (documentation) but maybe there is some issue around this.

This was happening to me and I tracked it down to rust-analyzer. I believe what was happening is that rust-analyzer was calling cargo commands without the environment variables I had set in my shell and invalidating the cache. I was able to fix this by adding the environment variables to VSCode settings (where rust-analyzer is running as an extension):

"rust-analyzer.cargo.extraEnv": {
    "LIBTORCH": "/root/miniconda/lib/python3.10/site-packages/torch",
    "LD_LIBRARY_PATH": "/root/miniconda/lib/python3.10/site-packages/torch/lib",
    "LIBTORCH_CXX11_ABI": "0"
}

I'm not sure if you are using rust-analysizer or if this is what was causing your issues, but hopefully it's helpful.

An entry in the FAQ has been added so that it's easier to find this issue if needed, so closing this for now.