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: make Compare in Chat load the full fine-tune that just finished (#12380)

Nilay6c7f0445ff80
diff --git a/studio/frontend/src/features/chat/chat-page.tsx b/studio/frontend/src/features/chat/chat-page.tsx
index f7673a3a38f..723b06d28bc 100644
--- a/studio/frontend/src/features/chat/chat-page.tsx
+++ b/studio/frontend/src/features/chat/chat-page.tsx
@@ -189,6 +189,9 @@ import { useFileProjectInSection } from "./hooks/use-file-project-in-section";
import {
clearTrainingCompareHandoff,
getTrainingCompareHandoff,
+ normalizeModelRef,
+ pickTrainingCompareTarget,
+ trainingCompareSelection,
} from "./lib/training-compare-handoff";
import {
externalReasoningTakesEffort,
@@ -283,13 +286,6 @@ const ProjectSourcesPanel = lazy(() =>
})),
);
-type LoraCandidate = {
- id: string;
- baseModel: string;
- updatedAt?: number;
- exportType?: "lora" | "merged" | "gguf";
-};
-
const EXTERNAL_PROVIDER_DROPDOWN_ORDER: Record<string, number> = {
openai: 0,
anthropic: 1,
@@ -299,38 +295,6 @@ function getExternalProviderDropdownRank(providerType: string): number {
return EXTERNAL_PROVIDER_DROPDOWN_ORDER[providerType] ?? 2;
}
-function normalizeModelRef(value: string | null | undefined): string {
- return value?.trim().toLowerCase() ?? "";
-}
-
-function pickBestLoraForBase(
- loras: LoraCandidate[],
- baseModel: string | null,
-): LoraCandidate | null {
- const adapterOnly = loras.filter((lora) => lora.exportType === "lora");
- if (adapterOnly.length === 0) return null;
- const sorted = [...adapterOnly].sort(
- (a, b) => (b.updatedAt ?? -1) - (a.updatedAt ?? -1),
- );
- const normalizedBase = normalizeModelRef(baseModel);
- if (!normalizedBase) return sorted[0] ?? null;
-
- const exact = sorted.find(
- (lora) => normalizeModelRef(lora.baseModel) === normalizedBase,
- );
- if (exact) return exact;
-
- const partial = sorted.find((lora) => {
- const normalizedLoraBase = normalizeModelRef(lora.baseModel);
- if (!normalizedLoraBase) return false;
- return (
- normalizedLoraBase.includes(normalizedBase) ||
- normalizedBase.includes(normalizedLoraBase)
- );
- });
- return partial ?? sorted[0] ?? null;
-}
-
function messageHasImage(message: MessageRecord): boolean {
const contentParts = Array.isArray(message.content) ? message.content : [];
if (contentParts.some((part) => part.type === "image")) {
@@ -4060,9 +4024,12 @@ export function ChatPage({
if (canceled) return;
const state = useChatRuntimeStore.getState();
- const targetLora = pickBestLoraForBase(state.loras, handoff.baseModel);
+ const target = pickTrainingCompareTarget(state.loras, handoff);
const selectWithConfig = async (
- selection: Pick<SelectedModelInput, "id" | "isLora">,
+ selection: Pick<
+ SelectedModelInput,
+ "id" | "isLora" | "isDownloaded"
+ >,
) => {
const previousConfig = currentRuntimePerModelConfig({
includeMaxSeqLength: true,
@@ -4078,18 +4045,19 @@ export function ChatPage({
...(remembered ? { config: remembered } : {}),
});
};
- if (targetLora) {
- console.info("[chat-handoff] loading lora", {
- id: targetLora.id,
- baseModel: targetLora.baseModel,
+ if (target) {
+ const selection = trainingCompareSelection(target);
+ console.info("[chat-handoff] loading trained model", {
+ ...selection,
+ baseModel: target.baseModel,
});
- await selectWithConfig({ id: targetLora.id, isLora: true });
+ await selectWithConfig(selection);
if (canceled) return;
useChatRuntimeStore.getState().setActiveThreadId(null);
useChatRuntimeStore.getState().setContextUsage(null);
navigate({ to: "/chat", search: { compare: crypto.randomUUID() } });
clearHandoff();
- console.info("[chat-handoff] loaded lora + opened compare");
+ console.info("[chat-handoff] loaded trained model + opened compare");
return;
}
diff --git a/studio/frontend/src/features/chat/lib/training-compare-handoff.ts b/studio/frontend/src/features/chat/lib/training-compare-handoff.ts
index 0afa95d4bce..9d8d9c9ca23 100644
--- a/studio/frontend/src/features/chat/lib/training-compare-handoff.ts
+++ b/studio/frontend/src/features/chat/lib/training-compare-handoff.ts
@@ -7,15 +7,27 @@ const HANDOFF_MAX_AGE_MS = 15 * 60 * 1000;
export type TrainingCompareHandoff = {
intent: "compare";
baseModel: string | null;
+ outputDir: string | null;
requestedAt: number;
};
-export function setTrainingCompareHandoff(baseModel: string | null): void {
+type TrainingCompareCandidate = {
+ id: string;
+ baseModel: string;
+ updatedAt?: number;
+ exportType?: "lora" | "merged" | "gguf";
+};
+
+export function setTrainingCompareHandoff(
+ baseModel: string | null,
+ outputDir: string | null = null,
+): void {
if (typeof window === "undefined") return;
const payload: TrainingCompareHandoff = {
intent: "compare",
baseModel,
+ outputDir,
requestedAt: Date.now(),
};
window.sessionStorage.setItem(
@@ -42,6 +54,8 @@ export function getTrainingCompareHandoff(): TrainingCompareHandoff | null {
intent: "compare",
baseModel:
typeof parsed.baseModel === "string" ? parsed.baseModel : null,
+ outputDir:
+ typeof parsed.outputDir === "string" ? parsed.outputDir : null,
requestedAt: parsed.requestedAt,
};
} catch {
@@ -54,3 +68,53 @@ export function clearTrainingCompareHandoff(): void {
if (typeof window === "undefined") return;
window.sessionStorage.removeItem(TRAINING_COMPARE_HANDOFF_KEY);
}
+
+export function normalizeModelRef(value: string | null | undefined): string {
+ return value?.trim().toLowerCase() ?? "";
+}
+
+function normalizePath(path: string): string {
+ return path.replace(/[/\\]+/g, "/").replace(/\/$/, "");
+}
+
+export function pickTrainingCompareTarget<T extends TrainingCompareCandidate>(
+ loras: T[],
+ handoff: Pick<TrainingCompareHandoff, "baseModel" | "outputDir">,
+): T | null {
+ const outputDir = handoff.outputDir ? normalizePath(handoff.outputDir) : "";
+ const run = outputDir
+ ? loras.find((lora) => normalizePath(lora.id) === outputDir)
+ : undefined;
+ if (run) return run;
+
+ const adapterOnly = loras.filter((lora) => lora.exportType === "lora");
+ if (adapterOnly.length === 0) return null;
+ const sorted = [...adapterOnly].sort(
+ (a, b) => (b.updatedAt ?? -1) - (a.updatedAt ?? -1),
+ );
+ const normalizedBase = normalizeModelRef(handoff.baseModel);
+ if (!normalizedBase) return sorted[0] ?? null;
+
+ const exact = sorted.find(
+ (lora) => normalizeModelRef(lora.baseModel) === normalizedBase,
+ );
+ if (exact) return exact;
+
+ const partial = sorted.find((lora) => {
+ const normalizedLoraBase = normalizeModelRef(lora.baseModel);
+ if (!normalizedLoraBase) return false;
+ return (
+ normalizedLoraBase.includes(normalizedBase) ||
+ normalizedBase.includes(normalizedLoraBase)
+ );
+ });
+ return partial ?? null;
+}
+
+export function trainingCompareSelection(target: TrainingCompareCandidate) {
+ return {
+ id: target.id,
+ isLora: target.exportType === "lora",
+ isDownloaded: true,
+ };
+}
diff --git a/studio/frontend/src/features/studio/sections/progress-section.tsx b/studio/frontend/src/features/studio/sections/progress-section.tsx
index f56cce3f60a..11e71fd0438 100644
--- a/studio/frontend/src/features/studio/sections/progress-section.tsx
+++ b/studio/frontend/src/features/studio/sections/progress-section.tsx
@@ -156,7 +156,7 @@ export function ProgressSection({
data.phase === "training" && pct >= 50 && pct < 100;
const showCompletedHint = data.phase === "completed";
const handleCompareInChat = async () => {
- setTrainingCompareHandoff(data.modelName);
+ setTrainingCompareHandoff(data.modelName, data.outputDir);
await navigate({ to: "/chat" });
};
diff --git a/studio/frontend/tests/training-compare-handoff.test.ts b/studio/frontend/tests/training-compare-handoff.test.ts
new file mode 100644
index 00000000000..6942bb2a182
--- /dev/null
+++ b/studio/frontend/tests/training-compare-handoff.test.ts
@@ -0,0 +1,107 @@
+// 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";
+import * as handoff from "../src/features/chat/lib/training-compare-handoff.ts";
+
+const OUTPUTS = "/home/u/.unsloth/studio/outputs";
+const QWEN = "unsloth/Qwen3-4B-Instruct-2507";
+const fullFinetune = {
+ id: `${OUTPUTS}/unsloth_Qwen3-4B-Instruct-2507_1759100000`,
+ baseModel: QWEN,
+ updatedAt: 1759100000,
+ exportType: "merged" as const,
+};
+const olderLlamaLora = {
+ id: `${OUTPUTS}/unsloth_Llama-3.2-1B-Instruct_1759000000`,
+ baseModel: "unsloth/Llama-3.2-1B-Instruct",
+ updatedAt: 1759000000,
+ exportType: "lora" as const,
+};
+
+function withSessionStorage(run: () => void): void {
+ const values = new Map<string, string>();
+ const prior = Object.getOwnPropertyDescriptor(globalThis, "window");
+ Object.defineProperty(globalThis, "window", {
+ value: {
+ sessionStorage: {
+ getItem: (key: string) => values.get(key) ?? null,
+ setItem: (key: string, value: string) => values.set(key, value),
+ removeItem: (key: string) => values.delete(key),
+ },
+ },
+ configurable: true,
+ });
+ try {
+ run();
+ } finally {
+ if (prior) Object.defineProperty(globalThis, "window", prior);
+ else delete (globalThis as { window?: unknown }).window;
+ }
+}
+
+function pick(
+ loras: (typeof fullFinetune | typeof olderLlamaLora)[],
+ outputDir: string | null,
+) {
+ return handoff.pickTrainingCompareTarget(loras, {
+ baseModel: QWEN,
+ outputDir,
+ });
+}
+
+test("the compare handoff carries the finished run's folder to Chat", () => {
+ withSessionStorage(() => {
+ handoff.setTrainingCompareHandoff(QWEN, fullFinetune.id);
+ assert.equal(
+ handoff.getTrainingCompareHandoff()?.outputDir,
+ fullFinetune.id,
+ );
+ });
+});
+
+test("a finished full fine-tune beats an older LoRA on another base", () => {
+ const target = pick([fullFinetune, olderLlamaLora], `${fullFinetune.id}/`);
+ assert.equal(target?.id, fullFinetune.id);
+});
+
+test("a finished LoRA run beats a newer LoRA on the same base", () => {
+ const newerQwenLora = {
+ ...olderLlamaLora,
+ id: `${OUTPUTS}/unsloth_Qwen3-4B-Instruct-2507_1759200000`,
+ baseModel: QWEN,
+ updatedAt: 1759200000,
+ };
+ const finishedQwenLora = {
+ ...newerQwenLora,
+ id: `${OUTPUTS}/unsloth_Qwen3-4B-Instruct-2507_1759150000`,
+ updatedAt: 1759150000,
+ };
+ const target = pick([newerQwenLora, finishedQwenLora], finishedQwenLora.id);
+ assert.equal(target?.id, finishedQwenLora.id);
+});
+
+test("an adapter trained on another base model is never picked", () => {
+ assert.equal(pick([olderLlamaLora], fullFinetune.id), null);
+});
+
+test("without the run's folder, the newest same-base LoRA is picked", () => {
+ const qwenLora = {
+ ...olderLlamaLora,
+ id: `${OUTPUTS}/qwen_lora`,
+ baseModel: QWEN,
+ };
+ assert.equal(
+ pick([olderLlamaLora, qwenLora, fullFinetune], null)?.id,
+ qwenLora.id,
+ );
+});
+
+test("a finished full fine-tune loads as a local model, not a download", () => {
+ assert.deepEqual(handoff.trainingCompareSelection(fullFinetune), {
+ id: fullFinetune.id,
+ isLora: false,
+ isDownloaded: true,
+ });
+});