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: let Run settings load a Hugging Face model in 16-bit (#13841)

Daniel Hanbebba39ac35d
diff --git a/studio/backend/routes/settings.py b/studio/backend/routes/settings.py
index 2069743aafc..6639c678eb8 100644
--- a/studio/backend/routes/settings.py
+++ b/studio/backend/routes/settings.py
@@ -1048,6 +1048,8 @@ class ModelOverridePayload(BaseModel):
tensor_parallel: bool = False
disable_vision: bool = False
mlx_int8_prefill: bool = False
+ # Default-engine 16-bit load; only False is stored.
+ load_in_4bit: bool = True
# Validated in bytes below: pydantic counts characters, so a multi-byte template would pass.
chat_template_override: Optional[str] = None
gpu_memory_mode: Optional[Literal["auto", "manual"]] = None
@@ -2644,10 +2646,12 @@ def update_openai_auto_switch_override(
not payload.tensor_parallel
and not payload.disable_vision
and not payload.mlx_int8_prefill
+ and payload.load_in_4bit
and not {
key: value
for key, value in saved_fields.items()
- if key not in ("tensor_parallel", "disable_vision", "mlx_int8_prefill")
+ if key
+ not in ("tensor_parallel", "disable_vision", "mlx_int8_prefill", "load_in_4bit")
}
)
if requested_extra_args is None and not is_removal:
@@ -2880,6 +2884,7 @@ def update_openai_auto_switch_override(
tensor_parallel = payload.tensor_parallel,
disable_vision = payload.disable_vision,
mlx_int8_prefill = payload.mlx_int8_prefill,
+ load_in_4bit = payload.load_in_4bit,
chat_template_override = payload.chat_template_override,
gpu_memory_mode = payload.gpu_memory_mode,
gpu_layers = payload.gpu_layers,
diff --git a/studio/backend/tests/test_load_in_4bit_override.py b/studio/backend/tests/test_load_in_4bit_override.py
new file mode 100644
index 00000000000..0591d841cf5
--- /dev/null
+++ b/studio/backend/tests/test_load_in_4bit_override.py
@@ -0,0 +1,47 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
+
+"""The Run settings "Load in 4-bit" switch (#5639): a 16-bit choice is remembered per model and
+reaches every load that rebuilds the picker's request, while an untouched model stores nothing."""
+
+import sys
+from pathlib import Path
+
+sys.path.insert(0, str(Path(__file__).resolve().parent))
+
+import utils.openai_auto_switch_settings as settings # noqa: E402
+from models.inference import LoadRequest # noqa: E402
+from test_openai_auto_switch import _mock_override_store, _put # noqa: E402
+
+DEFAULTS = {"engine": "auto", "engine_precision": "auto", "engine_parallelism": "tensor"}
+
+
+def test_a_16_bit_choice_is_stored_and_turning_it_back_on_clears_it(monkeypatch):
+ _mock_override_store(monkeypatch)
+ _put("org/m", load_in_4bit = False, **DEFAULTS)
+ assert settings.get_model_override("org/m") == {"load_in_4bit": False}
+ _put("org/m", load_in_4bit = True, **DEFAULTS)
+ assert "org/m" not in settings.get_model_overrides()
+
+
+def test_an_older_client_that_never_sends_the_field_stores_nothing(monkeypatch):
+ _mock_override_store(monkeypatch)
+ _put("org/m", max_seq_length = 8192, **DEFAULTS)
+ assert "load_in_4bit" not in settings.get_model_override("org/m")
+
+
+def test_a_saved_16_bit_choice_reaches_the_load_request():
+ kwargs = settings.model_override_load_kwargs({"load_in_4bit": False}, is_gguf = False)
+ assert kwargs == {"load_in_4bit": False}
+ assert LoadRequest(model_path = "org/m", **kwargs).load_in_4bit is False
+ assert LoadRequest(model_path = "org/m").load_in_4bit is True
+
+
+def test_gguf_and_optional_engines_are_unaffected():
+ assert "load_in_4bit" not in settings.model_override_load_kwargs(
+ {"load_in_4bit": False}, is_gguf = True
+ )
+ kwargs = settings.model_override_load_kwargs(
+ {"engine": "vllm", "engine_precision": "int4"}, is_gguf = False
+ )
+ assert kwargs["load_in_4bit"] is False and kwargs["engine_precision"] == "int4"
diff --git a/studio/backend/utils/openai_auto_switch_settings.py b/studio/backend/utils/openai_auto_switch_settings.py
index ee2f8253b2a..b45fb47e6d6 100644
--- a/studio/backend/utils/openai_auto_switch_settings.py
+++ b/studio/backend/utils/openai_auto_switch_settings.py
@@ -547,6 +547,10 @@ def normalize_model_override(
if _coerce_bool(payload.get("mlx_int8_prefill")):
entry["mlx_int8_prefill"] = True
+ # Stored only when off: absent is the 4-bit default, so an untouched model follows it.
+ if payload.get("load_in_4bit") is False:
+ entry["load_in_4bit"] = False
+
# Stored only when set. Like tensor_parallel: absent means the default, so an override that never touched the switch does not pin it off for a later load.
if _coerce_bool(payload.get("disable_vision")):
entry["disable_vision"] = True
@@ -655,6 +659,8 @@ def model_override_load_kwargs(override: dict[str, Any], *, is_gguf: bool) -> di
kwargs["load_in_4bit"] = False
if override.get("gpu_ids") is not None:
kwargs["gpu_ids"] = override["gpu_ids"]
+ elif not is_gguf and override.get("load_in_4bit") is False:
+ kwargs["load_in_4bit"] = False
max_seq_length = resolve_fit_max_seq_length(override, is_gguf = is_gguf)
if max_seq_length is not None:
diff --git a/studio/frontend/scripts/check-bundle-budget.ts b/studio/frontend/scripts/check-bundle-budget.ts
index f128b55a5de..521941bc72b 100644
--- a/studio/frontend/scripts/check-bundle-budget.ts
+++ b/studio/frontend/scripts/check-bundle-budget.ts
@@ -163,8 +163,12 @@ export const BUDGET = {
// Drafter training in the Train tab adds about 4.9 KB raw / 1.4 KB transfer (6,628.3 KB raw, 1,992.9 KB transfer
// measured against cd424654a, one machine and build, 95 chunks): its persisted training-store fields, their
// migration and the en strings hydrate at startup; the section itself is not in the startup set.
- transferBytes: 2_041_000,
- rawBytes: 6_787_500,
+ // The Run settings Load in 4-bit switch (#13841: the per-model field threaded through every chat load path and
+ // the resident-config check) adds 1,448 B raw / 433 B transfer, inline in the eager chat chunk (6,787,367 ->
+ // 6,788,815 B raw, 2,040,805 -> 2,041,238 B transfer against 4494fa58c, one machine and build, Node 24, chunk
+ // count unchanged at 95). Raised by that growth.
+ transferBytes: 2_041_433,
+ rawBytes: 6_788_948,
};
// The chunk count is reported but not budgeted. Splitting a page out of the entry raises it while lowering the
diff --git a/studio/frontend/src/features/api-monitor/components/saved-model-settings.tsx b/studio/frontend/src/features/api-monitor/components/saved-model-settings.tsx
index 2fef1cc0bc3..dde6b5396ec 100644
--- a/studio/frontend/src/features/api-monitor/components/saved-model-settings.tsx
+++ b/studio/frontend/src/features/api-monitor/components/saved-model-settings.tsx
@@ -51,6 +51,9 @@ function describeOverride(override: ApiModelOverride): string[] {
`${Math.round(override.engine_gpu_memory_utilization * 100)}% GPU memory`,
);
}
+ if (override.load_in_4bit === false && (override.engine ?? "auto") === "auto") {
+ parts.push("16-bit");
+ }
if (override.custom_context_length) {
parts.push(`${override.custom_context_length.toLocaleString()} context`);
}
diff --git a/studio/frontend/src/features/chat/api/chat-adapter.ts b/studio/frontend/src/features/chat/api/chat-adapter.ts
index 01707d09108..0330bcde5f6 100644
--- a/studio/frontend/src/features/chat/api/chat-adapter.ts
+++ b/studio/frontend/src/features/chat/api/chat-adapter.ts
@@ -3520,13 +3520,14 @@ async function autoLoadSmallestModel(options?: AutoLoadOptions): Promise<{
speculative_type?: string | null;
spec_draft_n_max?: number | null;
n_parallel?: number | null;
+ load_in_4bit?: boolean;
}): Promise<boolean> {
// Before the POST, so an abort costs nothing: no request was sent.
options?.abortSignal?.throwIfAborted();
const validation = await validateModel({
...payload,
hf_token: hfToken,
- load_in_4bit: true,
+ load_in_4bit: payload.load_in_4bit ?? true,
trust_remote_code: trustRemoteCode,
}).catch((error: unknown) => {
// A rejection is a spent /validate that never reaches loadAttempts, so nothing else bounds it.
@@ -3752,6 +3753,7 @@ async function autoLoadSmallestModel(options?: AutoLoadOptions): Promise<{
max_seq_length: fitMaxSeqLength,
is_lora: false,
gguf_variant: candidate.ggufVariant,
+ load_in_4bit: config.loadIn4bit !== false,
cache_type_kv: config.kvCacheDtype,
tensor_parallel: effectiveTensorParallel,
disable_vision: effectiveDisableVision,
@@ -3807,7 +3809,7 @@ async function autoLoadSmallestModel(options?: AutoLoadOptions): Promise<{
model_path: modelPath,
hf_token: hfToken,
max_seq_length: fitMaxSeqLength,
- load_in_4bit: true,
+ load_in_4bit: config.loadIn4bit !== false,
is_lora: false,
gguf_variant: candidate.ggufVariant,
trust_remote_code: trustRemoteCode,
diff --git a/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts b/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts
index 15761430cbe..54f1f3104ca 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
@@ -2009,13 +2009,18 @@ export function useChatModelRuntime() {
let mlxLoadProgress = false;
const liveBeforeLoad = useChatRuntimeStore.getState();
// A switch without a saved config starts on the default engine, as the dedupe above assumes.
+ const switchesModel = Boolean(
+ liveBeforeLoad.params.checkpoint &&
+ (liveBeforeLoad.params.checkpoint !== modelId ||
+ (liveBeforeLoad.activeGgufVariant ?? null) !== (ggufVariant ?? null)),
+ );
if (
(typeof selection === "string" || !selection.config) &&
!keepSpeculative &&
- liveBeforeLoad.params.checkpoint &&
- (liveBeforeLoad.params.checkpoint !== modelId ||
- (liveBeforeLoad.activeGgufVariant ?? null) !== (ggufVariant ?? null)) &&
- (liveBeforeLoad.params.engine ?? "auto") !== "auto"
+ (((liveBeforeLoad.params.engine ?? "auto") !== "auto" && switchesModel) ||
+ // An unload clears the checkpoint but not the precision, so 16-bit resets either way.
+ (liveBeforeLoad.params.loadIn4bit === false &&
+ (switchesModel || !liveBeforeLoad.params.checkpoint)))
) {
liveBeforeLoad.setParams({
...liveBeforeLoad.params,
@@ -2025,6 +2030,7 @@ export function useChatModelRuntime() {
engineKvCacheDtype: "auto",
engineSeed: null,
engineGpuMemoryUtilization: null,
+ loadIn4bit: true,
});
}
const requestedEngine =
@@ -2297,6 +2303,7 @@ export function useChatModelRuntime() {
stateBeforeUnload.ctxCheckpoints,
cacheRam: pendingLoadConfig?.cacheRam ?? stateBeforeUnload.cacheRam,
};
+ const loadIn4bitChoice = stateBeforeUnload.params.loadIn4bit !== false;
let loadEngineFields = {
engine: stateBeforeUnload.params.engine ?? "auto",
engine_precision: stateBeforeUnload.params.enginePrecision ?? "auto",
@@ -2404,7 +2411,9 @@ export function useChatModelRuntime() {
nativePathLease: validateNativePathLease,
hf_token: hfToken,
max_seq_length: validateMaxSeqLength,
- load_in_4bit: (stateBeforeUnload.params.engine ?? "auto") === "auto",
+ load_in_4bit:
+ (stateBeforeUnload.params.engine ?? "auto") === "auto" &&
+ stateBeforeUnload.params.loadIn4bit !== false,
is_lora: isLora,
gguf_variant: ggufVariant ?? null,
cache_type_kv: loadKvCacheDtype,
@@ -2790,7 +2799,8 @@ export function useChatModelRuntime() {
loadCustomContextLength,
loadMaxSeqLength,
),
- load_in_4bit: loadEngineFields.engine === "auto",
+ load_in_4bit:
+ loadEngineFields.engine === "auto" && loadIn4bitChoice,
is_lora: isLora,
gguf_variant: ggufVariant ?? null,
trust_remote_code: trustRemoteCode,
@@ -3187,7 +3197,9 @@ export function useChatModelRuntime() {
nativePathLease: rollbackNativePathLease,
hf_token: hfToken,
max_seq_length: rollbackMaxSeqLength,
- load_in_4bit: stateBeforeUnload.loadedEngine === "auto",
+ load_in_4bit:
+ stateBeforeUnload.loadedEngine === "auto" &&
+ rollbackConfig?.loadIn4bit !== false,
is_lora: previousIsLora,
gguf_variant: previousVariant,
trust_remote_code:
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 bbfbdce9a88..c8005d7df4c 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
@@ -158,7 +158,12 @@ function residentEngineParams(status: InferenceStatusResponse) {
engineKvCacheDtype: status.engine_kv_cache_dtype ?? "auto",
engineSeed: status.engine_seed ?? null,
engineGpuMemoryUtilization: status.engine_gpu_memory_utilization ?? null,
- } as const;
+ // As requested, so a model started with --no-load-in-4bit reloads in 16-bit too. vLLM / SGLang
+ // record false because they take engine_precision instead, so they leave the choice alone.
+ ...((status.engine ?? "auto") === "auto"
+ ? { loadIn4bit: status.load_in_4bit !== false }
+ : {}),
+ };
}
/** Mirror refresh() hydration so adopted CLI models get reasoning/tools flags. */
diff --git a/studio/frontend/src/features/chat/lib/resident-config-match.ts b/studio/frontend/src/features/chat/lib/resident-config-match.ts
index 6b2662f615a..46aea025d7a 100644
--- a/studio/frontend/src/features/chat/lib/resident-config-match.ts
+++ b/studio/frontend/src/features/chat/lib/resident-config-match.ts
@@ -27,6 +27,7 @@ type ResidentRuntime = Pick<
| "engine_kv_cache_dtype"
| "engine_seed"
| "engine_gpu_memory_utilization"
+ | "load_in_4bit"
| "context_length"
| "requested_context_length"
| "cache_type_kv"
@@ -612,6 +613,12 @@ export function residentRuntimeMatchesConfig(
return true;
}
if ((status.engine ?? "auto") !== (config.engine ?? "auto")) return false;
+ if (
+ (status.engine ?? "auto") === "auto" &&
+ typeof status.load_in_4bit === "boolean" &&
+ status.load_in_4bit !== (config.loadIn4bit !== false)
+ )
+ return false;
if (status.engine === "vllm" || status.engine === "sglang") {
if (
(status.engine_precision ?? "auto") !== (config.enginePrecision ?? "auto") ||
diff --git a/studio/frontend/src/features/chat/shared-composer.tsx b/studio/frontend/src/features/chat/shared-composer.tsx
index 24ae76c152a..11b22643225 100644
--- a/studio/frontend/src/features/chat/shared-composer.tsx
+++ b/studio/frontend/src/features/chat/shared-composer.tsx
@@ -1820,7 +1820,7 @@ export function SharedComposer({
engine_precision: ownConfig.enginePrecision ?? "auto",
engine_parallelism: ownConfig.engineParallelism ?? "tensor",
...engineLaunchFieldsFromParams(ownConfig),
- load_in_4bit: paneEngine === "auto",
+ load_in_4bit: paneEngine === "auto" && ownConfig.loadIn4bit !== false,
...(paneEngine !== "auto" && ownConfig.selectedGpuIds !== undefined
? {
gpu_ids:
diff --git a/studio/frontend/src/features/chat/types/api.ts b/studio/frontend/src/features/chat/types/api.ts
index d8d164700fc..29c7a79359c 100644
--- a/studio/frontend/src/features/chat/types/api.ts
+++ b/studio/frontend/src/features/chat/types/api.ts
@@ -365,6 +365,8 @@ export interface UnloadModelRequest {
}
export interface InferenceStatusResponse {
+ /** The 4-bit setting the resident non-GGUF load was requested with; null for GGUF. */
+ load_in_4bit?: boolean | null;
engine_parallelism?: "tensor" | "pipeline" | "data";
engine_precision?: "auto" | "bf16" | "fp16" | "int4" | "int8" | "fp8";
engine_kv_cache_dtype?: "auto" | "fp8";
diff --git a/studio/frontend/src/features/chat/types/runtime.ts b/studio/frontend/src/features/chat/types/runtime.ts
index 0e3c03ce7b0..ea64ceb44a2 100644
--- a/studio/frontend/src/features/chat/types/runtime.ts
+++ b/studio/frontend/src/features/chat/types/runtime.ts
@@ -10,6 +10,8 @@ export interface InferenceParams {
engineSeed?: number | null;
engineGpuMemoryUtilization?: number | null;
engine?: "auto" | "vllm" | "sglang";
+ /** Default engine only: quantize an unquantized Hugging Face checkpoint to 4 bits on load. Unset means on. */
+ loadIn4bit?: boolean;
temperature: number;
topP: number;
topK: number;
@@ -71,6 +73,7 @@ export type PersistedInferenceParams = Partial<
| "engineKvCacheDtype"
| "engineSeed"
| "engineGpuMemoryUtilization"
+ | "loadIn4bit"
>
>;
diff --git a/studio/frontend/src/features/model-picker/api/model-overrides.ts b/studio/frontend/src/features/model-picker/api/model-overrides.ts
index 0ed4c3c50dc..205c18df66b 100644
--- a/studio/frontend/src/features/model-picker/api/model-overrides.ts
+++ b/studio/frontend/src/features/model-picker/api/model-overrides.ts
@@ -45,6 +45,9 @@ export interface ApiModelOverride {
mlx_kv_bits?: number;
// biome-ignore lint/style/useNamingConvention: API schema
mlx_int8_prefill?: boolean;
+ // Stored only when false: absent is the 4-bit default.
+ // biome-ignore lint/style/useNamingConvention: API schema
+ load_in_4bit?: boolean;
// biome-ignore lint/style/useNamingConvention: API schema
speculative_type?: string;
// biome-ignore lint/style/useNamingConvention: API schema
@@ -375,6 +378,7 @@ export function fromApiOverride(
tensorParallel: override.tensor_parallel ?? local.tensorParallel,
disableVision: override.disable_vision ?? local.disableVision,
mlxInt8Prefill: override.mlx_int8_prefill ?? local.mlxInt8Prefill,
+ loadIn4bit: override.load_in_4bit ?? local.loadIn4bit,
chatTemplateOverride:
override.chat_template_override ?? local.chatTemplateOverride,
llamaExtraArgs: extraArgs,
@@ -476,6 +480,9 @@ export function toApiOverride(config: PerModelConfig | null): ApiModelOverride {
if (config.mlxInt8Prefill) {
payload.mlx_int8_prefill = true;
}
+ if (config.loadIn4bit === false) {
+ payload.load_in_4bit = false;
+ }
if (config.chatTemplateOverride?.trim()) {
payload.chat_template_override = config.chatTemplateOverride;
}
diff --git a/studio/frontend/src/features/model-picker/components/model-config-page.tsx b/studio/frontend/src/features/model-picker/components/model-config-page.tsx
index 0da6e44ea1c..c8f063c26bd 100644
--- a/studio/frontend/src/features/model-picker/components/model-config-page.tsx
+++ b/studio/frontend/src/features/model-picker/components/model-config-page.tsx
@@ -3702,6 +3702,25 @@ export function ModelConfigPage({
{!target.isGguf && !targetIsMlx && !targetIsNpu && !classifiedIsDiffusion && !target.meta.isLora && !target.meta.audioType && (
<InferenceEnginePicker parallelism={config.engineParallelism ?? "tensor"} onParallelismChange={engineParallelism => update({ engineParallelism })} precision={config.enginePrecision ?? "auto"} onPrecisionChange={enginePrecision => update({ enginePrecision })} kvCacheDtype={config.engineKvCacheDtype ?? "auto"} onKvCacheDtypeChange={engineKvCacheDtype => update({ engineKvCacheDtype })} gpuMemoryUtilization={config.engineGpuMemoryUtilization ?? null} onGpuMemoryUtilizationChange={engineGpuMemoryUtilization => update({ engineGpuMemoryUtilization })} seed={config.engineSeed ?? null} onSeedChange={engineSeed => update({ engineSeed })} value={config.engine ?? "auto"} onChange={engine => update({ engine })} onReadyChange={setEngineReady} onUse={handleRun} gpuIds={config.selectedGpuIds} onGpuChange={ids => update({ selectedGpuIds: ids, selectedGpuIndexKind: "physical" })} />
)}
+ {/* LoRA adapters keep the precision they were trained in, so they get no switch. */}
+ {!target.isGguf && !targetIsMlx && !targetIsNpu && !classifiedIsDiffusion && !target.meta.isLora && !target.meta.audioType && (config.engine ?? "auto") === "auto" && (
+ <div className={ROW_CLASS}>
+ <div className="flex min-w-0 items-center gap-1.5">
+ <span className={LABEL_CLASS}>Load in 4-bit</span>
+ <InfoHint>
+ Quantizes the model to 4 bits as it loads, using about a quarter
+ of the memory. Turn it off to run the model in 16-bit, the same
+ precision as a 16-bit LoRA or full fine-tune.
+ </InfoHint>
+ </div>
+ <Switch
+ className="panel-switch shrink-0"
+ aria-label="Load in 4-bit"
+ checked={config.loadIn4bit !== false}
+ onCheckedChange={(checked) => update({ loadIn4bit: checked })}
+ />
+ </div>
+ )}
{audioRuntimeGguf ? (
<p className="text-ui-12 leading-snug text-muted-foreground">
This model runs on the audio runtime, so llama.cpp settings do not
diff --git a/studio/frontend/src/features/model-picker/hooks/use-active-model-config.ts b/studio/frontend/src/features/model-picker/hooks/use-active-model-config.ts
index 3e6df867463..cc43710e4e4 100644
--- a/studio/frontend/src/features/model-picker/hooks/use-active-model-config.ts
+++ b/studio/frontend/src/features/model-picker/hooks/use-active-model-config.ts
@@ -30,6 +30,7 @@ export function useActiveModelConfig(): ActiveModelConfigState {
const engineGpuMemoryUtilization = useChatRuntimeStore(
(s) => s.params.engineGpuMemoryUtilization ?? null,
);
+ const loadIn4bit = useChatRuntimeStore((s) => s.params.loadIn4bit !== false);
const activeGgufVariant = useChatRuntimeStore((s) => s.activeGgufVariant);
const loadedIsGguf = useChatRuntimeStore((s) => s.loadedIsGguf);
const loadedIsMlx = useChatRuntimeStore((s) => s.loadedIsMlx);
@@ -129,6 +130,7 @@ export function useActiveModelConfig(): ActiveModelConfigState {
tensorParallel: tensorParallel ?? false,
disableVision: disableVision ?? false,
chatTemplateOverride: chatTemplateOverride ?? null,
+ ...(isGguf || isMlx ? {} : { loadIn4bit }),
};
if (!isGguf) {
return engine === "vllm" || engine === "sglang"
@@ -166,6 +168,7 @@ export function useActiveModelConfig(): ActiveModelConfigState {
engineKvCacheDtype,
engineSeed,
engineGpuMemoryUtilization,
+ loadIn4bit,
customContextLength,
kvCacheDtype,
effectiveMlxKvQuant,
diff --git a/studio/frontend/src/features/model-picker/model-config/apply-per-model-config.ts b/studio/frontend/src/features/model-picker/model-config/apply-per-model-config.ts
index e05a617f081..b26bc55db48 100644
--- a/studio/frontend/src/features/model-picker/model-config/apply-per-model-config.ts
+++ b/studio/frontend/src/features/model-picker/model-config/apply-per-model-config.ts
@@ -42,6 +42,7 @@ export function applyPerModelConfigToRuntime(
const engineKvCacheDtype = config.engineKvCacheDtype ?? "auto";
const engineSeed = config.engineSeed ?? null;
const engineGpuMemoryUtilization = config.engineGpuMemoryUtilization ?? null;
+ const loadIn4bit = config.loadIn4bit !== false;
if (
maxSeqLength !== store.params.maxSeqLength ||
engine !== (store.params.engine ?? "auto") ||
@@ -50,7 +51,8 @@ export function applyPerModelConfigToRuntime(
engineKvCacheDtype !== (store.params.engineKvCacheDtype ?? "auto") ||
engineSeed !== (store.params.engineSeed ?? null) ||
engineGpuMemoryUtilization !==
- (store.params.engineGpuMemoryUtilization ?? null)
+ (store.params.engineGpuMemoryUtilization ?? null) ||
+ loadIn4bit !== (store.params.loadIn4bit !== false)
) {
store.setParams({
...store.params,
@@ -61,6 +63,7 @@ export function applyPerModelConfigToRuntime(
engineKvCacheDtype,
engineSeed,
engineGpuMemoryUtilization,
+ loadIn4bit,
});
}
const gpuSelection =
@@ -143,6 +146,7 @@ export function currentRuntimePerModelConfig(
engineKvCacheDtype: s.params.engineKvCacheDtype ?? "auto",
engineSeed: s.params.engineSeed ?? null,
engineGpuMemoryUtilization: s.params.engineGpuMemoryUtilization ?? null,
+ loadIn4bit: s.params.loadIn4bit !== false,
customContextLength: s.customContextLength ?? null,
maxSeqLength: options.includeMaxSeqLength
? normalizeMaxSeqLength(s.params.maxSeqLength)
@@ -200,6 +204,7 @@ export function perModelConfigsEqual(
(a.engineSeed ?? null) === (b.engineSeed ?? null) &&
(a.engineGpuMemoryUtilization ?? null) ===
(b.engineGpuMemoryUtilization ?? null) &&
+ (a.loadIn4bit !== false) === (b.loadIn4bit !== false) &&
(a.customContextLength ?? null) === (b.customContextLength ?? null) &&
normalizeMaxSeqLength(a.maxSeqLength) ===
normalizeMaxSeqLength(b.maxSeqLength) &&
diff --git a/studio/frontend/src/features/model-picker/model-config/config-signature.ts b/studio/frontend/src/features/model-picker/model-config/config-signature.ts
index c617f96e79e..b97d354ab80 100644
--- a/studio/frontend/src/features/model-picker/model-config/config-signature.ts
+++ b/studio/frontend/src/features/model-picker/model-config/config-signature.ts
@@ -54,6 +54,7 @@ export function loadedConfigSignature(
config.engineKvCacheDtype ?? "auto",
config.engineSeed ?? "",
config.engineGpuMemoryUtilization ?? "",
+ config.loadIn4bit === false ? "16" : "4",
config.customContextLength ?? "",
config.maxSeqLength ?? "",
config.kvCacheDtype ?? "",
diff --git a/studio/frontend/src/features/model-picker/model-config/per-model-config.ts b/studio/frontend/src/features/model-picker/model-config/per-model-config.ts
index 2f7964e46be..eddf39094c1 100644
--- a/studio/frontend/src/features/model-picker/model-config/per-model-config.ts
+++ b/studio/frontend/src/features/model-picker/model-config/per-model-config.ts
@@ -28,6 +28,8 @@ export interface PerModelConfig {
engineSeed?: number | null;
engineGpuMemoryUtilization?: number | null;
engine?: "auto" | "vllm" | "sglang";
+ /** Default engine only; optional so older blobs parse, and anything but false is the 4-bit default. */
+ loadIn4bit?: boolean;
customContextLength: number | null;
maxSeqLength: number | null;
kvCacheDtype: string | null;
@@ -80,6 +82,7 @@ export const DEFAULT_PER_MODEL_CONFIG: PerModelConfig = {
engineKvCacheDtype: "auto",
engineSeed: null,
engineGpuMemoryUtilization: null,
+ loadIn4bit: true,
customContextLength: null,
maxSeqLength: null,
kvCacheDtype: null,
@@ -471,6 +474,7 @@ const STORED_CONFIG_FIELDS = new Set([
"kvCacheDtype",
"mlxKvQuant",
"mlxInt8Prefill",
+ "loadIn4bit",
"speculativeType",
"specDraftNMax",
"specDraftCacheDtype",
@@ -1112,6 +1116,7 @@ function normalizeV1(partial: RawConfig): PerModelConfig {
engineGpuMemoryUtilization: normalizeEngineGpuMemoryUtilization(
partial.engineGpuMemoryUtilization,
),
+ loadIn4bit: partial.loadIn4bit !== false,
customContextLength:
typeof partial.customContextLength === "number" &&
Number.isFinite(partial.customContextLength) &&
@@ -1393,6 +1398,7 @@ export function isDefaultConfig(config: PerModelConfig): boolean {
(config.engineKvCacheDtype ?? "auto") === "auto" &&
config.engineSeed == null &&
config.engineGpuMemoryUtilization == null &&
+ config.loadIn4bit !== false &&
config.customContextLength == null &&
config.maxSeqLength == null &&
(config.kvCacheDtype ?? null) === DEFAULT_PER_MODEL_CONFIG.kvCacheDtype &&
diff --git a/studio/frontend/src/features/model-picker/sharing/fields.ts b/studio/frontend/src/features/model-picker/sharing/fields.ts
index 471be173652..eb0ab5de32a 100644
--- a/studio/frontend/src/features/model-picker/sharing/fields.ts
+++ b/studio/frontend/src/features/model-picker/sharing/fields.ts
@@ -53,6 +53,7 @@ export type SharedConfigKey = Exclude<
| "engineKvCacheDtype"
| "engineSeed"
| "engineGpuMemoryUtilization"
+ | "loadIn4bit"
// A named drafter can be a local directory.
| "specDraftModel"
>;
diff --git a/studio/frontend/tests/load-in-4bit-setting.test.ts b/studio/frontend/tests/load-in-4bit-setting.test.ts
new file mode 100644
index 00000000000..1197b730e99
--- /dev/null
+++ b/studio/frontend/tests/load-in-4bit-setting.test.ts
@@ -0,0 +1,141 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
+
+/** Run settings "Load in 4-bit" for default-engine Hugging Face models (#5639). */
+
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import { readSrc, registerStoreStubResolver } from "./helpers/kit.ts";
+
+registerStoreStubResolver();
+const { normalizePerModelConfig, isDefaultConfig, DEFAULT_PER_MODEL_CONFIG } =
+ await import("../src/features/model-picker/model-config/per-model-config.ts");
+const { loadedConfigSignature } = await import(
+ "../src/features/model-picker/model-config/config-signature.ts"
+);
+const { toApiOverride, fromApiOverride } = await import(
+ "../src/features/model-picker/api/model-overrides.ts"
+);
+const { residentRuntimeMatchesConfig } = await import(
+ "../src/features/chat/lib/resident-config-match.ts"
+);
+
+const standing = {
+ speculativeType: "auto",
+ gpuMemoryMode: "auto" as const,
+ gpuLayers: -1,
+ nCpuMoe: 0,
+ reconcileGpuIds: (ids: number[] | null) => ids,
+ resolveContextLength: (value: number | null) => value ?? 0,
+ parallelSlots: 1,
+ splitRatio: null,
+ normalizeSpeculative: (value: string | null | undefined) => value ?? null,
+};
+
+test("4-bit stays the default, and only an explicit off is a setting", () => {
+ assert.equal(normalizePerModelConfig({}).loadIn4bit, true);
+ assert.equal(normalizePerModelConfig({ loadIn4bit: "no" }).loadIn4bit, true);
+ assert.equal(isDefaultConfig(normalizePerModelConfig({})), true);
+ const off = normalizePerModelConfig({ loadIn4bit: false });
+ assert.equal(off.loadIn4bit, false);
+ assert.equal(isDefaultConfig(off), false);
+ assert.notEqual(
+ loadedConfigSignature(off),
+ loadedConfigSignature(DEFAULT_PER_MODEL_CONFIG),
+ );
+});
+
+test("the server row carries only a 16-bit choice and reads it back", () => {
+ assert.equal(
+ "load_in_4bit" in toApiOverride(DEFAULT_PER_MODEL_CONFIG),
+ false,
+ );
+ const row = toApiOverride({ ...DEFAULT_PER_MODEL_CONFIG, loadIn4bit: false });
+ assert.equal(row.load_in_4bit, false);
+ assert.equal(fromApiOverride(row).loadIn4bit, false);
+ assert.equal(fromApiOverride({}).loadIn4bit, true);
+});
+
+test("a resident loaded at the other precision is reloaded, GGUF never is", () => {
+ const sixteen = { ...DEFAULT_PER_MODEL_CONFIG, loadIn4bit: false };
+ const four = DEFAULT_PER_MODEL_CONFIG;
+ const residentFour = {
+ engine: "auto" as const,
+ is_gguf: false,
+ load_in_4bit: true,
+ };
+ const residentSixteen = { ...residentFour, load_in_4bit: false };
+ assert.equal(
+ residentRuntimeMatchesConfig(residentFour, four, standing),
+ true,
+ );
+ assert.equal(
+ residentRuntimeMatchesConfig(residentSixteen, sixteen, standing),
+ true,
+ );
+ assert.equal(
+ residentRuntimeMatchesConfig(residentFour, sixteen, standing),
+ false,
+ );
+ assert.equal(
+ residentRuntimeMatchesConfig(residentSixteen, four, standing),
+ false,
+ );
+ const gguf = { engine: "auto" as const, is_gguf: true, load_in_4bit: null };
+ assert.equal(
+ residentRuntimeMatchesConfig(gguf, sixteen, standing),
+ residentRuntimeMatchesConfig(gguf, four, standing),
+ );
+});
+
+test("every default-engine load path sends the choice, vLLM and SGLang never 4-bit", () => {
+ const runtime = readSrc("features/chat/hooks/use-chat-model-runtime.ts");
+ assert.match(
+ runtime,
+ /load_in_4bit:\s*loadEngineFields\.engine === "auto" && loadIn4bitChoice,/,
+ );
+ assert.match(
+ runtime,
+ /load_in_4bit:\s*\(stateBeforeUnload\.params\.engine \?\? "auto"\) === "auto" &&\s*stateBeforeUnload\.params\.loadIn4bit !== false,/,
+ );
+ const composer = readSrc("features/chat/shared-composer.tsx");
+ assert.match(
+ composer,
+ /load_in_4bit: paneEngine === "auto" && ownConfig\.loadIn4bit !== false,/,
+ );
+ const adapter = readSrc("features/chat/api/chat-adapter.ts");
+ assert.equal(
+ (adapter.match(/load_in_4bit: config\.loadIn4bit !== false,/g) ?? [])
+ .length,
+ 2,
+ );
+});
+
+test("only a default-engine resident hydrates the switch, and an unload resets 16-bit", () => {
+ const applier = readSrc(
+ "features/chat/lib/apply-inference-status-to-store.ts",
+ );
+ const start = applier.indexOf("function residentEngineParams(");
+ const body = applier.slice(
+ applier.indexOf("return {", start),
+ applier.indexOf("\n}\n", start),
+ );
+ const hydrate = new Function("status", body) as (
+ status: Record<string, unknown>,
+ ) => Record<string, unknown>;
+ assert.equal(hydrate({ load_in_4bit: false }).loadIn4bit, false);
+ assert.equal(hydrate({ load_in_4bit: true }).loadIn4bit, true);
+ // A managed engine leaves the default-engine choice as the user left it.
+ assert.equal(
+ "loadIn4bit" in hydrate({ engine: "vllm", load_in_4bit: false }),
+ false,
+ );
+ assert.equal(hydrate({ is_gguf: true, load_in_4bit: null }).loadIn4bit, true);
+
+ const runtime = readSrc("features/chat/hooks/use-chat-model-runtime.ts");
+ assert.match(
+ runtime,
+ /liveBeforeLoad\.params\.loadIn4bit === false &&\s*\(switchesModel \|\| !liveBeforeLoad\.params\.checkpoint\)/,
+ );
+});
diff --git a/studio/frontend/tests/managed-engine-rollback.test.ts b/studio/frontend/tests/managed-engine-rollback.test.ts
index 727f2cb97b7..9cb072f8ccd 100644
--- a/studio/frontend/tests/managed-engine-rollback.test.ts
+++ b/studio/frontend/tests/managed-engine-rollback.test.ts
@@ -28,6 +28,7 @@ const rollback = new Function(
"rollbackNativePathLease",
"hfToken",
"rollbackMaxSeqLength",
+ "rollbackConfig",
`return { ${runtime.slice(rollbackStart, rollbackEnd)} };`,
) as (state: Record<string, unknown>, ...rest: unknown[]) => Record<string, unknown>;
@@ -54,6 +55,13 @@ test("a default-backend resident still rolls back with 4-bit loading", () => {
assert.equal(request.load_in_4bit, true);
});
+test("a default-backend resident loaded in 16-bit rolls back in 16-bit", () => {
+ const resident = hydrate("org/model", { load_in_4bit: false });
+ const request = rollback(resident, undefined, null, 4096, { loadIn4bit: false });
+ assert.equal(request.engine, "auto");
+ assert.equal(request.load_in_4bit, false);
+});
+
test("a failed switch restores the managed resident's KV cache, seed and memory limit", () => {
const resident = hydrate("org/model", {
engine: "vllm",
diff --git a/studio/frontend/tests/resident-config-match-accelerator-matrix.test.ts b/studio/frontend/tests/resident-config-match-accelerator-matrix.test.ts
index 07601ea1736..583bdf85483 100644
--- a/studio/frontend/tests/resident-config-match-accelerator-matrix.test.ts
+++ b/studio/frontend/tests/resident-config-match-accelerator-matrix.test.ts
@@ -494,6 +494,8 @@ test("every PerModelConfig field is either compared or deliberately excluded", (
"engineKvCacheDtype",
"engineSeed",
"engineGpuMemoryUtilization",
+ // Compared ahead of the table, against the status's requested load_in_4bit.
+ "loadIn4bit",
// Qualifies selectedGpuIds rather than adding a dimension of its own: it is read, as
// the reconciler's namespace argument, but /status has no field to compare it against.
"selectedGpuIndexKind",