fix(model): deterministic, type-filtered backend auto-detection (#9287)#10286
Open
localai-bot wants to merge 1 commit into
Open
fix(model): deterministic, type-filtered backend auto-detection (#9287)#10286localai-bot wants to merge 1 commit into
localai-bot wants to merge 1 commit into
Conversation
) When a model config declares no explicit `backend:`, Load() fell into a trial loop built by ranging the external-backends Go map (random order) with no filtering, returning the first backend whose gRPC LoadModel succeeded. An unrelated installed backend - e.g. the "opus" audio codec - could therefore win a GGUF/LLM model load, so a model that should run on llama.cpp wrongly tried to use opus. Extract the candidate selection into a pure, testable function SelectAutoLoadBackends that: - sorts the candidate list deterministically (no more map-order nondeterminism), and - for a `.gguf` model, filters to LLM-capable backends (via core/config.BackendCapabilities) and puts llama-cpp first, so an incompatible audio/codec/image backend can never win the trial loop. If filtering would leave zero candidates, the full sorted set is returned unchanged, so a previously-loadable model is never made unloadable. Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Assisted-by: claude:claude-opus-4-8 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #9287
Problem
When a model config has no explicit
backend:,(*ModelLoader).Loadbuilt the auto-detect candidate list by ranging an unordered Go map of installed backends with no filtering, then loaded the first one whose gRPCLoadModelsucceeded. Every installed backend is registered there - including non-LLM ones like theopusaudio codec - so after installing such a backend it could win a GGUF/LLM load, sending the model to the wrong backend.Fix
New pure, unit-tested
SelectAutoLoadBackends(available, modelFile):.gguffiles, filters to LLM-capable backends (chat/completion/edit/embeddings usecases viacore/config.BackendCapabilities) withllama-cppfirst,Load()now calls this instead of ranging the map directly. (Verifiedpkg/model->core/configintroduces no import cycle.)Test plan
pkg/model/autoload_test.go(red -> green): given{opus, llama-cpp}+ a.gguf,opusis excluded andllama-cppis first; deterministic order; zero-candidate fallback returns the original set.go test ./pkg/model/... ./core/config/...green; scopedgolangci-lint --new-from-merge-baseclean.Follow-up (noted, not done)
Did not force
cfg.Backend = "llama-cpp"in the empty-backend GGUF hook (more blast radius on non-llama GGUFs); the candidate filter alone fixes the bug. A metadata-based GGUF architecture check is a possible refinement.Assisted-by: claude:claude-opus-4-8 [Claude Code]