From f414c2858934d9fe2c21446b73b2f879a0485a3a Mon Sep 17 00:00:00 2001 From: Aaron Miller Date: Fri, 20 Oct 2023 21:26:46 -0700 Subject: [PATCH] llmodel: whitelist library name patterns this fixes some issues that were being seen on installed windows builds of 2.5.0 only load dlls that actually might be model impl dlls, otherwise we pull all sorts of random junk into the process before it might expect to be Signed-off-by: Aaron Miller --- gpt4all-backend/llmodel.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gpt4all-backend/llmodel.cpp b/gpt4all-backend/llmodel.cpp index ad498563..45578fa1 100644 --- a/gpt4all-backend/llmodel.cpp +++ b/gpt4all-backend/llmodel.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #ifdef _MSC_VER #include #endif @@ -81,6 +82,13 @@ const std::vector &LLModel::Implementation::implementat static auto* libs = new std::vector([] () { std::vector fres; + std::string impl_name_re = "(bert|llama|gptj|llamamodel-mainline)"; + if (requires_avxonly()) { + impl_name_re += "-avxonly"; + } else { + impl_name_re += "-(default|metal)"; + } + std::regex re(impl_name_re); auto search_in_directory = [&](const std::string& paths) { std::stringstream ss(paths); std::string path; @@ -90,7 +98,10 @@ const std::vector &LLModel::Implementation::implementat // Iterate over all libraries for (const auto& f : std::filesystem::directory_iterator(fs_path)) { const std::filesystem::path& p = f.path(); + if (p.extension() != LIB_FILE_EXT) continue; + if (!std::regex_search(p.stem().string(), re)) continue; + // Add to list if model implementation try { Dlhandle dl(p.string());