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

tch::utils unavailable / how to detect MPS? #644

Closed
GaryBoone opened this issue Mar 14, 2023 · 4 comments
Closed

tch::utils unavailable / how to detect MPS? #644

GaryBoone opened this issue Mar 14, 2023 · 4 comments

Comments

@GaryBoone
Copy link
Contributor

I've installed tch-rs on an M1 Mac using ssoudan's repo.

Adding this line to the main.rs there:

println!("has_mps: {}", tch::utils::has_mps());

causes a compilation error:

    println!("has_mps: {}", tch::utils::has_mps());
                                 ^^^^^ could not find `utils` in `tch`

That line is also present in examples/basics.rs in the tch-rs repo.

Is tch::utils intended to be public? It appears so, as it's marked:

pub use wrappers::utils;

in src/lib.rs.

If not, how do we detect if MPS is available? The Python way is to use torch.backends.mps.is_available(). However, backends isn't exposed in tch either, even though it's a 1.13.0 feature: MPS Backend.

@LaurentMazare
Copy link
Owner

Are you using the github version or some crates.io one? Maybe you should try using the github tip if that's not already the case.

@GaryBoone
Copy link
Contributor Author

After finding this comment, I followed the directions as shown at ssoudan/tch-m1. Looking at the Cargo.toml there, it looks like it installs tip:

[dependencies]
tch = { git = "https://github.com/LaurentMazare/tch-rs", default-features = false }

@GaryBoone
Copy link
Contributor Author

GaryBoone commented Mar 14, 2023

Two more datapoints:

  1. On an x86 mac :
$ git clone https://github.com/LaurentMazare/tch-rs
$ cd tch-rs
$ cargo run --example basics

compiles and runs like:

has_mps: false
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Torch("Cannot query cuDNN version without ATen_cuda library.

...which shows that tch::utils::has_mps() was found at compilation and worked fine.

[The unhandled errors for tch::utils::version_cudnn() (and tch::utils::version_cudart()) may be just a demo code issue.]

  1. On an arm64 (M1) mac:
$ git clone https://github.com/LaurentMazare/tch-rs
$ cd tch-rs
$ cargo run --example basics

fails to build with a long string of errors that includes:

 = note: ld: warning: ignoring file /Users/.../tch-rs/target/debug/build/torch-sys-a977f0f5d9f9425f/out/libtorch/libtorch/lib/libtorch.dylib, building for macOS-arm64 but attempting to
 link with file built for macOS-x86_64

...replicating tch-rs issue #488.

ssoudan's method in repo is just a way to obtain a version of libtorch that compiles on the M1 macOS-arm64 and control the versions. So it doesn't seem like this issue should be filed against that repo.

The above may be telling us that there's something happening in the way utils is exposed that's varying by installation method/architecture. Ideally, there would be a way to detect which devices (CUDA/MPS/None) are available.

@LaurentMazare
Copy link
Owner

Closing this as version 0.11.0 of this crate was released which should include the utils module.

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

2 participants