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: follow a same-model MLX reload in the KV width and int8 prefill settings (#14210)

Daniel Han06223a9556b4
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.ts
index c8005d7df4c..16f26e6ef66 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
@@ -243,6 +243,8 @@ export function applyActiveModelStatusToStore(
const supportsTools = status.supports_tools ?? false;
const storedReasoningEnabled = loadOptionalBool(CHAT_REASONING_ENABLED_KEY);
const currentSpecType = normalizeSpeculativeType(status.speculative_type);
+ const incomingMlxKvQuant = normalizeMlxKvQuant(status.mlx_kv_quant_requested);
+ const incomingMlxInt8Prefill = status.mlx_int8_prefill_requested === true;
const prevState = useChatRuntimeStore.getState();
// The chat's own level when the model this replaces was running a per-model pin's: the clamp
// narrows the chat's level to this model's ladder, and a pin is one model's, not the chat's.
@@ -571,22 +573,27 @@ export function applyActiveModelStatusToStore(
status.vision_disabled_by_user !== undefined && {
loadedVisionDisabledByUser: status.vision_disabled_by_user,
}),
- // Hydration only, so a steady poll never rewrites settings the store owns. Width, verdict
- // and request move together; a late reply can overwrite a newer one.
+ // Like kvCacheDtype: baselines and verdict follow a same-model reload, each control only while clean.
...(seedLoadParams &&
- hydratingExistingModel &&
status.mlx_kv_quant_requested !== undefined &&
(status.is_mlx === true
? {
- mlxKvQuant: normalizeMlxKvQuant(status.mlx_kv_quant_requested),
- loadedMlxKvQuantRequested: normalizeMlxKvQuant(status.mlx_kv_quant_requested),
+ loadedMlxKvQuantRequested: incomingMlxKvQuant,
mlxKvQuantReason: status.mlx_kv_quant_reason ?? null,
chatTemplateOverrideReason:
status.chat_template_override_reason ?? null,
mlxKvQuantNote: status.mlx_kv_quant_note ?? null,
- mlxInt8Prefill: status.mlx_int8_prefill_requested === true,
- loadedMlxInt8PrefillRequested:
- status.mlx_int8_prefill_requested === true,
+ loadedMlxInt8PrefillRequested: incomingMlxInt8Prefill,
+ ...((hydratingExistingModel ||
+ (prevState.mlxKvQuant ?? null) ===
+ (prevState.loadedMlxKvQuantRequested ?? null)) && {
+ mlxKvQuant: incomingMlxKvQuant,
+ }),
+ ...((hydratingExistingModel ||
+ prevState.mlxInt8Prefill ===
+ prevState.loadedMlxInt8PrefillRequested) && {
+ mlxInt8Prefill: incomingMlxInt8Prefill,
+ }),
}
: {
// The verdict retires; the editable width is dormant, not wrong.
@@ -596,26 +603,6 @@ export function applyActiveModelStatusToStore(
mlxKvQuantNote: null,
loadedMlxInt8PrefillRequested: false,
})),
- // Recovery for a hydration this tab never saw, and only when nothing is staged: re-seeding
- // over an earlier edit would discard it.
- ...(seedLoadParams &&
- !hydratingExistingModel &&
- status.is_mlx === true &&
- status.mlx_kv_quant_requested !== undefined &&
- prevState.mlxKvQuant === null &&
- prevState.loadedMlxKvQuantRequested === null &&
- prevState.mlxKvQuantReason === null &&
- prevState.chatTemplateOverrideReason === null &&
- !prevState.mlxInt8Prefill && {
- mlxKvQuant: normalizeMlxKvQuant(status.mlx_kv_quant_requested),
- loadedMlxKvQuantRequested: normalizeMlxKvQuant(status.mlx_kv_quant_requested),
- mlxKvQuantReason: status.mlx_kv_quant_reason ?? null,
- chatTemplateOverrideReason: status.chat_template_override_reason ?? null,
- mlxKvQuantNote: status.mlx_kv_quant_note ?? null,
- mlxInt8Prefill: status.mlx_int8_prefill_requested === true,
- loadedMlxInt8PrefillRequested:
- status.mlx_int8_prefill_requested === true,
- }),
// Baseline only, never the control: the echo is the RESOLVED count and would pin a blank
...(seedLoadParams &&
status.requested_parallel_slots != null && {
diff --git a/studio/frontend/tests/same-model-reload-load-settings.test.ts b/studio/frontend/tests/same-model-reload-load-settings.test.ts
new file mode 100644
index 00000000000..39dbacf5bab
--- /dev/null
+++ b/studio/frontend/tests/same-model-reload-load-settings.test.ts
@@ -0,0 +1,161 @@
+// 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 } from "./helpers/kit.ts";
+
+installLocalStorageFake();
+register("./store-settings-resolver.mjs", import.meta.url);
+
+const { useChatRuntimeStore } = await import(
+ "../src/features/chat/stores/chat-runtime-store.ts"
+);
+const { applyActiveModelStatusToStore } = await import(
+ "../src/features/chat/lib/apply-inference-status-to-store.ts"
+);
+
+const GGUF = "unsloth/Qwen3-0.6B-GGUF";
+const MLX = "mlx-community/Qwen3.5-2B-4bit";
+
+function hydrate(status: Record<string, unknown>, model: string): void {
+ useChatRuntimeStore.setState({
+ modelLoading: false,
+ params: { ...useChatRuntimeStore.getState().params, checkpoint: "" },
+ });
+ applyActiveModelStatusToStore(status as never, { previousCheckpoint: "" });
+ useChatRuntimeStore.setState({
+ params: { ...useChatRuntimeStore.getState().params, checkpoint: model },
+ });
+}
+
+function reload(status: Record<string, unknown>, model: string): void {
+ applyActiveModelStatusToStore(status as never, { previousCheckpoint: model });
+}
+
+function ggufStatus(over: Record<string, unknown>) {
+ return {
+ active_model: GGUF,
+ model_identifier: GGUF,
+ is_gguf: true,
+ gguf_variant: "Q8_0",
+ cache_type_kv: "f16",
+ tensor_parallel: false,
+ spec_draft_n_max: 16,
+ speculative_type: "ngram-mod",
+ chat_template_override: null,
+ ...over,
+ };
+}
+
+function mlxStatus(over: Record<string, unknown>) {
+ return {
+ active_model: MLX,
+ model_identifier: MLX,
+ is_gguf: false,
+ is_mlx: true,
+ gguf_variant: null,
+ mlx_kv_quant_requested: null,
+ mlx_kv_quant_reason: null,
+ mlx_kv_quant_note: null,
+ chat_template_override_reason: null,
+ mlx_int8_prefill_requested: false,
+ ...over,
+ };
+}
+
+test("a same-model GGUF reload elsewhere moves every clean control and baseline", () => {
+ useChatRuntimeStore.setState({ activeGgufVariant: "Q8_0" });
+ hydrate(ggufStatus({}), GGUF);
+ reload(
+ ggufStatus({
+ cache_type_kv: "q8_0",
+ tensor_parallel: true,
+ spec_draft_n_max: 32,
+ speculative_type: "off",
+ chat_template_override: "{{ messages }}",
+ }),
+ GGUF,
+ );
+ const s = useChatRuntimeStore.getState();
+ assert.deepEqual(
+ [s.kvCacheDtype, s.tensorParallel, s.specDraftNMax, s.speculativeType, s.chatTemplateOverride],
+ ["q8_0", true, 32, "off", "{{ messages }}"],
+ );
+ assert.deepEqual(
+ [
+ s.loadedKvCacheDtype,
+ s.loadedTensorParallel,
+ s.loadedSpecDraftNMax,
+ s.loadedSpeculativeType,
+ s.loadedChatTemplateOverride,
+ ],
+ ["q8_0", true, 32, "off", "{{ messages }}"],
+ );
+});
+
+test("a same-model MLX reload elsewhere moves the KV width, int8 prefill and verdict", () => {
+ useChatRuntimeStore.setState({ activeGgufVariant: null });
+ hydrate(mlxStatus({}), MLX);
+ reload(
+ mlxStatus({
+ mlx_kv_quant_requested: "8",
+ mlx_kv_quant_reason: "Quantized KV cache to 8 bits",
+ mlx_kv_quant_note: "from token 256",
+ mlx_int8_prefill_requested: true,
+ }),
+ MLX,
+ );
+ const s = useChatRuntimeStore.getState();
+ assert.equal(s.mlxKvQuant, "8", "the clean control follows the resident");
+ assert.equal(s.loadedMlxKvQuantRequested, "8", "the baseline describes the resident");
+ assert.equal(s.mlxKvQuantReason, "Quantized KV cache to 8 bits");
+ assert.equal(s.mlxKvQuantNote, "from token 256");
+ assert.equal(s.mlxInt8Prefill, true);
+ assert.equal(s.loadedMlxInt8PrefillRequested, true);
+});
+
+test("a same-model MLX reload elsewhere moves a width that was already seeded", () => {
+ useChatRuntimeStore.setState({ activeGgufVariant: null });
+ hydrate(
+ mlxStatus({
+ mlx_kv_quant_requested: "8",
+ mlx_kv_quant_reason: "Quantized KV cache to 8 bits",
+ }),
+ MLX,
+ );
+ reload(
+ mlxStatus({
+ mlx_kv_quant_requested: "4",
+ mlx_kv_quant_reason: "Quantized KV cache to 4 bits",
+ }),
+ MLX,
+ );
+ const s = useChatRuntimeStore.getState();
+ assert.equal(s.mlxKvQuant, "4");
+ assert.equal(s.loadedMlxKvQuantRequested, "4");
+ assert.equal(s.mlxKvQuantReason, "Quantized KV cache to 4 bits");
+});
+
+test("a same-model MLX reload keeps a value this tab staged but advances the baseline", () => {
+ useChatRuntimeStore.setState({ activeGgufVariant: null });
+ hydrate(mlxStatus({ mlx_kv_quant_requested: "8" }), MLX);
+ useChatRuntimeStore.setState({ mlxKvQuant: "4" });
+ reload(mlxStatus({ mlx_kv_quant_requested: null }), MLX);
+ const s = useChatRuntimeStore.getState();
+ assert.equal(s.mlxKvQuant, "4");
+ assert.equal(s.loadedMlxKvQuantRequested, null);
+});
+
+test("a steady MLX poll leaves a staged value alone", () => {
+ useChatRuntimeStore.setState({ activeGgufVariant: null });
+ hydrate(mlxStatus({ mlx_kv_quant_requested: "8" }), MLX);
+ useChatRuntimeStore.setState({ mlxKvQuant: "4", mlxInt8Prefill: true });
+ reload(mlxStatus({ mlx_kv_quant_requested: "8" }), MLX);
+ const s = useChatRuntimeStore.getState();
+ assert.equal(s.mlxKvQuant, "4");
+ assert.equal(s.mlxInt8Prefill, true);
+ assert.equal(s.loadedMlxKvQuantRequested, "8");
+});