Skip to content

Studio: add per-model custom llama.cpp INI configuration - #10783

Merged
danielhanchen merged 63 commits into
unslothai:mainfrom
Etherll:codex/issue-10359-custom-llama-config-20260911
Oct 2, 2026
Merged

danielhanchen merged 63 commits into
unslothai:mainfrom
Etherll:codex/issue-10359-custom-llama-config-20260911

Conversation

@Etherll

@Etherll Etherll commented Sep 11, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds a per-model custom llama.cpp configuration for GGUF models. In custom mode, llama-server runs with exactly the pasted preset INI (llama.cpp's own --models-preset format); Studio adds only the model, projector, host, port and alias.

Motivation

Extra arguments are additive and compete with the settings Studio generates. Users who already tune llama-server with a preset file want Studio to run that file as written, keep it across loads, and use its sampling values as the chat defaults.

Changes

  • llama_custom_config.py compiles the INI against the selected llama-server --help catalogue, following common/preset.cpp: keys above the first header form the default section and only [*] cascades; keys resolve to options (CLI spellings or env names) before the section merge; switch polarity comes from the help declaration; router-only keys are ignored. Two spellings of one option in one section, unknown options, Studio-managed flags and out-of-range sampling values are refused before the resident model is touched.
  • Custom launches are a separate path in LlamaCppBackend: no tuning planner or fallback, inherited LLAMA_ARG_* and denied env vars are scrubbed, the ROCm arch-gate mask still applies, and runtime state (context, slots, unified KV pool, cache types, reasoning budget, projector, audio probe) is read back from the launched server.
  • The INI's sampling values (temp, top-p, top-k, min-p, repeat-penalty, presence-penalty) become the request defaults for that model: below explicit request values and operator pins, above Studio's recommendations. The load response carries them so the chat sliders start from the INI.
  • Run settings gets a "Use custom configuration" control under Advanced settings, with the INI editor and a Section picker when the INI names more than one section. Studio's llama.cpp rows are locked while custom mode is on; the Vision switch stays usable. The source is saved per model and survives reloads.

How to test

From studio/backend:
python -m pytest tests/test_llama_custom_config.py tests/test_llama_custom_routes.py tests/test_llama_server_args.py -q

From studio/frontend:
node --experimental-strip-types --test tests/llama-cpp-custom-config.test.ts tests/llama-cpp-custom-status-managed-fields.test.ts
npx tsc -b --noEmit

A real load on a B200 with Qwen3-0.6B Q8_0 and c=4096, np=2, fa=on, temp=0.6, top-k=20, ctk/ctv=q8_0 started llama-server with exactly those flags, reported 2 slots of 2048, used temperature 0.6 as the server default and the chat default, and answered a chat request. An INI naming a missing device failed with llama-server's own error in the message.

Migration notes

The llama_cpp_config field is optional; existing managed settings are unchanged. Custom mode does not carry legacy extra arguments over.

Screenshots

Run settings for a GGUF model with Advanced settings open, before (merge base) and after this PR. The custom configuration control sits at the end of Advanced settings.

Run settings, custom configuration control

After "Use custom configuration" with an INI that names a [fast] section: the INI editor and Section picker appear, Load waits for a section, and Studio's llama.cpp rows are locked while Vision stays available.

Custom configuration enabled

Related

Refs #10359

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-15T13:49:58.076736Z 7b9dc83 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@Etherll

Etherll commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed the remaining custom-config fixes in four focused commits, ending at 11cd83c. Local validation passed: 7,314 frontend tests, 1,061 targeted Python tests, and TypeScript checks. New-head CI is running; browser evidence and security-review completion remain outstanding.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@Etherll

Etherll commented Sep 15, 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: 13056b650c

ℹ️ 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 +5100 to +5103
...customSamplingPayload(
runtime.loadedLlamaCppConfig,
params.samplingFieldsExplicit,
),

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 Apply custom sampling defaults to direct audio generation

When the active custom model is a GGUF TTS model, adding sampling_fields_explicit here has no effect because /audio/generate calls generate_audio directly and that route never invokes _fill_recommended_sampling_openai. The frontend still sends its automatic temperature/top-p/top-k/min-p/repetition values, and _generate_tts_wav forwards them verbatim, so they override the INI's launch-time sampling defaults even when the user never edited those fields; apply the custom-default resolver on this route before generating.

Useful? React with 👍 / 👎.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 1, 2026
Its fix for the hook-order test supersedes f10357a (it also counts
request_template_kwargs as a hook in the optional-default check), so that
file takes the branch's version.
@LeoBorcherding

LeoBorcherding commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Second round, in Unsloth Desktop on Windows: CPU-only, plus the mixed RX 6500 XT + RX 5700 XT box for GPU loads. Every feature this PR adds works end to end. The data behind each one is on the mirror: LeoBorcherding#84

Run at 54dcb65 on CPU (device = none), unsloth/Qwen3-1.7B-GGUF UD-Q4_K_XL, real mouse and keys, each row checked against the backend API, the llama-server process table or its /slots. The INI was [*] np 1, device none, gpu-layers 0, temp 0.3, top-k 7; [short] ctx-size 2048; [long] ctx-size 6144, seed 42.

feature evidence result
custom mode locks the managed controls Managed llama.cpp settings fieldset disabled and inert, 37 controls inside; Vision stays live works
INI editor + Section picker picker lists short, long works
Validate shows the effective config [long] gives n_ctx 6144, n_parallel 1, device none, sampling seed 42, temperature 0.3, top_k 7 works
reserved keys refused before the model is touched host = 0.0.0.0 refused on Validate and on Reload; same llama-server PID, /health ok works
the INI owns tuning on load llama-server argv --parallel 1 --ctx-size 6144 --device none --n-gpu-layers 0 --seed 42 --temperature 0.3 --top-k 7, none of Studio's --fit/--spec-default works
INI sampling under explicit values /slots ran seed 42 and top_k 7 from the INI with the request's explicit values on top works
config survives a llama-server crash after taskkill /F, the next chat restarted it with the same INI argv and config digest works
Remember per model after closing and reopening the app, a plain load restored custom mode with long works
Use Studio settings switches back llama-server back to the exact managed argv works

custom mode, sections and validate
Left: custom mode dims and locks the managed rows. Middle: the Section picker lists short and long. Right: Validate with long shows n_ctx 6144 and the INI's sampling.

reserved key refused
host = 0.0.0.0 is refused on Validate (top) and on Reload (bottom), and Qwen3 stays loaded on the same llama-server.

crash recovery and Remember
Left: after llama-server was killed, the next message restarted it with the same INI and answered. Right: after reopening the app, a plain load restored the remembered config.

Custom GPU loads now work on that mixed box with 2a7c63d's mask: no device and device = ROCm0 both load onto the RX 6500 XT (1,658 MB there, nothing on the RX 5700 XT) and answer "Paris". At 54dcb65 both were refused. So my earlier "the guard is right" is moot.

INI (gpu-layers 99, np 1, ctx 3072) at 21617c1
no device loads in 7 s, 1,658 MB on the RX 6500 XT, 0 MB on the RX 5700 XT, reply "The capital of France is Paris."
device = ROCm0 same, 1,658 MB on the RX 6500 XT
device = ROCm1 400 with a bare "could not start" (fixed in dd3d4f0 below)

VRAM is llama-server's dedicated usage per adapter from Windows' GPU Process Memory counters, matched to the card by LUID.

I've pushed these onto your branch on top of 6a93bb3 (fast-forward, nothing of yours rewritten):

  • 4e28b5b: turning Thinking off on a Qwen3 model marked the non-thinking sampling as user edits, so with Remember on it was saved and beat a later INI's temp. It's applied unmarked now, like a preset. The test still fails with the qwen-params.ts at 6a93bb3.

    before 4e28b5b
    saved explicit list after Thinking off ["temperature","top_p","enable_thinking"] ["enable_thinking"]
    llama-server /slots on the next chat with the INI temperature 0.7 temperature 0.3, top_k 7, seed 42
  • e3e0667 + 28ed0a7: in custom mode the Sampling sliders showed the preset's values while llama-server ran the INI's. A note under Sampling now lists the INI defaults in effect and anything set here over them (an INI n-predict counts as set here, since Max Tokens is always sent).

    Sampling note before and after
    Left, before: sliders read 0.7 and 20 while llama-server ran 0.3 and 7. Middle, e3e0667: the note lists seed 42, temperature 0.3, top_k 7. Right: after moving Temperature it shows as set here over the config.

  • dd3d4f0: with the mask, INI device names count only the supported cards, so the RX 6500 XT, which Unsloth Studio's own startup list shows as [1], is ROCm0 in custom mode. device = ROCm1 passed the config checks and then failed with a bare "could not start"; llama-server's invalid device: ROCm1 was only in the log. The error now includes llama-server's reason and names the visible devices.

  • 8577cf6: an INI with split-mode = tensor was echoed back as tensor_parallel and copied into the managed Tensor Parallelism toggle, so after Use Studio settings the next managed reload turned tensor parallelism on. It now gets the same custom-mode gate as placement, KV cache and speculative settings.

  • f10357a: the same hook-order test fix you made in 6a93bb3; the merge 5c59bc2 takes your version, so it's a no-op now.

  • 4515ee5: a merge of main (14ebbe876d, a few commits past the one your 5a26f8e took), with a test that a share link can't carry llamaCppConfig. Your merge already excludes the key; the test pins it. b684ee4, 33b23ad and 5c59bc2 merge your 9c1f707, 21617c1 and 6a93bb3 back in.

Each fix has a test. If any of them isn't what you want, revert that commit.

danielhanchen and others added 3 commits October 2, 2026 00:49
…piler

The INI now compiles straight to llama-server argv against the binary's probed
option table. llama-server applies its own sampling and template defaults, so
Studio only seeds the chat sliders from the INI sampling values in the load
response. Drops the option catalog parser, tuning planner, template kwargs
plumbing, separate validate round trip and sampling provenance tracking.
The mirror commits on top of 6a93bb3 refine machinery the slim removes
(template kwargs order, sampling provenance note, tensor toggle mapping).
llama-server's start failure reason is carried over in the compiler path.
…ns, repeat penalty seed, Vision outside the lock

Keys above the first header form the default section and only [*] cascades,
as in common/preset.cpp. CPU-only now needs --device none with no GPU projector
or drafter device, since -ngl 0 still offloads ops and the projector. The INI
repeat penalty seeds the chat slider, and the Vision switch stays usable in
custom mode because custom launches honour disable_vision.
… on CPU-only loads, refuse duplicate aliases
…, count every drafter spelling, report the preset's reasoning budget
…wnloaded diffusion GGUFs, reset diffusion targets explicitly
…, fetch it with vision off like managed loads
…nv keys map to the positive option, fallback autoload records the config
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 2, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 2, 2026
@danielhanchen
danielhanchen merged commit 864fec4 into unslothai:main Oct 2, 2026
JoshuaL3000 pushed a commit to JoshuaL3000/unsloth that referenced this pull request Oct 4, 2026
…0783)

* Studio: add per-model custom llama.cpp INI configuration

* Fix custom llama.cpp validation and load behavior

* Preserve sampling choices across settings reloads

* Update custom-config schema compatibility tests

* fix(studio): isolate custom llama launch state and defaults

* test(studio): refresh load compatibility assertions

* fix(studio): preserve inherited sampling and clear removed sections

* fix(studio): retain custom sampling across background inference

* Fix CPU-only custom device placement

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Track custom sidecars in load identity

* Respect CPU-only custom projector placement

* Apply custom sampling defaults to Anthropic

* Align custom INI section suggestions

* Publish custom runtime state atomically

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* studio: let the managed llama.cpp fieldset shrink to its column

A fieldset defaults to min-inline-size: min-content, so the advanced
settings grid pushed it past the config panel. min-w-0 keeps it inside.

* studio: keep a custom llama.cpp load's placement out of the managed controls

A custom load's status reports the INI's placement (manual, its gpu-layers)
and ctx-size. Status hydration seeded those into the managed GPU memory and
context controls, so Use Studio settings plus a reload launched llama-server
with --gpu-layers 0 --fit off and the INI's context.

* studio: don't adopt a custom load's placement from its load response either

The status gate alone didn't hold in Unsloth Desktop: the Reload path adopts
the load response through loadedGpuMemoryFields, which set GPU memory to
Manual with the INI's gpu-layers. managedGpuMemoryFields skips that for a
custom load and keeps only the layer counts.

* studio: keep a custom load's KV cache and speculative echo out of managed controls

Same leak as the placement one: after a custom load, Use Studio settings
plus Reload sent the INI's speculative mode (off) and an explicit f16 KV
cache. managedKvCacheFields and managedSpeculativeSettings skip a custom
response at the load sites, and the status path skips those three spreads.

* studio: type the custom-load store test for tsconfig.test.json

* tests: stub the managed load-field helpers in the autoload gate slice

* studio: keep the GPU-memory fields comment on loadedGpuMemoryFields

* studio: show the llama.cpp mode switch as a button and keep the custom source across a switch or refused load

* studio: keep a custom n-predict from overriding the client's max_tokens on /v1/completions

* studio: restore Run settings spacing around the GGUF advanced block

Splitting the panel into fieldsets left the Advanced settings toggle and the
managed rows outside main's space-y-5 container, so rows sat 32px apart instead
of 52px and the toggle touched the context divider. Wrap the GGUF advanced block
in mt-5 space-y-5 and give the managed fieldset the same rhythm; drop the mt-3.5
wrappers it no longer needs.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* studio: keep the Thinking toggle's Qwen sampling unmarked

applyQwenThinkingParams handed setParams the live samplingFieldsExplicit array,
so setParams re-marked the changed temperature, top_p and min_p as user edits.
With Remember on they were saved per model and beat a later INI's sampling.
Pass a fresh copy of the mask, as presets do.

* studio: say which sampling values the custom config supplies

In custom mode the Sampling sliders kept showing the preset values (Temperature
0.7, Top K 20) while llama-server ran the INI's request defaults (0.3, 7), since
unpinned fields are left out of the request. A note under Sampling now lists
the INI defaults in effect and any field set here over them.

* studio: list a custom n-predict as overridden by Max Tokens in the Sampling note

The composer always sends Max Tokens as max_tokens, which keeps the INI's
n_predict out of chat requests, so the note must not show it as applied.

* Studio: read chat_template_kwargs from extra_body and mask ROCm arch-gate survivors for custom loads

* Studio: slim custom llama.cpp config and fix review findings

Dedupe custom memory-state, extra-args validation, override-row lookup and
loaded-config store plumbing; compile once; trim comments.

Fixes: record cache-prompt=false as prompt cache disabled; append
request_template_kwargs after the tools loop's positional parameters; count
admission with the request's template kwargs; keep managed KV and speculative
baselines when rolling back to a custom load.

* Studio: skip template kwargs merge when no custom config or request kwargs

* studio: say why a custom llama-server failed to start, and how masked GPUs are named

With the ROCm arch-gate mask, INI device names count only the supported
cards, so on a mixed host the card Unsloth Studio lists as [1] is ROCm0
here. Naming it ROCm1 validated and then failed with a bare 'could not
start'; llama-server's own 'invalid device: ROCm1' was only in the log.
The error now carries llama-server's last error line, and on a masked
load names the visible devices. Test added.

* studio: keep a custom INI's split-mode tensor out of the managed tensor parallel toggle

A custom load echoes tensor_parallel from the INI's split-mode, and the load,
rollback, auto-load and /status paths adopted it into tensorParallel and
loadedTensorParallel. Switching back to Use Studio settings then reloaded with
tensor parallelism on. Gate it on custom mode like the GPU placement, KV cache
and speculative fields.

* studio: pin request_template_kwargs behind the tool-loop hooks, where the branch appends it

The signature has no bare *, so a new parameter must be appended or it rebinds
positional callers. The branch appends request_template_kwargs after the hooks,
but the test still expected it in front of them and failed in CI.

* Studio: keep request_template_kwargs appended after the tool-loop hooks

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Custom llama.cpp config: llama.cpp section grammar, CPU-only companions, repeat penalty seed, Vision outside the lock

Keys above the first header form the default section and only [*] cascades,
as in common/preset.cpp. CPU-only now needs --device none with no GPU projector
or drafter device, since -ngl 0 still offloads ops and the projector. The INI
repeat penalty seeds the chat slider, and the Vision switch stays usable in
custom mode because custom launches honour disable_vision.

* Custom llama.cpp config: show the editor under Advanced settings unless custom mode is on

* Custom llama.cpp config: probe audio after launch, keep the ROCm mask on CPU-only loads, refuse duplicate aliases

* Custom llama.cpp config: zero-VRAM arbitration, sampling aliases, chat-range defaults, preset-only keys

* Custom llama.cpp config: resolve options by identity before cascading, count every drafter spelling, report the preset's reasoning budget

* Custom llama.cpp config: follow upstream switch semantics for negative aliases and one-way switches

* Custom llama.cpp config: publish unified KV as one pool, accept env-name preset keys

* Custom llama.cpp config: cap a unified pool at an explicit ctx-size, read CRLF section headers

* Custom llama.cpp config: probe audio outside the load lock, refuse downloaded diffusion GGUFs, reset diffusion targets explicitly

* Custom llama.cpp config: scrub denied env vars on custom launches, reset diffusion compare loads

* Custom llama.cpp config: honour the INI's projector switch-off, clear auto tensor split state

* Custom llama.cpp config: skip projector work when the INI disables it, fetch it with vision off like managed loads

* Custom llama.cpp config: switch polarity from the help declaration, env keys map to the positive option, fallback autoload records the config

* Custom llama.cpp config: force_reload never adopts a resident custom server

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: LeoBorcherding <[email protected]>
Co-authored-by: Daniel Han <[email protected]>
danielhanchen added a commit that referenced this pull request Oct 5, 2026
)" (#12725)

This reverts commit 864fec4.

Conflicts with later commits were resolved by keeping their changes and
removing only the custom llama.cpp config parts. The custom config
handling #12661 added to _owner_chosen_launch and
_refuse_managed_custom_projector is removed too; the owner-only path
check for llama_extra_args stays.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants