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
// 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 test from "node:test";
// The indicator .tsx imports router/motion/icons, so the plain mapping module is tested.
import { modelIdsMatch } from "../src/features/hub/lib/model-identity.ts";
import {
type LoadedModelEntry,
describeDiffusionStatus,
describeInferenceStatus,
describeSttStatus,
describeVideoStatus,
loadedModelKindLabel,
loadedModelTarget,
mergeLoadedModels,
withPendingLoads,
shortModelLabel,
verifyResident,
withServingResident,
} from "../src/features/loaded-models/loaded-models-sources.ts";
function inferenceStatus(
overrides: Record<string, unknown> = {},
): Parameters<typeof describeInferenceStatus>[0] {
return {
active_model: null,
is_vision: false,
loading: [],
loaded: [],
...overrides,
} as Parameters<typeof describeInferenceStatus>[0];
}
test("no runtime loaded produces no rows", () => {
assert.deepEqual(describeInferenceStatus(inferenceStatus()), []);
assert.deepEqual(describeDiffusionStatus({ loaded: false } as never), []);
assert.deepEqual(describeVideoStatus({ loaded: false } as never), []);
assert.deepEqual(describeSttStatus({}), []);
});
test("an unreachable runtime yields no rows rather than throwing", () => {
assert.deepEqual(describeInferenceStatus(null), []);
assert.deepEqual(describeDiffusionStatus(null), []);
assert.deepEqual(describeVideoStatus(null), []);
assert.deepEqual(describeSttStatus(null), []);
});
test("a GGUF chat model reports its variant", () => {
const [row] = describeInferenceStatus(
inferenceStatus({
active_model: "unsloth/gemma-3-4b-it-GGUF",
is_gguf: true,
gguf_variant: "Q4_K_M",
loaded: ["unsloth/gemma-3-4b-it-GGUF"],
}),
);
assert.equal(row.kind, "text");
assert.equal(row.source, "chat");
assert.equal(row.detail, "GGUF · Q4_K_M");
});
test("an audio model is a speech row, and a whisper one is dictation", () => {
const [tts] = describeInferenceStatus(
inferenceStatus({
active_model: "unsloth/orpheus-3b-0.1-ft",
is_audio: true,
audio_type: "tts",
}),
);
assert.equal(tts.kind, "tts");
const [stt] = describeInferenceStatus(
inferenceStatus({
active_model: "openai/whisper-large-v3",
is_audio: true,
audio_type: "whisper",
}),
);
assert.equal(stt.kind, "stt");
assert.equal(stt.source, "chat");
});
test("a model the runtime still holds besides the active one gets its own row", () => {
const rows = describeInferenceStatus(
inferenceStatus({
active_model: "unsloth/Llama-3.2-3B",
loaded: ["unsloth/Llama-3.2-3B", "unsloth/Qwen3-4B"],
}),
);
assert.equal(rows.length, 2);
assert.equal(rows[0].inactive, undefined);
assert.equal(rows[1].name, "unsloth/Qwen3-4B");
assert.equal(rows[1].inactive, true);
});
test("a legacy STT status still shows its resident Transformers model", () => {
const rows = describeSttStatus({
loaded_model: "openai/whisper-large-v3",
device: "cuda",
});
assert.deepEqual(
rows.map((row) => [row.sttEngine, row.name, row.detail]),
[["transformers", "openai/whisper-large-v3", "Transformers · cuda"]],
);
});
test("an engine block wins over the legacy fields, and never doubles a row", () => {
const rows = describeSttStatus({
loaded_model: "openai/whisper-large-v3",
device: "cuda",
transformers: { loaded_model: null },
});
assert.deepEqual(rows, []);
});
test("each STT engine that has a model resident gets a row naming its engine", () => {
const rows = describeSttStatus({
transformers: { loaded_model: null },
mtmd: { loaded_model: "unsloth/voxtral-mini", device: "cuda" },
gguf: { loaded_model: "ggml-base.en", device: "metal" },
});
assert.deepEqual(
rows.map((row) => [row.sttEngine, row.name]),
[
["mtmd", "unsloth/voxtral-mini"],
["gguf", "ggml-base.en"],
],
);
assert.equal(rows[0].detail, "llama.cpp · cuda");
});
test("an engine that reports itself as its device is named once", () => {
const rows = describeSttStatus({
mtmd: { loaded_model: "qwen3-asr-0.6b", device: "llama.cpp" },
gguf: { loaded_model: "ggml-base.en", device: "whisper.cpp" },
});
assert.deepEqual(
rows.map((row) => row.detail),
["llama.cpp", "whisper.cpp"],
);
});
test("a real device is still reported next to its engine", () => {
const [row] = describeSttStatus({
transformers: { loaded_model: "openai/whisper-large-v3", device: "cuda" },
});
assert.equal(row.detail, "Transformers · cuda");
});
test("image and video rows omit the parts the backend did not report", () => {
const [image] = describeDiffusionStatus({
loaded: true,
repo_id: "unsloth/FLUX.1-dev",
family: "flux",
device: null,
} as never);
assert.equal(image.detail, "flux");
const [video] = describeVideoStatus({
loaded: true,
repo_id: "unsloth/Wan2.2-T2V-A14B",
family: "wan",
model_kind: "gguf",
device: "cuda",
} as never);
assert.equal(video.detail, "wan · GGUF · cuda");
});
test("a row names the precision the pipeline actually loaded at", () => {
const [image] = describeDiffusionStatus({
loaded: true,
repo_id: "unsloth/FLUX.1-dev",
family: "flux",
dtype: "bfloat16",
device: "cuda",
} as never);
assert.equal(image.detail, "flux · BF16 · cuda");
const [video] = describeVideoStatus({
loaded: true,
repo_id: "unsloth/Wan2.2-T2V-A14B",
family: "wan",
dtype: "bfloat16",
transformer_quant: "fp8",
device: "cuda",
} as never);
assert.equal(video.detail, "wan · FP8 · cuda");
});
test("a bf16 video load falls back to the pipeline dtype", () => {
const [video] = describeVideoStatus({
loaded: true,
repo_id: "unsloth/Wan2.2-T2V-A14B",
family: "wan",
dtype: "bfloat16",
// "none" is the backend's word for plain bf16.
transformer_quant: "none",
device: "cuda",
} as never);
assert.equal(video.detail, "wan · BF16 · cuda");
});
test("a GGUF video row names its selected quant instead of its compute dtype", () => {
const [video] = describeVideoStatus({
loaded: true,
repo_id: "unsloth/Wan2.2-T2V-A14B-GGUF",
family: "wan",
model_kind: "gguf",
gguf_variant: "Q4_K_M",
dtype: "bfloat16",
device: "cuda",
} as never);
assert.equal(video.detail, "wan · GGUF · Q4_K_M · cuda");
});
test("a lowercase quant filename still reads as an upper-case quant", () => {
const [image] = describeDiffusionStatus({
loaded: true,
repo_id: "unsloth/Z-Image-Turbo-GGUF",
family: "z-image",
model_kind: "gguf",
gguf_variant: "q8_0",
dtype: "bfloat16",
device: "cuda",
} as never);
assert.equal(image.detail, "z-image · GGUF · Q8_0 · cuda");
});
test("a GGUF image load does not print GGUF twice", () => {
const [image] = describeDiffusionStatus({
loaded: true,
repo_id: "unsloth/FLUX.1-dev-GGUF",
family: "flux",
model_kind: "gguf",
dtype: "gguf",
device: "cuda",
} as never);
assert.equal(image.detail, "flux · GGUF · cuda");
});
test("a GGUF image row names the quant that was picked, not the compute dtype", () => {
// dtype is the compute dtype (bf16 on CUDA); the quant identifies the file.
const [image] = describeDiffusionStatus({
loaded: true,
repo_id: "unsloth/Z-Image-Turbo-GGUF",
family: "z-image",
model_kind: "gguf",
gguf_variant: "Q8_0",
transformer_quant: null,
dtype: "bfloat16",
device: "cuda",
} as never);
assert.equal(image.detail, "z-image \u00b7 GGUF \u00b7 Q8_0 \u00b7 cuda");
});
test("a native GGUF image row names its selected quant without model_kind", () => {
const [image] = describeDiffusionStatus({
loaded: true,
repo_id: "unsloth/Z-Image-Turbo-GGUF",
family: "z-image",
gguf_variant: "Q8_0",
dtype: "gguf",
device: "cpu",
} as never);
assert.equal(image.detail, "z-image \u00b7 GGUF \u00b7 Q8_0 \u00b7 cpu");
});
test("a GGUF pick the dense fast path replaced names that build instead", () => {
// The fast path uses a torchao build and never opens the .gguf.
const [image] = describeDiffusionStatus({
loaded: true,
repo_id: "unsloth/Z-Image-Turbo-GGUF",
family: "z-image",
model_kind: "gguf",
gguf_variant: "Q8_0",
transformer_quant: "fp8",
dtype: "bfloat16",
device: "cuda",
} as never);
assert.equal(image.detail, "z-image \u00b7 FP8 \u00b7 cuda");
});
// Backends set is_audio false for audio_vlm.
test("an audio-input VLM stays a chat row, not Speech", () => {
const [row] = describeInferenceStatus(
inferenceStatus({
active_model: "unsloth/gemma-3n-E4B-it",
is_audio: false,
audio_type: "audio_vlm",
has_audio_input: true,
}),
);
assert.equal(row.kind, "text");
});
test("a row opens the page its runtime is used on", () => {
assert.deepEqual(loadedModelTarget("chat"), {
open: "route",
to: "/chat",
label: "Chat",
});
assert.deepEqual(loadedModelTarget("image"), {
open: "route",
to: "/images",
label: "Images",
});
assert.deepEqual(loadedModelTarget("video"), {
open: "route",
to: "/video",
label: "Video",
});
});
test("a dictation row opens Voice settings", () => {
assert.deepEqual(loadedModelTarget("stt"), {
open: "settings",
tab: "voice",
label: "Voice settings",
});
});
test("the target follows the runtime, not the kind", () => {
const [chatWhisper] = describeInferenceStatus(
inferenceStatus({
active_model: "unsloth/whisper-large-v3",
is_audio: true,
audio_type: "whisper",
}),
);
assert.equal(chatWhisper.kind, "stt");
assert.equal(loadedModelTarget(chatWhisper.source).label, "Chat");
});
test("every runtime's rows appear together, in a fixed order", () => {
const merged = mergeLoadedModels([
describeInferenceStatus(
inferenceStatus({
active_model: "unsloth/orpheus-3b-0.1-ft",
is_audio: true,
}),
),
describeDiffusionStatus({
loaded: true,
repo_id: "unsloth/FLUX.1-dev",
} as never),
describeVideoStatus(null),
describeSttStatus({ gguf: { loaded_model: "ggml-base.en" } }),
]);
assert.deepEqual(
merged.map((row) => row.kind),
["tts", "image", "stt"],
);
});
test("one runtime naming the same model twice is still one row", () => {
const duplicated: LoadedModelEntry[] = [
{
id: "chat:unsloth/Qwen3-4B",
kind: "text",
source: "chat",
name: "unsloth/Qwen3-4B",
detail: "GGUF",
},
];
assert.equal(mergeLoadedModels([duplicated, duplicated]).length, 1);
});
// The image, video and STT unload routes take no model id, so the row is checked first.
test("a runtime holding the row's model is safe to unload", () => {
assert.equal(
verifyResident("unsloth/FLUX.1-dev", "unsloth/FLUX.1-dev", modelIdsMatch),
"match",
);
});
test("a runtime holding something else must not be unloaded", () => {
assert.equal(
verifyResident("unsloth/FLUX.1-dev", "unsloth/Qwen-Image", modelIdsMatch),
"replaced",
);
});
test("an idle runtime is already free, so there is nothing to unload", () => {
assert.equal(
verifyResident("unsloth/FLUX.1-dev", null, modelIdsMatch),
"gone",
);
assert.equal(
verifyResident("unsloth/FLUX.1-dev", undefined, modelIdsMatch),
"gone",
);
});
test("a trailing separator or casing difference is not a replacement", () => {
assert.equal(
verifyResident("/models/flux", "/models/flux/", modelIdsMatch),
"match",
);
assert.equal(
verifyResident("unsloth/FLUX.1-dev", "unsloth/flux.1-dev", modelIdsMatch),
"match",
);
});
test("a local load shows its model folder rather than leading directories", () => {
assert.equal(
shortModelLabel("unsloth/gemma-3-4b-it"),
"unsloth/gemma-3-4b-it",
);
assert.equal(
shortModelLabel("/Users/me/models/hub/gemma-3-4b-it"),
"hub/gemma-3-4b-it",
);
assert.equal(shortModelLabel("C:\\models\\hub\\gemma\\"), "hub/gemma");
});
test("a chat model still loading gets its own row", () => {
const rows = describeInferenceStatus(
inferenceStatus({ loading: ["unsloth/Qwen3.5-9B-GGUF"] }),
);
assert.equal(rows.length, 1);
assert.equal(rows[0].loading, true);
assert.equal(rows[0].detail, "Loading");
});
test("a model that finished loading is not listed twice", () => {
const rows = describeInferenceStatus(
inferenceStatus({
active_model: "unsloth/Qwen3.5-9B-GGUF",
is_gguf: true,
loading: ["unsloth/Qwen3.5-9B-GGUF"],
}),
);
assert.equal(rows.length, 1);
assert.notEqual(rows[0].loading, true);
});
test("a dictation sidecar that is starting shows as loading", () => {
const [row] = describeSttStatus({ mtmd: { loading: true } });
assert.equal(row.loading, true);
assert.equal(row.sttEngine, "mtmd");
});
test("an announced load shows before any status confirms it", () => {
const rows = withPendingLoads(
[],
new Map([["image", "unsloth/Z-Image-Turbo-GGUF"]]),
);
assert.equal(rows.length, 1);
assert.equal(rows[0].kind, "image");
assert.equal(rows[0].loading, true);
assert.equal(rows[0].name, "unsloth/Z-Image-Turbo-GGUF");
});
test("a status row for that runtime replaces the announced one", () => {
const loaded = describeDiffusionStatus({
loaded: true,
repo_id: "unsloth/Z-Image-Turbo-GGUF",
family: "z-image",
} as never);
const rows = withPendingLoads(
loaded,
new Map([["image", "unsloth/Z-Image-Turbo-GGUF"]]),
);
assert.equal(rows.length, 1);
assert.notEqual(rows[0].loading, true);
});
test("nothing announced leaves the polled rows untouched", () => {
const rows: LoadedModelEntry[] = [];
assert.equal(withPendingLoads(rows, new Map()), rows);
});
// The outgoing image model stays resident during a swap.
test("a swap shows the incoming model alongside the outgoing one", () => {
const resident = describeDiffusionStatus({
loaded: true,
repo_id: "unsloth/FLUX.1-dev",
family: "flux",
} as never);
const rows = withPendingLoads(
resident,
new Map([["image", "unsloth/Z-Image-Turbo-GGUF"]]),
);
assert.equal(rows.length, 2);
const incoming = rows.find((row) => row.loading);
assert.equal(incoming?.name, "unsloth/Z-Image-Turbo-GGUF");
assert.ok(rows.some((row) => row.name === "unsloth/FLUX.1-dev"));
});
test("the announced row yields once that same model is resident", () => {
const resident = describeDiffusionStatus({
loaded: true,
repo_id: "unsloth/Z-Image-Turbo-GGUF",
family: "z-image",
} as never);
const rows = withPendingLoads(
resident,
new Map([["image", "unsloth/Z-Image-Turbo-GGUF"]]),
);
assert.equal(rows.length, 1);
assert.notEqual(rows[0].loading, true);
});
test("an nvfp4 image row names the kernel backend that served it", () => {
const [flashinfer] = describeDiffusionStatus({
loaded: true,
repo_id: "unsloth/Z-Image-Turbo-NVFP4",
family: "z-image",
transformer_quant: "nvfp4",
transformer_quant_backend: "flashinfer",
dtype: "bfloat16",
device: "cuda",
} as never);
assert.equal(flashinfer.detail, "z-image · NVFP4 · FlashInfer · cuda");
const [torchao] = describeDiffusionStatus({
loaded: true,
repo_id: "unsloth/Z-Image-Turbo-NVFP4",
family: "z-image",
transformer_quant: "nvfp4",
transformer_quant_backend: "torchao",
dtype: "bfloat16",
device: "cuda",
} as never);
assert.equal(torchao.detail, "z-image · NVFP4 · torchao · cuda");
});
test("a row without a quant backend is unchanged, on old and new backends alike", () => {
const [fp8] = describeDiffusionStatus({
loaded: true,
repo_id: "unsloth/Z-Image-Turbo",
family: "z-image",
transformer_quant: "fp8",
transformer_quant_backend: null,
dtype: "bfloat16",
device: "cuda",
} as never);
assert.equal(fp8.detail, "z-image · FP8 · cuda");
const [old] = describeDiffusionStatus({
loaded: true,
repo_id: "unsloth/Z-Image-Turbo",
family: "z-image",
transformer_quant: "fp8",
dtype: "bfloat16",
device: "cuda",
} as never);
assert.equal(old.detail, "z-image · FP8 · cuda");
});
test("an nvfp4 video row names the kernel backend that served it", () => {
const [flashinfer] = describeVideoStatus({
loaded: true,
repo_id: "unsloth/Wan2.2-T2V-A14B-NVFP4",
family: "wan2.2-t2v-a14b",
transformer_quant: "nvfp4",
transformer_quant_backend: "flashinfer",
dtype: "bfloat16",
device: "cuda",
} as never);
assert.equal(
flashinfer.detail,
"wan2.2-t2v-a14b · NVFP4 · FlashInfer · cuda",
);
const [torchao] = describeVideoStatus({
loaded: true,
repo_id: "unsloth/Wan2.2-T2V-A14B-NVFP4",
family: "wan2.2-t2v-a14b",
transformer_quant: "nvfp4",
transformer_quant_backend: "torchao",
dtype: "bfloat16",
device: "cuda",
} as never);
assert.equal(torchao.detail, "wan2.2-t2v-a14b · NVFP4 · torchao · cuda");
});
test("a video row without a quant backend is unchanged", () => {
const [row] = describeVideoStatus({
loaded: true,
repo_id: "unsloth/Wan2.2-T2V-A14B",
family: "wan2.2-t2v-a14b",
transformer_quant: "fp8",
dtype: "bfloat16",
device: "cuda",
} as never);
assert.equal(row.detail, "wan2.2-t2v-a14b · FP8 · cuda");
});
// Chat refuses a speech-only model, so its row opens the Audio page on the workflow that runs it.
test("an audio model in the chat slot opens its Audio workflow, named for what it does", () => {
const row = (overrides: Record<string, unknown>) => {
const [entry] = describeInferenceStatus(
inferenceStatus({ active_model: "m/x", is_audio: true, ...overrides }),
);
return {
target: loadedModelTarget(entry.source, entry.workflows),
label: loadedModelKindLabel(entry),
};
};
const audio = (workflow: string) => ({
open: "route",
to: "/audio",
search: { workflow },
label: "Audio",
});
assert.deepEqual(row({ audio_type: "snac", audio_workflows: ["speak"] }), {
target: audio("speak"),
label: "Speech",
});
assert.deepEqual(
row({ audio_type: "audiocpp_music", audio_workflows: ["music"] }),
{ target: audio("music"), label: "Music" },
);
assert.deepEqual(
row({ audio_type: "audiocpp_sep", audio_workflows: ["separate"] }),
{
target: audio("separate"),
label: "Separation",
},
);
assert.deepEqual(
row({ audio_type: "audiocpp_tts", audio_workflows: ["convert"] }),
{ target: audio("convert"), label: "Voice conversion" },
);
// An older backend sends no workflows; the audio type still tells Music from Speak.
assert.deepEqual(
row({ audio_type: "minimax_music3" }).target,
audio("music"),
);
assert.deepEqual(row({ audio_type: "csm" }).target, audio("speak"));
// The first workflow names the row and is where the Audio page opens.
assert.deepEqual(
row({ audio_type: "audiocpp_tts", audio_workflows: ["speak", "edit"] }),
{ target: audio("speak"), label: "Speech" },
);
// The GGUF audio runtime reports is_gguf false; its rows still read GGUF.
const [sep] = describeInferenceStatus(
inferenceStatus({
active_model: "audio-cpp/audio.cpp-gguf/HTDemucs-GGUF",
is_audio: true,
is_gguf: false,
audio_type: "audiocpp_sep",
gguf_variant: "Q8_0",
}),
);
assert.equal(sep.detail, "GGUF · Q8_0");
// Whisper in the chat slot is still Chat's.
assert.equal(row({ audio_type: "whisper" }).target.label, "Chat");
});
// Switching the Audio page's workflow stops a generation running on it, and the card only navigates.
test("an Audio page already on a workflow the model runs is left there", () => {
const [row] = describeInferenceStatus(
inferenceStatus({
active_model: "audio-cpp/audio.cpp-gguf/DotTTS-Edit-GGUF",
is_audio: true,
audio_type: "audiocpp_tts",
audio_workflows: ["speak", "edit"],
}),
);
assert.deepEqual(row.workflows, ["speak", "edit"]);
assert.deepEqual(loadedModelTarget(row.source, row.workflows, "edit"), {
open: "route",
to: "/audio",
label: "Audio",
});
// A workflow the model does not run still opens its first one.
assert.deepEqual(loadedModelTarget(row.source, row.workflows, "music"), {
open: "route",
to: "/audio",
search: { workflow: "speak" },
label: "Audio",
});
});
test("only a model known to sit on the reported GPUs counts toward VRAM", () => {
const gguf = (resident_on_gpu: unknown) =>
describeInferenceStatus(
inferenceStatus({
active_model: "unsloth/gemma-3-4b-it-GGUF",
is_gguf: true,
loaded: ["unsloth/gemma-3-4b-it-GGUF"],
resident_mib: 3072,
resident_on_gpu,
}),
)[0];
assert.equal(gguf(true).residentOnGpu, true);
assert.equal(gguf(false).residentOnGpu, false);
// A Vulkan run (buffers not parsed) and an older server stay unknown.
assert.equal(gguf(null).residentOnGpu, undefined);
assert.equal(gguf(undefined).residentOnGpu, undefined);
const image = (device: string | null) =>
describeDiffusionStatus({ loaded: true, repo_id: "a/b", resident_mib: 2048, device } as never)[0];
assert.equal(image("cuda:0").residentOnGpu, true);
assert.equal(image("cpu").residentOnGpu, false);
assert.equal(image(null).residentOnGpu, undefined);
});
test("a kept chat model takes its size from its own slot, never from a primary that answered instead", () => {
const [, kept] = describeInferenceStatus(
inferenceStatus({
active_model: "unsloth/gemma-3-4b-it-GGUF",
model_identifier: "unsloth/gemma-3-4b-it-GGUF",
serving: ["unsloth/gemma-3-4b-it-GGUF", "unsloth/Qwen3-4B-GGUF"],
serving_checkpoints: ["unsloth/gemma-3-4b-it-GGUF", "unsloth/Qwen3-4B-GGUF"],
}),
);
assert.equal(kept.residentMib, undefined);
const slot = inferenceStatus({
active_model: "unsloth/Qwen3-4B-GGUF",
model_identifier: "unsloth/Qwen3-4B-GGUF",
resident_mib: 2376,
resident_on_gpu: true,
});
const sized = withServingResident(kept, slot);
assert.equal(sized.residentMib, 2376);
assert.equal(sized.residentOnGpu, true);
const primary = inferenceStatus({
active_model: "unsloth/Qwen3-4B-GGUF",
model_identifier: "unsloth/gemma-3-4b-it-GGUF",
resident_mib: 6617,
});
assert.equal(withServingResident(kept, primary), kept);
assert.equal(withServingResident(kept, null), kept);
});