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

torch-rb BuildError #35

Closed
elbowdonkey opened this issue Sep 23, 2022 · 4 comments
Closed

torch-rb BuildError #35

elbowdonkey opened this issue Sep 23, 2022 · 4 comments

Comments

@elbowdonkey
Copy link

When trying to install torch-rb on a Mac M1 Pro, I get:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

Looking at the mkmf.log, something that stands out to me is:

ld: library not found for -ltorch
clang: error: linker command failed with exit code 1 (use -v to see invocation)

System info:

macOS 12.6
Macbook Pro, M1 Pro 32MB

I've tried installing libtorch using brew. After seeing the extension fail to build, I noticed that the brew version of libtorch for M1 is 1.12.1.

I uninstalled the brew version in favor of using pip install libtorch - that installs 1.2.0.1, which is quite old. Still. when trying to install the torch-rb gem, I get the same error in the mkmf.log.

Given the age of the pip installed libtorch, I removed it and reinstalled it via brew.

When running brew info libtorch I noticed that python@3.10 was listed as a build dependency, and that it wasn't satisfied:

==> Dependencies
Build: cmake ✔, python@3.10 ✘
Required: eigen ✔, libyaml ✔, protobuf ✔, pybind11 ✔, libomp ✔

So now I'm looking at python.

I installed python 3.10.0 through pyenv and verified its working. brew info libtorch doesn't show the dependency as being satisfied still, which I suspect is because brew is assuming I did brew install python@3.10.

I may try installing python@3.10 through brew just to see if it helps, but in the meantime, am I missing something important here?

mkmf.log

@elbowdonkey
Copy link
Author

I tried the following and was able to build the gem without errors:

bundle config build.torch-rb --with-torch-dir=/opt/homebrew/Cellar/libtorch/1.12.1
bundle install

My Gemfile:

source "https://rubygems.org"

gem "torch-rb"

@elbowdonkey
Copy link
Author

I just realized that the README.md already describes how to solve my issue and I just didn't see it. Closing.

@ankane
Copy link
Owner

ankane commented Sep 24, 2022

Glad you found it. Just pushed a change to automatically detect so no additional config is needed.

@Eric-Guo
Copy link
Contributor

In issue #48 I found the current brew renaming 'libtorch' to pytorch, so there still needs further tuning.

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