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-rs does not run on m1 mac #629

Closed
antimora opened this issue Feb 27, 2023 · 12 comments · Fixed by #661
Closed

tch-rs does not run on m1 mac #629

antimora opened this issue Feb 27, 2023 · 12 comments · Fixed by #661

Comments

@antimora
Copy link

tch-rs does not run on m1 MacOS. To fix the problem I followed these steps adopted from https://github.com/ssoudan/tch-m1.

  1. pip3 install torch
  2. export paths:
export LIBTORCH=$(python3 -c 'import torch; from pathlib import Path; print(Path(torch.__file__).parent)')
export DYLD_LIBRARY_PATH=${LIBTORCH}/lib
@chrisvander
Copy link

What's the error message you're running into? How did you install torch?

I ended up symlinking the torch directory into the project directory.

@chrisvander
Copy link

Could also check out this repository, pretty much exactly what I did and seems to be a fairly minimal environment setup.

@antimora
Copy link
Author

@chrisvander builds ok but when I tried running I got some linking errors. I think tch-rs downloads for mac but the version is not correct. I think it downloads for x86 but it needs ARM64 version which is provided by python3's pytorch.

I used the same solution as your suggested repository.

This is the script I created to help users to overcome. Unfortunately there is no way to set the variables by build.rs script.

Instead I updated our build.rs to error out and let the users know to run the script.

Also I updated our Cargo.toml to skip download for mac users.

Hope this temporary workaround helps others too. I looking forward when this will be fixed in tch-rs.

@kornelski
Copy link

The Mac download at https://download.pytorch.org/libtorch/cpu/libtorch-macos-1.13.0.zip contains only the Intel version.

Maybe disable downloads on aarch64 and build from source instead?

@chrisvander
Copy link

I made an environment in Conda and installed it that way. That version is aarch64.

@LaurentMazare
Copy link
Owner

Thanks, I just made some changes to the torch-sys build.rs to avoid the download for apple aarch64 and point to this issue + display the pip install commands from the first post, hopefully this will make it clearer to end users how to get this to work until pytorch folks provide pre-built aarch64 binaries.
(also I don't have an actual way to test the changes but hopefully they were straightforward enough)

@antimora
Copy link
Author

@LaurentMazare I tested your changes on Mac and I can confirm it panics as intended:

   Compiling torch-sys v0.11.0 (/Users/user/Projects/tch-rs/torch-sys)
error: failed to run custom build command for `torch-sys v0.11.0 (/Users/user/Projects/tch-rs/torch-sys)`

Caused by:
  process didn't exit successfully: `/Users/user/Projects/tch-rs/target/debug/build/torch-sys-04e74d17bc8358a0/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=TORCH_CUDA_VERSION
  cargo:rerun-if-env-changed=LIBTORCH

  --- stderr
  thread 'main' panicked at 'Pre-built version of libtorch for apple silicon are not available.
                              You can install torch manually following the indications from https://github.com/LaurentMazare/tch-rs/issues/629
                              pip3 install torch==2.0.0

                              Then update the following environment variables:
                              export LIBTORCH=$(python3 -c 'import torch; from pathlib import Path; print(Path(torch.__file__).parent)')
                              export DYLD_LIBRARY_PATH=${LIBTORCH}/lib
                              ', torch-sys/build.rs:123:29
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[tch-rs]$ uname -a
Darwin MacBook-Pro.local 22.3.0 Darwin Kernel Version 22.3.0: 
Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 arm64
[tch-rs]$ 


@LaurentMazare
Copy link
Owner

Great thanks a lot @antimora

@antimora
Copy link
Author

Linking a Torch's issue ticket here: pytorch/pytorch#96046 Someone requested "Add arm64 builds for libtorch on MacOS with mps support"

@patientplatypus6
Copy link

Thanks for the python script antimora - that's what fixed the problem for me!

@anmolduainter
Copy link

I am getting error
symbol not found in flat namespace '__ZN3c1019UndefinedTensorImpl10_singletonE'

@xsa-dev
Copy link

xsa-dev commented Nov 18, 2023

I am getting error symbol not found in flat namespace '__ZN3c1019UndefinedTensorImpl10_singletonE'

i got:

dyld[49777]: symbol not found in flat namespace '__ZN3c1019UndefinedTensorImpl10_singletonE'

Indeed, I am experiencing a similar issue. Have you attempted to address the problems arising from colleagues' earlier writing?

Solved by this: #629 (comment)

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

Successfully merging a pull request may close this issue.

7 participants