ggerganov / whisper.cpp

Port of OpenAI's Whisper model in C/C++
MIT License
35.86k stars 3.65k forks source link

whisper.objc crashes on iPhone 14 Pro Max #2556

Open alimysoyang opened 1 week ago

alimysoyang commented 1 week ago

Crash Log: Assertion failed: (ctx != NULL), function ggml_backend_metal_device_acq, file ggml-metal.m, line 53.

Input Data, ViewController.m(Line 70):

stateInp.ctx = whisper_init_from_file_with_params([modelPath UTF8String], cparams);
Screenshot 2024-11-14 at 06 18 40
tomer-schles commented 1 week ago

Similar crash happend to me. On iPhone 16 Pro.

I was not interested in metal, but only in coreml, so I disabled metal according to the readme and then it worked properly. Core ml was much faster then without it (20X?).

Also was a bit confusing to understand how to use coreml and how to change the model from base.en to another one, so I opened a PR with updates to the readme here - https://github.com/ggerganov/whisper.cpp/pull/2569

A bit more info on my original crash using metal - I crashed on this line if (ctx->mtl_device == nil) { because ctx was NULL. For some reason the assert was not triggering the crash.

static id<MTLDevice> ggml_backend_metal_device_acq(struct ggml_backend_metal_device_context * ctx) {
    assert(ctx != NULL);

    if (ctx->mtl_device == nil) {
        ctx->mtl_device = MTLCreateSystemDefaultDevice();
JulianPscheid commented 5 days ago

I was not interested in metal, but only in coreml, so I disabled metal according to the readme and then it worked properly. Core ml was much faster then without it (20X?).

Thanks, removing the -DGGML_USE_METAL parameter indeed fixed this error. Performance appears to be the same as before upgrading to the latest Whisper.cpp release (1.7.2) that introduced this error. I was previously using 1.7.1. Tested on iPhone X and 12.