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

Failed to load native whisper library #65

Closed
milanstamenkovic opened this issue Jun 4, 2023 · 21 comments
Closed

Failed to load native whisper library #65

milanstamenkovic opened this issue Jun 4, 2023 · 21 comments

Comments

@milanstamenkovic
Copy link

I can't get it work, I keep getting error "Failed to load native whisper library". Not sure if I'm supposed to do something rather then adding packages in project, downloading model and creating processor. I'm doing exactly what is done in Simple example.
The error appears at following line:
using var whisperFactory = WhisperFactory.FromPath("ggml-base.bin");

I'm integrating into dotnet core 5 application running on linux-x64 machine.
Should I manually run whisper library or add it somewhere? Not sure that I understand the process at all..

`

    // This section detects whether the "ggml-base.bin" file exists in our project disk. If it doesn't, it downloads it from the internet
    if (!System.IO.File.Exists(modelFileName))
    {
      await DownloadModel(modelFileName, ggmlType);
    }

    // This section creates the whisperFactory object which is used to create the processor object.
    using var whisperFactory = WhisperFactory.FromPath("ggml-base.bin");

    // This section creates the processor object which is used to process the audio file, it uses language `auto` to detect the language of the audio file.
    using var processor = whisperFactory.CreateBuilder()
        .WithLanguage("auto")
        .Build();

`

@sandrohanea
Copy link
Owner

Hello @milanstamenkovic,

Did you also install the Runtime package with the same version?

e.g

    <PackageReference Include="Whisper.net" Version="1.4.3" />
    <PackageReference Include="Whisper.net.Runtime" Version="1.4.3" />

@sandrohanea
Copy link
Owner

If you installed that, or try to run the examples without success, the most likely issue is that you're missing glibc dependency.

@milanstamenkovic
Copy link
Author

milanstamenkovic commented Jun 4, 2023

Hi @sandrohanea,
Thanks on a quick response!

I installed both packages, but didn't know about glibc and it seems that it wasn't installed.
I just installed glibc and then tried again but the same error appears:
Full error is:

System.Exception: Failed to load native whisper library. Error: Unknown error
at Whisper.net.WhisperFactory..ctor(IWhisperProcessorModelLoader loader, Boolean delayInit, String libraryPath, Boolean bypassLoading)
at Whisper.net.WhisperFactory.FromPath(String path, Boolean delayInitialization, String libraryPath, Boolean bypassLoading)

Not sure if by "missing glibc dependency", You meant to install it in ubuntu.

@sandrohanea
Copy link
Owner

Hello,
Yes, It is a dependency of the runtime (to be installed on the os). Checked more details here: #11

@milanstamenkovic
Copy link
Author

Hi @sandrohanea ,
First, I apologize for not going through closed issues, I didn't see filter for only opened issues.
I'm still in the battle with this one.

Taking your steps to see which library is missing I found that I'm missing GLIB_2.32 and GLIBC_2.34. As I found out, it is not recommended to mess with those dependencies so I tried to upgrade ubuntu packages but that didn't do anything. I deployed code to server which is running Ubuntu 20.04.5 LTS and it throws the same error.

As I can see here I recompiled whistler.cpp and replaced the original file.. I'm not sure where this original file should be, I checked everything that is installed with Whisper.net and Whisper.net.Runtime and I couldn't find where I should replace it.

Because I don't have previous experience with this kind of integration, can You please confirm that I'm doing everything that is needed:

  1. Install Whisper.net
  2. Install Whisper.net.Runtime
  3. Consume them in code

Is regular workflow expected to be this way or there is something else under the hood?
Thanks in Advance!

@sandrohanea
Copy link
Owner

Hello @milanstamenkovic,
Yes, regular flow is expected to be like you described (those 3 steps).

You don't need to rebuild the library, just to ensure that the native library can be loaded. You can use ldd tool on Linux in order to find which dependency you are missing.

Once Whisper.net.Runtime is added to a project, in the output (e.g. bin/debug) you will see a directory runtimes, in that, you have linux-x64 which contains whisper.so.

Navigate to that path and execute ldd whisper.so in order to see the list of dependencies and where they are on your system.

This is not a normal flow as usually all the dependencies are automatically provisioned in most of the distributions.

@pkese
Copy link

pkese commented Jun 15, 2023

I've found out providing custom whisper.so library will work only if I specify full path to that file in the program's environment:

LD_LIBRARY_PATH=$(pwd)/bin/x64/Debug/net6.0/runtimes/linux-x64/:$LD_LIBRARY_PATH dotnet watch run

Otherwise I always got System.DllNotFoundException

@csharpfritz
Copy link

In working with containers, I found that I needed to be sure to include the latest GLIBC libraries, and using a base image of Ubuntu 22.04 (Jammy) solved this problem for me

@sandrohanea
Copy link
Owner

Hello all,
Last version 1.4.4 which was just published on nuget is working with older glibc ( 2.31 )
For all the people still having issues with loading the native library, feel free to give it a try.

Also, VS 2019 redistributable is not required on Windows and not VS 2022 as before.

Ofc, on both platforms, the library is working with the latest GLIBC and/or latest VS.

@xqiu
Copy link

xqiu commented Jun 28, 2023

For me, the demo with clblast GPU, one need to download and copy clblast.dll to the exe directory, or somewhere in path, download from https://github.com/CNugteren/CLBlast/releases/tag/1.6.0 .

The demo with cublas GPU on windows, one need to download https://developer.nvidia.com/cuda-toolkit , and only need to install CUBLAS, CUDART runtime. Then copy the dlls from C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1\bin. The 3 needed dlls are : cublas64_12.dll , cublasLt64_12.dll and cudart64_12.dll

@philippjbauer
Copy link

@sandrohanea I got my application working without problems on macOS Ventura, Ubuntu 20.22 and Windows 11 ARM64.

Windows 11 on an x64 machine unfortunately fails with:

System.Exception: Failed to load native whisper library. Error: A dynamic link library (DLL) initialization routine failed.

I followed all suggestions in this and the other threads except for hunting down a GLIBC since it only relates to Linux as far as I can tell.

The suggestion to use a custom loader doesn't work with the provided code because the LoadLibraryEx method is missing a 3rd parameter and I have no idea what a valid uint dwFlags value might be. I tried 0 and 1 just to try but it didn't work with those.

I've been trying the "Simple" example with version 1.4.6 of the project packages on an up-to-date install of Win 11 that has VS 2022 installed (including C++ development package).

@laanhca
Copy link

laanhca commented Oct 7, 2023

same problem

@sapoiuyt
Copy link

same problem。env is windows 11, and user net 6.0 version.

@abdulkadirbener
Copy link

[[Failed to load native whisper library. Error: The specified module could not be found.]
Same problem with Win11, x64, VisualStudio2022, C++ SDK and Runtime ok, .NetCore 7, Whisper.Net version 1.4.7

I created a console application from scratch, installed everything necessary, and then run it in debug mode: Resulted with error. The compiler was in AnyCpu mode. Then I changed to x64 (tested with debug + release modes): Then, sometimes I get this error and sometimes I don't. The ratio is approximately 1 to 5. If it fails 5 times, it works correctly once???.... I know it's meaningless, but that's how it is. I have no idea why. I tried everything written in other titles as well as what is written in this title. It does not work. Has anyone experienced similar problems? Did anyone find a solution?

@Kuprich
Copy link

Kuprich commented Nov 17, 2023

Hello, I also have a similar problem.
Unhandled exception. System.Exception: Failed to load native whisper library.
I used the simplest implementation.
PC: widows 10 x64,
C++ SDK and Runtime. It seems like I installed everything

But on another computer the same project runs without errors. what could it be?

@fwaris
Copy link

fwaris commented Nov 18, 2023

running into a similar problem
Windows 11, x64,
Perhaps better diagnostics can help pinpoint the exact issue

@fwaris
Copy link

fwaris commented Nov 18, 2023

Issue is fixed for me. In my case I found that I did not have CUDA Toolkit 12 installed (I had 11.8)

I used the "Dependency Walker" tool to find the native library dependency issue. It has been useful on several occasions.

https://github.com/isindicic/DependencyWalker.Net

I dropped the "\whisper.net.runtime.cublas\1.4.7\build\win-x64\whisper.dll" file into the tool's gui and it pointed out that it could not find the cuda12_XX DLLs, which prompted me to install CUDA 12.

@fwaris
Copy link

fwaris commented Nov 21, 2023

BTW I was able to run whisper.net with CUDA support on Linux.
Need to compile the whisper.cpp git submodule on the Linux box with make:

make clean
WHISPER_CUBLAS=1 make libwhisper.so -j

And then copy the shared library to 'runtimes' (renamed to whisper.so):

 cp ./libwhisper.so <path from root to runtimes>/runtimes/linux-x64/whisper.so

I also had to set the LD_LIBRARY_PATH variable to /runtimes/linux-x64/ to let the system find the shared library.

Note: don't use the main whisper.cpp repo to compile whisper as that may not be compatible. Use the one referenced from the Whisper.net repo as a git submodule.

@sandrohanea
Copy link
Owner

Yes, that should work.
The problem which I had was that on my linux build machine, couldn't use CUDA to build the linux runtime.

It is still in my plan, and hopefully will make it automatically in Whisper.net.Cublas in the next release 1.5.0.

@han1157
Copy link

han1157 commented Dec 25, 2023

I solved this problem by running VS with administrator privileges

@sandrohanea
Copy link
Owner

Added the exact dependencies for each runtime in the readme. Also we support multiple runtimes now referenced at the same time in one project. see https://github.com/sandrohanea/whisper.net?tab=readme-ov-file#multiple-runtimes-support

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

No branches or pull requests