Skip to content

feat: expose explicit backend loaders in the internal GGML module - #2451

Open
original4422 wants to merge 2 commits into
abetlen:mainfrom
original4422:feat/internal-ggml-backend-loaders
Open

original4422 wants to merge 2 commits into
abetlen:mainfrom
original4422:feat/internal-ggml-backend-loaders

Conversation

@original4422

Copy link
Copy Markdown

Summary

Refs #2069 for the explicit-loader bindings only.
Bind the four existing GGML registry functions in the private _ggml module with the native pointer, path and void-return types, using the existing ctypes decorator.

_ggml.ggml_backend_load(path) -> opaque handle or None
_ggml.ggml_backend_unload(handle)
_ggml.ggml_backend_load_all()
_ggml.ggml_backend_load_all_from_path(directory or None)

Keep native automatic discovery unchanged and document explicit loading, the existing GGML_BACKEND_PATH option, and the requirement to close all users before unloading a handle.
Add native subprocess regressions, a private-API installation guide and an Unreleased changelog entry.

Evidence

  • Before: an independently built, unmodified dynamic-backend package imports successfully but its real Llama consumer fails with “no backends are loaded” from an ordinary working directory. Native registration enables the same tiny-model consumer. The four new binding tests fail on the original Python module.
    After: all 4 new tests pass without skips using the new Python bindings over real modules. They check missing paths/NULL handles, byte-path arguments, void returns, load → real 2-token completion → close/unload → model-load failure, and directory/default discovery. No model or loader mocks are used.
  • Dynamic build, GGML_BACKEND_DL=ON: full make test 30 passed, no skips. The ordinary tests use the existing native GGML_BACKEND_PATH option to find the CPU plugin; the new subprocess cases clear it to exercise explicit registration.
  • Separately rebuilt ordinary build, GGML_BACKEND_DL=OFF: normal make test 27 passed, 3 skipped. Only the three opt-in dynamic-module cases skip; all 26 original tests and the missing-path/argument case pass.
  • make lint: Ruff checks and formatting pass for all 30 Python files. Both documentation Python fences compile, the MkDocs YAML/navigation parses, and git diff --check passes; the full documentation site was not built.

macOS arm64, Python 3.12.14, bundled llama.cpp f5e6915c2, two build workers, GGML_NATIVE=OFF and GGML_ACCELERATE=ON.
The original macOS build also enables Metal; model controls use n_gpu_layers=0.
Tests reuse existing local GGUF data with Hub offline mode.
The first full-suite attempt lacked the SOCKS client's optional socksio dependency; installing that normal prerequisite offline resolved the environment failure without changing proxy settings or test code.
Linux x86 CPU-variant dispatch, cross-platform/GPU compatibility and performance were not validated, so this does not close that broader part of #2069.

Implementation, source/diff review and validation were performed by an AI coding agent under the contributor's authorization.

Merge Danger

Door: two-way.

Blast Radius: explicit internal GGML backend registration. Callers own handle/resource lifetime; no top-level public export or automatic loading behavior is added.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant