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
Studio: pick which LoRA to add from a searchable list instead of cycling through them (#16964)
oobabooga671a16c92d7a
diff --git a/studio/frontend/src/features/images/images-page.tsx b/studio/frontend/src/features/images/images-page.tsxindex d003a5d9749..33eda789e4d 100644--- a/studio/frontend/src/features/images/images-page.tsx+++ b/studio/frontend/src/features/images/images-page.tsx@@ -4,6 +4,7 @@import { generationFailureLogsAction } from "@/features/settings/lib/view-logs-action";import { isRetiredCopySnapshot, readImageModel, retiredSnapshotAsLoaded, rememberImageModel, matchesRememberedModel, componentFilesMatch, componentFieldsOwnerAfterLoad, componentFilesForModel, forgetStaleImageComponents, forgetStaleResidentComponents, recalledComponentFiles, reconcileRememberedComponents, rememberLoadedImageComponents, recoveredComponentFields, seedImageComponents, rememberPendingImageLoad, clearPendingImageLoad, finishedLoadTarget, type ImageComponentFiles, type ImageModelKey, type RememberedImageModel } from "./image-model-recall";import { componentFileFields, splitComponentFileList } from "./component-files";+import { LoraAddMenu } from "./lora-add-menu";import type { CompareContext } from "./compare/compare-axes";import type { CompareRun } from "./compare/compare-run";// Statically imported: this page is already its own lazy chunk, and a nested import() of the panel split modules@@ -1919,11 +1920,14 @@ export function ImagesPage({const [availableLoras, setAvailableLoras] = useState<DiffusionLoraInfo[]>([]);// The family availableLoras was fetched for; undefined while none is current (loading, failed, no model).const [loraCatalogFamily, setLoraCatalogFamily] = useState<string | null | undefined>(undefined);- // Fine-tuned (trained in Unsloth) first, for both the suggestions and the Add LoRA prefill.+ // Fine-tuned (trained in Unsloth) first, for both the row suggestions and the Add LoRA picker.const sortedLoras = useMemo(() => [...availableLoras].sort((a, b) => Number(Boolean(b.fine_tuned)) - Number(Boolean(a.fine_tuned))),[availableLoras],);+ // Trimmed like the request payload, whose duplicate-id check this mirrors.+ const takenLoraIds = useMemo(() => new Set(loras.map((l) => l.id.trim())), [loras]);+ const [focusLoraRow, setFocusLoraRow] = useState<number | null>(null);// Page mode: "create" is the generation workspace, "train" the LoRA training workspace.const pageMode = useImageWorkflowStore((s) => s.pageMode);// Mounted on first visit, then hidden rather than unmounted, so switching to Create keeps the training form.@@ -6772,7 +6776,7 @@ export function ImagesPage({{loraCapable && (<Fieldlabel="LoRAs"- hint="Style or character adapters applied on top of the model. Enter a Hugging Face repo id, pick a suggestion, or add a folder of LoRA files, then set the strength (1.0 = full effect, 0 disables). Stack several."+ hint="Style or character adapters applied on top of the model. Pick one from Add LoRA, enter a Hugging Face repo id, or add a folder of LoRA files, then set the strength (1.0 = full effect, 0 disables). Stack several."><div className="space-y-2">{availableLoras.length > 0 && (@@ -6794,6 +6798,9 @@ export function ImagesPage({<div className="flex items-center gap-2"><Inputvalue={sel.id}+ autoFocus={i === focusLoraRow}+ // One-shot, so a later row mounting at this index (recipe restore) stays unfocused.+ onFocus={i === focusLoraRow ? () => setFocusLoraRow(null) : undefined}list={availableLoras.length > 0 ? "diffusion-lora-suggestions" : undefined}placeholder="owner/name or owner/name:file.safetensors"spellCheck={false}@@ -6831,24 +6838,14 @@ export function ImagesPage({))}<div className="flex gap-2">{loras.length < 8 && (- <Button- type="button"- variant="secondary"- size="sm"- className="flex-1"- onClick={() => {- // Prefill with the first unused suggestion when a curated catalog exists, else an empty row.- const taken = new Set(loras.map((l) => l.id));- const next = sortedLoras.find((a) => !taken.has(a.id));- setLoras((prev) => [- ...prev,- next ? { id: next.id, weight: next.weight_default || 1 } : { id: "", weight: 1 },- ]);+ <LoraAddMenu+ catalog={sortedLoras}+ takenIds={takenLoraIds}+ onAdd={(spec, focusRow) => {+ setFocusLoraRow(focusRow ? loras.length : null);+ setLoras((prev) => [...prev, spec]);}}- >- <HugeiconsIcon icon={PlusSignIcon} className="size-3.5" />- Add LoRA- </Button>+ />)}<Buttontype="button"diff --git a/studio/frontend/src/features/images/lib/lora-add-options.ts b/studio/frontend/src/features/images/lib/lora-add-options.tsnew file mode 100644index 00000000000..2f4deffca7e--- /dev/null+++ b/studio/frontend/src/features/images/lib/lora-add-options.ts@@ -0,0 +1,62 @@+// 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 { DiffusionLoraInfo } from "../api.ts";++export interface LoraAddOption {+ lora: DiffusionLoraInfo;+ added: boolean;+}++export interface LoraAddGroup {+ heading: string;+ options: LoraAddOption[];+}++const GROUPS: { heading: string; match: (l: DiffusionLoraInfo) => boolean }[] =+ [+ { heading: "Fine-tuned in Unsloth", match: (l) => Boolean(l.fine_tuned) },+ {+ heading: "On this device",+ match: (l) => !l.fine_tuned && l.source === "local",+ },+ {+ heading: "From Hugging Face",+ match: (l) => !l.fine_tuned && l.source !== "local",+ },+ ];++/** Keeps catalog order within each group. */+export function loraAddGroups(+ catalog: readonly DiffusionLoraInfo[],+ takenIds: ReadonlySet<string>,+ query: string,+): LoraAddGroup[] {+ const needle = query.trim().toLowerCase();+ const shown = needle+ ? catalog.filter(+ (l) =>+ l.display_name.toLowerCase().includes(needle) ||+ l.id.toLowerCase().includes(needle),+ )+ : catalog;+ return GROUPS.map(({ heading, match }) => ({+ heading,+ options: shown+ .filter(match)+ .map((lora) => ({ lora, added: takenIds.has(lora.id) })),+ })).filter((g) => g.options.length > 0);+}++/** A typed `owner/name[:file]` not in the catalog, offered as a Hugging Face id. */+export function customLoraId(+ query: string,+ catalog: readonly DiffusionLoraInfo[],+ takenIds: ReadonlySet<string>,+): { id: string; added: boolean } | null {+ const id = query.trim();+ if (!id.includes("/") || /\s/.test(id)) return null;+ return catalog.some((l) => l.id === id)+ ? null+ : { id, added: takenIds.has(id) };+}diff --git a/studio/frontend/src/features/images/lora-add-menu.tsx b/studio/frontend/src/features/images/lora-add-menu.tsxnew file mode 100644index 00000000000..3f065850607--- /dev/null+++ b/studio/frontend/src/features/images/lora-add-menu.tsx@@ -0,0 +1,183 @@+// 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 { PlusSignIcon } from "@hugeicons/core-free-icons";+import { HugeiconsIcon } from "@hugeicons/react";+import { useMemo, useRef, useState } from "react";++import { Button } from "@/components/ui/button";+import {+ Command,+ CommandGroup,+ CommandInput,+ CommandItem,+ CommandList,+ CommandSeparator,+} from "@/components/ui/command";+import {+ Popover,+ PopoverContent,+ PopoverTrigger,+} from "@/components/ui/popover";+import { ChevronDownStandardIcon } from "@/lib/chevron-icons";++import type { DiffusionLoraInfo, LoraSpecInput } from "./api";+import { customLoraId, loraAddGroups } from "./lib/lora-add-options";++const EMPTY_ROW = "__empty-row__";+const CUSTOM_ROW = "__custom-row__";++/** `onAdd`'s `focusRow` asks the caller to focus the new row's id field; the popover then leaves focus alone. */+export function LoraAddMenu({+ catalog,+ takenIds,+ onAdd,+}: {+ catalog: readonly DiffusionLoraInfo[];+ takenIds: ReadonlySet<string>;+ onAdd: (spec: LoraSpecInput, focusRow: boolean) => void;+}) {+ const [open, setOpen] = useState(false);+ const [query, setQuery] = useState("");+ const keepFocusOnRow = useRef(false);+ const groups = useMemo(+ () => loraAddGroups(catalog, takenIds, query),+ [catalog, takenIds, query],+ );+ const custom = customLoraId(query, catalog, takenIds);++ if (catalog.length === 0) {+ return (+ <Button+ type="button"+ variant="secondary"+ size="sm"+ className="flex-1"+ onClick={() => onAdd({ id: "", weight: 1 }, true)}+ >+ <HugeiconsIcon icon={PlusSignIcon} className="size-3.5" />+ Add LoRA+ </Button>+ );+ }++ const openChange = (next: boolean) => {+ setOpen(next);+ if (!next) setQuery("");+ };+ const add = (spec: LoraSpecInput, focusRow: boolean) => {+ keepFocusOnRow.current = focusRow;+ onAdd(spec, focusRow);+ openChange(false);+ };++ return (+ <Popover open={open} onOpenChange={openChange}>+ <PopoverTrigger asChild={true}>+ <Button type="button" variant="secondary" size="sm" className="flex-1">+ <HugeiconsIcon icon={PlusSignIcon} className="size-3.5" />+ Add LoRA+ <HugeiconsIcon+ icon={ChevronDownStandardIcon}+ strokeWidth={2}+ className="size-3.5 opacity-60"+ />+ </Button>+ </PopoverTrigger>+ <PopoverContent+ align="start"+ sideOffset={4}+ collisionPadding={12}+ className="w-[max(var(--radix-popover-trigger-width),20rem)] gap-0 overflow-hidden rounded-lg p-1"+ onCloseAutoFocus={(e) => {+ if (keepFocusOnRow.current) e.preventDefault();+ keepFocusOnRow.current = false;+ }}+ >+ {/* Own filtering: the list is small and grouped, and the custom-id row must not be filtered away. */}+ <Command+ shouldFilter={false}+ className="min-h-0 rounded-none bg-transparent p-0"+ >+ <CommandInput+ value={query}+ onValueChange={setQuery}+ aria-label="Search LoRAs"+ placeholder="Search LoRAs or paste owner/name"+ />+ {/* Only the catalog scrolls and shrinks, so the footer stays visible in a short window; the flex column runs through cmdk's sizer div. */}+ <CommandList className="flex max-h-none min-h-0 flex-col overflow-hidden [&>[cmdk-list-sizer]]:flex [&>[cmdk-list-sizer]]:min-h-0 [&>[cmdk-list-sizer]]:flex-col">+ {/* Not CommandEmpty: the Hugging Face row below is always an item, so cmdk never counts zero. */}+ {groups.length === 0 && !custom && (+ <p className="px-3 py-4 text-center text-sm text-muted-foreground">+ No LoRA matches.+ </p>+ )}+ <div className="hover-scrollbar max-h-64 min-h-0 overflow-y-auto overscroll-contain">+ {groups.map((group) => (+ <CommandGroup key={group.heading} heading={group.heading}>+ {group.options.map(({ lora, added }) => (+ <CommandItem+ key={lora.id}+ value={lora.id}+ disabled={added}+ data-checked={added}+ title={lora.id}+ onSelect={() =>+ add(+ { id: lora.id, weight: lora.weight_default || 1 },+ false,+ )+ }+ className="cursor-pointer"+ >+ <span className="line-clamp-2 min-w-0 flex-1 [overflow-wrap:anywhere]">+ {lora.display_name}+ </span>+ {added && (+ <span className="shrink-0 text-xs text-muted-foreground">+ Added+ </span>+ )}+ </CommandItem>+ ))}+ </CommandGroup>+ ))}+ </div>+ {groups.length > 0 && <CommandSeparator className="shrink-0" />}+ <CommandGroup className="shrink-0">+ {custom ? (+ <CommandItem+ value={CUSTOM_ROW}+ disabled={custom.added}+ data-checked={custom.added}+ onSelect={() => add({ id: custom.id, weight: 1 }, false)}+ className="cursor-pointer"+ >+ <span className="min-w-0 flex-1 [overflow-wrap:anywhere]">+ Use <span className="font-mono text-xs">{custom.id}</span>+ </span>+ {custom.added && (+ <span className="shrink-0 text-xs text-muted-foreground">+ Added+ </span>+ )}+ </CommandItem>+ ) : (+ <CommandItem+ value={EMPTY_ROW}+ onSelect={() => add({ id: "", weight: 1 }, true)}+ className="cursor-pointer"+ >+ <span className="min-w-0 flex-1 truncate text-muted-foreground">+ Enter a Hugging Face repo or file…+ </span>+ </CommandItem>+ )}+ </CommandGroup>+ </CommandList>+ </Command>+ </PopoverContent>+ </Popover>+ );+}diff --git a/studio/frontend/tests/image-lora-add-options.test.ts b/studio/frontend/tests/image-lora-add-options.test.tsnew file mode 100644index 00000000000..c76e9e5d905--- /dev/null+++ b/studio/frontend/tests/image-lora-add-options.test.ts@@ -0,0 +1,114 @@+// 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 type { DiffusionLoraInfo } from "../src/features/images/api.ts";+import {+ customLoraId,+ loraAddGroups,+} from "../src/features/images/lib/lora-add-options.ts";++function lora(+ id: string,+ extra: Partial<DiffusionLoraInfo> = {},+): DiffusionLoraInfo {+ return {+ id,+ display_name: id.replace(/-[0-9a-f]{8}$/, ""),+ source: "local",+ format: "safetensors",+ families: [],+ size_bytes: 1,+ weight_default: 1,+ ...extra,+ };+}++const CATALOG = [+ lora("sks-dog", { fine_tuned: true }),+ lora("jyzjk-0f53895d"),+ lora("NexBlend12-14b044d2"),+ lora("pixel_art-2c81fb07"),+ lora("krea/Krea-2-LoRA-neondrip", {+ source: "hub",+ display_name: "Krea 2 Neon Drip",+ }),+];++const headings = (groups: ReturnType<typeof loraAddGroups>) =>+ groups.map((g) => g.heading);+const ids = (groups: ReturnType<typeof loraAddGroups>) =>+ groups.flatMap((g) => g.options.map((o) => o.lora.id));++test("every catalog LoRA is listed, grouped as fine-tuned, on this device, then Hugging Face", () => {+ const groups = loraAddGroups(CATALOG, new Set(), "");+ assert.deepEqual(headings(groups), [+ "Fine-tuned in Unsloth",+ "On this device",+ "From Hugging Face",+ ]);+ assert.deepEqual(+ ids(groups),+ CATALOG.map((l) => l.id),+ );+});++test("a LoRA already in a row stays listed, marked added", () => {+ const groups = loraAddGroups(CATALOG, new Set(["NexBlend12-14b044d2"]), "");+ const added = groups.flatMap((g) => g.options).filter((o) => o.added);+ assert.deepEqual(+ added.map((o) => o.lora.id),+ ["NexBlend12-14b044d2"],+ );+ assert.equal(ids(groups).length, CATALOG.length);+});++test("search matches the display name or the id, case-insensitively, and drops empty groups", () => {+ assert.deepEqual(ids(loraAddGroups(CATALOG, new Set(), "nexblend")), [+ "NexBlend12-14b044d2",+ ]);+ assert.deepEqual(ids(loraAddGroups(CATALOG, new Set(), " NEON drip ")), [+ "krea/Krea-2-LoRA-neondrip",+ ]);+ assert.deepEqual(ids(loraAddGroups(CATALOG, new Set(), "2c81fb07")), [+ "pixel_art-2c81fb07",+ ]);+ assert.deepEqual(headings(loraAddGroups(CATALOG, new Set(), "pixel")), [+ "On this device",+ ]);+ assert.deepEqual(loraAddGroups(CATALOG, new Set(), "no such lora"), []);+});++test("only a typed owner/name that is not listed is offered as a Hugging Face id", () => {+ const none = new Set<string>();+ assert.deepEqual(customLoraId(" someone/cool-lora ", CATALOG, none), {+ id: "someone/cool-lora",+ added: false,+ });+ assert.deepEqual(+ customLoraId("someone/cool-lora:style.safetensors", CATALOG, none),+ { id: "someone/cool-lora:style.safetensors", added: false },+ );+ assert.equal(customLoraId("pixel", CATALOG, none), null);+ assert.equal(customLoraId("", CATALOG, none), null);+ assert.equal(customLoraId("some one/lora", CATALOG, none), null);+ assert.equal(customLoraId("krea/Krea-2-LoRA-neondrip", CATALOG, none), null);+});++test("a typed id already in a row is offered as added, so it cannot be added twice", () => {+ const taken = new Set(["someone/custom"]);+ assert.deepEqual(customLoraId("someone/custom", CATALOG, taken), {+ id: "someone/custom",+ added: true,+ });+ assert.deepEqual(customLoraId(" someone/custom ", CATALOG, taken), {+ id: "someone/custom",+ added: true,+ });+ assert.deepEqual(customLoraId("someone/other", CATALOG, taken), {+ id: "someone/other",+ added: false,+ });+});