Skip to content

feat(studio): presets include load settings (#7347) - #7352

Merged
danielhanchen merged 5 commits into
unslothai:mainfrom
Souravrajvi0:feat/custom-profiles-load-settings-4af7
Jul 24, 2026
Merged

danielhanchen merged 5 commits into
unslothai:mainfrom
Souravrajvi0:feat/custom-profiles-load-settings-4af7

Conversation

@Souravrajvi0

@Souravrajvi0 Souravrajvi0 commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #7347

Problem

Chat presets only saved sampling params (temperature, top_p, system prompt, etc.). Load knobs like context length and KV cache dtype lived in per-model config / the runtime store, so users couldn't save named bundles like "Long context + q8_0 KV".

Fix

  • Add optional loadConfig on Preset (context, KV cache dtype, speculative decoding, GPU layers/mode, tensor parallel)
  • Save preset captures current load settings via capturePresetLoadConfig()
  • Switch preset applies both sampling params and load settings; toast to reload if a model is already loaded
  • Startup hydrate restores load settings from the active saved preset
  • UI note under preset controls shows what's captured / saved

Excluded from presets (by design): chat template override (too large), GPU device pick (machine-specific), tensor split.

Verification

pytest tests/studio/test_chat_preset_load_config.py tests/studio/test_chat_preset_builtin_invariants.py -q
cd studio/frontend && npm run typecheck
  • 13 preset contract tests passed
  • typecheck clean
  • Manual: save preset with custom context + KV dtype → switch presets → load settings update (reload model to apply)

Presets previously stored only sampling params (temperature, top_p, etc.).
Extend them with an optional loadConfig blob that captures context length,
KV cache dtype, speculative decoding, and GPU layer knobs from the current
runtime when saving.

- Apply loadConfig when switching presets or hydrating on startup
- Show a short summary under the preset controls
- Prompt to reload when a model is already loaded

Fixes unslothai#7347
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@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: 33c365d492

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +138 to +140
maxSeqLength: normalizeMaxSeqLength(snapshot.maxSeqLength),
kvCacheDtype: snapshot.kvCacheDtype ?? null,
speculativeType: normalizeSpeculativeType(snapshot.speculativeType),

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 Treat default load knobs as empty

With a fresh/default runtime, currentRuntimePerModelConfig({ includeMaxSeqLength: true }) returns the app default max sequence length (4096) and the default speculative mode (auto), so capturePresetLoadConfig() produces a non-empty loadConfig even though the built-in Default preset has none. That makes hasUnsavedPresetChanges mark Default (and older presets without loadConfig) dirty immediately, enabling “Save”/copy behavior on first open when nothing changed. Coalesce default maxSeqLength/auto speculative mode to the empty preset load config, or give built-ins an equivalent loadConfig.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 11c71466: capturePresetLoadConfig() now runs through coalesceDefaultLoadKnobs(), which strips app-default maxSeqLength (4096) and speculativeType (auto) before save/compare. Built-in Default and legacy presets without loadConfig no longer show as dirty on first open.

Comment on lines +1411 to +1412
if (activeDefinition?.loadConfig) {
applyPresetLoadConfig(activeDefinition.loadConfig);

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 Don’t replay stale preset load settings on hydration

When a user saves a preset, then later changes load settings such as Max Seq Length or GGUF context without saving that preset again, the current values are still restored by getHydratedSettingsState/per-model config. This unconditional replay of the active preset’s older loadConfig immediately overwrites those restored values on every refresh whenever the active preset has loadConfig, silently reverting the user's current load settings. Only apply the preset loadConfig here when it is known to be the current state, or persist/compare the current load settings separately.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 11c71466: removed the post-hydration applyPresetLoadConfig(activeDefinition.loadConfig) block. Load settings now apply only when the user explicitly selects a preset, so a refresh no longer overwrites newer per-model settings with stale preset data.

gpuMemoryMode: config?.gpuMemoryMode,
gpuLayers: config?.gpuLayers,
nCpuMoe: config?.nCpuMoe,
selectedGpuIds: null,

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 Preserve GPU pin when applying presets

PresetLoadConfig intentionally excludes per-model-only fields, but passing selectedGpuIds: null clears the active GPU selection every time a preset loadConfig is applied or hydrated. On multi-GPU machines this makes the next reload use automatic/all-GPU placement instead of the user's saved per-model GPU pin, even though presets do not expose or save that setting. Preserve the current GPU IDs rather than resetting an excluded field.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 11c71466: applyPresetLoadConfig() now passes selectedGpuIds: store.selectedGpuIds instead of null, since GPU device selection is intentionally excluded from presets.

{
name: saveName,
params: toPresetParams(params),
...(loadConfig ? { loadConfig } : {}),

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 Allow the backend to accept loadConfig

Saving a preset now sends loadConfig inside each customPresets entry, but the /api/chat/settings backend still validates ChatPreset with extra = "forbid" and only name/params fields (studio/backend/routes/chat_history.py:163-167). As soon as this field is present, the PUT is rejected with a 400, so presets with load settings update only local state and disappear after refresh. Add loadConfig to the backend schema/storage contract before sending it from the UI.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 0882a8c7: added ChatPresetLoadConfig to studio/backend/routes/chat_history.py and wired it into ChatPreset.loadConfig. PUT /api/chat/settings now accepts presets with load settings; verified locally that saves persist across refresh.

onParamsChange({
...applyPresetParams(params, p.params),
});
applyPresetLoadConfig(p.loadConfig);

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 Skip load resets for legacy presets

This runs for every preset, including existing custom presets loaded from storage that have no loadConfig. In that case applyPresetLoadConfig(undefined) applies the default per-model config and 4096 max sequence length, so selecting an older sampling/system-prompt preset unexpectedly wipes the user's current context length, KV/speculative settings, and GPU offload knobs. Treat missing loadConfig as “no saved load settings” for legacy/custom presets, or add an explicit default loadConfig only where reset semantics are intended.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 11c71466: applyPreset() only calls applyPresetLoadConfig when p.loadConfig is present, and applyPresetLoadConfig(null) is a no-op. Legacy sampling-only presets no longer reset context/KV/GPU knobs on selection.

applyPerModelConfigToRuntime({
...DEFAULT_PER_MODEL_CONFIG,
maxSeqLength: normalizeMaxSeqLength(config?.maxSeqLength) ?? DEFAULT_MAX_SEQ_LENGTH,
customContextLength: config?.customContextLength ?? null,

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 Distinguish cleared GGUF context from reuse-current

For a preset that owns load settings but intentionally has no custom GGUF context, this stores null; however the same-model reload path treats customContextLength === null as “reuse the currently loaded ggufContextLength” in resolveLoadMaxSeqLength. If a user switches from an 8k-context preset to a KV-only/default-context preset and reloads the already-loaded GGUF, the old 8k context is kept instead of the preset clearing it. Preserve an explicit “preset cleared context” sentinel or force the reload to send the auto/default context when applying such a preset.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Acknowledged — valid edge case. A KV-only preset with customContextLength: null can still reuse the loaded ggufContextLength on same-model reload (resolveLoadMaxSeqLength). Deferred to a follow-up; needs an explicit sentinel or reload-path change. Out of scope for #7347.

Add ChatPresetLoadConfig to the chat settings API schema so presets with
load settings no longer 400 on save. Capture effective GGUF context from
ggufContextLength when customContextLength is cleared after auto-mode load.
Coalesce default maxSeqLength/speculative/gpu knobs when capturing presets,
no-op apply for legacy presets without loadConfig, preserve GPU pin on apply,
and stop replaying stale loadConfig during settings hydration.
@Souravrajvi0
Souravrajvi0 force-pushed the feat/custom-profiles-load-settings-4af7 branch from 9b6b5dd to 11c7146 Compare July 23, 2026 03:29
@Souravrajvi0

Copy link
Copy Markdown
Contributor Author

Thanks for the review — addressed the actionable items in 11c71466 (on top of 0882a8c7 for the backend schema).

Fixed

P1 — Backend loadConfig schema (chat-settings-sheet.tsx)
Added ChatPresetLoadConfig to studio/backend/routes/chat_history.py so PUT /api/chat/settings accepts customPresets[].loadConfig. Verified locally: preset save persists and survives refresh.

P2 — Default load knobs treated as empty (preset-load-config.ts)
capturePresetLoadConfig() now coalesces app-default maxSeqLength (4096) and speculativeType (auto) before save/compare, so built-in Default and legacy presets without loadConfig are not marked dirty on first open.

P2 — No stale hydration replay (chat-runtime-store.ts)
Removed the post-hydration applyPresetLoadConfig(activeDefinition.loadConfig) call. Load settings apply only when the user explicitly selects a preset from the dropdown, not on every refresh.

P2 — Legacy presets skip load reset (chat-settings-sheet.tsx)
applyPreset() now calls applyPresetLoadConfig only when p.loadConfig is present. applyPresetLoadConfig(null) is a no-op, so older sampling-only presets no longer wipe context/KV/GPU settings.

P2 — Preserve GPU pin (preset-load-config.ts)
applyPresetLoadConfig() keeps the current selectedGpuIds instead of passing null, since GPU device selection is intentionally excluded from presets.

Deferred (follow-up)

P2 — Cleared GGUF context vs reuse-current
Agree this is a real edge case (KV-only preset with customContextLength: null may still reuse loaded ggufContextLength on same-model reload). Needs an explicit sentinel or reload-path change; left for a follow-up so this PR stays scoped to #7347.

Manual verification

Playwright flow: load model with ctx 256 + KV q8_0 → save preset → change KV to bf16 + reload → re-apply preset → Run settings shows Active now: Ctx 256 · KV q8_0 (reload still required for the loaded model, as toasts indicate).

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: da5653ec68

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

Copy link
Copy Markdown
Member

Reviewed and verified. Presets did not carry load settings, so restoring a preset lost the load configuration. This includes load settings in presets so restoring a preset reapplies them. Confirmed presets round trip the load settings and simulated save and restore. Codex review has no open items. The remaining red CI is pre-existing upstream breakage unrelated to this change. Good to merge.

@danielhanchen
danielhanchen merged commit 434fac6 into unslothai:main Jul 24, 2026
44 of 45 checks passed
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.

[Feature] [STUDIO] Custom Profiles that includes ALL settings

2 participants