ankane / torch.rb

Deep learning for Ruby, powered by LibTorch
Other
704 stars 30 forks source link

torch-rb BuildError #35

Closed elbowdonkey closed 1 year ago

elbowdonkey commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

ankane commented 1 year ago

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

Eric-Guo commented 10 months ago

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