Skip to content

Studio: use a custom llama.cpp build - #9292

Merged
danielhanchen merged 11 commits into
unslothai:mainfrom
Etherll:feat/studio-custom-llama-cpp-path
Aug 19, 2026
Merged

danielhanchen merged 11 commits into
unslothai:mainfrom
Etherll:feat/studio-custom-llama-cpp-path

Conversation

@Etherll

@Etherll Etherll commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

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-server for GGUF inference while keeping the
bundled 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

  • Adds validation and persistence for custom llama.cpp folders in studio/backend/utils/llama_cpp_path_settings.py:23.
  • Adds authenticated read and update routes in studio/backend/routes/settings.py:969. Only an interactive Studio session can change the executable path.
  • Resolves the selected runtime before bundled discovery in studio/backend/core/inference/llama_cpp.py:4841. Missing or non-executable pinned binaries fail without silently switching runtimes.
  • Tracks pending and active binary revisions so Studio can tell users when a loaded model needs to be reloaded.
  • Prevents the bundled updater and orphan cleanup from treating a user-managed llama.cpp directory as Studio-owned.
  • Adds manual path entry, folder browsing, status messages, reset-to-bundled behavior, and validation errors in studio/frontend/src/features/settings/components/llama-backend-section.tsx:44.
  • Adds translated UI strings for all 12 Studio locales.
  • Adds path, environment precedence, permissions, API authorization, runtime selection, updater, reload, and cleanup regression tests.

How to test

  1. Open Settings > System > GGUF inference engine.
  2. Enter or select a folder containing llama-server, build/bin/llama-server, or the Windows build/bin/Release/llama-server.exe.
  3. Save the folder, navigate away, and confirm the selection persists.
  4. Load a GGUF model and confirm the selected executable starts.
  5. Submit a folder without llama-server and confirm the previous valid selection is preserved.
  6. Select "Use bundled" and confirm automatic runtime discovery is restored.

@Etherll
Etherll requested a review from danielhanchen as a code owner August 19, 2026 13:21

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread studio/backend/main.py Outdated
Comment on lines +225 to +229
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"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 216d5c4: inherited launcher paths are now canonically matched against Studio's managed llama.cpp directory, while genuinely user-supplied paths remain locked.

Comment on lines +4873 to +4874
if sys.platform != "win32" and not os.access(p, os.X_OK):
return "denied"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@Etherll

Etherll commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

Etherll pushed a commit to Etherll/unsloth that referenced this pull request Aug 19, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 216d5c4d38

ℹ️ 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".

@Etherll

Etherll commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +4919 to +4922
return (
(str(non_executable), None)
if include_denied
else (None, non_executable)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Etherll

Etherll commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

1 similar comment
@Etherll

Etherll commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Etherll

Etherll commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author

UI evidence

Compared merge base ba9e207ac (BEFORE) with head 1b209b67c (AFTER) using two isolated Studio installs. Each side launched on its own bind-tested port and authenticated against its own SHA-stamped home.

Before and after: custom llama.cpp folder setting

Verified:

  • The custom-path input count changes from 0 to 1, and the settings endpoint changes from 404 to 200.
  • AFTER reports source=default, editable=true, and path=null on a clean home.
  • The input is writable, shows Automatic (bundled), and has an enabled Change control. Save is disabled only because the untouched empty value is not dirty.
  • No model was downloaded or loaded by the scene.

@Etherll

Etherll commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

1 similar comment
@Etherll

Etherll commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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)} />

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +156 to +160
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)}
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Etherll

Etherll commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: fc41eafac3

ℹ️ 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".

@danielhanchen
danielhanchen merged commit e99dfe5 into unslothai:main Aug 19, 2026
43 of 48 checks passed
coinhubx pushed a commit to NetDefender-Inc/unsloth that referenced this pull request Aug 20, 2026
… 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.
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.

2 participants