tazz4843/whisper-rs

illegal hardware instruction

Closed this issue · 2 comments

Getting a illegal hardware instruction when running the readme example code inside main. Is there something I should be passing or environmental variable to toggle these instructions?

❯ RUSTFLAGS="-Clink-args=-lstdc++" cargo run
   Compiling whisper-rs-test v0.1.0 (/mnt/900/builds/whisper-rs-test)
    Finished dev [unoptimized + debuginfo] target(s) in 0.54s
     Running `target/debug/whisper-rs-test`
whisper_model_load: loading model from './models/ggml-small.en.bin'
whisper_model_load: n_vocab       = 51864
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 1607 extra tokens
whisper_model_load: ggml ctx size = 533.05 MB
[1]    9381 illegal hardware instruction (core dumped)  RUSTFLAGS="-Clink-args=-lstdc++" cargo run

coredump

           PID: 9381 (whisper-rs-test)
           UID: 1000 (rockerboo)
           GID: 1000 (rockerboo)
        Signal: 4 (ILL)
     Timestamp: Tue 2022-12-06 22:02:26 EST (4min 44s ago)
  Command Line: target/debug/whisper-rs-test
    Executable: /mnt/900/builds/whisper-rs-test/target/debug/whisper-rs-test
 Control Group: /user.slice/user-1000.slice/session-2.scope
          Unit: session-2.scope
         Slice: user-1000.slice
       Session: 2
     Owner UID: 1000 (rockerboo)
       Boot ID: 668c40d3cf97417ca11db782c8592c34
    Machine ID: 963583cfb782420faa5aa1ada463e5e2
      Hostname: Monolith
       Storage: /var/lib/systemd/coredump/core.whisper-rs-test.1000.668c40d3cf97417ca11db782c8592c34.9381.1670382146000000.zst (present)
  Size on Disk: 1.9M
       Message: Process 9381 (whisper-rs-test) of user 1000 dumped core.

                Stack trace of thread 9381:
                #0  0x000055e44946dd37 ggml_new_tensor_1d (whisper-rs-test + 0x2fd37)
                #1  0x000055e44945f603 _Z18whisper_model_loadRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEER15whisper_context (whisper-rs-test + 0x21603)
                #2  0x000055e449468864 whisper_init (whisper-rs-test + 0x2a864)
                #3  0x000055e449454736 _ZN10whisper_rs11whisper_ctx14WhisperContext3new17h87363f96f88a3ac2E (whisper-rs-test + 0x16736)
                #4  0x000055e449451241 _ZN15whisper_rs_test4main17hf6f1ca4420e2be30E (whisper-rs-test + 0x13241)
                #5  0x000055e44945026b _ZN4core3ops8function6FnOnce9call_once17h4f1eaff3b8de6063E (whisper-rs-test + 0x1226b)
                #6  0x000055e449450a6e _ZN3std10sys_common9backtrace28__rust_begin_short_backtrace17h867026dba0c90cf2E (whisper-rs-test + 0x12a6e)
                #7  0x000055e449450221 _ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17hc2ea9e99dd3d3c12E (whisper-rs-test + 0x12221)
                #8  0x000055e44949ad2f _ZN3std2rt19lang_start_internal17h6ba1bb743c1e9df9E (whisper-rs-test + 0x5cd2f)
                #9  0x000055e4494501fa _ZN3std2rt10lang_start17h3f62a1a1479ec313E (whisper-rs-test + 0x121fa)
                #10 0x000055e4494516b1 main (whisper-rs-test + 0x136b1)
                #11 0x00007ff5fed36290 n/a (libc.so.6 + 0x23290)
                #12 0x00007ff5fed3634a __libc_start_main (libc.so.6 + 0x2334a)
                #13 0x000055e4494500e5 _start (whisper-rs-test + 0x120e5)
                ELF object binary architecture: AMD x86-64
 neofetch
                   -`                    rockerboo@Monolith
                  .o+`                   ------------------
                 `ooo/                   OS: Arch Linux x86_64
                `+oooo:                  Kernel: 6.0.10-arch2-1
               `+oooooo:                 Uptime: 41 mins
               -+oooooo+:                Packages: 2172 (pacman), 7 (flatpak)
             `/:-:++oooo+:               Shell: zsh 5.9
            `/++++/+++++++:              Resolution: 1920x1080, 2560x1440
           `/++++++++++++++:             WM: dwm
          `/+++ooooooooooooo/`           Theme: Arc-Darker [GTK3]
         ./ooosssso++osssssso+`          Icons: Arc-Darker [GTK3]
        .oossssso-````/ossssss+`         Terminal: st
       -osssssso.      :ssssssso.        CPU: Intel i7-4820K (8) @ 4.400GHz
      :osssssss/        osssso+++.       GPU: NVIDIA GeForce RTX 2080 Rev. A
     /ossssssss/        +ssssooo/-       Memory: 4161MiB / 32042MiB
   `/ossssso+/:-        -:/+osssso+-
  `+sso+:-`                 `.-/+oso:
 `++:.                           `-/+/
 .`                                 `/

While assembling this ticket, I did some searching upstream, and it seems to require AVX instructions by default. And the suggestion is to disable -mavx -mavx2 -mfma -mf16c in the build. Bun was giving me simular issues and this is how they were detecting support for AVX on linux

Ultimately, it would be nice to be able to disable -mavx -mavx2 -mfma -mf16c build options to get a working build, even if it would be slow for my current CPU. I can give it a go if you give some direction of how to do it.

Thanks!

Clone the repo as usual, run git submodule init and git submodule update to check out the correct hash of whisper.cpp, and then edit the Makefile in sys/whisper.cpp to remove those flags. Then a regular cargo run should work.

Ok, that seemed to have gotten it to work. The demo took 4m22s to run on, small.en 😮 I think I need to finally upgrade my CPU.

Also seems they updated their Makefile to handle AVX better, so should be better into the future.

Thank you!