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
feat(studio): Mac-aware training controls for MLX (optimizers, LoftQ, packing) (#7358)
Long Yixinge143e1ce33b7
diff --git a/studio/frontend/src/config/training.ts b/studio/frontend/src/config/training.tsindex 873e9aa2039..10f7e93e5ee 100644--- a/studio/frontend/src/config/training.ts+++ b/studio/frontend/src/config/training.ts@@ -92,6 +92,19 @@ export const OPTIMIZER_OPTIONS: ReadonlyArray<{ value: string; label: string }>{ value: "adamw_torch_fused", label: "AdamW (PyTorch Fused)" },];+// Optimizers the MLX trainer actually supports on Apple Silicon. Values must+// match SUPPORTED_MLX_OPTIMIZERS in unsloth-zoo's mlx/trainer.py; on MLX the+// bitsandbytes/torch names above have no meaning and are remapped to plain+// AdamW, so Studio offers this list instead when running on a Mac.+export const MLX_OPTIMIZER_OPTIONS: ReadonlyArray<{ value: string; label: string }> = [+ { value: "adamw", label: "AdamW" },+ { value: "adam", label: "Adam" },+ { value: "lion", label: "Lion" },+ { value: "muon", label: "Muon" },+ { value: "sgd", label: "SGD" },+ { value: "adafactor", label: "Adafactor" },+];+export const LR_SCHEDULER_OPTIONS: ReadonlyArray<{ value: string; label: string }> = [{ value: "linear", label: "Linear" },{ value: "cosine", label: "Cosine" },diff --git a/studio/frontend/src/features/studio/sections/params-section.tsx b/studio/frontend/src/features/studio/sections/params-section.tsxindex 029fef4e195..3270eb4e3df 100644--- a/studio/frontend/src/features/studio/sections/params-section.tsx+++ b/studio/frontend/src/features/studio/sections/params-section.tsx@@ -36,6 +36,7 @@ import {CONTEXT_LENGTHS,CPT_TARGET_MODULES,LR_SCHEDULER_OPTIONS,+ MLX_OPTIMIZER_OPTIONS,OPTIMIZER_OPTIONS,TARGET_MODULES,} from "@/config/training";@@ -204,6 +205,42 @@ export function ParamsSection(): ReactElement {setCtxInput(String(store.contextLength));}, [store.contextLength]);+ // On Apple Silicon the MLX trainer supports a different optimizer set than+ // the CUDA/bitsandbytes list, so offer the MLX names there.+ const isMac = platformDeviceType === "mac";+ const optimizerOptions = isMac ? MLX_OPTIMIZER_OPTIONS : OPTIMIZER_OPTIONS;++ // On Mac, the MLX backend normalizes every CUDA/bitsandbytes optimizer in+ // OPTIMIZER_OPTIONS (including the shared default) to plain AdamW, so show+ // AdamW for those to keep the control truthful and non-blank. Any other+ // value -- an MLX optimizer the user picked, or an unrecognized/non-canonical+ // imported one -- is shown as-is rather than mislabeled as AdamW, since the+ // backend would run or reject it on its own terms. Non-Mac display unchanged.+ const isCudaAliasOptimizer = OPTIMIZER_OPTIONS.some(+ (o) => o.value === store.optimizerType,+ );+ const selectedOptimizer =+ isMac && isCudaAliasOptimizer ? "adamw" : store.optimizerType;++ // LoftQ is not supported on MLX (the backend rejects it), so clear a stale+ // selection to lora on Apple Silicon -- whether persisted, applied from a+ // model default, or imported -- so the backend never receives it.+ const setLoraVariant = store.setLoraVariant;+ useEffect(() => {+ if (isMac && store.loraVariant === "loftq") {+ setLoraVariant("lora");+ }+ }, [isMac, store.loraVariant, setLoraVariant]);++ // Packing is not supported on MLX (the backend forces it off), so clear it on+ // Apple Silicon -- the checkbox is disabled and the flag is never sent.+ const setPacking = store.setPacking;+ useEffect(() => {+ if (isMac && store.packing) {+ setPacking(false);+ }+ }, [isMac, store.packing, setPacking]);+const trySetContextLength = (input: string): number | null => {const n = Number(input);if (Number.isInteger(n) && n > 0) {@@ -706,8 +743,9 @@ export function ParamsSection(): ReactElement {<buttonkey={opt.value}type="button"+ disabled={isMac && opt.value === "loftq"}onClick={() => store.setLoraVariant(opt.value)}- className={`flex-1 corner-squircle rounded-xl border px-3 py-2 text-left transition-colors cursor-pointer ${+ className={`flex-1 corner-squircle rounded-xl border px-3 py-2 text-left transition-colors cursor-pointer disabled:cursor-not-allowed disabled:opacity-60 ${store.loraVariant === opt.value? "border-ring-strong bg-primary/5": "border-border hover:border-foreground/20"@@ -715,7 +753,9 @@ export function ParamsSection(): ReactElement {><p className="text-xs font-medium">{opt.label}</p><p className="text-ui-10 text-muted-foreground">- {opt.desc}+ {isMac && opt.value === "loftq"+ ? "Not supported on Apple Silicon"+ : opt.desc}</p></button>))}@@ -765,7 +805,11 @@ export function ParamsSection(): ReactElement {label={t("studio.params.optimizer")}tooltip={<>- {t("studio.params.optimizerTooltip")}{" "}+ {t(+ isMac+ ? "studio.params.optimizerTooltipMlx"+ : "studio.params.optimizerTooltip",+ )}{" "}<ahref="https://unsloth.ai/docs/get-started/fine-tuning-llms-guide/lora-hyperparameters-guide"target="_blank"@@ -778,14 +822,14 @@ export function ParamsSection(): ReactElement {}><Select- value={store.optimizerType}+ value={selectedOptimizer}onValueChange={(v) => store.setOptimizerType(v)}><SelectTrigger className="w-48"><SelectValue /></SelectTrigger><SelectContent>- {OPTIMIZER_OPTIONS.map((opt) => (+ {optimizerOptions.map((opt) => (<SelectItem key={opt.value} value={opt.value}>{formatOptimizerLabel(opt.value, opt.label, t)}</SelectItem>@@ -1105,14 +1149,37 @@ export function ParamsSection(): ReactElement {<Checkboxid="packing"checked={store.packing}+ disabled={isMac}onCheckedChange={(v) => store.setPacking(!!v)}/><labelhtmlFor="packing"- className="text-xs cursor-pointer text-muted-foreground"+ className={`text-xs text-muted-foreground ${+ isMac+ ? "cursor-not-allowed opacity-60"+ : "cursor-pointer"+ }`}>{t("studio.params.enablePacking")}</label>+ {isMac && (+ <Tooltip>+ <TooltipTrigger asChild={true}>+ <button+ type="button"+ className="text-foreground/70 hover:text-foreground"+ >+ <HugeiconsIcon+ icon={InformationCircleIcon}+ className="size-3"+ />+ </button>+ </TooltipTrigger>+ <TooltipContent>+ Packing is not supported on Apple Silicon (MLX).+ </TooltipContent>+ </Tooltip>+ )}</div>)}{!store.isEmbeddingModel && !isCpt && !isRawText && (diff --git a/studio/frontend/src/features/studio/sections/progress-section.tsx b/studio/frontend/src/features/studio/sections/progress-section.tsxindex 105657e2ef2..ad813e888e4 100644--- a/studio/frontend/src/features/studio/sections/progress-section.tsx+++ b/studio/frontend/src/features/studio/sections/progress-section.tsx@@ -19,7 +19,8 @@ import {PopoverTrigger,} from "@/components/ui/popover";import { Progress } from "@/components/ui/progress";-import { OPTIMIZER_OPTIONS } from "@/config/training";+import { usePlatformStore } from "@/config/env";+import { MLX_OPTIMIZER_OPTIONS, OPTIMIZER_OPTIONS } from "@/config/training";import { setTrainingCompareHandoff } from "@/features/chat";import {useTrainingActions,@@ -92,6 +93,7 @@ export function ProgressSection({}: ProgressSectionProps): ReactElement {const t = useT();const navigate = useNavigate();+ const platformDeviceType = usePlatformStore((s) => s.deviceType);const trainingMethodLabel = getTrainingMethodLabel(data.trainingMethod);const config = useTrainingConfigStore(@@ -187,9 +189,18 @@ export function ProgressSection({const cfgLoraDropout = cfg?.loraDropout;const cfgLoraVariant = cfg?.loraVariant;+ // Mirror the training form: on Mac the CUDA/bitsandbytes optimizer names run+ // as plain AdamW (the MLX backend normalizes them), so label them AdamW here+ // too rather than by the requested, unnormalized name.+ const effectiveOptimizer =+ platformDeviceType === "mac" &&+ OPTIMIZER_OPTIONS.some((o) => o.value === cfgOptimizerType)+ ? "adamw"+ : cfgOptimizerType;const optimizerLabel =- OPTIMIZER_OPTIONS.find((o) => o.value === cfgOptimizerType)?.label ??- cfgOptimizerType;+ [...OPTIMIZER_OPTIONS, ...MLX_OPTIMIZER_OPTIONS].find(+ (o) => o.value === effectiveOptimizer,+ )?.label ?? effectiveOptimizer;const configItems: ConfigGroup[] = [{diff --git a/studio/frontend/src/i18n/locales/en.ts b/studio/frontend/src/i18n/locales/en.tsindex 57f06ceb7ec..a0f9bfc1cd6 100644--- a/studio/frontend/src/i18n/locales/en.ts+++ b/studio/frontend/src/i18n/locales/en.ts@@ -1051,6 +1051,8 @@ export const en = {optimizer: "Optimizer",optimizerTooltip:"Optimization algorithm. 8-bit variants reduce memory usage. Fused is recommended for vision models.",+ optimizerTooltipMlx:+ "Optimization algorithm. AdamW is the default. Lion uses less memory but usually needs a lower learning rate.",lrScheduler: "LR scheduler",lrSchedulerTooltip:"How the learning rate changes over training. Linear decays steadily; cosine decays in a curve.",diff --git a/tests/studio/playwright_ui_font_scale.py b/tests/studio/playwright_ui_font_scale.pyindex 7dbe36127c5..89c7894929b 100644--- a/tests/studio/playwright_ui_font_scale.py+++ b/tests/studio/playwright_ui_font_scale.py@@ -38,7 +38,11 @@ def fail(m):raise AssertionError(f"[font-scale] FAIL: {m}")-def near(a, b, tol = 0.35):+def near(+ a,+ b,+ tol = 0.35,+):return a is not None and b is not None and abs(a - b) <= tol@@ -86,9 +90,7 @@ def open_appearance(page):page.wait_for_timeout(700)if page.get_by_role("dialog").count() == 0:fail("settings dialog did not open")- page.get_by_role("dialog").get_by_role("button").filter(- has_text = "Appearance"- ).first.click()+ page.get_by_role("dialog").get_by_role("button").filter(has_text = "Appearance").first.click()page.wait_for_timeout(600)@@ -153,9 +155,7 @@ def main():page.wait_for_timeout(400)step("overflowing select scrolls its Radix viewport")- page.get_by_role("dialog").get_by_role("button").filter(- has_text = "Voice"- ).first.click()+ page.get_by_role("dialog").get_by_role("button").filter(has_text = "Voice").first.click()page.wait_for_timeout(600)page.set_viewport_size({"width": 1440, "height": 480})page.locator("[aria-label='Dictation language']").click()@@ -194,9 +194,7 @@ def main():page.wait_for_timeout(400)step("default restores exactly")- page.get_by_role("dialog").get_by_role("button").filter(- has_text = "Appearance"- ).first.click()+ page.get_by_role("dialog").get_by_role("button").filter(has_text = "Appearance").first.click()page.wait_for_timeout(500)set_input(page, "UI font size", DEFAULT)final = measure(page)diff --git a/tests/studio/test_ui_font_scale_contract.py b/tests/studio/test_ui_font_scale_contract.pyindex 62bf80e82b1..393c60dd6b6 100644--- a/tests/studio/test_ui_font_scale_contract.py+++ b/tests/studio/test_ui_font_scale_contract.py@@ -15,9 +15,7 @@ from pathlib import PathREPO = Path(__file__).resolve().parents[2]SRC = REPO / "studio/frontend/src"INDEX_CSS = (SRC / "index.css").read_text(encoding = "utf-8")-STORE = (SRC / "features/settings/stores/appearance-custom-store.ts").read_text(- encoding = "utf-8"-)+STORE = (SRC / "features/settings/stores/appearance-custom-store.ts").read_text(encoding = "utf-8")SELECT = (SRC / "components/ui/select.tsx").read_text(encoding = "utf-8")# Raw numeric fontSize props are only allowed where a scaled stylesheet rule@@ -70,9 +68,7 @@ def test_ui_token_families_exist():def test_explicit_code_font_size_is_never_multiplied():- match = re.search(- r"html\[data-code-font-size\][^{]*\{([^}]*)\}", INDEX_CSS- )+ match = re.search(r"html\[data-code-font-size\][^{]*\{([^}]*)\}", INDEX_CSS)assert match is not Nonebody = match.group(1)assert "var(--custom-code-font-size)" in body@@ -83,7 +79,9 @@ def test_radix_select_viewport_owns_the_scroll_state():viewport = SELECT[SELECT.index("SelectPrimitive.Viewport") :]assert "overflow-y-auto" in viewport.split("</SelectPrimitive.Viewport>")[0]# The rounded surface itself must not scroll (WebKit squares its corners).- content_cls = re.search(r"SelectPrimitive\.Content[\s\S]*?className=\{cn\(\s*\"([^\"]+)\"", SELECT)+ content_cls = re.search(+ r"SelectPrimitive\.Content[\s\S]*?className=\{cn\(\s*\"([^\"]+)\"", SELECT+ )assert content_cls is not Noneassert "overflow-hidden" in content_cls.group(1)assert "overflow-y-auto" not in content_cls.group(1)