josevalim
(José Valim)
October 2, 2022, 6:13pm
1
Hi everyone, congratulations on the Apple Silicon and MPS support on Torch v1.12!
Are there any plans to also provide precompiled LibTorch for Apple Silicon on the Installation page ? We are using the C++ version of the libraries and for now the only way to automate installation is by downloading the wheel file and extracting the precompiled artifacts.
However, given the precompiled artifacts are already built for wheels, maybe they could also be made available on the website?
Thank you!
1 Like
dfalbel
(Daniel Falbel)
October 3, 2022, 8:17pm
2
Oi José
It would be nice to have pre-built binaries on the official installation page!
FWIW I have set up a small repository with M1 builds here: GitHub - mlverse/libtorch-mac-m1: LibTorch builds for the M1 Macs .
I will use builds in this repository for the R bindings while we don’t have official builds available.
2 Likes
josevalim
(José Valim)
October 3, 2022, 11:33pm
3
Cool, obrigado!
Any plans to build 1.12.1 as well?
dfalbel
(Daniel Falbel)
October 3, 2022, 11:57pm
4
1 Like
josevalim
(José Valim)
October 4, 2022, 12:03pm
5
Thanks! The wheel version also included libomp (or so it seems), but I have to install it manually with the precompiled version. Do you think this is something worth including too?
dfalbel
(Daniel Falbel)
October 4, 2022, 1:23pm
6
Yes, it seems they manually do this in setup.py:
# Copy libiomp5.dylib inside the wheel package on OS X
def _embed_libiomp(self):
lib_dir = os.path.join(self.build_lib, 'torch', 'lib')
libtorch_cpu_path = os.path.join(lib_dir, 'libtorch_cpu.dylib')
if not os.path.exists(libtorch_cpu_path):
return
# Parse libtorch_cpu load commands
otool_cmds = subprocess.check_output(['otool', '-l', libtorch_cpu_path]).decode('utf-8').split('\n')
rpaths, libs = [], []
for idx, line in enumerate(otool_cmds):
if line.strip() == 'cmd LC_LOAD_DYLIB':
lib_name = otool_cmds[idx + 2].strip()
assert lib_name.startswith('name ')
libs.append(lib_name.split(' ', 1)[1].rsplit('(', 1)[0][:-1])
if line.strip() == 'cmd LC_RPATH':
rpath = otool_cmds[idx + 2].strip()
assert rpath.startswith('path ')
rpaths.append(rpath.split(' ', 1)[1].rsplit('(', 1)[0][:-1])
This file has been truncated. show original
We can probably do the same in our builds.
dfalbel
(Daniel Falbel)
October 4, 2022, 1:38pm
7
Actually it seems it only embeds openMP in the x86_64 builds, because in this case it’s embedding libiomp5.dylib (the Intel OpenMP version).
I think we could still copy libomp.dylib to the lib directory though, but not sure what kind of problems that could cause.
josevalim
(José Valim)
October 4, 2022, 2:21pm
8
Interesting. I can find “libiomp5.dylib” in the Apple arm64 wheel too, so if this is straightforward to add, it would be very helpful.
dfalbel
(Daniel Falbel)
October 4, 2022, 5:01pm
9
Makes sense! I just added a copy of libomp.dylib to the archive.
josevalim
(José Valim)
October 4, 2022, 5:37pm
10
Excellent, it works. Thank you!
1 Like