fix(void): report pywhispercpp 1.5.0 and load CPU variants at runtime (#49)
CI / security (push) Successful in 1m9s
CI / lint (push) Successful in 23s
CI / ai-review (push) Skipped

Fixes #43
Fixes #44
This commit was merged in pull request #49.
This commit is contained in:
2026-11-06 18:51:30 +00:00
parent b0d8afad92
commit 0c48db5b5e
11 changed files with 376 additions and 66 deletions
@@ -0,0 +1,39 @@
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -16,6 +16,10 @@
#include <pybind11/numpy.h>
#include "whisper.h"
+#include "ggml-backend.h"
+
+#include <dlfcn.h>
+#include <string>
#define STRINGIFY(x) #x
@@ -850,7 +854,25 @@
////////////
+// With GGML_BACKEND_DL the CPU and GPU backends are libraries next to this
+// extension, and whisper.cpp cannot create a context until a CPU device is
+// registered. ggml searches the executable's directory (the interpreter's, for
+// Python) and the working directory, so load them from this module's directory.
+static void load_ggml_backends_beside_module() {
+ Dl_info info;
+ if (dladdr(reinterpret_cast<void *>(&load_ggml_backends_beside_module), &info) == 0 ||
+ info.dli_fname == nullptr) {
+ ggml_backend_load_all();
+ return;
+ }
+ const std::string path(info.dli_fname);
+ const std::size_t slash = path.find_last_of('/');
+ const std::string dir = slash == std::string::npos ? std::string(".") : path.substr(0, slash);
+ ggml_backend_load_all_from_path(dir.c_str());
+}
+
PYBIND11_MODULE(_pywhispercpp, m) {
+ load_ggml_backends_beside_module();
m.doc() = R"pbdoc(
Pywhispercpp: Python binding to whisper.cpp
-----------------------