Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: run each Compare model with its own recommended sampling (#16686)

Nilayf7e499a349cb
diff --git a/studio/frontend/src/features/chat/shared-composer.tsx b/studio/frontend/src/features/chat/shared-composer.tsx
index 172d764302d..734367365b0 100644
--- a/studio/frontend/src/features/chat/shared-composer.tsx
+++ b/studio/frontend/src/features/chat/shared-composer.tsx
@@ -53,6 +53,7 @@ import {
} from "@/components/ui/dropdown-menu";
import { NonModalDropdownMenu } from "@/components/ui/non-modal-dropdown-menu";
import { applyQwenThinkingParams } from "@/features/chat/utils/qwen-params";
+import { resolveQwenThinkingParams } from "./utils/qwen-sampling-table";
import { FIND_SKIP_ATTRIBUTE } from "@/features/find-in-page";
import {
DRAFT_N_MAX_SPEC_TYPES,
@@ -195,6 +196,7 @@ import {
} from "./compare-run-ownership";
import {
loadedContextForParams,
+ mergeBackendRecommendedInference,
resolveExplicitCtxPin,
resolveFitMaxSeqLength,
retainedContextPin,
@@ -1964,17 +1966,48 @@ export function SharedComposer({
}
upgradeUnloadedActive = false;
const store = useChatRuntimeStore.getState();
+ const paneMaxTokensCap = replayMaxTokensCap(
+ loadedContextFields(resp).loadedContextLength ??
+ (!resp.is_gguf && effectiveMaxSeqLength > 0
+ ? effectiveMaxSeqLength
+ : null),
+ );
store.setCheckpoint(
resp.model,
resp.is_gguf ? (sel.ggufVariant ?? undefined) : null,
+ { maxTokensCap: paneMaxTokensCap },
+ );
+ const paneState = useChatRuntimeStore.getState();
+ const paneParams = paneState.params;
+ const paneQwenParams =
+ resp.supports_reasoning &&
+ paneState.activePresetSource === "builtin-default"
+ ? resolveQwenThinkingParams(
+ resp.model,
+ (resp.reasoning_always_on ?? false) || paneState.reasoningEnabled,
+ )
+ : null;
+ store.setParams(
{
- maxTokensCap: replayMaxTokensCap(
- loadedContextFields(resp).loadedContextLength ??
- (!resp.is_gguf && effectiveMaxSeqLength > 0
- ? effectiveMaxSeqLength
- : null),
- ),
+ ...mergeBackendRecommendedInference({
+ current: paneParams,
+ response: resp,
+ modelId: resp.model,
+ presetSource: paneState.activePresetSource,
+ loadedContextLength: loadedContextFields(resp).loadedContextLength,
+ }),
+ ...paneQwenParams,
+ ...(targetIsGguf
+ ? {}
+ : {
+ maxSeqLength: loadedContextForParams(
+ loadedContextFields(resp).loadedContextLength,
+ effectiveMaxSeqLength,
+ paneParams.maxSeqLength,
+ ),
+ }),
},
+ { fromModelDefaults: true, maxTokensCap: paneMaxTokensCap },
);
store.setModelRequiresTrustRemoteCode(
resp.requires_trust_remote_code ?? false,
@@ -2079,17 +2112,6 @@ export function SharedComposer({
activeNativePathExpiresAtMs: null,
...resolveLoadedSpeculativeSettings(resp),
});
- if (!targetIsGguf) {
- const paneParams = useChatRuntimeStore.getState().params;
- store.setParams({
- ...paneParams,
- maxSeqLength: loadedContextForParams(
- loadedContextFields(resp).loadedContextLength,
- effectiveMaxSeqLength,
- paneParams.maxSeqLength,
- ),
- });
- }
loadedFromConfig = config != null;
// /api/models/list can lag the model's actual state.
const currentModels = useChatRuntimeStore.getState().models;
diff --git a/studio/frontend/tests/compare-pane-model-defaults.test.ts b/studio/frontend/tests/compare-pane-model-defaults.test.ts
new file mode 100644
index 00000000000..c4923cbb3b8
--- /dev/null
+++ b/studio/frontend/tests/compare-pane-model-defaults.test.ts
@@ -0,0 +1,193 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import assert from "node:assert/strict";
+import { register } from "node:module";
+import test from "node:test";
+
+import { installLocalStorageFake, readSrc } from "./helpers/kit.ts";
+
+const { store: localStorageFake } = installLocalStorageFake();
+localStorageFake.set("unsloth_chat_settings_imported_to_studio_db", "true");
+register("./store-settings-resolver.mjs", import.meta.url);
+
+const { settingsHttp, deepMerge } = await import(
+ "./helpers/store-stubs/settings-http.ts"
+);
+const { useChatRuntimeStore } = await import(
+ "../src/features/chat/stores/chat-runtime-store.ts"
+);
+const {
+ loadedContextForParams,
+ mergeBackendRecommendedInference,
+ replayMaxTokensCap,
+} = await import("../src/features/chat/presets/preset-policy.ts");
+const { resolveQwenThinkingParams } = await import(
+ "../src/features/chat/utils/qwen-sampling-table.ts"
+);
+const { loadedContextFields } = await import(
+ "../src/features/model-picker/model-config/per-model-config.ts"
+);
+
+const QWEN = "unsloth/Qwen3-0.6B-GGUF";
+const GEMMA = "unsloth/gemma-3-270m-it-GGUF";
+const QWEN35 = "unsloth/Qwen3.5-27B-GGUF";
+const CONTEXT = 32768;
+const REQUESTED_CONTEXT = 4096;
+const RECOMMENDED: Record<string, { temperature: number; top_p: number; top_k: number }> = {
+ [QWEN]: { temperature: 0.6, top_p: 0.95, top_k: 20 },
+ [GEMMA]: { temperature: 1, top_p: 0.95, top_k: 64 },
+ [QWEN35]: { temperature: 0.7, top_p: 0.8, top_k: 20 },
+};
+
+const composer = readSrc("features/chat/shared-composer.tsx");
+const loadAt = composer.indexOf("const resp = await loadModel(");
+const start = composer.indexOf("upgradeUnloadedActive = false;", loadAt);
+const end = composer.indexOf("store.setModelRequiresTrustRemoteCode(", start);
+assert.ok(loadAt >= 0 && start > loadAt && end > start);
+const commitPaneLoad = new Function(
+ "useChatRuntimeStore",
+ "resp",
+ "sel",
+ "targetIsGguf",
+ "effectiveMaxSeqLength",
+ "loadedContextFields",
+ "replayMaxTokensCap",
+ "mergeBackendRecommendedInference",
+ "loadedContextForParams",
+ "resolveQwenThinkingParams",
+ `let upgradeUnloadedActive; ${composer.slice(start, end)}`,
+);
+
+function response(model: string, gguf = true) {
+ return {
+ status: "loaded",
+ model,
+ supports_reasoning: model === QWEN35,
+ is_gguf: gguf,
+ context_length: CONTEXT,
+ inference: RECOMMENDED[model],
+ };
+}
+
+function pickerLoad(model: string): void {
+ const store = useChatRuntimeStore.getState();
+ store.setParams(
+ mergeBackendRecommendedInference({
+ current: store.params,
+ response: response(model),
+ modelId: model,
+ presetSource: store.activePresetSource,
+ loadedContextLength: CONTEXT,
+ }),
+ { fromModelDefaults: true, maxTokensCap: CONTEXT },
+ );
+ store.setCheckpoint(model, "Q4_K_M");
+}
+
+function compareLoad(model: string, gguf = true): void {
+ commitPaneLoad(
+ useChatRuntimeStore,
+ response(model, gguf),
+ { id: model, ggufVariant: gguf ? "Q4_K_M" : null },
+ gguf,
+ gguf ? 0 : REQUESTED_CONTEXT,
+ loadedContextFields,
+ replayMaxTokensCap,
+ mergeBackendRecommendedInference,
+ loadedContextForParams,
+ resolveQwenThinkingParams,
+ );
+}
+
+function sampling() {
+ const { temperature, topP, topK } = useChatRuntimeStore.getState().params;
+ return { temperature, topP, topK };
+}
+
+function stored(): Record<string, Record<string, unknown>> {
+ const settings = settingsHttp.puts.reduce(
+ (merged, put) => deepMerge(merged, put),
+ settingsHttp.settings,
+ );
+ return (settings.inferenceParamsByModel ?? {}) as Record<string, Record<string, unknown>>;
+}
+
+async function settled(): Promise<void> {
+ await new Promise((resolve) => setTimeout(resolve, 600));
+}
+
+test.before(async () => {
+ settingsHttp.settings = {};
+ await useChatRuntimeStore.getState().hydratePersistedSettings();
+ assert.equal(useChatRuntimeStore.getState().rememberParamsPerModel, true);
+ assert.equal(useChatRuntimeStore.getState().activePresetSource, "builtin-default");
+});
+
+test.beforeEach(() => {
+ useChatRuntimeStore.getState().clearCheckpoint();
+ useChatRuntimeStore.setState({ paramsByModel: {} });
+ settingsHttp.settings = {};
+ settingsHttp.puts = [];
+});
+
+test("a compare pane model runs with its own recommended sampling", async () => {
+ pickerLoad(QWEN);
+ assert.deepEqual(sampling(), { temperature: 0.6, topP: 0.95, topK: 20 });
+
+ compareLoad(GEMMA);
+ assert.deepEqual(sampling(), { temperature: 1, topP: 0.95, topK: 64 });
+
+ compareLoad(QWEN);
+ assert.deepEqual(sampling(), { temperature: 0.6, topP: 0.95, topK: 20 });
+
+ const byModel = useChatRuntimeStore.getState().paramsByModel;
+ assert.equal(byModel[GEMMA]?.temperature, 1);
+ assert.equal(byModel[GEMMA]?.topK, 64);
+ await settled();
+ assert.equal(stored()[GEMMA]?.temperature, 1);
+ assert.equal(stored()[GEMMA]?.topK, 64);
+
+ pickerLoad(GEMMA);
+ assert.deepEqual(sampling(), { temperature: 1, topP: 0.95, topK: 64 });
+});
+
+test("a compare pane model keeps its remembered sampling over the recommendation", () => {
+ useChatRuntimeStore.setState({
+ paramsByModel: { [GEMMA]: { temperature: 0.4, topK: 30 } },
+ });
+ pickerLoad(QWEN);
+ compareLoad(GEMMA);
+ assert.equal(sampling().temperature, 0.4);
+ assert.equal(sampling().topK, 30);
+ compareLoad(QWEN);
+ assert.deepEqual(sampling(), { temperature: 0.6, topP: 0.95, topK: 20 });
+ assert.equal(useChatRuntimeStore.getState().paramsByModel[GEMMA]?.temperature, 0.4);
+});
+
+test("a non-GGUF compare pane load takes its sampling and context without filing an entry", async () => {
+ pickerLoad(QWEN);
+ compareLoad(GEMMA, false);
+ assert.deepEqual(sampling(), { temperature: 1, topP: 0.95, topK: 64 });
+ assert.equal(useChatRuntimeStore.getState().params.maxSeqLength, REQUESTED_CONTEXT);
+ assert.equal(useChatRuntimeStore.getState().paramsByModel[GEMMA], undefined);
+
+ compareLoad(QWEN, false);
+ assert.deepEqual(sampling(), { temperature: 0.6, topP: 0.95, topK: 20 });
+ await settled();
+ assert.equal(stored()[GEMMA]?.temperature, 1);
+ assert.equal(stored()[GEMMA]?.topK, 64);
+});
+
+test("a compare pane Qwen model gets the sampling for the active thinking mode", () => {
+ pickerLoad(GEMMA);
+ useChatRuntimeStore.setState({ reasoningEnabled: true });
+ compareLoad(QWEN35);
+ assert.deepEqual(sampling(), { temperature: 0.6, topP: 0.95, topK: 20 });
+
+ compareLoad(GEMMA);
+ useChatRuntimeStore.setState({ reasoningEnabled: false });
+ useChatRuntimeStore.setState({ paramsByModel: {} });
+ compareLoad(QWEN35);
+ assert.deepEqual(sampling(), { temperature: 0.7, topP: 0.8, topK: 20 });
+});
diff --git a/studio/frontend/tests/per-model-params-hydration.test.ts b/studio/frontend/tests/per-model-params-hydration.test.ts
index 3ebf2b02bd8..27b927e83a5 100644
--- a/studio/frontend/tests/per-model-params-hydration.test.ts
+++ b/studio/frontend/tests/per-model-params-hydration.test.ts
@@ -530,7 +530,7 @@ test("a remembered budget is capped by a non-GGUF load", () => {
const composer = readSrc("features/chat/shared-composer.tsx");
assert.match(
composer,
- /maxTokensCap: replayMaxTokensCap\(\s*loadedContextFields\(resp\)\.loadedContextLength \?\?\s*\(!resp\.is_gguf && effectiveMaxSeqLength > 0/,
+ /const paneMaxTokensCap = replayMaxTokensCap\(\s*loadedContextFields\(resp\)\.loadedContextLength \?\?\s*\(!resp\.is_gguf && effectiveMaxSeqLength > 0/,
);
const status = readSrc("features/chat/lib/apply-inference-status-to-store.ts");