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

Installation on apple silicon (M1) #1573

Closed
anticdimi opened this issue Jun 14, 2021 · 37 comments
Closed

Installation on apple silicon (M1) #1573

anticdimi opened this issue Jun 14, 2021 · 37 comments
Labels

Comments

@anticdimi
Copy link

❓ Questions and Help

Hi, is there a possibility of installing this package on the Apple M1 machine? Since the installation fails for me from both pip and conda.
Thanks!

@mthrok
Copy link
Collaborator

mthrok commented Jun 14, 2021

Hi @antic11d

Thanks for the report. Our build process for M1 mac is unstable right now. Could you confirm that you can install PyTorch?

@seemethere @malfet could you take a look at it?

@anticdimi
Copy link
Author

Hi @mthrok,

Yes, I can install PyTorch. :)

@mthrok
Copy link
Collaborator

mthrok commented Jun 14, 2021

@antic11d

Thanks for the confirmation. Can you try installing torchaudio from source?
https://github.com/pytorch/audio/blob/master/CONTRIBUTING.md#install-torchaudio

It might take a while for us to fix binary build, but I think there is a good chance that you can simply build it.

@anticdimi
Copy link
Author

@mthrok

I gave it a try, this is the error I get:

BUILD_SOX=1 MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++ python setup.py develop
-- Building version 0.10.0a0+c5d0390
running develop
running egg_info
writing torchaudio.egg-info/PKG-INFO
writing dependency_links to torchaudio.egg-info/dependency_links.txt
writing requirements to torchaudio.egg-info/requires.txt
writing top-level names to torchaudio.egg-info/top_level.txt
reading manifest file 'torchaudio.egg-info/SOURCES.txt'
writing manifest file 'torchaudio.egg-info/SOURCES.txt'
running build_ext
-- The C compiler identification is AppleClang 12.0.5.12050022
-- The CXX compiler identification is AppleClang 12.0.5.12050022
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- CLANG_VERSION_STRING: Apple clang version 12.0.5 (clang-1205.0.22.9)
Target: arm64-apple-darwin20.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
-- Caffe2: Found protobuf with new-style protobuf targets.
-- Caffe2: Protobuf version 3.15.8
Updated 3 paths from the index
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/dimi/Misc/audio/build/temp.macosx-11.0-arm64-3.9
ninja: error: '/Users/dimi/miniforge3/envs/compression/lib/libopenblas.dylib', needed by 'torchaudio/csrc/_torchaudio.so', missing and no known rule to make it
Traceback (most recent call last):
File "/Users/dimi/Misc/audio/setup.py", line 60, in
setup(
File "/Users/dimi/miniforge3/envs/compression/lib/python3.9/site-packages/setuptools/init.py", line 163, in setup
return distutils.core.setup(**attrs)
File "/Users/dimi/miniforge3/envs/compression/lib/python3.9/distutils/core.py", line 148, in setup
dist.run_commands()
File "/Users/dimi/miniforge3/envs/compression/lib/python3.9/distutils/dist.py", line 966, in run_commands
self.run_command(cmd)
File "/Users/dimi/miniforge3/envs/compression/lib/python3.9/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/Users/dimi/miniforge3/envs/compression/lib/python3.9/site-packages/setuptools/command/develop.py", line 38, in run
self.install_for_development()
File "/Users/dimi/miniforge3/envs/compression/lib/python3.9/site-packages/setuptools/command/develop.py", line 140, in install_for_development
self.run_command('build_ext')
File "/Users/dimi/miniforge3/envs/compression/lib/python3.9/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/Users/dimi/miniforge3/envs/compression/lib/python3.9/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/Users/dimi/Misc/audio/build_tools/setup_helpers/extension.py", line 56, in run
super().run()
File "/Users/dimi/miniforge3/envs/compression/lib/python3.9/site-packages/setuptools/command/build_ext.py", line 87, in run
_build_ext.run(self)
File "/Users/dimi/miniforge3/envs/compression/lib/python3.9/distutils/command/build_ext.py", line 340, in run
self.build_extensions()
File "/Users/dimi/miniforge3/envs/compression/lib/python3.9/distutils/command/build_ext.py", line 449, in build_extensions
self._build_extensions_serial()
File "/Users/dimi/miniforge3/envs/compression/lib/python3.9/distutils/command/build_ext.py", line 474, in _build_extensions_serial
self.build_extension(ext)
File "/Users/dimi/Misc/audio/build_tools/setup_helpers/extension.py", line 112, in build_extension
subprocess.check_call(
File "/Users/dimi/miniforge3/envs/compression/lib/python3.9/subprocess.py", line 373, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--target', 'install']' returned non-zero exit status 1.

Any hint for a potential fix? 😊

@mthrok
Copy link
Collaborator

mthrok commented Jun 14, 2021

@antic11d

I have never seen this error , so I do not have an definitive answer but there is a similar error reported numpy/numpy#14165 (comment)
Maybe installing libopenblas and symlink is a way to go.

This might be something specific to M1 Mac

@anticdimi
Copy link
Author

@mthrok

Symlink definitely helped, but there is one more error...

FAILED: torchaudio/csrc/CMakeFiles/_torchaudio.dir/lfilter.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -DINCLUDE_KALDI -DINCLUDE_SOX -DTORCH_API_INCLUDE_EXTENSION_H -D_torchaudio_EXPORTS -I../../ -I/Users/dimi/miniforge3/envs/compression/include/python3.9 -I../../third_party/sox/../install/include -I../../third_party/kaldi/src -I../../third_party/kaldi/submodule/src -isystem /Users/dimi/miniforge3/envs/compression/lib/python3.9/site-packages/torch/include -isystem /Users/dimi/miniforge3/envs/compression/lib/python3.9/site-packages/torch/include/torch/csrc/api/include -isystem /Users/dimi/miniforge3/envs/compression/include -Wall -O3 -DNDEBUG -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -mmacosx-version-min=10.9 -fPIC -std=gnu++14 -MD -MT torchaudio/csrc/CMakeFiles/_torchaudio.dir/lfilter.cpp.o -MF torchaudio/csrc/CMakeFiles/_torchaudio.dir/lfilter.cpp.o.d -o torchaudio/csrc/CMakeFiles/_torchaudio.dir/lfilter.cpp.o -c ../../torchaudio/csrc/lfilter.cpp
../../torchaudio/csrc/lfilter.cpp:251:32: error: no member named 'CompositeImplicitAutograd' in 'c10::DispatchKey'
TORCH_LIBRARY_IMPL(torchaudio, CompositeImplicitAutograd, m) {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/dimi/miniforge3/envs/compression/lib/python3.9/site-packages/torch/include/torch/library.h:786:62: note: expanded from macro 'TORCH_LIBRARY_IMPL'
#define TORCH_LIBRARY_IMPL(ns, k, m) _TORCH_LIBRARY_IMPL(ns, k, m, C10_UID)
~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
/Users/dimi/miniforge3/envs/compression/lib/python3.9/site-packages/torch/include/torch/library.h:797:87: note: expanded from macro '_TORCH_LIBRARY_IMPL'
c10::guts::if_constexprc10::impl::dispatch_key_whitelist_check(c10::DispatchKey::k)(
~~~~~~~~~~~~~~~~~~^
../../torchaudio/csrc/lfilter.cpp:251:32: error: no member named 'CompositeImplicitAutograd' in 'c10::DispatchKey'
TORCH_LIBRARY_IMPL(torchaudio, CompositeImplicitAutograd, m) {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/dimi/miniforge3/envs/compression/lib/python3.9/site-packages/torch/include/torch/library.h:786:62: note: expanded from macro 'TORCH_LIBRARY_IMPL'
#define TORCH_LIBRARY_IMPL(ns, k, m) _TORCH_LIBRARY_IMPL(ns, k, m, C10_UID)
~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
/Users/dimi/miniforge3/envs/compression/lib/python3.9/site-packages/torch/include/torch/library.h:801:47: note: expanded from macro '_TORCH_LIBRARY_IMPL'
#ns, c10::make_optional(c10::DispatchKey::k),
~~~~~~~~~~~~~~~~~~^
2 errors generated.

Does this one maybe look familiar? :)

@mthrok
Copy link
Collaborator

mthrok commented Jun 14, 2021

Does this one maybe look familiar? :)

Somewhat yes. Are you using nightly build of PyTorch? C++-related stuff are often updated in PyTorch, so this kind of error arises when using old (or the last stable release) version of PyTorch.

@malfet
Copy link
Contributor

malfet commented Jun 14, 2021

@antic11d can you please run python -m torch.utils.collect_env and post its output here?
Also, 10.9 deployment target is too old for M1, please try building without this option.

@anticdimi
Copy link
Author

anticdimi commented Jun 14, 2021

Hi @malfet, here's the output:

Collecting environment information...
PyTorch version: 1.8.0
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A
OS: macOS 11.4 (arm64)
GCC version: Could not collect
Clang version: 12.0.5 (clang-1205.0.22.9)
CMake version: version 3.20.2
Python version: 3.9 (64-bit runtime)
Is CUDA available: False
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Versions of relevant libraries:
[pip3] numpy==1.20.3
[pip3] torch==1.8.0
[conda] numpy 1.20.3 py39h1f3b974_1 conda-forge
[conda] pytorch 1.8.0 cpu_py39hc766e51_1 conda-forge

Also, trying to build without the obsolete flag gives this error:

FAILED: torchaudio/csrc/CMakeFiles/_torchaudio.dir/lfilter.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -DINCLUDE_KALDI -DINCLUDE_SOX -DTORCH_API_INCLUDE_EXTENSION_H -D_torchaudio_EXPORTS -I../../ -I/Users/dimi/miniforge3/envs/compression/include/python3.9 -I../../third_party/sox/../install/include -I../../third_party/kaldi/src -I../../third_party/kaldi/submodule/src -isystem /Users/dimi/miniforge3/envs/compression/lib/python3.9/site-packages/torch/include -isystem /Users/dimi/miniforge3/envs/compression/lib/python3.9/site-packages/torch/include/torch/csrc/api/include -isystem /Users/dimi/miniforge3/envs/compression/include -Wall -O3 -DNDEBUG -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -mmacosx-version-min=10.9 -fPIC -std=gnu++14 -MD -MT torchaudio/csrc/CMakeFiles/_torchaudio.dir/lfilter.cpp.o -MF torchaudio/csrc/CMakeFiles/_torchaudio.dir/lfilter.cpp.o.d -o torchaudio/csrc/CMakeFiles/_torchaudio.dir/lfilter.cpp.o -c ../../torchaudio/csrc/lfilter.cpp
../../torchaudio/csrc/lfilter.cpp:251:32: error: no member named 'CompositeImplicitAutograd' in 'c10::DispatchKey'
TORCH_LIBRARY_IMPL(torchaudio, CompositeImplicitAutograd, m){~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~/Users/dimi/miniforge3/envs/compression/lib/python3.9/site-packages/torch/include/torch/library.h:786:62: note: expanded from macro 'TORCH_LIBRARY_IMPL'
#define TORCH_LIBRARY_IMPL(ns, k, m) _TORCH_LIBRARY_IMPL(ns, k, m, C10_UID) ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~/Users/dimi/miniforge3/envs/compression/lib/python3.9/site-packages/torch/include/torch/library.h:797:87: note: expanded from macro '_TORCH_LIBRARY_IMPL'
c10::guts::if_constexprc10::impl::dispatch_key_whitelist_check(c10::DispatchKey::k)( ~~~~~~~~~~~~~~~~~~^
../../torchaudio/csrc/lfilter.cpp:251:32: error: no member named 'CompositeImplicitAutograd' in 'c10::DispatchKey'
TORCH_LIBRARY_IMPL(torchaudio, CompositeImplicitAutograd, m) {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~/Users/dimi/miniforge3/envs/compression/lib/python3.9/site-packages/torch/include/torch/library.h:786:62: note: expanded from macro 'TORCH_LIBRARY_IMPL'
#define TORCH_LIBRARY_IMPL(ns, k, m) _TORCH_LIBRARY_IMPL(ns, k, m, C10_UID) ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
'/Users/dimi/miniforge3/envs/compression/lib/python3.9/site-packages/torch/include/torch/library.h:801:47: note: expanded from macro '_TORCH_LIBRARY_IMPL'
#ns, c10::make_optional(c10::DispatchKey::k), ~~~~~~~~~~~~~~~~~~^
2 errors generated.

@malfet
Copy link
Contributor

malfet commented Jun 14, 2021

@antic11d since you've installed PyTorch-1.8.0 you need to build torchauio from https://github.com/pytorch/audio/tree/release/0.8, which can be cloned by running something like:

git clone --recurse-submodules --depth 1 --branch release/0.8 https://github.com/pytorch/audio

@anticdimi
Copy link
Author

@malfet
Unfortunately, there are still errors happening...

CMake Warning at /Users/dimi/miniforge3/envs/compression/lib/python3.9/site-packages/torch/share/cmake/Caffe2/public/protobuf.cmake:88 (message):
Protobuf cannot be found. Depending on whether you are building Caffe2 or
a Caffe2 dependent library, the next warning / error will give you more
info.
Call Stack (most recent call first):
/Users/dimi/miniforge3/envs/compression/lib/python3.9/site-packages/torch/share/cmake/Caffe2/Caffe2Config.cmake:56 (include)
/Users/dimi/miniforge3/envs/compression/lib/python3.9/site-packages/torch/share/cmake/Torch/TorchConfig.cmake:68 (find_package)
CMakeLists.txt:55 (find_package)
CMake Error at /Users/dimi/miniforge3/envs/compression/lib/python3.9/site-packages/torch/share/cmake/Caffe2/Caffe2Config.cmake:58 (message):
Your installed Caffe2 version uses protobuf but the protobuf library cannot
be found. Did you accidentally remove it, or have you set the right
CMAKE_PREFIX_PATH? If you do not have protobuf, you will need to install
protobuf and set the library path accordingly.
Call Stack (most recent call first):
/Users/dimi/miniforge3/envs/compression/lib/python3.9/site-packages/torch/share/cmake/Torch/TorchConfig.cmake:68 (find_package)
CMakeLists.txt:55 (find_package)
-- Configuring incomplete, errors occurred!
See also "/Users/dimi/Misc/audio/build/temp.macosx-11.0-arm64-3.9/CMakeFiles/CMakeOutput.log".
See also "/Users/dimi/Misc/audio/build/temp.macosx-11.0-arm64-3.9/CMakeFiles/CMakeError.log".
Traceback (most recent call last):
File "/Users/dimi/Misc/audio/setup.py", line 60, in
setup(
File "/Users/dimi/miniforge3/envs/compression/lib/python3.9/site-packages/setuptools/init.py", line 163, in setup
return distutils.core.setup(**attrs)
File "/Users/dimi/miniforge3/envs/compression/lib/python3.9/distutils/core.py", line 148, in setup
dist.run_commands()
File "/Users/dimi/miniforge3/envs/compression/lib/python3.9/distutils/dist.py", line 966, in run_commands
self.run_command(cmd)
File "/Users/dimi/miniforge3/envs/compression/lib/python3.9/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/Users/dimi/miniforge3/envs/compression/lib/python3.9/site-packages/setuptools/command/develop.py", line 38, in run
self.install_for_development()
File "/Users/dimi/miniforge3/envs/compression/lib/python3.9/site-packages/setuptools/command/develop.py", line 140, in install_for_development
self.run_command('build_ext')
File "/Users/dimi/miniforge3/envs/compression/lib/python3.9/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/Users/dimi/miniforge3/envs/compression/lib/python3.9/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/Users/dimi/Misc/audio/build_tools/setup_helpers/extension.py", line 52, in run
super().run()
File "/Users/dimi/miniforge3/envs/compression/lib/python3.9/site-packages/setuptools/command/build_ext.py", line 87, in run
_build_ext.run(self)
File "/Users/dimi/miniforge3/envs/compression/lib/python3.9/distutils/command/build_ext.py", line 340, in run
self.build_extensions()
File "/Users/dimi/miniforge3/envs/compression/lib/python3.9/distutils/command/build_ext.py", line 449, in build_extensions
self._build_extensions_serial()
File "/Users/dimi/miniforge3/envs/compression/lib/python3.9/distutils/command/build_ext.py", line 474, in _build_extensions_serial
self.build_extension(ext)
File "/Users/dimi/Misc/audio/build_tools/setup_helpers/extension.py", line 96, in build_extension
subprocess.check_call(
File "/Users/dimi/miniforge3/envs/compression/lib/python3.9/subprocess.py", line 373, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '/Users/dimi/Misc/audio', '-DCMAKE_BUILD_TYPE=Release', '-DCMAKE_PREFIX_PATH=/Users/dimi/miniforge3/envs/compression/lib/python3.9/site-packages/torch/share/cmake', '-DCMAKE_INSTALL_PREFIX=/Users/dimi/Misc/audio/build/lib.macosx-11.0-arm64-3.9/torchaudio/', '-DCMAKE_VERBOSE_MAKEFILE=ON', '-DPython_INCLUDE_DIR=/Users/dimi/miniforge3/envs/compression/include/python3.9', '-DBUILD_SOX:BOOL=ON', '-DBUILD_KALDI:BOOL=ON', '-DBUILD_TRANSDUCER:BOOL=OFF', '-DBUILD_TORCHAUDIO_PYTHON_EXTENSION:BOOL=ON', '-DBUILD_LIBTORCHAUDIO:BOOL=OFF', '-GNinja']' returned non-zero exit status 1.

@suissemaxx
Copy link

@mthrok
Symlink definitely helped, but there is one more error...

Could you be so kind a quickly post how exactly you symlinked? I unfortunately can't get it working. Thanks in advance!

@anticdimi
Copy link
Author

anticdimi commented Jun 17, 2021

Hi @suissemaxx,

As far as I remember, the command I used was

ln -s /Users/dimi/miniforge3/envs/compression/lib/libopenblas.0.dylib /Users/dimi/miniforge3/envs/compression/lib/libopenblas.dylib

Where, of course, you should change the paths to your environment.

@malfet Sorry for the spam, but is there any fix for the problem I listed up there? We could really use some help, seems I am not alone. 😂

@suissemaxx
Copy link

@antic11d Thanks, Dimitrije! Appreciate your help! 👍

@malfet I second @antic11d's request for a solution. It would be superhelpful to be able to install torchaudio along pytorch et al. Thanks in advance for any help or hint you can give us.

@malfet Sorry for the spam, but is there any fix for the problem I listed up there? We could really use some help, seems I am not alone. 😂

@malfet
Copy link
Contributor

malfet commented Jun 17, 2021

As of PyTorch-1.9 releases TorchAudio builds should be available for both aarch64 and M1

Can you please try running

pip install torchaudio

And let me know whether it works for you

@anticdimi
Copy link
Author

anticdimi commented Jun 17, 2021

Hi @malfet,
Yes, it works for me!
AFAIC, this issue can be closed. Thank you!

@mthrok
Copy link
Collaborator

mthrok commented Jun 17, 2021

Thanks @malfet!

@mthrok
Copy link
Collaborator

mthrok commented Jun 17, 2021

Closing the issue. Thanks for the report @antic11d @suissemaxx

@mthrok mthrok closed this as completed Jun 17, 2021
@suissemaxx
Copy link

Closing the issue. Thanks for the report @antic11d @suissemaxx

Works for me too now! Thanks a lot! 👍

@redwankarimsony
Copy link

Thanks lot.

@rcoenen
Copy link

rcoenen commented Nov 5, 2021

this is working with PIP but not with Miniconda... which, as far as I know, is still the preferred way running Python on M1? How do we get this fixed?

@ngam
Copy link

ngam commented Nov 6, 2021

this is working with PIP but not with Miniconda... which, as far as I know, is still the preferred way running Python on M1? How do we get this fixed?

@rcoenen yes, it's frustrating... but I think I managed to make it work: check this out, https://anaconda.org/ngam/torchaudio

Let me know if you test it and something fails --- I had to suppress a few things (e.g. the intel mlk library) in the build

conda install torchaudio -c ngam

@ngam
Copy link

ngam commented Nov 6, 2021

@malfet @rcoenen

torchaudio 0.10.0 doesn't work with pip, only 0.9.1 and only when matched with torch 1.9.1 fwiw

@kju196
Copy link

kju196 commented Nov 8, 2021

@ngam Could you help to build with python 3.8?

@ngam
Copy link

ngam commented Nov 8, 2021

@ngam Could you help to build with python 3.8?

@kju196 , done! let me know if you face any errors --- i had to suppress the intel mkl library since there is no conda pakage for it for osx-arm64 (yet; may build it myself at this rate lol)

@malfet
Copy link
Contributor

malfet commented Nov 8, 2021

Thank you for the reminder. M1 torchaudio builds are not yet automated, so those kinds of mishaps are unfortunate. Will post an update when new builds will become available.

@arshinmar
Copy link

https://anaconda.org/ngam/torchaudio

thank you for this modification!

@divideconcept
Copy link

It seems the ngam torchaudio doesn't work.
Installing miniconda for osx-arm64 and then the packages with the following command:
conda install -y pytorch torchvision torchaudio -c pytorch -c conda-forge -c anaconda -c ngam
works, but then when launching python and doing a simple import torchaudio I get the following error:

Python 3.8.11 (default, Jul 29 2021, 14:57:32) 
[Clang 12.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import torchaudio
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/divide/TorchStudio/python/lib/python3.8/site-packages/torchaudio/__init__.py", line 1, in <module>
    from torchaudio import _extension  # noqa: F401
  File "/Users/divide/TorchStudio/python/lib/python3.8/site-packages/torchaudio/_extension.py", line 27, in <module>
    _init_extension()
  File "/Users/divide/TorchStudio/python/lib/python3.8/site-packages/torchaudio/_extension.py", line 21, in _init_extension
    torch.ops.load_library(path)
  File "/Users/divide/TorchStudio/python/lib/python3.8/site-packages/torch/_ops.py", line 110, in load_library
    ctypes.CDLL(path)
  File "/Users/divide/TorchStudio/python/lib/python3.8/ctypes/__init__.py", line 373, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(/Users/divide/TorchStudio/python/lib/python3.8/site-packages/torchaudio/lib/libtorchaudio.so, 0x0006): Library not loaded: @rpath/libprotobuf.29.dylib
  Referenced from: /Users/divide/TorchStudio/python/lib/python3.8/site-packages/torchaudio/lib/libtorchaudio.so
  Reason: tried: '/Users/divide/TorchStudio/python/lib/python3.8/site-packages/torchaudio/lib/../../../../libprotobuf.29.dylib' (no such file), '/Users/divide/TorchStudio/python/lib/python3.8/site-packages/torchaudio/lib/../../../../libprotobuf.29.dylib' (no such file), '/Users/divide/TorchStudio/python/lib/libprotobuf.29.dylib' (no such file), '/Users/divide/TorchStudio/python/lib/libprotobuf.29.dylib' (no such file), '/Users/divide/TorchStudio/python/lib/python3.8/lib-dynload/../../libprotobuf.29.dylib' (no such file), '/Users/divide/TorchStudio/python/lib/libprotobuf.29.dylib' (no such file), '/Users/divide/TorchStudio/python/bin/../lib/libprotobuf.29.dylib' (no such file), '/usr/local/lib/libprotobuf.29.dylib' (no such file), '/usr/lib/libprotobuf.29.dylib' (no such file)

@divideconcept
Copy link

divideconcept commented Mar 2, 2022

NB: what I have in my python/lib folder is libprotobuf.30.dylib.
I suppose the issue is making libtorchaudio.so dependent on a specific version of libprotobuf instead of the generic libprotobuf.dylib shortcut.

@mthrok
Copy link
Collaborator

mthrok commented Mar 2, 2022

@divideconcept ngam is not our release so you need to check with the ngam package publisher. It seems that when they built torchaudio, some extra dependencies were introduced, which suggests that it was not build on the PyTorch you have in your env.

@divideconcept
Copy link

@mthrok do you plan to officially have an osx-arm64 build of torchaudio for conda ?
Because as-is, the official and recommended way to install PyTorch on an M1 mac is still:
conda install pytorch torchvision torchaudio -c pytorch
but this doesn't work because of lack of conda torchaudio package for osx-arm64.

@divideconcept
Copy link

PS: installing pytorch+torchvision via conda and then installing torchaudio via pip doesn't work either

conda install pytorch torchvision -c pytorch
pip install torchaudio

Then when I run python and try to import torchaudio I get the following error:

Python 3.8.11 (default, Jul 29 2021, 14:57:32) 
[Clang 12.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import torchaudio
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/divide/TorchStudio/python/lib/python3.8/site-packages/torchaudio/__init__.py", line 1, in <module>
    from torchaudio import _extension  # noqa: F401
  File "/Users/divide/TorchStudio/python/lib/python3.8/site-packages/torchaudio/_extension.py", line 27, in <module>
    _init_extension()
  File "/Users/divide/TorchStudio/python/lib/python3.8/site-packages/torchaudio/_extension.py", line 21, in _init_extension
    torch.ops.load_library(path)
  File "/Users/divide/TorchStudio/python/lib/python3.8/site-packages/torch/_ops.py", line 110, in load_library
    ctypes.CDLL(path)
  File "/Users/divide/TorchStudio/python/lib/python3.8/ctypes/__init__.py", line 373, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(/Users/divide/TorchStudio/python/lib/python3.8/site-packages/torchaudio/lib/libtorchaudio.so, 0x0006): Symbol not found: __ZN2at8internal13_parallel_runExxxRKNSt3__18functionIFvxxmEEE
  Referenced from: /Users/divide/TorchStudio/python/lib/python3.8/site-packages/torchaudio/lib/libtorchaudio.so
  Expected in: /Users/divide/TorchStudio/python/lib/python3.8/site-packages/torch/lib/libtorch_cpu.dylib

@mthrok
Copy link
Collaborator

mthrok commented Mar 2, 2022

@divideconcept

IIRC, Only Python 3.9 is supported by PyTorch on M1 mac. And the last time I checked miniforge 3 is the only Anaconda variant distribution that work natively on M1 mac.

UPDATE Now Anaconda has native M1 distribution: https://www.anaconda.com/products/distribution#Downloads

Installing Miniforge3 and simply pip install torch torchaudio should work.

$ pip install torch torchaudio
Collecting torch
  Downloading torch-1.10.2-cp39-none-macosx_11_0_arm64.whl (44.6 MB)
     |████████████████████████████████| 44.6 MB 1.5 MB/s
  Downloading torchaudio-0.10.2-cp39-cp39-macosx_11_0_arm64.whl (2.2 MB)
     |████████████████████████████████| 2.2 MB 2.0 MB/s

You need to make sure that the matching package is installed. cp39-none-macosx_11_0_arm64.

@ngam
Copy link

ngam commented Mar 2, 2022

@divideconcept sorry. I haven't updated that in a while. I could look at it again if you want me to, but I personally have started using the pypi version as @mthrok points out.

I can potentially rebuild torchaudio if you really need it --- we haven't had luck building it in conda-forge yet (you're welcome to try: conda-forge/staged-recipes)

@divideconcept
Copy link

@ngam Thanks but don't worry, I'll just use the x86_64 version for now, until the PyTorch team can provide an official arm conda package.

@nkuzyz
Copy link

nkuzyz commented Jul 26, 2022

conda install pytorch torchvision -c pytorch
pip install torchaudio
I use this command and this problem have been solved.
Thanks

@mthrok mthrok added the triaged label Jul 29, 2022
mthrok pushed a commit to mthrok/audio that referenced this issue Dec 13, 2022
@luohao123
Copy link

orchaudio/lib/libtorchaudio_sox.so, 0x0006): Library not loaded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests