Skip to content

Commit f414c28

Browse files
committed
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 <[email protected]>
1 parent 7e5e84f commit f414c28

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

gpt4all-backend/llmodel.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <cassert>
1111
#include <cstdlib>
1212
#include <sstream>
13+
#include <regex>
1314
#ifdef _MSC_VER
1415
#include <intrin.h>
1516
#endif
@@ -81,6 +82,13 @@ const std::vector<LLModel::Implementation> &LLModel::Implementation::implementat
8182
static auto* libs = new std::vector<Implementation>([] () {
8283
std::vector<Implementation> fres;
8384

85+
std::string impl_name_re = "(bert|llama|gptj|llamamodel-mainline)";
86+
if (requires_avxonly()) {
87+
impl_name_re += "-avxonly";
88+
} else {
89+
impl_name_re += "-(default|metal)";
90+
}
91+
std::regex re(impl_name_re);
8492
auto search_in_directory = [&](const std::string& paths) {
8593
std::stringstream ss(paths);
8694
std::string path;
@@ -90,7 +98,10 @@ const std::vector<LLModel::Implementation> &LLModel::Implementation::implementat
9098
// Iterate over all libraries
9199
for (const auto& f : std::filesystem::directory_iterator(fs_path)) {
92100
const std::filesystem::path& p = f.path();
101+
93102
if (p.extension() != LIB_FILE_EXT) continue;
103+
if (!std::regex_search(p.stem().string(), re)) continue;
104+
94105
// Add to list if model implementation
95106
try {
96107
Dlhandle dl(p.string());

0 commit comments

Comments
 (0)