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: show the context DiffusionGemma is really running with (#17566)

Nilaybcd920154d63
diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.py
index a178dddda5b..36341bbbb8d 100644
--- a/studio/backend/core/inference/llama_cpp.py
+++ b/studio/backend/core/inference/llama_cpp.py
@@ -19929,6 +19929,13 @@ class LlamaCppBackend:
if chosen and chosen > 0:
self._effective_context_length = chosen
self._max_context_length = chosen
+ if n_ctx and n_ctx > 0 and self._effective_context_length != n_ctx:
+ logger.warning(
+ "DiffusionGemma is running with a %s-token context, not the requested %d: "
+ "the runner did not apply that value and sized the context to fit memory.",
+ self._effective_context_length,
+ n_ctx,
+ )
self._requested_n_ctx = int(n_ctx)
if cancelled is not None and cancelled():
logger.info("DiffusionGemma start cancelled after it became healthy")
diff --git a/studio/backend/tests/test_diffusion_auto_fit_ngl.py b/studio/backend/tests/test_diffusion_auto_fit_ngl.py
index 96c430c384b..90d5557ad60 100644
--- a/studio/backend/tests/test_diffusion_auto_fit_ngl.py
+++ b/studio/backend/tests/test_diffusion_auto_fit_ngl.py
@@ -11,6 +11,7 @@ the only path a UI user has.
from __future__ import annotations
+import contextlib
import sys
import types as _types
from pathlib import Path
@@ -166,9 +167,10 @@ def _launch(
*,
shim_has_ngl = True,
n_ctx = 4096,
+ runner_log = None,
**kwargs,
):
- """Drive the real _start_diffusion_server to the health wait; return (argv, backend)."""
+ """Drive the real _start_diffusion_server to the health wait (past it with runner_log); return (argv, backend)."""
backend = _fit_host(monkeypatch, gpus)
monkeypatch.delenv("CUDA_VISIBLE_DEVICES", raising = False)
monkeypatch.delenv("DG_GPU", raising = False)
@@ -195,10 +197,15 @@ def _launch(
)
monkeypatch.setattr(llama_cpp_module, "_swa_cache_path", lambda: tmp_path / "swa.json")
monkeypatch.setattr(llama_cpp_module.subprocess, "Popen", _FakePopen)
- monkeypatch.setattr(
- backend, "_wait_for_health", lambda **_kw: (_ for _ in ()).throw(_StopAtHealth())
- )
- with pytest.raises(_StopAtHealth):
+
+ def _health(**_kw):
+ if runner_log is None:
+ raise _StopAtHealth()
+ backend._stdout_lines = list(runner_log)
+ return True
+
+ monkeypatch.setattr(backend, "_wait_for_health", _health)
+ with pytest.raises(_StopAtHealth) if runner_log is None else contextlib.nullcontext():
backend._start_diffusion_server(
model_path = "/m.gguf",
gguf_path = "/m.gguf",
@@ -240,6 +247,44 @@ def test_fitted_launch_pins_the_context_it_was_sized_for(monkeypatch, tmp_path):
assert (_ngl(cmd), _maxtok(cmd)) == ("11", "2048")
+def _warnings(monkeypatch):
+ lines = []
+ monkeypatch.setattr(
+ llama_cpp_module.logger,
+ "warning",
+ lambda msg, *a, **_kw: lines.append(msg % a if a else msg),
+ )
+ return lines
+
+
+ "gpus, n_ctx, runner_log, effective",
+ [
+ ([(0, 14_900, 15_360)], 24576, ["context: MAXTOK=4096 requested=4096"], 4096),
+ ([(0, 23_500, 24_576)], 24576, ["context: MAXTOK=65536 requested=0 budget=vram"], 65536),
+ ([(0, 23_500, 24_576)], 100_000, ["context: MAXTOK=32768 requested=0 budget=vram"], 32768),
+ ],
+)
+def test_a_context_the_runner_did_not_apply_is_logged(
+ monkeypatch, tmp_path, gpus, n_ctx, runner_log, effective
+):
+ lines = _warnings(monkeypatch)
+ _cmd, backend = _launch(monkeypatch, tmp_path, gpus, n_ctx = n_ctx, runner_log = runner_log)
+ assert backend._effective_context_length == effective
+ assert [ln for ln in lines if f"{effective}-token" in ln and str(n_ctx) in ln]
+ # The reload dedup still compares the request as it was made.
+ assert backend._requested_n_ctx == n_ctx
+
+
+ "n_ctx, runner_log", [(8192, ["context: MAXTOK=8192"]), (0, ["MAXTOK=65536"])]
+)
+def test_an_applied_or_auto_context_logs_nothing(monkeypatch, tmp_path, n_ctx, runner_log):
+ lines = _warnings(monkeypatch)
+ _launch(monkeypatch, tmp_path, [(0, 23_500, 24_576)], n_ctx = n_ctx, runner_log = runner_log)
+ assert not [ln for ln in lines if "context" in ln]
+
+
def test_zero_layer_fit_runs_on_the_cpu(monkeypatch, tmp_path):
cmd, backend = _launch(monkeypatch, tmp_path, [(0, 0, 8_188)])
assert (_ngl(cmd), cmd[cmd.index("--gpu") + 1]) == ("0", "")
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 0dc0aebbd15..4d8b6dc1665 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
@@ -647,6 +647,26 @@ function GgufContextLengthSetting({
);
}
+function DiffusionContextNote({
+ value,
+ requested,
+ loadedContext,
+}: {
+ value: number;
+ requested: number | null;
+ loadedContext: number | null;
+}) {
+ if (loadedContext == null || value !== requested || value === loadedContext) {
+ return null;
+ }
+ return (
+ <p className="text-ui-11 text-amber-500">
+ DiffusionGemma did not apply this value. It sized the context to fit
+ memory and is running with {loadedContext.toLocaleString()} tokens.
+ </p>
+ );
+}
+
function clampMaxSeqLength(value: number, max: number): number {
const normalized = normalizeMaxSeqLength(value) ?? MAX_SEQ_LENGTH_MIN;
return Math.max(MAX_SEQ_LENGTH_MIN, Math.min(max, normalized));
@@ -1900,9 +1920,13 @@ function GgufAdvancedSettings({
: N_BATCH_LLAMA_DEFAULT;
const ubatchExceedsBatch =
config.nUbatch != null && config.nUbatch > effectiveBatch;
+ const showGpuPicker =
+ (pinnableGpuContext(gpuDevices, isDiffusion).ids?.length ?? 0) > 1;
return (
<>
+ {(!isDiffusion || showGpuPicker) && (
<AdvancedGroup title="Memory">
+ {!isDiffusion && (
<div className={ROW_CLASS}>
<div className="flex min-w-0 items-center gap-1.5">
<span className={LABEL_CLASS}>KV Cache Dtype</span>
@@ -1937,6 +1961,7 @@ function GgufAdvancedSettings({
</SelectContent>
</Select>
</div>
+ )}
<GpuMemorySettings
config={config}
@@ -1968,7 +1993,9 @@ function GgufAdvancedSettings({
</div>
)}
</AdvancedGroup>
+ )}
+ {!isDiffusion && (
<AdvancedGroup title="Speed">
<div className={ROW_CLASS}>
<div className="flex min-w-0 items-center gap-1.5">
@@ -2206,6 +2233,7 @@ function GgufAdvancedSettings({
</div>
)}
</AdvancedGroup>
+ )}
<AdvancedGroup title="Output">
{!isDiffusion && (
@@ -4255,7 +4283,13 @@ export function ModelConfigPage({
inputRef={contextInputRef}
onChange={(v) => update({ customContextLength: v === 0 ? null : v })}
renderWarning={(v) =>
- isActiveModel &&
+ resolvedIsDiffusion ? (
+ <DiffusionContextNote
+ value={v}
+ requested={loadedConfig?.customContextLength ?? null}
+ loadedContext={activeLoadedContext}
+ />
+ ) : isActiveModel &&
loadedMaxContextLength != null &&
v > loadedMaxContextLength && (
<p className="text-ui-11 text-amber-500">
diff --git a/studio/frontend/tests/context-mode-ux.test.ts b/studio/frontend/tests/context-mode-ux.test.ts
index 84da4a34b36..39b73ef0cd9 100644
--- a/studio/frontend/tests/context-mode-ux.test.ts
+++ b/studio/frontend/tests/context-mode-ux.test.ts
@@ -63,7 +63,7 @@ test("the existing info hint owns the mode explanation and fitted result", () =>
);
assert.match(
panelCode,
- /renderWarning=\{\(v\) => isActiveModel && loadedMaxContextLength != null && v > loadedMaxContextLength && \(/,
+ /renderWarning=\{\(v\) => resolvedIsDiffusion \? \( <DiffusionContextNote [^)]*\) : isActiveModel && loadedMaxContextLength != null && v > loadedMaxContextLength && \(/,
);
assert.match(panelCode, /\{renderWarning\(shown\)\}/);
assert.doesNotMatch(
diff --git a/studio/frontend/tests/diffusion-run-settings-rows.test.ts b/studio/frontend/tests/diffusion-run-settings-rows.test.ts
new file mode 100644
index 00000000000..b322f6a1267
--- /dev/null
+++ b/studio/frontend/tests/diffusion-run-settings-rows.test.ts
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+// The config page cannot render under Node, so these checks are source-level.
+
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import { readSrc } from "./helpers/kit.ts";
+
+const LINES = readSrc(
+ "features/model-picker/components/model-config-page.tsx",
+).split("\n");
+
+function ggufAdvancedLines(): string[] {
+ const start = LINES.findIndex((line) =>
+ line.startsWith("function GgufAdvancedSettings("),
+ );
+ assert.notEqual(start, -1, "no GgufAdvancedSettings");
+ const length = LINES.slice(start + 1).findIndex((line) =>
+ /^(export )?function \w+\(/.test(line),
+ );
+ return LINES.slice(start, start + 1 + length);
+}
+
+function groupLines(title: string): { gate: string; body: string } {
+ const lines = ggufAdvancedLines();
+ const open = lines.findIndex(
+ (line) => line.trim() === `<AdvancedGroup title="${title}">`,
+ );
+ assert.notEqual(open, -1, `no ${title} group`);
+ const close = lines.findIndex(
+ (line, i) => i > open && line.trim() === "</AdvancedGroup>",
+ );
+ return {
+ gate: lines[open - 1].trim(),
+ body: lines.slice(open, close).join("\n"),
+ };
+}
+
+test("the diffusion runner has no slots or drafter argument, so the Speed group is not offered", () => {
+ const speed = groupLines("Speed");
+ assert.equal(speed.gate, "{!isDiffusion && (");
+ assert.ok(speed.body.includes(">Speculative Decoding</span>"));
+ assert.ok(speed.body.includes("<ParallelSlotsRow"));
+});
+
+test("KV Cache Dtype is not offered for a diffusion model", () => {
+ const lines = ggufAdvancedLines();
+ const label = lines.findIndex((line) =>
+ line.includes(">KV Cache Dtype</span>"),
+ );
+ assert.notEqual(label, -1, "no KV Cache Dtype row");
+ // A `)}` first means the gate closed before the row.
+ const above = lines
+ .slice(0, label)
+ .reverse()
+ .map((line) => line.trim())
+ .find((line) => line === "{!isDiffusion && (" || line === ")}");
+ assert.equal(above, "{!isDiffusion && (");
+});
+
+test("the Memory group renders for diffusion only when it has the GPU picker to show", () => {
+ assert.equal(
+ groupLines("Memory").gate,
+ "{(!isDiffusion || showGpuPicker) && (",
+ );
+});
+
+test("a diffusion context the runner did not apply says so, with the value it runs", () => {
+ const page = LINES.join("\n");
+ const start = page.indexOf("function DiffusionContextNote(");
+ assert.notEqual(start, -1, "no DiffusionContextNote");
+ const note = page.slice(start, page.indexOf("\nfunction ", start + 1));
+ assert.match(
+ note,
+ /if \(loadedContext == null \|\| value !== requested \|\| value === loadedContext\) \{\s+return null;/,
+ );
+ assert.match(note, /running with \{loadedContext\.toLocaleString\(\)\} tokens/);
+ // It replaces the VRAM-capacity warning, which describes a context the runner never uses.
+ assert.match(
+ page.replace(/\s+/g, " "),
+ /resolvedIsDiffusion \? \( <DiffusionContextNote value=\{v\} requested=\{loadedConfig\?\.customContextLength \?\? null\} loadedContext=\{activeLoadedContext\} \/> \) : isActiveModel &&/,
+ );
+});