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.

Keep a sampler's std and uuid format across a save and reopen (#9225)

Vineeth Sai Varikuntlaa6f267a4f52a
diff --git a/studio/frontend/src/features/recipe-studio/utils/import/parsers/sampler-parser.ts b/studio/frontend/src/features/recipe-studio/utils/import/parsers/sampler-parser.ts
index ff2dd004c61..651b5fb50c9 100644
--- a/studio/frontend/src/features/recipe-studio/utils/import/parsers/sampler-parser.ts
+++ b/studio/frontend/src/features/recipe-studio/utils/import/parsers/sampler-parser.ts
@@ -59,6 +59,31 @@ function parseCategoryConditionalParams(
return Object.keys(conditional).length > 0 ? conditional : undefined;
}
+// The words buildSamplerParams reads as a mode rather than as a prefix.
+const UUID_RESERVED_FORMATS = new Set(["uuid4", "short", "short_form", "upper", "uppercase"]);
+
+// buildSamplerParams spreads a uuid format over the three fields data_designer
+// defines, so rebuild the single UI string from those rather than from a
+// `format` key nothing writes. A prefix whose own value is one of the reserved
+// words comes back in the builder's `prefix:` escaped form, so re-saving writes
+// the prefix again instead of turning it into a flag.
+function readUuidFormat(params: Record<string, unknown>): string {
+ const prefix = readString(params.prefix)?.trim();
+ if (prefix) {
+ const lowered = prefix.toLowerCase();
+ return UUID_RESERVED_FORMATS.has(lowered) || lowered.startsWith("prefix:")
+ ? `prefix:${prefix}`
+ : prefix;
+ }
+ if (params.short_form === true) {
+ return "short";
+ }
+ if (params.uppercase === true) {
+ return "upper";
+ }
+ return readString(params.format) ?? "";
+}
+
export function parseSampler(
column: Record<string, unknown>,
name: string,
@@ -155,7 +180,7 @@ export function parseSampler(
// biome-ignore lint/style/useNamingConvention: api schema
convert_to: normalizedConvertTo,
mean: readNumberString(params.mean),
- std: readNumberString(params.std),
+ std: readNumberString(params.stddev ?? params.std),
};
}
@@ -229,7 +254,7 @@ export function parseSampler(
// biome-ignore lint/style/useNamingConvention: api schema
convert_to: normalizedConvertTo,
// biome-ignore lint/style/useNamingConvention: api schema
- uuid_format: readString(params.format) ?? "",
+ uuid_format: readUuidFormat(params),
};
}
diff --git a/studio/frontend/tests/recipe-studio-sampler-round-trip.test.ts b/studio/frontend/tests/recipe-studio-sampler-round-trip.test.ts
new file mode 100644
index 00000000000..c81f369a0b6
--- /dev/null
+++ b/studio/frontend/tests/recipe-studio-sampler-round-trip.test.ts
@@ -0,0 +1,127 @@
+// 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 { registerBundlerResolver } from "./helpers/kit.ts";
+
+registerBundlerResolver();
+
+const { buildSamplerColumn } = await import(
+ "../src/features/recipe-studio/utils/payload/builders-sampler.ts"
+);
+const { parseSampler } = await import(
+ "../src/features/recipe-studio/utils/import/parsers/sampler-parser.ts"
+);
+
+type SamplerConfig = Parameters<typeof buildSamplerColumn>[0];
+
+// Saving writes the payload, reopening re-imports that same payload
+// (use-recipe-persistence re-imports the stored payload on load), so whatever
+// survives this is what the user still sees after a reopen.
+function roundTrip(config: SamplerConfig): SamplerConfig {
+ const buildErrors: string[] = [];
+ const column = buildSamplerColumn(config, buildErrors);
+ assert.deepEqual(buildErrors, [], "the config should build without errors");
+
+ const parseErrors: string[] = [];
+ const parsed = parseSampler(column, config.name, config.id, parseErrors);
+ assert.deepEqual(
+ parseErrors,
+ [],
+ "the built column should parse without errors",
+ );
+ assert.ok(parsed, "the built column should parse back to a sampler");
+ return parsed;
+}
+
+test("a gaussian sampler keeps its standard deviation across a save and reopen", () => {
+ const parsed = roundTrip({
+ id: "gaussian-1",
+ kind: "sampler",
+ sampler_type: "gaussian",
+ name: "score",
+ mean: "10",
+ std: "2.5",
+ });
+
+ assert.equal(parsed.mean, "10");
+ assert.equal(parsed.std, "2.5");
+});
+
+test("a uuid sampler keeps its format across a save and reopen", () => {
+ for (const [uuidFormat, expected] of [
+ ["MY-", "MY-"],
+ ["short", "short"],
+ ["upper", "upper"],
+ ["", ""],
+ ] as const) {
+ const parsed = roundTrip({
+ id: "uuid-1",
+ kind: "sampler",
+ sampler_type: "uuid",
+ name: "row_id",
+ uuid_format: uuidFormat,
+ });
+
+ assert.equal(
+ parsed.uuid_format,
+ expected,
+ `uuid_format ${uuidFormat} should survive`,
+ );
+ }
+});
+
+test("a uuid prefix survives even when its value is a reserved word", () => {
+ // buildSamplerParams reads "short" / "upper" / "uuid4" as modes, so a prefix whose
+ // own value is one of those has to come back escaped or the next save turns the
+ // prefix into a flag. Checked as payload stability over two save/reopen cycles,
+ // which is what a user actually does.
+ for (const uuidFormat of [
+ "MY-",
+ "short",
+ "upper",
+ "uuid4",
+ "prefix:short",
+ "prefix:upper",
+ "prefix:uuid4",
+ "prefix:prefix:x",
+ "",
+ ] as const) {
+ const config: SamplerConfig = {
+ id: "uuid-1",
+ kind: "sampler",
+ sampler_type: "uuid",
+ name: "row_id",
+ uuid_format: uuidFormat,
+ };
+ const firstSave = buildSamplerColumn(config, []);
+ const reopened = roundTrip(config);
+ const secondSave = buildSamplerColumn(reopened, []);
+
+ assert.deepEqual(
+ secondSave.params,
+ firstSave.params,
+ `uuid_format ${JSON.stringify(uuidFormat)} should re-save to the same params`,
+ );
+ }
+});
+
+test("a gaussian sampler still reads a hand-written std key", () => {
+ const parseErrors: string[] = [];
+ const parsed = parseSampler(
+ {
+ column_type: "sampler",
+ sampler_type: "gaussian",
+ name: "score",
+ params: { mean: 1, std: 3 },
+ },
+ "score",
+ "gaussian-legacy",
+ parseErrors,
+ );
+
+ assert.deepEqual(parseErrors, []);
+ assert.equal(parsed?.std, "3");
+});