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: save LoRA and merged exports of a run to separate folders (#17260)

Nilay7caea9bc7b10
diff --git a/studio/frontend/src/features/export/export-page.tsx b/studio/frontend/src/features/export/export-page.tsx
index 2856878e2ff..b2c2c9da269 100644
--- a/studio/frontend/src/features/export/export-page.tsx
+++ b/studio/frontend/src/features/export/export-page.tsx
@@ -118,7 +118,11 @@ import {
reapSummaryLabel,
} from "./lib/reap";
import { exportRemoteCodeConsent } from "./lib/remote-code-consent";
-import { saveDirectoryField } from "./lib/save-directory";
+import {
+ type SourceMode,
+ buildRelativeSaveDirectory,
+ saveDirectoryField,
+} from "./lib/save-directory";
import { exportUnsupportedText } from "./lib/unsupported-text";
import {
isExportPanelActive,
@@ -144,46 +148,6 @@ const SOURCE_TAB_OPTIONS = [
] as const satisfies readonly { value: SourceTab; label: string }[];
const FIELD_LABEL =
"flex items-center gap-1.5 text-xs font-medium text-muted-foreground";
-type SourceMode = "checkpoint" | "model";
-
-function safePathSegment(
- value: string | null | undefined,
- fallback = "model",
- maxLength = 250,
-): string {
- const safe = (value ?? "")
- .replace(/[^a-zA-Z0-9._-]/g, "-")
- .replace(/^[._-]+|[._-]+$/g, "")
- .slice(0, maxLength)
- .replace(/[._-]+$/g, "");
- return safe || fallback;
-}
-
-function buildRelativeSaveDirectory(
- exportMethod: ExportMethod | null,
- sourceMode: SourceMode,
- sourceBaseModelName: string,
- selectedModelIdx: string | null,
- checkpoint: string | null,
-): string {
- if (exportMethod === "gguf") {
- const rawName =
- sourceMode === "checkpoint"
- ? (checkpoint ?? selectedModelIdx ?? sourceBaseModelName)
- : sourceBaseModelName;
- return `${safePathSegment(rawName)}-GGUF`;
- }
- if (sourceMode === "checkpoint" && selectedModelIdx && checkpoint) {
- return `${selectedModelIdx}/${checkpoint}`;
- }
- // Name from the model id to avoid "model/null".
- const rawName =
- sourceMode === "checkpoint"
- ? (checkpoint ?? selectedModelIdx ?? sourceBaseModelName)
- : sourceBaseModelName;
- return `${safePathSegment(rawName)}-${exportMethod === "lora" ? "adapter" : "merged"}`;
-}
-
function siblingGgufDirectory(sourcePath: string): string | null {
const trimmed = sourcePath.trim().replace(/[\\/]+$/, "");
if (!trimmed) return null;
diff --git a/studio/frontend/src/features/export/lib/save-directory.ts b/studio/frontend/src/features/export/lib/save-directory.ts
index 1535a10d223..065eab52da4 100644
--- a/studio/frontend/src/features/export/lib/save-directory.ts
+++ b/studio/frontend/src/features/export/lib/save-directory.ts
@@ -1,6 +1,52 @@
// 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 type { ExportMethod } from "../constants";
+
+export type SourceMode = "checkpoint" | "model";
+
+function safePathSegment(
+ value: string | null | undefined,
+ fallback = "model",
+ maxLength = 250,
+): string {
+ const safe = (value ?? "")
+ .replace(/[^a-zA-Z0-9._-]/g, "-")
+ .replace(/^[._-]+|[._-]+$/g, "")
+ .slice(0, maxLength)
+ .replace(/[._-]+$/g, "");
+ return safe || fallback;
+}
+
+export function buildRelativeSaveDirectory(
+ exportMethod: ExportMethod | null,
+ sourceMode: SourceMode,
+ sourceBaseModelName: string,
+ selectedModelIdx: string | null,
+ checkpoint: string | null,
+): string {
+ const suffix =
+ exportMethod === "gguf"
+ ? "GGUF"
+ : exportMethod === "lora"
+ ? "adapter"
+ : "merged";
+ if (sourceMode === "checkpoint" && selectedModelIdx && checkpoint) {
+ if (exportMethod !== "gguf") {
+ return `${selectedModelIdx}/${checkpoint}-${suffix}`;
+ }
+ if (checkpoint !== selectedModelIdx) {
+ return `${safePathSegment(`${selectedModelIdx}-${checkpoint}`)}-GGUF`;
+ }
+ }
+ // Name from the model id to avoid "model/null".
+ const rawName =
+ sourceMode === "checkpoint"
+ ? (checkpoint ?? selectedModelIdx ?? sourceBaseModelName)
+ : sourceBaseModelName;
+ return `${safePathSegment(rawName)}-${suffix}`;
+}
+
export function saveDirectoryField(
custom: string | null,
defaultSaveDirectory: string,
diff --git a/studio/frontend/tests/export-save-directory.test.ts b/studio/frontend/tests/export-save-directory.test.ts
index 13c60e6f51e..c6d3a767207 100644
--- a/studio/frontend/tests/export-save-directory.test.ts
+++ b/studio/frontend/tests/export-save-directory.test.ts
@@ -4,7 +4,10 @@
import assert from "node:assert/strict";
import test from "node:test";
-import { saveDirectoryField } from "../src/features/export/lib/save-directory.ts";
+import {
+ buildRelativeSaveDirectory,
+ saveDirectoryField,
+} from "../src/features/export/lib/save-directory.ts";
const DEFAULT = "qwen3-4b-GGUF";
@@ -35,3 +38,28 @@ test("a pasted absolute path is used as typed", () => {
saveDirectory: "/Volumes/ext/exports",
});
});
+
+const checkpointDir = (
+ method: "lora" | "merged" | "gguf",
+ run: string,
+ checkpoint: string,
+) => buildRelativeSaveDirectory(method, "checkpoint", "", run, checkpoint);
+
+test("a run's LoRA and merged exports get separate default folders", () => {
+ const lora = checkpointDir("lora", "run_A", "run_A");
+ const merged = checkpointDir("merged", "run_A", "run_A");
+ assert.notEqual(lora, merged);
+ assert.ok(lora.startsWith("run_A/"));
+ assert.ok(merged.startsWith("run_A/"));
+});
+
+test("the same checkpoint of two runs gets separate GGUF default folders", () => {
+ assert.notEqual(
+ checkpointDir("gguf", "run_A", "checkpoint-100"),
+ checkpointDir("gguf", "run_B", "checkpoint-100"),
+ );
+});
+
+test("a run's final checkpoint keeps its GGUF default folder", () => {
+ assert.equal(checkpointDir("gguf", "run_A", "run_A"), "run_A-GGUF");
+});