k2-fsa / k2

FSA/FST algorithms, differentiable, with PyTorch compatibility.
https://k2-fsa.github.io/k2
Apache License 2.0
1.1k stars 214 forks source link

Possible to install k2 in MacOS Apple Silicon #1240

Closed nabil6391 closed 1 year ago

nabil6391 commented 1 year ago

Thanks for the k2-icefall package, I usually use colab to run my tests on k2. However thought of installing k2-icefall in my m2 macbook. However looks like there are no pre-compiled cpu for arm in macos.

Requesting guidance on K2's compatibility and any potential workarounds for Apple Silicon users.

csukuangfj commented 1 year ago

@nabil6391 Please have a look at https://k2-fsa.github.io/k2/cpu.html

We just supported it. Could you have a test?

csukuangfj commented 1 year ago
Screenshot 2023-08-23 at 23 07 13
nabil6391 commented 1 year ago

This is the error I get when installing ! pip install https://huggingface.co/csukuangfj/k2/resolve/main/macos/k2-1.24.3.dev20230823+cpu.torch2.0.1-cp310-cp310-macosx_11_0_arm64.whl

Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/miniconda/base/envs/kaldi/lib/python3.10/runpy.py", line 187, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/kaldi/lib/python3.10/runpy.py", line 110, in _get_module_details
    __import__(pkg_name)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/kaldi/lib/python3.10/site-packages/k2/__init__.py", line 23, in <module>
    from _k2 import DeterminizeWeightPushingType
ImportError: dlopen(/opt/homebrew/Caskroom/miniconda/base/envs/kaldi/lib/python3.10/site-packages/_k2.cpython-310-darwin.so, 0x0002): tried: '/opt/homebrew/Caskroom/miniconda/base/envs/kaldi/lib/python3.10/site-packages/_k2.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/Caskroom/miniconda/base/envs/kaldi/lib/python3.10/site-packages/_k2.cpython-310-darwin.so' (no such file), '/opt/homebrew/Caskroom/miniconda/base/envs/kaldi/lib/python3.10/site-packages/_k2.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))
csukuangfj commented 1 year ago

Is it an installation error or a runtime error?

csukuangfj commented 1 year ago

I think I know the issue now. Please wait for a moment; I am rebuilding a wheel for you.

csukuangfj commented 1 year ago

Turns out cibuildwheel does not support installing an arm64 wheel for macos in github actions. Sorry that we cannot provide pre-compiled wheels for macos M1.

Please use

git clone https://github.com/k2-fsa/k2
cd k2
python3 setup.py install

to install k2 from source.

nabil6391 commented 1 year ago

Was able to install k2 from source. Thanks

csukuangfj commented 4 months ago

@nabil6391

Finally, we provide pre-built wheels for macOS M1 starting from torch 2.3.0

Please see

https://k2-fsa.github.io/k2/cpu.html

Screenshot 2024-04-25 at 11 16 51