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

Update whisper.cpp to 8e46ba8 #85

Merged
merged 10 commits into from
Oct 7, 2023
Merged

Update whisper.cpp to 8e46ba8 #85

merged 10 commits into from
Oct 7, 2023

Conversation

tazz4843
Copy link
Owner

See full diff at ggerganov/whisper.cpp@a5defbc...ggerganov:whisper.cpp:8e46ba80d3c1dcf532a0029f9bcdf99ce9ce7d40

Closes #70, #78, #80

Big features:

  • Adds OpenVINO support
  • Adds tdrz support

Will not be merged until we get a stable release to fix to.

@cenzovit
Copy link

cenzovit commented Sep 5, 2023

Looking at recent changes to whisper.cpp, it feels like this should be updated sooner rather than later. IMO the biggest "feature" is actually that it appears there were important fixes to the log_mel_spectrogram generation in whisper.cpp which improves WER for the smaller models significantly (ggerganov/whisper.cpp#1148).

@tazz4843
Copy link
Owner Author

tazz4843 commented Sep 5, 2023

I found a related issue yesterday and appears if everything goes well upstream should have a new release by end of week. See ggerganov/whisper.cpp#1233 (comment)

@tazz4843
Copy link
Owner Author

tazz4843 commented Sep 8, 2023

Figured I'd point out something possibly concerning for those who want to use this branch: ggerganov/whisper.cpp#1220 (comment)

These changes seem to be fine when using normal models, but quantized models produce broken output. For example, the jfk speech outputs only exclamation marks from my testing. I haven't changed any parameters.

It may be worth doing some local testing before upgrading whisper-rs, just in case this affects you.

@tazz4843
Copy link
Owner Author

OpenVINO support is broken: see ggerganov/whisper.cpp#1289

@tazz4843
Copy link
Owner Author

I think I'm gonna pull out the OpenVINO support into a separate PR (given it's completely borked right now), merge everything else, and then push a prerelease to crates.io since upstream seems to be taking a bit to merge stuff.

@chen-rn
Copy link

chen-rn commented Oct 3, 2023

I think I'm gonna pull out the OpenVINO support into a separate PR (given it's completely borked right now), merge everything else, and then push a prerelease to crates.io since upstream seems to be taking a bit to merge stuff.

That would be fantastic :)
As it seems that the performance boost is huge for both inference speed and WER! Esp the smaller models!

@tazz4843 tazz4843 marked this pull request as ready for review October 7, 2023 04:00
@tazz4843 tazz4843 merged commit 6e864d9 into master Oct 7, 2023
26 checks passed
@tazz4843
Copy link
Owner Author

tazz4843 commented Oct 7, 2023

0.9.0-rc.1 has been published to crates.io for anyone who would like to use this branch.

@cenzovit
Copy link

cenzovit commented Oct 7, 2023

Attempted to give 0.9.0-rc.1 a whirl but ran into a cmake error:
CMake Error: File .cargo/registry/src/index.crates.io-6f17d22bba15001f/whisper-rs-sys-0.7.0/whisper.cpp/ggml-metal.metal does not exist. CMake Error at CMakeLists.txt:149 (configure_file): configure_file Problem configuring file

@tazz4843
Copy link
Owner Author

tazz4843 commented Oct 7, 2023

@cenzovit Do a cargo update, I released -sys version 0.7.1 which adds ggml-metal.metal to the list of included files.

@cenzovit
Copy link

cenzovit commented Oct 8, 2023

Hmm, tried to update today and running into a new cmake error:

  CMake Error at CMakeLists.txt:462 (add_library):
    Cannot find source file:

      ggml-metal.m

    Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm
    .ccm .cxxm .c++m .h .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90
    .f95 .f03 .hip .ispc


  CMake Error at CMakeLists.txt:462 (add_library):
    No SOURCES given to target: whisper

@tazz4843
Copy link
Owner Author

tazz4843 commented Oct 8, 2023

Only macOS machine I have is a late 2012 MBP running 10.15, but should be recent enough to support whisper.cpp's Metal. Will give it a shot on there.

@tazz4843
Copy link
Owner Author

tazz4843 commented Oct 8, 2023

Should be fixed in -sys v0.7.2, compiles on macOS 10.15

@cenzovit
Copy link

cenzovit commented Oct 9, 2023

Got further this time, now running into a clang error on compile:

 Undefined symbols for architecture x86_64:
            "_MTLCopyAllDevices", referenced from:
                _ggml_metal_init in libwhisper_rs_sys-3c0021a7bf9aa3b1.rlib(ggml-metal.m.o)
            "_MTLCreateSystemDefaultDevice", referenced from:
                _ggml_metal_init in libwhisper_rs_sys-3c0021a7bf9aa3b1.rlib(ggml-metal.m.o)
            "_OBJC_CLASS_$_MTLComputePassDescriptor", referenced from:
                objc-class-ref in libwhisper_rs_sys-3c0021a7bf9aa3b1.rlib(ggml-metal.m.o)
          ld: symbol(s) not found for architecture x86_64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

This one may be an issue in whisper.cpp though?

@tazz4843
Copy link
Owner Author

tazz4843 commented Oct 9, 2023

That does seem like a whisper.cpp error since all we do is pass it off to upstream. Unless there's another missing file I don't think it's something we can fix.

@cenzovit
Copy link

cenzovit commented Oct 9, 2023

Maybe related: ggerganov/whisper.cpp#1344

@cenzovit
Copy link

cenzovit commented Oct 9, 2023

I wonder if other language bindings are seeing similar issues with the latest whisper.cpp

@cenzovit
Copy link

cenzovit commented Oct 9, 2023

Further notes, if I link the missing frameworks myself (which I think are suppose to be getting linked by ldflags in the whisper.cpp makefile) via config.toml or my build.rs -- for example in build.rs:

    println!("cargo:rustc-link-lib=framework=Foundation");
    println!("cargo:rustc-link-lib=framework=Metal");
    println!("cargo:rustc-link-lib=framework=MetalKit");

I can get my app to build. However, at runtime I run into a different issue as whisper goes to initialize:

ggml_metal_init: allocating
ggml_metal_init: found device: AMD Radeon Pro 5500M
ggml_metal_init: found device: Intel(R) UHD Graphics 630
ggml_metal_init: picking default device: AMD Radeon Pro 5500M
ggml_metal_init: loading '(null)'
ggml_metal_init: error: Error Domain=NSCocoaErrorDomain Code=258 "The file name is invalid."

Which seems to be occurring because ggml can't find the path to metallib: https://github.com/ggerganov/ggml/blob/6549d12f2e3176050040a86334f17c001e170f13/src/ggml-metal.m#L200C8-L200C8

At this point I am trying to figure out how to just build whisper.cpp without metal via the WHISPER_NO_METAL env variable; however, I can't seem to figure out how to have it set properly at the time whisper.cpp is being compiled.

@tazz4843
Copy link
Owner Author

tazz4843 commented Oct 9, 2023

It should just be as simple as setting it for the cargo build command I would think.

@cenzovit
Copy link

cenzovit commented Oct 9, 2023

That's what I would have thought, but when I do that it still tries to initialize metal during runtime and fails with the same issue above

@tazz4843
Copy link
Owner Author

tazz4843 commented Oct 9, 2023

If you have a local copy you could probably just edit it out of the Makefile as a temporary workaround, but we'd need to find something else for real use.

@tazz4843
Copy link
Owner Author

tazz4843 commented Oct 9, 2023

Oh I was able to hack macOS 14 onto this system so I can give it a shot again and see as well. Will do that now.

@cenzovit
Copy link

cenzovit commented Oct 9, 2023

Is there a chance that when whisper-rs-sys runs cmake on whisper.cpp that there is a metal file that needs to be copied to out as well (similar to coreml etc)? Separately, would it be possible to make metal configurable via a feature similar to how coreml is configured?

@tazz4843
Copy link
Owner Author

tazz4843 commented Oct 9, 2023

With macOS 14 I can indeed reproduce this issue. However I get some extra missing lib errors that it appears you didn't get

Full error
= note: ld: Undefined symbols:
            _MTLCopyAllDevices, referenced from:
                _ggml_metal_init in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
            _MTLCreateSystemDefaultDevice, referenced from:
                _ggml_metal_init in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
            _OBJC_CLASS_$_MTLComputePassDescriptor, referenced from:
                 in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
            _OBJC_CLASS_$_NSBundle, referenced from:
                 in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
            _OBJC_CLASS_$_NSObject, referenced from:
                _OBJC_CLASS_$_GGMLMetalClass in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
            _OBJC_CLASS_$_NSString, referenced from:
                 in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
            _OBJC_METACLASS_$_NSObject, referenced from:
                _OBJC_METACLASS_$_GGMLMetalClass in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                _OBJC_METACLASS_$_GGMLMetalClass in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
            ___CFConstantStringClassReference, referenced from:
                 in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                 in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                 in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                 in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                 in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                 in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                 in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                ...
            __objc_empty_cache, referenced from:
                _OBJC_METACLASS_$_GGMLMetalClass in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                _OBJC_CLASS_$_GGMLMetalClass in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
            _objc_autoreleasePoolPop, referenced from:
                _ggml_metal_graph_compute in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
            _objc_autoreleasePoolPush, referenced from:
                _ggml_metal_graph_compute in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
            _objc_enumerationMutation, referenced from:
                _ggml_metal_init in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
            _objc_msgSend, referenced from:
                _ggml_metal_init in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                _ggml_metal_init in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                _ggml_metal_init in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                _ggml_metal_init in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                _ggml_metal_init in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                _ggml_metal_add_buffer in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                _ggml_metal_add_buffer in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                _ggml_metal_add_buffer in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                _ggml_metal_add_buffer in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                _ggml_metal_add_buffer in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                ...
            _objc_opt_class, referenced from:
                _ggml_metal_init in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
            _objc_release, referenced from:
                _ggml_metal_free in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

@tazz4843
Copy link
Owner Author

tazz4843 commented Oct 9, 2023

Separately, would it be possible to make metal configurable via a feature similar to how coreml is configured?

This is what I want to do in the end to align Metal with all other acceleration layers.

@tazz4843
Copy link
Owner Author

tazz4843 commented Oct 9, 2023

I think I was able to hack together a Metal patch, will make a new branch and PR for it, you can try it out from there.

@cenzovit
Copy link

With macOS 14 I can indeed reproduce this issue. However I get some extra missing lib errors that it appears you didn't get

Full error

= note: ld: Undefined symbols:
            _MTLCopyAllDevices, referenced from:
                _ggml_metal_init in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
            _MTLCreateSystemDefaultDevice, referenced from:
                _ggml_metal_init in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
            _OBJC_CLASS_$_MTLComputePassDescriptor, referenced from:
                 in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
            _OBJC_CLASS_$_NSBundle, referenced from:
                 in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
            _OBJC_CLASS_$_NSObject, referenced from:
                _OBJC_CLASS_$_GGMLMetalClass in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
            _OBJC_CLASS_$_NSString, referenced from:
                 in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
            _OBJC_METACLASS_$_NSObject, referenced from:
                _OBJC_METACLASS_$_GGMLMetalClass in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                _OBJC_METACLASS_$_GGMLMetalClass in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
            ___CFConstantStringClassReference, referenced from:
                 in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                 in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                 in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                 in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                 in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                 in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                 in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                ...
            __objc_empty_cache, referenced from:
                _OBJC_METACLASS_$_GGMLMetalClass in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                _OBJC_CLASS_$_GGMLMetalClass in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
            _objc_autoreleasePoolPop, referenced from:
                _ggml_metal_graph_compute in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
            _objc_autoreleasePoolPush, referenced from:
                _ggml_metal_graph_compute in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
            _objc_enumerationMutation, referenced from:
                _ggml_metal_init in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
            _objc_msgSend, referenced from:
                _ggml_metal_init in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                _ggml_metal_init in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                _ggml_metal_init in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                _ggml_metal_init in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                _ggml_metal_init in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                _ggml_metal_add_buffer in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                _ggml_metal_add_buffer in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                _ggml_metal_add_buffer in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                _ggml_metal_add_buffer in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                _ggml_metal_add_buffer in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
                ...
            _objc_opt_class, referenced from:
                _ggml_metal_init in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
            _objc_release, referenced from:
                _ggml_metal_free in libwhisper_rs_sys-5632026198159c2d.rlib[17](ggml-metal.m.o)
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

When you add the libs and get past the undefined symbols errors, do you run into the same runtime issue where it can't find the path to the metal file?

@cenzovit
Copy link

Another maybe related issue (even though it is in llama.cpp)? ggerganov/llama.cpp#1912

@cenzovit
Copy link

Interestingly in: ggerganov/whisper.cpp#1270 there is an incomplete todo for "Can't figure out how to make the CMake build look for ggml-metal.metal in the bin folder"

@tazz4843
Copy link
Owner Author

whisper.cpp upstream error
ggml_metal_init: allocating
ggml_metal_init: found device: Intel HD Graphics 4000
ggml_metal_init: picking default device: Intel HD Graphics 4000
ggml_metal_init: loading '/Users/niko/whisper.cpp/ggml-metal.metal'
ggml_metal_init: loaded kernel_add                         0x600002cf0680 | th_max = 1024 | th_width =   32
ggml_metal_init: loaded kernel_add_row                     0x600002cf7600 | th_max = 1024 | th_width =   32
ggml_metal_init: loaded kernel_mul                         0x600002cf7880 | th_max = 1024 | th_width =   32
ggml_metal_init: loaded kernel_mul_row                     0x600002cfc880 | th_max = 1024 | th_width =   32
ggml_metal_init: loaded kernel_scale                       0x600002cf0c00 | th_max = 1024 | th_width =   32
ggml_metal_init: loaded kernel_silu                        0x600002cf1800 | th_max = 1024 | th_width =   32
ggml_metal_init: loaded kernel_relu                        0x600002cf7480 | th_max = 1024 | th_width =   32
ggml_metal_init: loaded kernel_gelu                        0x600002cf6e80 | th_max = 1024 | th_width =   32
ggml_metal_init: loaded kernel_soft_max                               0x0 | th_max =    0 | th_width =    0
ggml_metal_init: load pipeline error: Error Domain=CompilerError Code=2 "Compiler encountered an internal error" UserInfo={NSLocalizedDescription=Compiler encountered an internal error}
whisper_init_state: ggml_metal_init() failed
error: failed to initialize whisper context

However with whisper-rs I get a different error, regardless of features:

whisper_model_load: adding 1608 extra tokens
whisper_model_load: model ctx     =  464.68 MB
fish: Job 1, 'cargo run --example audio_trans…' terminated by signal SIGILL (Illegal instruction)

@tazz4843
Copy link
Owner Author

After thinking about it, chances are my error's related to trying to use Metal on a legacy Metal GPU (i5-3210M). Probably can't help further with this, as it appears to not just be an isolated case (the Photos app crashed a few days ago due to an internal shader compilation error as well).

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