whisper.cpp: Not working on MacOS (ARM)

Hi, I’ve been trying to get this to work a few times, but it always fails with an illegal hardware instruction error.

E.g. for ./main -m models/ggml-small.bin -f samples/jfk.wav I get the following output:

whisper_model_load: loading model from 'models/ggml-small.bin'
whisper_model_load: n_vocab       = 51865
whisper_model_load: n_audio_ctx   = 1500
whisper_model_load: n_audio_state = 768
whisper_model_load: n_audio_head  = 12
whisper_model_load: n_audio_layer = 12
whisper_model_load: n_text_ctx    = 448
whisper_model_load: n_text_state  = 768
whisper_model_load: n_text_head   = 12
whisper_model_load: n_text_layer  = 12
whisper_model_load: n_mels        = 80
whisper_model_load: f16           = 1
whisper_model_load: type          = 3
whisper_model_load: mem_required  = 1048.00 MB
whisper_model_load: adding 1608 extra tokens
whisper_model_load: ggml ctx size = 533.05 MB
fish: Job 1, './main -m models/ggml-small.b...' terminated by signal SIGILL (Illegal instruction)

I’ve tried other models as well, but the result is always the same.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 23 (12 by maintainers)

Commits related to this issue

Most upvoted comments

Because the uname contains two architectures. We need to use arch command to force it to use arm64 instead of x86_64.

$ file `which uname`
/usr/bin/uname: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64e:Mach-O 64-bit executable arm64e]
/usr/bin/uname (for architecture x86_64):	Mach-O 64-bit executable x86_64
/usr/bin/uname (for architecture arm64e):	Mach-O 64-bit executable arm64e
$ uname -mps
Darwin x86_64 i386
$ arch -arm64 uname -mps
Darwin arm64 arm

So all you need to do to compile an arm64 executable is to add arch -arm64 in front of make like this:

$ make -j8
$ file ./main
main: Mach-O 64-bit executable x86_64
$ arch -arm64 make -j8
$ file ./main
main: Mach-O 64-bit executable arm64

May this help you guys.

@xyx361100238 Yes, but it was too slow before fixing my terminal. So you probably need to fix this first (assuming you also have an ARM Mac).

So make sure you don’t have rosetta enabled (check box not ticked): image

And if that’s not it you can check if you have a m1 compatible homebrew. If you have a m1 compatible homebrew, the folder /opt/homebrew/ should exist. Otherwise uninstall homebrew and reinstall it. Be aware that this means you will also have to reinstall all your homebrew packages, but imo it’s worth it. Many things are faster now.

That’s unexpected.

In the meantime, if you just want to give whisper.cpp a try, you should be able to compile it properly like this:

cc  -O3 -std=c11   -Wall -Wextra -Wno-unused-parameter -Wno-unused-function -pthread -DGGML_USE_ACCELERATE   -c ggml.c
c++ -O3 -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-unused-function -pthread -c whisper.cpp
c++ -O3 -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-unused-function -pthread main.cpp whisper.o ggml.o -o main  -framework Accelerate

This is what I use on my MacBook M1 Pro and it works.

If you figure out why uname reports this as x86_64 please let me know, so I can somehow update the Makefile to support M1 Max.

Interesting… uname -mps gives me:

Darwin x86_64 i386

@undefdev item 选项不能点Rosetta 打开,否则第二张图就U _namep 显示为x86,m2 电脑正常显示应为arm ,执行make clean 在执行make 编辑即可成功

Snipaste_2023-03-13_03-10-04

make clean make

<img width=“253” alt=“Snipaste_2023-03-13_03-10-04” src=“https://user-images.githubusercontent.com/23565695/224567292-446342b0-b1c6-4acb-ae08-Snipaste_2023-03-13_03-11-00dd04ada0bd79.png”>

I was use whisper in macbook pro same system set:Darwin i386 x86_64 It works in ./main -m models/ggml-base.en.bin -f samples/jfk.wav But not work in ./stream -m models/ggml-base.en.bin -t 8 --step 500 --length 5000 Tips:

adeMacBook-Pro:whisper.cpp-master a$ ./stream -m models/ggml-base.en.bin -t 8 --step 500 --length 5000 audio_sdl_init: found 2 capture devices: audio_sdl_init: - Capture device #0: ‘Built-in Microphone’ audio_sdl_init: - Capture device #1: ‘BlackHole 2ch’ audio_sdl_init: attempt to open default capture device … audio_sdl_init: obtained spec for input device (SDL Id = 2): audio_sdl_init: - sample rate: 16000 audio_sdl_init: - format: 33056 (required: 33056) audio_sdl_init: - channels: 1 (required: 1) audio_sdl_init: - samples per frame: 1024 whisper_model_load: loading model from ‘models/ggml-base.en.bin’ whisper_model_load: n_vocab = 51864 whisper_model_load: n_audio_ctx = 1500 whisper_model_load: n_audio_state = 512 whisper_model_load: n_audio_head = 8 whisper_model_load: n_audio_layer = 6 whisper_model_load: n_text_ctx = 448 whisper_model_load: n_text_state = 512 whisper_model_load: n_text_head = 8 whisper_model_load: n_text_layer = 6 whisper_model_load: n_mels = 80 whisper_model_load: f16 = 1 whisper_model_load: type = 2 whisper_model_load: mem_required = 377.00 MB whisper_model_load: adding 1607 extra tokens whisper_model_load: ggml ctx size = 163.43 MB whisper_model_load: memory size = 22.83 MB whisper_model_load: model size = 140.54 MB main: processing 8000 samples (step = 0.5 sec / len = 5.0 sec), 8 threads, lang = en, task = transcribe, timestamps = 0 …

no content!

@undefdev Thanks for the investigation! I like the proposed change and have merged it into upstream.