Skip to content

feat: support GGML_BACKEND_DIR environment variable#17501

Open
o7si wants to merge 1 commit intoggml-org:masterfrom
o7si:issue-17491
Open

feat: support GGML_BACKEND_DIR environment variable#17501
o7si wants to merge 1 commit intoggml-org:masterfrom
o7si:issue-17491

Conversation

@o7si
Copy link
Copy Markdown
Contributor

@o7si o7si commented Nov 25, 2025

Currently, CMake supports setting the GGML_BACKEND_DIR variable to specify the backend installation path:

set(GGML_BACKEND_DIR "" CACHE PATH "ggml: directory to load dynamic backends from (requires GGML_BACKEND_DL")

This path gets embedded into the code as a search path:

std::vector<fs::path> search_paths;
if (user_search_path == nullptr) {
#ifdef GGML_BACKEND_DIR
search_paths.push_back(fs::u8path(GGML_BACKEND_DIR));
#endif
// default search paths: executable directory, current directory
search_paths.push_back(get_executable_path());
search_paths.push_back(fs::current_path());
} else {
search_paths.push_back(fs::u8path(user_search_path));
}

However, in some cases, users may need to adjust the backend path for various reasons, which would invalidate the embedded path in the code.

This PR adds an environment variable to improve this situation by allowing runtime path configuration.

Related Issue:

@github-actions github-actions Bot added the ggml changes relating to the ggml tensor library for machine learning label Nov 25, 2025
@o7si
Copy link
Copy Markdown
Contributor Author

o7si commented Nov 25, 2025

Both the macro and environment variable use the same name GGML_BACKEND_DIR. To avoid confusion, should I rename the macro from GGML_BACKEND_DIR to GGML_BACKEND_INSTALL_DIR?

@ckastner
Copy link
Copy Markdown
Collaborator

I think this is a useful idea, for example when experimenting with other backend builds / third-party backends. There already exists a GGML_BACKEND_PATH but AFAICT that's for a single backend.

Personally I would expect that GGML_BACKEND_DIR would supersede a build-time GGML_BACKEND_DIR, but from how I read ggml_backend_load_best(), all backends in search dirs are looked at and the best is chosen. But if this is a problem, it probably deserves its own PR.

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

Labels

ggml changes relating to the ggml tensor library for machine learning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants