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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Fix Qwen3.8 presence penalty defaults (#9372)
Lee Jackson9574476ba6ce
diff --git a/studio/backend/assets/configs/inference_defaults.json b/studio/backend/assets/configs/inference_defaults.jsonindex 6a6b2d4d09f..31358b02074 100644--- a/studio/backend/assets/configs/inference_defaults.json+++ b/studio/backend/assets/configs/inference_defaults.json@@ -1,6 +1,14 @@{"_comment": "Per-model-family inference parameter defaults. Sources: (1) Ollama params blobs, (2) Existing Unsloth Studio YAML configs. Patterns ordered longest-match-first.","families": {+ "qwen3.8": {+ "temperature": 0.7,+ "top_p": 0.8,+ "top_k": 20,+ "min_p": 0.0,+ "repetition_penalty": 1.0,+ "presence_penalty": 1.5+ },"qwen3.6": {"temperature": 0.7,"top_p": 0.8,@@ -405,7 +413,7 @@}},"patterns": [- "qwen3.6", "qwen3.5",+ "qwen3.8", "qwen3.6", "qwen3.5","qwen3-coder", "qwen3-next", "qwen3-vl", "qwen3","qwen2.5-coder", "qwen2.5-vl", "qwen2.5-omni", "qwen2.5-math", "qwen2.5","qwen2-vl", "qwen2",diff --git a/studio/backend/tests/test_sampling_resolution.py b/studio/backend/tests/test_sampling_resolution.pyindex 1ebbae2502f..7c6c1dd0044 100644--- a/studio/backend/tests/test_sampling_resolution.py+++ b/studio/backend/tests/test_sampling_resolution.py@@ -110,6 +110,21 @@ def test_recommendation_matches_ui_source(model):assert rec.get(f) == cleaned, f"{model}:{f} rec={rec.get(f)} ui={ui.get(f)}"+def test_qwen38_reuses_qwen36_sampling_defaults():+ qwen36 = ic.load_inference_config("unsloth/Qwen3.6-27B-GGUF")+ qwen38 = ic.load_inference_config("unsloth/Qwen3.8-27B-GGUF")++ assert qwen38 == qwen36+ assert qwen38 == {+ "temperature": 0.7,+ "top_p": 0.8,+ "top_k": 20,+ "min_p": 0.0,+ "presence_penalty": 1.5,+ "trust_remote_code": False,+ }++def test_repetition_penalty_not_auto_recommended(monkeypatch):# The Chat UI's mergeBackendRecommendedInference never adopts a backend repetition_penalty# (e.g. lfm2's family value 1.05), so the server must not auto-apply one either. It stays atdiff --git a/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts b/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.tsindex 24598539a95..d35de359f45 100644--- a/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts+++ b/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts@@ -81,6 +81,7 @@ import {} from "../presets/preset-policy";import { recordLastLocalModelLoad } from "../utils/last-local-model-load";import { loadFallbackNotice } from "../utils/mmproj-fallback";+import { resolveQwenThinkingParams } from "../utils/qwen-params";import { refreshContextUsage } from "../utils/refresh-context-usage";import { ensureGpuDeviceCache } from "@/hooks/use-gpu-info";import {@@ -1760,35 +1761,17 @@ export function useChatModelRuntime() {});// Unlock attach menus for capabilities the catalog entry lacked.syncModelCapabilities(modelId, loadResponse);- // Qwen3/3.5/3.6: apply thinking-mode-specific params after load+ // Qwen3-family: apply thinking-mode-specific params after load.+ const p = resolveQwenThinkingParams(+ modelId,+ nextReasoningEnabled,+ );if (- modelId.toLowerCase().includes("qwen3") &&+ p !== null &&(loadResponse.supports_reasoning ?? false)) {const store = useChatRuntimeStore.getState();if (store.activePresetSource === "builtin-default") {- const mid = modelId.toLowerCase();- const needsPresencePenalty =- mid.includes("qwen3.5") || mid.includes("qwen3.6");- const p = nextReasoningEnabled- ? {- temperature: 0.6,- topP: 0.95,- topK: 20,- minP: 0.0,- ...(needsPresencePenalty- ? { presencePenalty: 1.5 }- : {}),- }- : {- temperature: 0.7,- topP: 0.8,- topK: 20,- minP: 0.0,- ...(needsPresencePenalty- ? { presencePenalty: 1.5 }- : {}),- };// Same rule as the load response: defaults first, this model's// remembered settings over them.store.setParams({ ...store.params, ...p }, {diff --git a/studio/frontend/src/features/chat/lib/apply-inference-status-to-store.ts b/studio/frontend/src/features/chat/lib/apply-inference-status-to-store.tsindex cec1f43fb16..a417ae919fc 100644--- a/studio/frontend/src/features/chat/lib/apply-inference-status-to-store.ts+++ b/studio/frontend/src/features/chat/lib/apply-inference-status-to-store.ts@@ -28,6 +28,7 @@ import {isMultimodalResponse,} from "../types/api";import type { ChatModelSummary } from "../types/runtime";+import { resolveQwenThinkingParams } from "../utils/qwen-params";import { sameGpuSelection } from "@/hooks/gpu-selection";import { resolveBatchSizeSeed } from "./resolve-batch-size-seed";import { resolveChatTemplateSeed } from "./resolve-chat-template-seed";@@ -569,6 +570,28 @@ export function applyActiveModelStatusToStore(}useChatRuntimeStore.setState({ reasoningEnabled: reasoningDefault });}++ // Every status merge carries the base family recommendation, including the+ // refresh immediately after performLoad. Layer the active Qwen mode over it+ // so that refresh cannot undo performLoad's thinking table. This also covers+ // startup/CLI/external adoption, while model memory still wins because this+ // remains a defaults update.+ if (status.inference && supportsReasoning) {+ const current = useChatRuntimeStore.getState();+ const qwenParams = resolveQwenThinkingParams(+ checkpointId,+ reasoningAlwaysOn || current.reasoningEnabled,+ );+ if (qwenParams !== null && current.activePresetSource === "builtin-default") {+ current.setParams(+ { ...current.params, ...qwenParams },+ {+ fromModelDefaults: true,+ maxTokensCap: status.context_length ?? undefined,+ },+ );+ }+ }}/**diff --git a/studio/frontend/src/features/chat/utils/qwen-params.ts b/studio/frontend/src/features/chat/utils/qwen-params.tsindex b4d48d8df43..5a3601984e6 100644--- a/studio/frontend/src/features/chat/utils/qwen-params.ts+++ b/studio/frontend/src/features/chat/utils/qwen-params.ts@@ -3,10 +3,38 @@import { useChatRuntimeStore } from "../stores/chat-runtime-store";+export type QwenThinkingParams = {+ temperature: number;+ topP: number;+ topK: number;+ minP: number;+ presencePenalty?: number;+};++/** Resolve the sampling table shared by model load and the Think toggle. */+export function resolveQwenThinkingParams(+ checkpoint: string,+ thinkingOn: boolean,+): QwenThinkingParams | null {+ const normalized = checkpoint.toLowerCase();+ if (!normalized.includes("qwen3")) {+ return null;+ }++ const needsPresencePenalty =+ normalized.includes("qwen3.5") ||+ normalized.includes("qwen3.6") ||+ normalized.includes("qwen3.8");+ const base = thinkingOn+ ? { temperature: 0.6, topP: 0.95, topK: 20, minP: 0.0 }+ : { temperature: 0.7, topP: 0.8, topK: 20, minP: 0.0 };+ return needsPresencePenalty ? { ...base, presencePenalty: 1.5 } : base;+}+/*** Apply Qwen3-family recommended sampling parameters when the Think toggle- * changes. Qwen3.5 and Qwen3.6 also need a presence_penalty bump on top of- * the Qwen3 defaults.+ * changes. Qwen3.5, Qwen3.6, and Qwen3.8 also need a presence_penalty bump on+ * top of the Qwen3 defaults.** Used by both the thread assistant UI and the shared chat composer so the* two call sites stay in sync.@@ -14,20 +42,10 @@ import { useChatRuntimeStore } from "../stores/chat-runtime-store";export function applyQwenThinkingParams(thinkingOn: boolean): void {const store = useChatRuntimeStore.getState();const checkpoint = store.params.checkpoint?.toLowerCase() ?? "";- if (- !checkpoint.includes("qwen3") ||- store.activePresetSource !== "builtin-default"- ) {+ const params = resolveQwenThinkingParams(checkpoint, thinkingOn);+ if (params === null || store.activePresetSource !== "builtin-default") {return;}- const needsPresencePenalty =- checkpoint.includes("qwen3.5") || checkpoint.includes("qwen3.6");- const base = thinkingOn- ? { temperature: 0.6, topP: 0.95, topK: 20, minP: 0.0 }- : { temperature: 0.7, topP: 0.8, topK: 20, minP: 0.0 };- const params = needsPresencePenalty- ? { ...base, presencePenalty: 1.5 }- : base;// Deliberately unmarked, unlike the post-load path applying the same table: the// user asked for this mode here, so it must land even on a chat pinning sampling.store.setParams({ ...store.params, ...params });diff --git a/studio/frontend/tests/qwen38-sampling-defaults.test.ts b/studio/frontend/tests/qwen38-sampling-defaults.test.tsnew file mode 100644index 00000000000..36a689a09f3--- /dev/null+++ b/studio/frontend/tests/qwen38-sampling-defaults.test.ts@@ -0,0 +1,74 @@+// 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 { readFileSync } from "node:fs";+import { register } from "node:module";+import test from "node:test";++import { installLocalStorageFake } from "./helpers/kit.ts";++installLocalStorageFake();+register("./store-settings-resolver.mjs", import.meta.url);++const { applyQwenThinkingParams, resolveQwenThinkingParams } = await import(+ "../src/features/chat/utils/qwen-params.ts"+);+const { useChatRuntimeStore } = await import(+ "../src/features/chat/stores/chat-runtime-store.ts"+);++test("Qwen3.8 reuses the Qwen3.6 sampling table in both modes", () => {+ for (const thinkingOn of [true, false]) {+ const qwen36 = resolveQwenThinkingParams(+ "unsloth/Qwen3.6-27B-GGUF",+ thinkingOn,+ );+ const qwen38 = resolveQwenThinkingParams(+ "unsloth/Qwen3.8-27B-GGUF",+ thinkingOn,+ );++ assert.deepEqual(qwen38, qwen36);+ assert.equal(qwen38?.presencePenalty, 1.5);+ }+});++test("the Qwen3.8 Think toggle puts 1.5 in the live chat settings", () => {+ for (const thinkingOn of [true, false]) {+ const store = useChatRuntimeStore.getState();+ useChatRuntimeStore.setState({+ params: {+ ...store.params,+ checkpoint: "unsloth/Qwen3.8-27B-GGUF",+ presencePenalty: 0.0,+ },+ activePresetSource: "builtin-default",+ });++ applyQwenThinkingParams(thinkingOn);++ assert.equal(useChatRuntimeStore.getState().params.presencePenalty, 1.5);+ }+});++test("every status merge is wired to the active Qwen thinking table", () => {+ const source = readFileSync(+ new URL(+ "../src/features/chat/lib/apply-inference-status-to-store.ts",+ import.meta.url,+ ),+ "utf8",+ );+ assert.match(+ source,+ /if \(status\.inference && supportsReasoning\) \{[\s\S]*?resolveQwenThinkingParams\(\s*checkpointId,\s*reasoningAlwaysOn \|\| current\.reasoningEnabled,\s*\)/,+ );+});++test("Qwen3.8 does not change the generic Qwen3 presence penalty", () => {+ assert.equal(+ resolveQwenThinkingParams("unsloth/Qwen3-8B-GGUF", true)?.presencePenalty,+ undefined,+ );+});