Repository navigation
Studio: use a custom llama.cpp build - #9292
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e135c7d21d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if not os.environ.get("UNSLOTH_LLAMA_CPP_PATH"): | ||
| os.environ["UNSLOTH_LLAMA_CPP_PATH"] = str(_STUDIO_ROOT_RESOLVED / "llama.cpp") | ||
| # Direct uvicorn launches need the same managed-vs-explicit distinction | ||
| # as run.py so Settings can replace Studio's default install directory. | ||
| os.environ["UNSLOTH_STUDIO_MANAGED_LLAMA_CPP_PATH"] = "1" |
There was a problem hiding this comment.
Mark inherited managed paths before classifying overrides
When Studio is installed under a custom root and launched normally through unsloth studio or an installed desktop launcher, the parent process already exports UNSLOTH_LLAMA_CPP_PATH to the managed <studio-home>/llama.cpp directory (for example, unsloth_cli/commands/studio.py:145-146). This conditional therefore skips setting the new marker, causing _environment_override() to misclassify Studio's own managed path as a user override; the custom-path control becomes read-only and rejects every update. Set the marker when the inherited value matches the managed directory, while continuing to leave genuinely user-supplied paths unmarked.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 216d5c4: inherited launcher paths are now canonically matched against Studio's managed llama.cpp directory, while genuinely user-supplied paths remain locked.
| if sys.platform != "win32" and not os.access(p, os.X_OK): | ||
| return "denied" |
There was a problem hiding this comment.
Continue past non-executable layout candidates
When a selected directory contains a non-executable root-level llama-server plus a valid executable under build/bin, validation accepts the folder because resolve_llama_server_binary() skips the unusable candidate, but runtime discovery now classifies that first candidate as denied and _scan_pinned() immediately stops instead of reaching the valid build. Thus a folder accepted and persisted by Settings can still fail every model load; non-executable candidates in a directory layout should be skipped unless no supported executable candidate exists.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 216d5c4: runtime discovery now continues past non-executable sibling layout candidates, but still fails closed for access-denied files or when no executable candidate exists. This follows Python X_OK permission semantics: https://docs.python.org/3/library/os.html#os.access and POSIX access(): https://pubs.opengroup.org/onlinepubs/9699919799/functions/access.html
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9c9b2e7c64
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return ( | ||
| (str(non_executable), None) | ||
| if include_denied | ||
| else (None, non_executable) |
There was a problem hiding this comment.
Do not classify non-executable files as transiently denied
On Unix, when the selected folder's only llama-server loses its execute bit, the first discovery correctly rejects it, but the subsequent include_denied=True probe returns that same file through this branch. The load path at load_model() then reports it as temporarily access-denied by antivirus or an in-flight install and tells the user to retry, although retries can never succeed until permissions are fixed. Preserve the non_executable distinction so this case produces actionable permission guidance while genuine access-denied files retain the transient message.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 1b209b6. The include-denied probe now preserves only genuine access-denied paths; a known non-executable binary fails preflight and receives explicit execute-permission guidance. Added regression coverage for the include_denied path.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1b209b67c7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # `binary` below (capability probe, revision stamp) shares one path | ||
| # space; `_binary_changed_since_launch` compares against this one. | ||
| binary = self._exec_path_for_launch(binary) | ||
| self._binary_revision_pending = self._binary_revision(binary) |
There was a problem hiding this comment.
Check the selected binary before deduplicating a load
When a custom path is saved while a GGUF model is already loaded, the binary snapshot is not captured until after both the route-level and load_model() calls to adopt_load_intent_if_matched. Consequently, a normal request to load the same model without force_reload returns already_loaded and keeps serving from the old llama-server even though the settings response says a reload is required. Include _binary_changed_since_launch() in the runtime-match predicate (as is already done for Model Memory and VRAM changes), or resolve the binary before either duplicate-load fast path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in ff8c2fa. adopt_load_intent_if_matched now rejects an otherwise identical resident GGUF request when the selected llama-server revision differs from the launch revision, so both duplicate-load fast paths perform the required reload. Added a focused regression.
UI evidenceCompared merge base Verified:
|
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ff8c2fafcb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| </div> | ||
| </SettingsRow> | ||
|
|
||
| <LlamaCppPathRow onChanged={() => void refresh(true)} /> |
There was a problem hiding this comment.
Invalidate the llama flag catalog after changing paths
When the custom folder is saved, this callback refreshes only the backend-switch status. The flag catalog in features/model-picker/api/llama-flags.ts is explicitly cached by binary revision on the client, and cachedManaged has no TTL; invalidateLlamaFlagCatalog() is currently called only after an installer/backend-switch job. Consequently, after selecting a different build, the extra-arguments UI can indefinitely retain the previous build's effective slot limits and temporarily retain its supported flags/arity, rejecting valid arguments or allowing a load that the newly selected server cannot parse. Invalidate the catalog in this path-change callback as well.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in fc41eaf. A successful path save now invalidates the cached llama flag catalog before refreshing backend status, through the model-picker public API. ESLint and the full frontend typecheck pass.
| with _settings_lock: | ||
| from storage.studio_db import upsert_app_settings | ||
| upsert_app_settings( | ||
| {CUSTOM_LLAMA_CPP_PATH_SETTING_KEY: (str(directory) if directory is not None else None)} | ||
| ) |
There was a problem hiding this comment.
Restart auxiliary llama servers when saving the path
When the setting changes while an auxiliary llama-server is already running, this write updates only the database and chat reload status. The RAG backend caches its resolved executable in core/rag/embed_llama_server.py::_binary and _current() checks only the embedding model, so it keeps using and even respawns the old executable indefinitely; MtmdSttSidecar._load_locked() similarly reuses a warm same-model dictation process without comparing the newly resolved binary. Thus the advertised custom runtime is not applied to embeddings or supported voice models until those services happen to be recreated or unloaded. Invalidate/restart these consumers as part of the path update, or make their currency checks include the selected binary revision.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in fc41eaf. Path saves now advance an in-process revision; the RAG embedder and warm mtmd STT sidecar record their launch revision and lazily respawn on the next use when it changes. Focused lifecycle regressions pass.
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
… leg (unslothai#9348) * Stub the two helpers the sliced harnesses started importing Backend CI's "Repo tests (CPU)" has been red on main since 588405d, with 111 failures in two files. Both are the same defect, and neither is about what the tests claim to be testing. These harnesses replay real studio source with its import block stripped, so every name the sliced region calls has to be defined in the harness. Two landed without one: refresh-context-usage.ts findLatestUserVideoBase64 (unslothai#9056, decline to price a prompt carrying video) chat-runtime-store.ts resolvePreserveThinkingOnLoad Both product changes are right. The first is the more dangerous shape: with no stub the replayed body throws a ReferenceError, the effect bails, `counts` stays 0, and the assertion reads "the empty New Chat view must be priced exactly once" -- a pricing bug that does not exist. 41 tests failed that way, and bisecting main was the only way to see it, because the message points at the wrong thing. test_chat_autoload_failure_gate.py already guards this and said exactly what was missing, which is why its 70 failures named resolvePreserveThinkingOnLoad outright. test_new_chat_context_recount.py had no such guard; it does now, built the same way -- parse the real import list, assert the harness defines each name. Mutation-tested: dropping the video stub turns it red with the name in the message. The preserve-thinking stub is the real resolver's rule verbatim, since no scenario here sets a stored preference. tests/studio: 0 failures, from 111. * Let the duplicate-load fast path read the binary it now has to compare Backend CI's "(Python 3.13)" leg has been red on main since e99dfe5, "Studio: use a custom llama.cpp build (unslothai#9292)", with three failures. All three are the tests, not the change. Two in test_metal_paravirtual_guard.py forbade BOTH _kill_process and _find_llama_server_binary on a duplicate /load, under one message: "tore down a healthy server on a duplicate /load". Only the first is teardown. unslothai#9292 put _binary_changed_since_launch() on the fast path, which reads the current llama-server to see whether a different one is installed than the live process was launched from -- exactly what a custom build has to check, since an identical request must still reload when the binary underneath it changed. So the read is correct and forbidding it reported a lookup as a teardown. _kill_process stays forbidden; the binary lookup now returns a fixed path, so the revision comparison sees no change and the fast path is still what is exercised. One in test_vram_budget_settings.py asserted the compacted source of _serial_load_scope ENDS WITH self._vram_fraction_pending=None. unslothai#9292 added a sibling clear, _binary_revision_pending, so the release is still in the finally but no longer last in it. The assertion now checks it is inside the finally, which is the property the test names. Mutation-tested: deleting the vram release from the finally still turns it red. Note on the leg name: 3.11 is not a second copy of this suite. The matrix is 3.13 scope=full and 3.11 scope=floor-spot-check, about 40 tests in three files, so "3.11 green, 3.13 red" is not a version difference -- 3.13 is simply the only leg that runs these. Reproduced locally on 3.13.12. test_metal_paravirtual_guard.py 119 passed, test_vram_budget_settings.py 90 passed. Test files only; no product code touched.

Summary
Adds a custom llama.cpp folder setting under Settings > System > GGUF inference engine. Studio validates and stores the selected folder, then uses its
llama-serverfor GGUF inference while keeping thebundled runtime as the default.
Motivation
Users with a custom llama.cpp build currently need to configure it outside Studio. This adds an in-app selector while preserving existing environment-variable overrides.
Changes
studio/backend/utils/llama_cpp_path_settings.py:23.studio/backend/routes/settings.py:969. Only an interactive Studio session can change the executable path.studio/backend/core/inference/llama_cpp.py:4841. Missing or non-executable pinned binaries fail without silently switching runtimes.studio/frontend/src/features/settings/components/llama-backend-section.tsx:44.How to test
llama-server,build/bin/llama-server, or the Windowsbuild/bin/Release/llama-server.exe.llama-serverand confirm the previous valid selection is preserved.