SciSharp / LLamaSharp

A C#/.NET library to run LLM (🦙LLaMA/LLaVA) on your local device efficiently.
https://scisharp.github.io/LLamaSharp
MIT License
2.71k stars 350 forks source link

Incompatibility with Whisper.net #974

Closed Lyrcaxis closed 1 week ago

Lyrcaxis commented 3 weeks ago

Seems there's an incompatibility with Whisper.net after latest updates; It appears impossible to have them both loaded at the same time no matter what libraries/backends you specify or in what order you load them up. I drafted a minimal reproduction snippet:

// NOTE: If you only call a single method, it'll work.
void StartupLLamaSharp() {
    NativeLibraryConfig.LLama.WithLibrary(@"dlls\llama.dll"); // or comment out
    var modelParams = new ModelParams("");
}

void StartupWhisper() {
    RuntimeOptions.Instance.SetLibraryPath(@"dlls\whisper.dll"); // or comment out
    var whisperFactory = WhisperFactory.FromPath("");
}

void StartupBoth_LLamaFirst()   { SetupLLamaSharpModel(); SetupWhisperModel(); } // Throws from Whisper.net
void StartupBoth_WhisperFirst() { SetupWhisperModel(); SetupLLamaSharpModel(); } // Throws from LLamaSharp

I assume that because both llama.dll and whisper.dll depend on ggml.dll, the llama.dll and whisper.dll just check on the already loaded ggml of the other library, disregarding versioning.

Is this something that any one of [LLamaSharp, Whisper.net] can fix by itself? Aka make its dependencies standalone.

PS: I've cross-posted this in the Whisper.net repo to link in case it needs back and forth: https://github.com/sandrohanea/whisper.net/issues/251
martindevans commented 3 weeks ago

LLamaSharp is currently based on this version of llama.cpp. It looks like whisper.net is based on whisper.cpp 1.7.0, so probably this version.

Comparing the ggml/include/ggml.h files between those two versions, there are definitely incompatible changes.

My guess is whichever lib is loaded first loads ggml, and that causes the other one to explode.

Lyrcaxis commented 1 week ago

This issue is resolved from Whisper.Net side after @sandrohanea's tweak in https://github.com/sandrohanea/whisper.net/pull/252. Thanks!