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
// 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 { useTimeFormat, withTimeFormat } from "@/lib/time-format";
import { useAppShellReadySignal } from "@/components/app-readiness";
import { SectionBox } from "@/components/section-box";
import { SegmentedControl } from "@/components/segmented-control";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { Button } from "@/components/ui/button";
import {
Combobox,
ComboboxContent,
ComboboxEmpty,
ComboboxInput,
ComboboxItem,
ComboboxList,
} from "@/components/ui/combobox";
import {
DropdownMenu,
DropdownMenuCheckboxItem,
DropdownMenuContent,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import {
InputGroup,
InputGroupAddon,
InputGroupInput,
} from "@/components/ui/input-group";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { Spinner } from "@/components/ui/spinner";
import { Switch } from "@/components/ui/switch";
import {
Tooltip,
TooltipContent,
TooltipTrigger,
} from "@/components/ui/tooltip";
import { usePlatformStore } from "@/config/env";
import { prepareHfTokenForUse } from "@/features/hf-auth";
import { hfApiToken, useHfTokenStore, useHubModelSearch } from "@/features/hub";
import { confirmRemoteCodeIfNeeded } from "@/features/security";
import { useNpuStatus } from "@/features/npu";
import { GuidedTour, useGuidedTourController } from "@/features/tour";
import type { LocalModelInfo } from "@/features/training";
import { useDebouncedValue, useHfTokenValidation } from "@/hooks";
import { useFullInstallUpgrade } from "@/hooks/use-full-install-upgrade";
import { FullInstallDialog } from "@/features/settings";
import { useHardwareInfo } from "@/hooks/use-hardware-info";
import { useT } from "@/i18n";
import { ChevronDownStandardIcon } from "@/lib/chevron-icons";
import { cn } from "@/lib/utils";
import {
Alert02Icon,
InformationCircleIcon,
Key01Icon,
PackageIcon,
Search01Icon,
} from "@hugeicons/core-free-icons";
import { FolderSearchIcon } from "@/lib/folder-icons";
import { HugeiconsIcon } from "@hugeicons/react";
import { useSearch } from "@tanstack/react-router";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useShallow } from "zustand/react/shallow";
import {
type DecisionExportInfo,
type DiffusionLmExportInfo,
type ModelCheckpoints,
type MoeInfo,
fetchCheckpointExportProbe,
fetchMoeInfo,
} from "./api/export-api";
import { adapterCompatibilityTip, type AdapterFormat } from "./constants";
import { ExportRunPanel } from "./components/export-run-panel";
import {
ExportSummaryCard,
type ExportSummaryRow,
} from "./components/export-summary-card";
import { ImageLoraExportCard } from "./components/image-lora-export-card";
import { MethodPicker } from "./components/method-picker";
import { Q4nxConvertCard } from "./components/q4nx-convert-card";
import { QuantPicker } from "./components/quant-picker";
import { ReapCard } from "./components/reap-card";
import {
EXPORT_METHODS,
type ExportMethod,
GUIDE_STEPS,
MERGED_FORMATS,
type MergedFormatOption,
Q4NX_SOURCE_QUANTS,
QUANT_OPTIONS,
buildQuantSizeLabels,
getEstimatedSize,
mergedFormatPayload,
} from "./constants";
import {
getCachedCheckpoints,
getCachedLocalModels,
refreshCheckpoints,
refreshLocalModels,
} from "./export-navigation-cache";
import { confirmLlmCompressorInstallIfNeeded } from "./hooks/use-llm-compressor-consent";
import { useExportSizeEstimate } from "./hooks/use-export-size-estimate";
import {
DEFAULT_REAP_SETTINGS,
type ReapSettings,
reapAllowedSparsities,
reapProbeFailed,
reapProbePending,
reapUnavailable,
reapRequest,
reapSummaryLabel,
} from "./lib/reap";
import { exportRemoteCodeConsent } from "./lib/remote-code-consent";
import {
type SourceMode,
buildRelativeSaveDirectory,
saveDirectoryField,
} from "./lib/save-directory";
import { exportUnsupportedText } from "./lib/unsupported-text";
import {
isExportPanelActive,
useExportRuntimeStore,
} from "./stores/export-runtime-store";
import { exportTourSteps } from "./tour";
import { ChipIcon } from "@/lib/hugeicons-derived";
const SEARCH_INPUT_REASONS = new Set([
"input-change",
"input-paste",
"input-clear",
]);
// Q8_0 falls back to F16 per tensor for dims not divisible by 32; no "auto".
const LORA_GGUF_OUTTYPES = ["q8_0", "f16", "bf16", "f32"] as const;
type SourceTab = "local" | "checkpoint" | "hf";
const SOURCE_TAB_OPTIONS = [
{ value: "local", label: "Local" },
{ value: "checkpoint", label: "Fine-tuned" },
{ value: "hf", label: "Hugging Face" },
] as const satisfies readonly { value: SourceTab; label: string }[];
const FIELD_LABEL =
"flex items-center gap-1.5 text-xs font-medium text-muted-foreground";
function siblingGgufDirectory(sourcePath: string): string | null {
const trimmed = sourcePath.trim().replace(/[\\/]+$/, "");
if (!trimmed) return null;
const slash = Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\"));
// Lowercase `_gguf` matches the backend's intermediate dir; `_GGUF` would relocate and delete it.
if (slash < 0) return `${trimmed}_gguf`;
const parent =
slash === 0 || (slash === 2 && /^[A-Za-z]:/.test(trimmed))
? trimmed.slice(0, slash + 1)
: trimmed.slice(0, slash);
const name = trimmed.slice(slash + 1);
if (!name) return null;
const sep =
parent.endsWith("/") || parent.endsWith("\\")
? ""
: trimmed.includes("\\")
? "\\"
: "/";
return `${parent}${sep}${name}_gguf`;
}
export function ExportPage() {
const t = useT();
useTimeFormat();
const signalReady = useAppShellReadySignal();
const { hfToken, setHfToken } = useHfTokenStore(
useShallow((s) => ({
hfToken: s.token,
setHfToken: s.setToken,
})),
);
const [models, setModels] = useState<ModelCheckpoints[]>(
() => getCachedCheckpoints() ?? [],
);
const [loadingCheckpoints, setLoadingCheckpoints] = useState(
getCachedCheckpoints() === null,
);
const [checkpointError, setCheckpointError] = useState<string | null>(null);
const [selectedModelIdx, setSelectedModelIdx] = useState<string | null>(null);
const [checkpoint, setCheckpoint] = useState<string | null>(null);
const [sourceMode, setSourceMode] = useState<SourceMode>("checkpoint");
const [modelSource, setModelSource] = useState<"hf" | "local">("hf");
const [modelInput, setModelInput] = useState("");
const [selectedSourceModel, setSelectedSourceModel] = useState<string | null>(
null,
);
const [localModelInput, setLocalModelInput] = useState("");
const [localModels, setLocalModels] = useState<LocalModelInfo[]>(
() => getCachedLocalModels() ?? [],
);
const [isLoadingLocalModels, setIsLoadingLocalModels] = useState(
getCachedLocalModels() === null,
);
const [localModelsError, setLocalModelsError] = useState<string | null>(null);
const debouncedModelQuery = useDebouncedValue(modelInput);
const debouncedHfToken = useDebouncedValue(hfToken, 500);
// Seed from the live run so a remount keeps the selection.
const [exportMethod, setExportMethod] = useState<ExportMethod | null>(() => {
const s = useExportRuntimeStore.getState();
return isExportPanelActive(s) && s.summary ? s.summary.method : null;
});
const [quantLevels, setQuantLevels] = useState<string[]>(() => {
const s = useExportRuntimeStore.getState();
return isExportPanelActive(s) && s.summary?.method === "gguf"
? s.summary.quantLevels
: [];
});
const [useImatrix, setUseImatrix] = useState(false);
const [npuQ4nx, setNpuQ4nx] = useState(false);
const [reapSettings, setReapSettings] = useState<ReapSettings>(
DEFAULT_REAP_SETTINGS,
);
const [customImatrix, setCustomImatrix] = useState({
sourceKey: "",
path: "",
});
const [selectedFormats, setSelectedFormats] = useState<string[]>(() => {
const s = useExportRuntimeStore.getState();
return isExportPanelActive(s) &&
s.summary?.method === "merged" &&
s.summary.mergedFormats.length > 0
? s.summary.mergedFormats
: ["16-bit"];
});
const [loraAsGguf, setLoraAsGguf] = useState(false);
const [adapterFormat, setAdapterFormat] = useState<AdapterFormat>("mlx");
const [loraGgufOuttype, setLoraGgufOuttype] = useState<string>("q8_0");
const [ggufTarget, setGgufTarget] = useState<"model" | "lora">("model");
const hardware = useHardwareInfo();
// On Mac, GGUF LoRA adapters ship through the LoRA method's toggle, not the GGUF method.
const isMacHost = usePlatformStore((s) => s.deviceType) === "mac";
const torchaoUnavailable = !hardware.torchaoExportSupported;
const hasNvidia = hardware.cuda != null && hardware.rocm == null;
// Only gray out on an authoritative unsupported response.
const exportUnsupported =
hardware.loaded && hardware.exportSupported === false;
const fullInstall = useFullInstallUpgrade();
const canUpgrade = fullInstall !== null;
const [fullInstallOpen, setFullInstallOpen] = useState(false);
const exportUnsupportedMessage = exportUnsupportedText(
hardware.exportUnsupportedReason,
hardware.exportUnsupportedMessage,
canUpgrade,
);
// Only where the full install brings export: without a GPU it trains on CPU and still cannot export.
const offerFullInstall = canUpgrade && hardware.exportUnsupportedReason === "no_torch";
const availableFormats = useMemo<MergedFormatOption[]>(
() =>
MERGED_FORMATS.filter((f) => {
if (f.backend === "compressed") return hasNvidia;
// torchao is hidden on NVIDIA, macOS/MLX and where torchao cannot load.
if (f.backend === "torchao")
return !hasNvidia && !isMacHost && !torchaoUnavailable;
return true;
}),
[hasNvidia, isMacHost, torchaoUnavailable],
);
const toggleFormat = useCallback((value: string) => {
setSelectedFormats((prev) =>
prev.includes(value) ? prev.filter((v) => v !== value) : [...prev, value],
);
}, []);
// Wait for hardware to load: before that hasNvidia reads false.
useEffect(() => {
if (!hardware.loaded) return;
const allowed = new Set(availableFormats.map((f) => f.value));
setSelectedFormats((prev) => {
const next = prev.filter((v) => allowed.has(v));
return next.length === prev.length ? prev : next;
});
}, [availableFormats, hardware.loaded]);
// IQ quants are imatrix-only; llama.cpp rejects them without one.
const requiresImatrix = quantLevels.some(
(q) => QUANT_OPTIONS.find((o) => o.value === q)?.imatrix,
);
const effectiveImatrix = useImatrix || requiresImatrix;
const q4nxSourceSelected = quantLevels.some((q) =>
Q4NX_SOURCE_QUANTS.includes(q),
);
// The panel also shows whenever a run is active or terminal (see `panelActive`).
const [panelOpen, setPanelOpen] = useState(false);
const [destination, setDestination] = useState<"local" | "hub">("local");
// The converter writes beside the GGUFs, so a Hub-only export has nowhere to put it.
const [npuStatus] = useNpuStatus();
const hasNpu = !!npuStatus?.supported;
const effectiveNpuQ4nx =
hasNpu && npuQ4nx && q4nxSourceSelected && destination === "local";
const [customSaveDirectory, setCustomSaveDirectory] = useState<string | null>(
null,
);
const [hfUsername, setHfUsername] = useState("");
const [modelName, setModelName] = useState("");
const [privateRepo, setPrivateRepo] = useState(false);
const runExport = useExportRuntimeStore((s) => s.runExport);
const resetExportRun = useExportRuntimeStore((s) => s.reset);
const isExporting = useExportRuntimeStore((s) => s.isExporting);
const panelActive = useExportRuntimeStore(isExportPanelActive);
const hfComboboxAnchorRef = useRef<HTMLDivElement>(null);
const localComboboxAnchorRef = useRef<HTMLDivElement>(null);
const selectingHfModelRef = useRef(false);
const hfModelInputRef = useRef("");
const localModelInputRef = useRef("");
const tour = useGuidedTourController({
id: "export",
steps: exportTourSteps,
});
useEffect(() => {
let cancelled = false;
const hadCache = getCachedCheckpoints() !== null;
refreshCheckpoints()
.then((models) => {
if (!cancelled) {
setModels(models);
}
})
.catch((err) => {
if (!cancelled && !hadCache) {
setCheckpointError(
err instanceof Error ? err.message : "Failed to load checkpoints",
);
}
})
.finally(() => {
if (!cancelled) setLoadingCheckpoints(false);
});
return () => {
cancelled = true;
};
}, []);
// Apply the ?run= deep link once its run appears in the checkpoint list: select the run and
// default to GGUF. The main checkpoint is auto-selected below, after the model-change effect.
const { run: preselectRun, imageLora: preselectImageLora } = useSearch({
from: "/export",
});
const appliedRunRef = useRef<string | null>(null);
useEffect(() => {
if (!preselectRun) {
appliedRunRef.current = null;
return;
}
if (models.length === 0) return;
if (appliedRunRef.current === preselectRun) return;
const match = models.find((m) => m.name === preselectRun);
if (!match) return;
appliedRunRef.current = preselectRun;
setSourceMode("checkpoint");
setSelectedModelIdx(match.name);
setExportMethod("gguf");
}, [preselectRun, models]);
useEffect(() => {
let cancelled = false;
const hadCache = getCachedLocalModels() !== null;
void refreshLocalModels()
.then((models) => {
if (cancelled) return;
setLocalModels(models);
})
.catch((error) => {
if (cancelled || hadCache) return;
setLocalModelsError(
error instanceof Error
? error.message
: "Failed to load local models",
);
})
.finally(() => {
if (cancelled) return;
setIsLoadingLocalModels(false);
});
return () => {
cancelled = true;
};
}, []);
const reloadReadySent = useRef(false);
useEffect(() => {
if (loadingCheckpoints || isLoadingLocalModels || reloadReadySent.current) {
return;
}
reloadReadySent.current = true;
signalReady();
}, [isLoadingLocalModels, loadingCheckpoints, signalReady]);
const selectedModelData = useMemo(
() =>
selectedModelIdx != null
? (models.find((m) => m.name === selectedModelIdx) ?? null)
: null,
[models, selectedModelIdx],
);
const checkpointsForModel = useMemo(
() => selectedModelData?.checkpoints ?? [],
[selectedModelData],
);
const baseModelName = selectedModelData?.base_model ?? "—";
const isAdapter = !!selectedModelData?.peft_type;
const isQuantized = !!selectedModelData?.is_quantized;
// Checkpoint metadata is stale in "model" source mode, so ignore it there.
const effectiveIsAdapter = sourceMode === "checkpoint" && isAdapter;
const effectiveIsQuantized = sourceMode === "checkpoint" && isQuantized;
const loraRank = selectedModelData?.lora_rank ?? null;
const trainingMethodLabel = selectedModelData?.peft_type
? "LoRA / QLoRA"
: "Full Fine-tune";
const sourceBaseModelName =
sourceMode === "model" ? (selectedSourceModel ?? "—") : baseModelName;
// Full fine-tune weights live in the checkpoint dir; LoRA adapters merge into the base.
const sizeTargetModel = useMemo(() => {
if (sourceMode === "checkpoint" && !isAdapter) {
const cp = checkpointsForModel.find((c) => c.display_name === checkpoint);
if (cp?.path) {
return cp.path;
}
}
return sourceBaseModelName;
}, [
sourceMode,
isAdapter,
checkpointsForModel,
checkpoint,
sourceBaseModelName,
]);
const { fp16Bytes } = useExportSizeEstimate(
sizeTargetModel,
debouncedHfToken,
);
const quantSizeLabels = useMemo(
() => buildQuantSizeLabels(fp16Bytes),
[fp16Bytes],
);
const {
results: hfResults,
isLoading: isLoadingHfModels,
error: hfSearchError,
} = useHubModelSearch(debouncedModelQuery, {
accessToken: hfApiToken(debouncedHfToken),
excludeGguf: true,
ownerScope: debouncedModelQuery.trim() ? "all" : "unsloth",
});
const { error: tokenValidationError, isChecking: isCheckingToken } =
useHfTokenValidation(hfToken);
const hfResultIds = useMemo(() => {
const ids = hfResults.map((r) => r.id);
if (
selectedSourceModel &&
modelSource === "hf" &&
!ids.includes(selectedSourceModel)
) {
ids.push(selectedSourceModel);
}
return ids;
}, [hfResults, modelSource, selectedSourceModel]);
const exportableLocalModels = useMemo(
() =>
localModels.filter((m) => {
if (m.path.endsWith(".gguf")) return false;
if (m.id.toLowerCase().includes("-gguf")) return false;
return true;
}),
[localModels],
);
const localMetaById = useMemo(() => {
const map = new Map<string, LocalModelInfo>();
for (const model of exportableLocalModels) map.set(model.id, model);
return map;
}, [exportableLocalModels]);
// Decision models (Clef / Laya) are local run folders; the backend says which and what they allow.
const decisionProbePath = useMemo(() => {
if (sourceMode === "checkpoint") {
return (
checkpointsForModel.find((c) => c.display_name === checkpoint)?.path ??
null
);
}
if (modelSource !== "local" || !selectedSourceModel) {
return null;
}
return localMetaById.get(selectedSourceModel)?.path ?? selectedSourceModel;
}, [
sourceMode,
checkpointsForModel,
checkpoint,
modelSource,
selectedSourceModel,
localMetaById,
]);
const [decisionState, setDecisionState] = useState<{
path: string;
info: DecisionExportInfo | null;
diffusionLm?: DiffusionLmExportInfo | null;
} | null>(null);
useEffect(() => {
if (!decisionProbePath) {
return;
}
const controller = new AbortController();
fetchCheckpointExportProbe(decisionProbePath, controller.signal)
.then(({ decision: info, diffusionLm }) => {
setDecisionState({ path: decisionProbePath, info, diffusionLm });
if (!info) {
return;
}
// A decision model exports to GGUF only, saved locally in its run folder.
const allowed = new Set(info.quantizations);
setExportMethod("gguf");
setGgufTarget("model");
setDestination("local");
setQuantLevels((prev) => {
const kept = prev.filter((q) => allowed.has(q));
if (kept.length === prev.length && kept.length > 0) {
return prev;
}
return kept.length > 0 ? kept : [info.default_quantization];
});
})
.catch(() => {
if (!controller.signal.aborted) {
setDecisionState({ path: decisionProbePath, info: null });
}
});
return () => controller.abort();
}, [decisionProbePath]);
const decisionInfo =
decisionProbePath && decisionState?.path === decisionProbePath
? decisionState.info
: null;
const isDecision = decisionInfo != null;
// Text-diffusion LMs: no GGUF (llama.cpp would serve them left to right); DiffusionGemma also no merge.
const diffusionLmInfo =
decisionProbePath && decisionState?.path === decisionProbePath
? (decisionState.diffusionLm ?? null)
: null;
const diffusionDisabledMethods = useMemo<ExportMethod[]>(
() => diffusionLmInfo?.disabled_methods ?? [],
[diffusionLmInfo],
);
const decisionIneligible = decisionInfo?.eligible === false;
const decisionQuantOptions = useMemo(
() =>
(decisionInfo?.quantizations ?? []).map((q) => ({
value: q,
label: q.toUpperCase(),
recommended: q === decisionInfo?.default_quantization,
})),
[decisionInfo],
);
const decisionExistingQuants =
decisionInfo?.existing_export?.quantizations ?? [];
// REAP is offered only for routed-MoE models: a local checkpoint / model folder, or a Hub id.
const moeProbeTarget =
decisionProbePath ??
(sourceMode !== "checkpoint" && modelSource === "hf"
? selectedSourceModel || null
: null);
const moeProbeToken = debouncedHfToken?.trim() || "";
const moeProbeKey = moeProbeTarget
? `${moeProbeTarget}|${moeProbeToken}`
: "";
const [moeState, setMoeState] = useState<{
key: string;
info: MoeInfo | null;
failed?: boolean;
} | null>(null);
const [moeRetry, setMoeRetry] = useState(0);
useEffect(() => {
if (!moeProbeTarget) return;
const controller = new AbortController();
fetchMoeInfo(moeProbeTarget, moeProbeToken || null, controller.signal)
.then((info) => {
if (!controller.signal.aborted) setMoeState({ key: moeProbeKey, info });
})
.catch(() => {
// A dense or unreadable config answers null; a thrown request is not an answer.
if (!controller.signal.aborted)
setMoeState({ key: moeProbeKey, info: null, failed: true });
});
return () => controller.abort();
}, [moeProbeKey, moeProbeTarget, moeProbeToken, moeRetry]);
const moeInfo =
moeProbeKey && moeState?.key === moeProbeKey ? moeState.info : null;
const localResultIds = useMemo(() => {
const ids = exportableLocalModels.map((model) => model.id);
const manual = localModelInput.trim();
if (manual && !ids.includes(manual)) {
ids.unshift(manual);
}
return ids;
}, [exportableLocalModels, localModelInput]);
const localFilteredIds = useMemo(() => {
const q = localModelInput.trim().toLowerCase();
if (!q) return localResultIds;
return localResultIds.filter((id) => {
const meta = localMetaById.get(id);
if (id.toLowerCase().includes(q)) return true;
if (meta?.display_name.toLowerCase().includes(q)) return true;
if (meta?.path.toLowerCase().includes(q)) return true;
return false;
});
}, [localMetaById, localModelInput, localResultIds]);
const exportGuideSteps = useMemo(
() =>
sourceMode === "model"
? [
"Select a Hugging Face or local model to export from",
"GGUF is used for non-finetuned model exports",
"Pick one or more GGUF quantization levels",
"Click Export and choose your destination",
"Test your model and compare outputs in Chat",
]
: GUIDE_STEPS,
[sourceMode],
);
const sourceTab: SourceTab =
sourceMode === "checkpoint" ? "checkpoint" : modelSource;
useEffect(() => {
setCheckpoint(null);
}, [selectedModelIdx]);
// Declared after the reset effect so it runs last.
useEffect(() => {
if (sourceMode !== "checkpoint") return;
if (checkpoint != null || checkpointsForModel.length === 0) return;
setCheckpoint(checkpointsForModel[0].display_name);
}, [sourceMode, selectedModelIdx, checkpoint, checkpointsForModel]);
useEffect(() => {
// Only LoRA needs a real adapter; Merged and GGUF work for non-PEFT base models too.
if (!effectiveIsAdapter && exportMethod === "lora") {
setExportMethod(null);
}
if (!effectiveIsAdapter && effectiveIsQuantized && exportMethod !== null) {
setExportMethod(null);
}
if (
exportMethod !== null &&
diffusionDisabledMethods.includes(exportMethod)
) {
setExportMethod(null);
}
if (diffusionDisabledMethods.includes("gguf") && loraAsGguf) {
setLoraAsGguf(false);
}
// The GGUF LoRA target only applies to an adapter checkpoint on a non-Mac host.
if ((!effectiveIsAdapter || isMacHost) && ggufTarget !== "model") {
setGgufTarget("model");
}
}, [
effectiveIsAdapter,
effectiveIsQuantized,
exportMethod,
isMacHost,
ggufTarget,
diffusionDisabledMethods,
loraAsGguf,
]);
const handleSourceTabChange = useCallback((next: string) => {
if (next === "checkpoint") {
setSourceMode("checkpoint");
} else if (next === "hf" || next === "local") {
setSourceMode("model");
setModelSource(next);
} else {
return;
}
setSelectedSourceModel(null);
setLocalModelInput("");
setModelInput("");
hfModelInputRef.current = "";
localModelInputRef.current = "";
}, []);
useEffect(() => {
setSelectedSourceModel(null);
setLocalModelInput("");
setModelInput("");
}, [modelSource]);
useEffect(() => {
hfModelInputRef.current = modelInput;
}, [modelInput]);
useEffect(() => {
localModelInputRef.current = localModelInput;
}, [localModelInput]);
const handleMethodChange = (method: ExportMethod) => {
setExportMethod(method);
if (method !== "gguf") {
setQuantLevels([]);
}
};
const estimatedSize = getEstimatedSize(exportMethod, quantLevels, fp16Bytes);
const selectedExportSource =
sourceMode === "checkpoint" ? checkpoint : selectedSourceModel;
// Derived, not reset in an effect: an imatrix is calibrated for one model only.
const imatrixSourceKey = JSON.stringify([
sourceTab,
sourceMode === "checkpoint" ? selectedModelIdx : null,
selectedExportSource,
]);
const imatrixPath =
customImatrix.sourceKey === imatrixSourceKey ? customImatrix.path : "";
const defaultSaveDirectory = useMemo(() => {
const relative = buildRelativeSaveDirectory(
exportMethod,
sourceMode,
sourceBaseModelName,
selectedModelIdx,
checkpoint,
);
if (
exportMethod === "gguf" &&
sourceMode === "model" &&
modelSource === "local" &&
selectedSourceModel
) {
const localModel = localMetaById.get(selectedSourceModel);
if (
localModel &&
(localModel.source === "models_dir" || localModel.source === "custom")
) {
return siblingGgufDirectory(localModel.path) ?? relative;
}
}
// One folder holds one adapter format.
if (
isMacHost &&
exportMethod === "lora" &&
(loraAsGguf || adapterFormat === "peft")
) {
return `${relative}-peft`;
}
return relative;
}, [
adapterFormat,
checkpoint,
exportMethod,
isMacHost,
localMetaById,
loraAsGguf,
modelSource,
selectedModelIdx,
selectedSourceModel,
sourceBaseModelName,
sourceMode,
]);
const { inputValue: saveDirectoryInput, saveDirectory } = saveDirectoryField(
customSaveDirectory,
defaultSaveDirectory,
);
// Each merged format uploads a full model to the repo root, so several to one repo would collide.
// GGUF method exporting an adapter checkpoint as a GGUF LoRA; reuses the LoRA export path.
const ggufAsLora =
exportMethod === "gguf" &&
ggufTarget === "lora" &&
effectiveIsAdapter &&
!isMacHost;
// REAP prunes the full model before a merged or full-model GGUF export (torch backends only).
const reapMethodApplies =
!isMacHost &&
!isDecision &&
!exportUnsupported &&
!!exportMethod &&
!diffusionDisabledMethods.includes(exportMethod) &&
(exportMethod === "merged" || (exportMethod === "gguf" && !ggufAsLora));
const showReap =
!!moeInfo && reapAllowedSparsities(moeInfo).length > 0 && reapMethodApplies;
// With REAP on, a merged / full-model GGUF export started before the new source's probe
// answers would go out unpruned. Other methods never send REAP, so they never wait.
const reapPending =
reapMethodApplies &&
reapProbePending(reapSettings, moeProbeKey, moeState?.key);
const reapFailed =
reapMethodApplies &&
reapProbeFailed(
reapSettings,
moeProbeKey,
moeState?.failed ? moeState.key : null,
);
const reapBlocked =
reapMethodApplies &&
reapUnavailable(
reapSettings,
moeProbeKey,
moeState?.key,
!!moeState?.failed,
showReap,
);
const reapOptions =
showReap && moeInfo ? reapRequest(reapSettings, moeInfo) : null;
const reapLabel =
showReap && moeInfo ? reapSummaryLabel(reapSettings, moeInfo) : null;
// Restrict a Hub merged export to a single format; multi-format stays available for local export.
const hubMultiFormat =
destination === "hub" &&
exportMethod === "merged" &&
selectedFormats.length > 1;
const canExport = !!(
selectedExportSource &&
exportMethod &&
!exportUnsupported &&
!diffusionDisabledMethods.includes(exportMethod) &&
!hubMultiFormat &&
(exportMethod !== "gguf" || ggufAsLora || quantLevels.length > 0) &&
(exportMethod !== "merged" || selectedFormats.length > 0) &&
(!isDecision || (exportMethod === "gguf" && !decisionIneligible)) &&
!reapPending &&
!reapFailed &&
!reapBlocked
);
const exportMethodTitle =
EXPORT_METHODS.find((m) => m.value === exportMethod)?.title ?? "—";
const summaryRows: ExportSummaryRow[] =
sourceMode === "checkpoint"
? [
{
label: "Training run",
value: selectedModelIdx
? selectedModelIdx.replace(/_(\d{10,})$/, "")
: "—",
},
{ label: "Checkpoint", value: checkpoint ?? "—" },
{ label: "Base model", value: baseModelName },
{
label: "Training",
value: selectedModelData ? trainingMethodLabel : "—",
},
...(isAdapter && loraRank != null
? [{ label: "LoRA rank", value: String(loraRank), mono: true }]
: []),
{ label: "Method", value: exportMethodTitle },
{ label: "Est. size", value: estimatedSize ?? "—" },
]
: [
{ label: "Model", value: selectedSourceModel ?? "—" },
{ label: "Method", value: exportMethodTitle },
{ label: "Est. size", value: estimatedSize ?? "—" },
];
const applyHfSourceModel = useCallback((value: string) => {
const next = value.trim();
setModelInput(next);
setSelectedSourceModel(next || null);
}, []);
const handleHfSourceModelSelect = useCallback((id: string | null) => {
selectingHfModelRef.current = true;
const next = id ?? "";
hfModelInputRef.current = next;
setModelInput(next);
setSelectedSourceModel(id);
}, []);
const handleHfSourceInputChange = useCallback(
(value: string, eventDetails?: { reason?: string }) => {
hfModelInputRef.current = value;
if (selectingHfModelRef.current) {
selectingHfModelRef.current = false;
return;
}
if (!SEARCH_INPUT_REASONS.has(eventDetails?.reason ?? "")) {
return;
}
setModelInput(value);
if (value.trim() === "") {
setSelectedSourceModel(null);
}
},
[],
);
const applyLocalSourceModel = useCallback((value: string) => {
const next = value.trim();
setLocalModelInput(next);
setSelectedSourceModel(next || null);
}, []);
useEffect(() => {
setCustomSaveDirectory(null);
}, [
checkpoint,
exportMethod,
modelSource,
selectedModelIdx,
selectedSourceModel,
sourceMode,
]);
const handleLocalSourceInputChange = useCallback(
(value: string, eventDetails?: { reason?: string }) => {
localModelInputRef.current = value;
if (!SEARCH_INPUT_REASONS.has(eventDetails?.reason ?? "")) {
return;
}
setLocalModelInput(value);
if (value.trim() === "") {
setSelectedSourceModel(null);
}
},
[],
);
// ---- Export handlers ----
const handleStart = useCallback(async () => {
const source =
sourceMode === "checkpoint" ? checkpoint : selectedSourceModel;
if (!source || !exportMethod) return;
if (exportUnsupported) return;
if (diffusionDisabledMethods.includes(exportMethod)) return;
// REAP is on but the new source's MoE probe has not answered (or failed): never send it unpruned.
if (reapPending || reapFailed || reapBlocked) return;
// GGUF with no quant, or merged with no format, would run an empty export; require at least one.
if (exportMethod === "gguf" && !ggufAsLora && quantLevels.length === 0)
return;
if (exportMethod === "merged" && selectedFormats.length === 0) return;
if (hubMultiFormat) return;
if (isDecision && (exportMethod !== "gguf" || decisionIneligible)) {
return;
}
const selectedCp =
sourceMode === "checkpoint"
? checkpointsForModel.find((cp) => cp.display_name === checkpoint)
: null;
if (sourceMode === "checkpoint" && !selectedCp) return;
const checkpointPath = selectedCp?.path ?? null;
const pushToHub = destination === "hub";
if (pushToHub && !isDecision && (!hfUsername.trim() || !modelName.trim()))
return;
const preparedToken = await prepareHfTokenForUse(hfToken, {
allowAnonymous: !pushToHub,
});
if (!preparedToken.proceed) return;
const actionHfToken = preparedToken.token ?? "";
const repoId =
pushToHub && hfUsername.trim() && modelName.trim()
? `${hfUsername.trim()}/${modelName.trim()}`
: undefined;
const token = pushToHub && actionHfToken ? actionHfToken : undefined;
const effectiveMethod: ExportMethod = ggufAsLora ? "lora" : exportMethod;
const emitLoraGguf =
ggufAsLora || (effectiveMethod === "lora" && loraAsGguf);
const methodLabel = isDecision
? t("exportDecision.methodLabel")
: ggufAsLora
? "GGUF LoRA adapter"
: (EXPORT_METHODS.find((m) => m.value === exportMethod)?.title ??
exportMethod);
const adapterExport = sourceMode === "checkpoint" && isAdapter;
// Consent gate for custom (auto_map) code, before handing off to runExport.
const consent = exportRemoteCodeConsent({
sourceMode,
modelSource,
source,
checkpointPath,
});
let trustRemoteCode = consent.trustByDefault;
let approvedRemoteCodeFingerprint: string | null = null;
const remoteCodeOk = await confirmRemoteCodeIfNeeded({
modelName: consent.scanTarget,
hfToken: actionHfToken || null,
requiresTrustRemoteCode: consent.requiresTrustRemoteCode,
onApprove: (fingerprint) => {
trustRemoteCode = true;
approvedRemoteCodeFingerprint = fingerprint;
},
});
if (!remoteCodeOk) return;
let installMissingDependencies = false;
if (effectiveMethod === "merged") {
const llmCompressor =
await confirmLlmCompressorInstallIfNeeded(selectedFormats);
if (!llmCompressor.ok) return;
installMissingDependencies = llmCompressor.installMissingDependencies;
}
void runExport({
sourceMode,
checkpointPath,
source,
modelSource,
trustRemoteCode,
approvedRemoteCodeFingerprint,
loadToken: actionHfToken || null,
exportMethod: effectiveMethod,
isAdapter: adapterExport,
quantLevels,
useImatrix: isDecision ? false : effectiveImatrix,
imatrixPath: isDecision ? "" : imatrixPath,
npuQ4nx: isDecision ? false : effectiveNpuQ4nx,
decisionOutputLabel: isDecision
? (quantizations: string[]) =>
t("exportDecision.outputLabel", {
quantizations: quantizations.join(", "),
})
: undefined,
mergedSelections: selectedFormats.map((v) => ({
...mergedFormatPayload(v),
label: MERGED_FORMATS.find((f) => f.value === v)?.label ?? v,
})),
loraGguf: emitLoraGguf,
loraGgufOuttype,
adapterFormat: isMacHost && !emitLoraGguf ? adapterFormat : undefined,
saveDirectory,
destination,
repoId,
token,
privateRepo,
installMissingDependencies,
baseModelId: selectedModelData?.base_model ?? undefined,
reap: reapOptions,
summary: {
baseModelName: sourceBaseModelName,
checkpointLabel: selectedExportSource,
methodLabel,
method: effectiveMethod,
quantLevels,
mergedFormats: exportMethod === "merged" ? selectedFormats : [],
destination,
reapLabel,
},
});
}, [
reapPending,
reapFailed,
reapBlocked,
reapOptions,
reapLabel,
checkpoint,
checkpointsForModel,
sourceMode,
selectedSourceModel,
selectedModelData,
selectedExportSource,
sourceBaseModelName,
exportMethod,
isAdapter,
quantLevels,
effectiveImatrix,
imatrixPath,
effectiveNpuQ4nx,
selectedFormats,
hubMultiFormat,
ggufAsLora,
loraAsGguf,
isMacHost,
loraGgufOuttype,
adapterFormat,
exportUnsupported,
destination,
saveDirectory,
hfUsername,
modelName,
hfToken,
privateRepo,
modelSource,
runExport,
isDecision,
decisionIneligible,
diffusionDisabledMethods,
t,
]);
const handleOpenPanel = useCallback(() => {
if (!isExporting) {
resetExportRun();
}
setPanelOpen(true);
}, [isExporting, resetExportRun]);
const handleClosePanel = useCallback(() => {
resetExportRun();
setPanelOpen(false);
}, [resetExportRun]);
const showPanel = panelOpen || panelActive;
const panelEndRef = useRef<HTMLDivElement>(null);
const [panelEndVisible, setPanelEndVisible] = useState(true);
useEffect(() => {
if (!showPanel) return;
const id = window.setTimeout(() => {
panelEndRef.current?.scrollIntoView({ behavior: "smooth", block: "end" });
}, 60);
return () => window.clearTimeout(id);
}, [showPanel]);
useEffect(() => {
const el = panelEndRef.current;
if (!showPanel || !el) return;
const obs = new IntersectionObserver(
([entry]) => setPanelEndVisible(entry.isIntersecting),
{ rootMargin: "0px 0px -40px 0px" },
);
obs.observe(el);
return () => obs.disconnect();
}, [showPanel]);
return (
<div data-wallpaper-page-canvas="" className="flex min-h-[calc(100dvh-var(--studio-titlebar-height,0px))] flex-col bg-background">
<main className="mx-auto flex w-full max-w-[calc(1180px*var(--ui-space-scale,1))] 3xl:max-w-[calc(1440px*var(--ui-space-scale,1))] 4xl:max-w-[calc(1760px*var(--ui-space-scale,1))] flex-col gap-7 px-5 pb-20 pt-8 max-sm:px-4 sm:px-9">
<GuidedTour {...tour.tourProps} />
<header className="font-heading flex flex-col gap-0.5">
<h1 className="text-ui-30 font-semibold leading-[1.04] tracking-[-0.028em] text-foreground sm:text-ui-34">
Export
</h1>
<p className="text-sm text-muted-foreground">
Export fine-tuned or base models for deployment
</p>
</header>
{loadingCheckpoints && (
<div className="flex items-center gap-3 rounded-2xl border border-border/60 p-8 text-sm text-muted-foreground">
<Spinner className="size-4 shrink-0" />
Loading checkpoints…
</div>
)}
{checkpointError && (
<div className="flex items-center gap-3 rounded-2xl border border-border/60 p-8 text-sm text-destructive">
<HugeiconsIcon icon={Alert02Icon} className="size-4 shrink-0" />
{checkpointError}
</div>
)}
{(loadingCheckpoints || !!checkpointError) && (
<>
<ImageLoraExportCard preselect={preselectImageLora} />
{hasNpu && <Q4nxConvertCard />}
</>
)}
{!loadingCheckpoints && !checkpointError && (
<div className="@container/export-configure">
<div className="grid grid-cols-1 gap-8 @4xl/export-configure:grid-cols-[minmax(0,1fr)_320px] @5xl/export-configure:gap-10">
<div className="flex min-w-0 flex-col gap-6">
<SectionBox
title="Source"
description="A local model, a fine-tuned checkpoint, or a Hugging Face model"
icon={ChipIcon}
chipTint="var(--chart-1)"
titleAction={
<SegmentedControl
value={sourceTab}
options={SOURCE_TAB_OPTIONS}
onValueChange={handleSourceTabChange}
ariaLabel="Export source"
size="compact"
className="@md/train-card:w-[calc(300px*var(--ui-space-scale,1))]"
/>
}
>
<div className="flex flex-col gap-4">
{sourceMode === "checkpoint" ? (
<div className="grid grid-cols-1 gap-4 overflow-visible @md/train-section:grid-cols-2">
<div
data-tour="export-training-run"
className="flex min-w-0 flex-col gap-2"
>
<label className={FIELD_LABEL}>Training run</label>
<Select
value={selectedModelIdx ?? ""}
onValueChange={setSelectedModelIdx}
>
<SelectTrigger className="w-full">
<SelectValue
placeholder={
models.length === 0
? "No training runs found"
: "Select a training run…"
}
/>
</SelectTrigger>
<SelectContent>
{models.map((m) => {
const tsMatch = m.name.match(/_(\d{10,})$/);
const displayName = tsMatch
? m.name.slice(0, tsMatch.index)
: m.name;
const timeStr = tsMatch
? new Date(
Number(tsMatch[1]) * 1000,
).toLocaleString(
undefined,
withTimeFormat({
dateStyle: "medium",
timeStyle: "short",
}),
)
: null;
return (
<SelectItem key={m.name} value={m.name}>
<span className="flex items-center gap-2">
{displayName}
<span className="text-muted-foreground text-xs">
{m.checkpoints.length} checkpoint
{m.checkpoints.length !== 1 ? "s" : ""}
</span>
{timeStr && (
<span className="text-muted-foreground text-xs">
· {timeStr}
</span>
)}
</span>
</SelectItem>
);
})}
</SelectContent>
</Select>
</div>
<div
data-tour="export-checkpoint"
className="flex min-w-0 flex-col gap-2"
>
<label className={FIELD_LABEL}>
Checkpoint
<Tooltip disableHoverableContent={false}>
<TooltipTrigger asChild={true}>
<button
type="button"
className="text-foreground/70 hover:text-foreground"
>
<HugeiconsIcon
icon={InformationCircleIcon}
className="size-3"
/>
</button>
</TooltipTrigger>
<TooltipContent>
Choose a saved checkpoint to export. Lower loss
generally means better quality.{" "}
<a
href="https://unsloth.ai/docs/basics/inference-and-deployment"
target="_blank"
rel="noopener noreferrer"
className="text-primary underline"
>
Read more
</a>
</TooltipContent>
</Tooltip>
</label>
<Select
value={checkpoint ?? ""}
onValueChange={setCheckpoint}
disabled={!selectedModelIdx}
>
<SelectTrigger className="w-full">
<SelectValue
placeholder={
selectedModelIdx
? checkpointsForModel.length === 0
? "No checkpoints found"
: "Select a checkpoint…"
: "Select a training run first"
}
/>
</SelectTrigger>
<SelectContent>
{checkpointsForModel.map((cp) => (
<SelectItem
key={cp.path}
value={cp.display_name}
>
<span className="flex items-center gap-2">
{cp.display_name}
{cp.loss != null && (
<span className="text-muted-foreground text-xs">
loss: {cp.loss.toFixed(4)}
</span>
)}
</span>
</SelectItem>
))}
</SelectContent>
</Select>
</div>
</div>
) : (
<div className="flex flex-col gap-4 overflow-visible">
{modelSource === "hf" ? (
<>
<div className="flex flex-col gap-2">
<label className={FIELD_LABEL}>
Hugging Face model
</label>
<div ref={hfComboboxAnchorRef}>
<Combobox
items={hfResultIds}
filteredItems={hfResultIds}
filter={null}
value={
modelInput || selectedSourceModel || null
}
onValueChange={handleHfSourceModelSelect}
onInputValueChange={handleHfSourceInputChange}
itemToStringValue={(id) => id}
autoHighlight={true}
>
<ComboboxInput
placeholder="Search models..."
className="w-full"
onBlur={() =>
applyHfSourceModel(
hfModelInputRef.current,
)
}
onKeyDown={(event) => {
if (event.key !== "Enter") return;
event.preventDefault();
applyHfSourceModel(
hfModelInputRef.current,
);
}}
>
<InputGroupAddon>
<HugeiconsIcon
icon={Search01Icon}
className="size-4"
/>
</InputGroupAddon>
</ComboboxInput>
<ComboboxContent anchor={hfComboboxAnchorRef}>
{isLoadingHfModels ? (
<div className="flex items-center justify-center py-4 gap-2 text-xs text-muted-foreground">
<Spinner className="size-4" />{" "}
Searching…
</div>
) : (
<ComboboxEmpty>
No models found
</ComboboxEmpty>
)}
<ComboboxList>
{(id: string) => (
<ComboboxItem
key={id}
value={id}
className="gap-2"
>
<span className="block min-w-0 flex-1 truncate">
{id}
</span>
</ComboboxItem>
)}
</ComboboxList>
</ComboboxContent>
</Combobox>
</div>
{(tokenValidationError ?? hfSearchError) && (
<p className="text-xs text-destructive">
{tokenValidationError ?? hfSearchError}
</p>
)}
</div>
<div className="flex flex-col gap-2">
<label className={FIELD_LABEL}>
Hugging Face token (optional)
</label>
<InputGroup>
<InputGroupAddon>
<HugeiconsIcon
icon={Key01Icon}
className="size-4"
/>
</InputGroupAddon>
<InputGroupInput
type="password"
autoComplete="new-password"
name="hf-token-export-source"
placeholder="hf_..."
value={hfToken}
onChange={(e) => setHfToken(e.target.value)}
/>
</InputGroup>
{isCheckingToken && (
<p className="text-xs text-muted-foreground">
Checking token…
</p>
)}
</div>
</>
) : (
<div className="flex flex-col gap-2">
<label className={FIELD_LABEL}>
Local model path
</label>
<div ref={localComboboxAnchorRef}>
<Combobox
items={localResultIds}
filteredItems={localFilteredIds}
filter={null}
value={localModelInput || null}
onValueChange={(id) => {
const next = id ?? "";
localModelInputRef.current = next;
setLocalModelInput(next);
setSelectedSourceModel(next || null);
}}
onInputValueChange={
handleLocalSourceInputChange
}
itemToStringValue={(id) => id}
autoHighlight={true}
>
<ComboboxInput
placeholder={
isLoadingLocalModels
? "Scanning local and cached models..."
: "./models/my-model"
}
className="w-full"
onBlur={() =>
applyLocalSourceModel(
localModelInputRef.current,
)
}
onKeyDown={(event) => {
if (event.key !== "Enter") return;
event.preventDefault();
applyLocalSourceModel(
localModelInputRef.current,
);
}}
>
<InputGroupAddon>
<HugeiconsIcon
icon={FolderSearchIcon}
className="size-4"
/>
</InputGroupAddon>
</ComboboxInput>
<ComboboxContent
anchor={localComboboxAnchorRef}
>
{isLoadingLocalModels ? (
<div className="flex items-center justify-center gap-2 py-4 text-xs text-muted-foreground">
<Spinner className="size-4" /> Scanning...
</div>
) : localModelsError ? (
<div className="px-3 py-2 text-xs text-red-500">
{localModelsError}
</div>
) : (
<ComboboxEmpty>
No local models found
</ComboboxEmpty>
)}
<ComboboxList>
{(id: string) => {
const model = localMetaById.get(id);
const source =
model?.source === "hf_cache"
? "HF cache"
: model?.source === "custom"
? "Custom Folders"
: "Local dir";
return (
<ComboboxItem
key={id}
value={id}
className="gap-2"
>
<span className="block min-w-0 flex-1 truncate">
{model?.display_name ?? id}
</span>
<span className="ml-auto shrink-0 text-ui-10 text-muted-foreground">
{source}
</span>
</ComboboxItem>
);
}}
</ComboboxList>
</ComboboxContent>
</Combobox>
</div>
{isLoadingLocalModels ? (
<p className="text-ui-10 text-muted-foreground">
Scanning local models...
</p>
) : localModelsError ? (
<p className="text-ui-10 text-red-500">
{localModelsError}
</p>
) : (
<p className="text-ui-10 text-muted-foreground">
{exportableLocalModels.length > 0
? `${exportableLocalModels.length} local/cached models found`
: "No local models found. Enter path manually."}
</p>
)}
</div>
)}
<div className="rounded-lg bg-[color-mix(in_oklab,var(--foreground)_calc(4%*var(--contrast-wash-gain,1)),transparent)] p-3">
<p className="text-ui-11 text-muted-foreground">
Direct model exports currently support GGUF only.
</p>
</div>
</div>
)}
</div>
</SectionBox>
<SectionBox
title="Export method"
description="How the model is packaged for deployment"
icon={PackageIcon}
chipTint="var(--chart-1)"
>
<div className="flex flex-col gap-6">
{exportUnsupported && (
<Alert variant="destructive">
<HugeiconsIcon
icon={Alert02Icon}
className="size-4"
/>
<AlertTitle>Export unavailable</AlertTitle>
<AlertDescription>
{exportUnsupportedMessage}
{offerFullInstall && (
<div className="mt-2">
<Button
size="xs"
onClick={() => setFullInstallOpen(true)}
>
Install Training
</Button>
</div>
)}
</AlertDescription>
</Alert>
)}
{fullInstall && (
<FullInstallDialog
open={fullInstallOpen}
onOpenChange={setFullInstallOpen}
onConfirm={() => void fullInstall.repairInstall()}
/>
)}
<MethodPicker
value={exportMethod}
onChange={handleMethodChange}
disabledMethods={
exportUnsupported
? ["merged", "lora", "gguf"]
: isDecision
? ["merged", "lora"]
: !effectiveIsAdapter && effectiveIsQuantized
? ["merged", "lora", "gguf"]
: [
...(effectiveIsAdapter
? []
: (["lora"] as const)),
...diffusionDisabledMethods,
]
}
disabledReason={
exportUnsupported
? exportUnsupportedMessage
: isDecision
? t("exportDecision.ggufOnly")
: !effectiveIsAdapter && effectiveIsQuantized
? "Pre-quantized (BNB 4-bit) models cannot be exported without LoRA adapters"
: [
effectiveIsAdapter
? null
: "LoRA-only export needs a LoRA adapter checkpoint",
diffusionDisabledMethods.length > 0
? diffusionLmInfo?.reason
: null,
]
.filter(Boolean)
.join(" ") || undefined
}
/>
{exportMethod === "merged" && !exportUnsupported && (
<div className="space-y-3">
<div className="space-y-2">
<div className="flex items-center justify-between">
<div className="text-sm font-medium">Precision</div>
{availableFormats.length > 1 && (
<span className="text-ui-11 text-muted-foreground/70">
Select one or more
</span>
)}
</div>
<div className="flex flex-wrap gap-2">
{availableFormats
.filter((f) => f.common)
.map((f) => {
const active = selectedFormats.includes(
f.value,
);
return (
<Button
key={f.value}
type="button"
variant={active ? "dark" : "outline"}
size="sm"
onClick={() => toggleFormat(f.value)}
title={f.hint}
>
{f.label}
{f.needsCalibration ? " *" : ""}
</Button>
);
})}
{availableFormats.some((f) => !f.common) && (
<DropdownMenu>
<DropdownMenuTrigger asChild={true}>
<Button
type="button"
variant="outline"
size="sm"
>
More formats
{selectedFormats.some((v) =>
availableFormats.find(
(f) => f.value === v && !f.common,
),
)
? " ✓"
: "…"}
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent
align="start"
className="w-64"
>
<DropdownMenuLabel>
Additional formats
</DropdownMenuLabel>
<DropdownMenuSeparator />
{availableFormats
.filter((f) => !f.common)
.map((f) => (
<DropdownMenuCheckboxItem
key={f.value}
checked={selectedFormats.includes(
f.value,
)}
onCheckedChange={() =>
toggleFormat(f.value)
}
onSelect={(e) => e.preventDefault()}
>
<span className="flex flex-col">
<span>
{f.label}
{f.needsCalibration ? " *" : ""}
</span>
<span className="text-ui-10 text-muted-foreground">
{f.hint}
</span>
</span>
</DropdownMenuCheckboxItem>
))}
</DropdownMenuContent>
</DropdownMenu>
)}
</div>
{availableFormats.length > 1 &&
selectedFormats.length > 0 && (
<div className="flex flex-wrap items-center gap-x-3 gap-y-1">
<span className="text-ui-11 text-muted-foreground">
{selectedFormats.length} selected:{" "}
{selectedFormats
.map(
(v) =>
MERGED_FORMATS.find(
(f) => f.value === v,
)?.label ?? v,
)
.join(", ")}
</span>
{selectedFormats.length > 1 && (
<button
type="button"
onClick={() =>
setSelectedFormats(["16-bit"])
}
className="text-ui-11 text-muted-foreground/70 hover:text-foreground transition-colors"
>
Reset to 16-bit
</button>
)}
</div>
)}
{hubMultiFormat && (
<div className="text-ui-11 text-amber-600 dark:text-amber-500">
Hub export supports one format at a time (each
writes to the repository root). Select a single
format, or export locally to produce several at
once.
</div>
)}
{selectedFormats.some(
(v) =>
MERGED_FORMATS.find((f) => f.value === v)
?.needsCalibration,
) && (
<div className="text-ui-11 text-muted-foreground">
* calibrates on data (uses a small calibration
set).
</div>
)}
{!hasNvidia && !torchaoUnavailable && (
<div className="text-ui-11 text-muted-foreground">
No NVIDIA GPU detected: compressed-tensors formats
are hidden. 16-bit and portable FP8/INT8 (torchao)
still work here and load in vLLM.
</div>
)}
{torchaoUnavailable && (
<div className="text-ui-11 text-muted-foreground">
Portable FP8/INT8 (torchao) export needs torchao
0.15 or newer, which is not installed here. Update
Unsloth, or use 16-bit or GGUF.
</div>
)}
</div>
</div>
)}
{exportMethod === "lora" &&
effectiveIsAdapter &&
!exportUnsupported && (
<div className="space-y-3">
<div className="space-y-2">
<div className="text-sm font-medium">
Adapter format
</div>
<div className="flex flex-wrap gap-2">
<Button
type="button"
variant={loraAsGguf ? "outline" : "dark"}
size="sm"
onClick={() => setLoraAsGguf(false)}
title="Adapter weights as safetensors."
>
Adapter (safetensors)
</Button>
<Button
type="button"
variant={loraAsGguf ? "dark" : "outline"}
size="sm"
onClick={() => setLoraAsGguf(true)}
disabled={diffusionDisabledMethods.includes(
"gguf",
)}
title={
diffusionDisabledMethods.includes("gguf")
? (diffusionLmInfo?.reason ?? undefined)
: "llama.cpp GGUF LoRA, loadable with `llama-cli --lora`."
}
>
GGUF adapter
</Button>
</div>
<div className="text-xs text-muted-foreground">
{loraAsGguf
? isMacHost
? "Converts the adapter to a GGUF LoRA (llama.cpp `--lora`); the adapter files are written in PEFT format. Not available for adapters with per-module alpha values, rsLoRA with per-module ranks, DoRA, replaced embeddings or modules_to_save, or expert-parameter targets."
: "Converts the adapter to a GGUF LoRA (llama.cpp `--lora`). The base model stays separate."
: isMacHost
? "Adapter weights only; pick the on-disk format below."
: "Standard PEFT adapter files. Pair with the base model at inference."}
</div>
</div>
{!loraAsGguf && isMacHost && (
<div
className="space-y-2"
data-testid="adapter-format-picker"
>
<div className="text-sm font-medium">
Safetensors format
</div>
<div className="flex flex-wrap gap-2">
<Button
type="button"
variant={
adapterFormat === "mlx" ? "dark" : "outline"
}
size="sm"
onClick={() => setAdapterFormat("mlx")}
title="Native mlx-lm adapter (adapters.safetensors)."
>
MLX
</Button>
<Button
type="button"
variant={
adapterFormat === "peft"
? "dark"
: "outline"
}
size="sm"
onClick={() => setAdapterFormat("peft")}
title="Standard Hugging Face PEFT adapter (adapter_model.safetensors)."
>
PEFT
</Button>
</div>
<div className="text-xs text-muted-foreground">
{adapterCompatibilityTip(
adapterFormat,
selectedModelData?.adapter_features,
)}{" "}
Training checkpoints always remain MLX; this
choice only affects the exported copy.
</div>
</div>
)}
{loraAsGguf && (
<div className="space-y-1.5">
<div className="text-sm font-medium">
Output type
</div>
<Select
value={loraGgufOuttype}
onValueChange={(v) => setLoraGgufOuttype(v)}
>
<SelectTrigger className="w-full sm:w-56">
<SelectValue />
</SelectTrigger>
<SelectContent>
{LORA_GGUF_OUTTYPES.map((t) => (
<SelectItem key={t} value={t}>
{t.toUpperCase()}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
)}
</div>
)}
{exportMethod === "gguf" &&
!exportUnsupported &&
decisionInfo && (
<div className="space-y-3">
{decisionIneligible ? (
<Alert variant="destructive">
<HugeiconsIcon
icon={Alert02Icon}
className="size-4"
/>
<AlertTitle>
{t("exportDecision.notEligibleTitle")}
</AlertTitle>
<AlertDescription>
{decisionInfo.reason}
</AlertDescription>
</Alert>
) : (
<>
<div className="space-y-1">
<div className="text-sm font-medium">
{t("exportDecision.title")}
</div>
<div className="text-xs text-muted-foreground">
{t("exportDecision.description", {
layout:
decisionInfo.layout === "clef"
? "Clef"
: "Laya",
})}
</div>
{decisionInfo.adapter_only && (
<div className="text-xs text-muted-foreground">
{t("exportDecision.adapterNote")}
</div>
)}
</div>
<QuantPicker
value={quantLevels}
onChange={setQuantLevels}
options={decisionQuantOptions}
/>
{decisionExistingQuants.length > 0 && (
<div className="text-xs text-muted-foreground">
{t("exportDecision.existing", {
quantizations:
decisionExistingQuants.join(", "),
})}
</div>
)}
</>
)}
</div>
)}
{exportMethod === "gguf" &&
!exportUnsupported &&
!decisionInfo && (
<div className="space-y-3">
{effectiveIsAdapter && !isMacHost && (
<div className="space-y-2">
<div className="text-sm font-medium">
Export target
</div>
<div className="flex flex-wrap gap-2">
<Button
type="button"
variant={
ggufTarget === "model" ? "dark" : "outline"
}
size="sm"
onClick={() => setGgufTarget("model")}
title="Merge the adapter into the base model, then quantize the full model to GGUF."
>
Full model
</Button>
<Button
type="button"
variant={
ggufTarget === "lora" ? "dark" : "outline"
}
size="sm"
onClick={() => setGgufTarget("lora")}
title="Export just the adapter as a GGUF LoRA (llama.cpp `--lora`); the base model stays separate."
>
LoRA adapter
</Button>
</div>
<div className="text-xs text-muted-foreground">
{ggufTarget === "lora"
? "Converts the adapter to a GGUF LoRA (llama.cpp `--lora`). The base model stays separate."
: "Merges the adapter into the base model, then quantizes the full model to GGUF."}
</div>
</div>
)}
{ggufAsLora ? (
<div className="space-y-1.5">
<div className="text-sm font-medium">
Output type
</div>
<Select
value={loraGgufOuttype}
onValueChange={(v) => setLoraGgufOuttype(v)}
>
<SelectTrigger className="w-full sm:w-56">
<SelectValue />
</SelectTrigger>
<SelectContent>
{LORA_GGUF_OUTTYPES.map((t) => (
<SelectItem key={t} value={t}>
{t.toUpperCase()}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
) : (
<>
<QuantPicker
value={quantLevels}
onChange={setQuantLevels}
sizes={quantSizeLabels}
/>
<div className="flex items-start justify-between gap-3 rounded-lg border p-3">
<div className="space-y-0.5">
<div className="text-sm font-medium">
Importance matrix (imatrix)
</div>
<div className="text-xs text-muted-foreground">
{requiresImatrix
? "Required for the selected IQ low-bit quant."
: "Improves quant quality and unlocks the IQ low-bit quants."}
</div>
</div>
<Switch
className="mt-[var(--ui-title-cap-inset)]"
aria-label="Importance matrix (imatrix)"
checked={effectiveImatrix}
onCheckedChange={setUseImatrix}
disabled={requiresImatrix}
/>
</div>
{effectiveImatrix && (
<div className="space-y-1.5">
<label
htmlFor="export-imatrix-path"
className="text-sm font-medium"
>
Local imatrix file (optional)
</label>
<InputGroup>
<InputGroupInput
id="export-imatrix-path"
aria-describedby="export-imatrix-path-help"
placeholder="/path/to/imatrix.gguf"
value={imatrixPath}
onChange={(e) =>
setCustomImatrix({
sourceKey: imatrixSourceKey,
path: e.target.value,
})
}
/>
</InputGroup>
<p
id="export-imatrix-path-help"
className="text-xs text-muted-foreground"
>
Absolute path to a .dat or .gguf imatrix
file on the machine running Unsloth. Leave
blank to auto-download the upstream Unsloth
imatrix for the base model, if one exists.
</p>
</div>
)}
{hasNpu && (
<div className="flex items-start justify-between gap-3 rounded-lg border p-3">
<div className="space-y-0.5">
<div className="text-sm font-medium">
Also convert to Q4NX (AMD NPU)
</div>
<div className="text-xs text-muted-foreground">
{destination !== "local"
? "Local destination only."
: q4nxSourceSelected
? "Adds a Q4NX copy next to the GGUFs. Only supported on AMD NPUs."
: "Needs Q4_0, Q4_1 or Q4_K_M."}
</div>
</div>
<Switch
className="mt-[var(--ui-title-cap-inset)]"
aria-label="Also convert to Q4NX (AMD NPU)"
checked={effectiveNpuQ4nx}
onCheckedChange={setNpuQ4nx}
disabled={
!q4nxSourceSelected ||
destination !== "local"
}
/>
</div>
)}
</>
)}
</div>
)}
{showReap && moeInfo && (
<ReapCard
moe={moeInfo}
settings={reapSettings}
onChange={setReapSettings}
disabled={isExporting}
/>
)}
{reapFailed && (
<div
role="alert"
className="rounded-lg border border-amber-500/40 bg-amber-500/5 p-3 text-xs"
>
<p>
Expert pruning (REAP) is on, but checking whether this
model can be pruned failed. Retry, or turn pruning off
to export the full model.
</p>
<div className="mt-2 flex gap-2">
<Button
type="button"
variant="outline"
size="sm"
onClick={() => setMoeRetry((n) => n + 1)}
>
Retry
</Button>
<Button
type="button"
variant="ghost"
size="sm"
onClick={() =>
setReapSettings((s) => ({ ...s, enabled: false }))
}
>
Turn off expert pruning
</Button>
</div>
</div>
)}
{reapBlocked && (
<div
role="alert"
className="rounded-lg border border-amber-500/40 bg-amber-500/5 p-3 text-xs"
>
<p>
Expert pruning (REAP) is on, but this model cannot be
pruned: it is not a routed MoE, or its weights or
setup are not supported. Turn pruning off to export
it.
</p>
<div className="mt-2 flex gap-2">
<Button
type="button"
variant="outline"
size="sm"
onClick={() =>
setReapSettings((s) => ({ ...s, enabled: false }))
}
>
Turn off expert pruning
</Button>
</div>
</div>
)}
</div>
</SectionBox>
{showPanel && (
<ExportRunPanel
exportMethod={exportMethod}
quantLevels={quantLevels}
checkpoint={selectedExportSource}
baseModelName={sourceBaseModelName}
isAdapter={sourceMode === "checkpoint" && isAdapter}
destination={destination}
onDestinationChange={setDestination}
saveDirectory={saveDirectory}
saveDirectoryInput={saveDirectoryInput}
defaultSaveDirectory={defaultSaveDirectory}
saveDirectoryOverridden={!!customSaveDirectory}
onSaveDirectoryChange={setCustomSaveDirectory}
hfUsername={hfUsername}
onHfUsernameChange={setHfUsername}
modelName={modelName}
onModelNameChange={setModelName}
hfToken={hfToken}
onHfTokenChange={setHfToken}
privateRepo={privateRepo}
onPrivateRepoChange={setPrivateRepo}
onStart={handleStart}
onClose={handleClosePanel}
decisionNote={
decisionInfo
? t("exportDecision.outputNote", {
path: decisionInfo.output_dir,
})
: undefined
}
reapLabel={reapLabel}
/>
)}
{showPanel && (
<div
ref={panelEndRef}
aria-hidden="true"
className="h-px w-full"
/>
)}
{showPanel && !panelEndVisible && (
<button
type="button"
onClick={() =>
panelEndRef.current?.scrollIntoView({
behavior: "smooth",
block: "end",
})
}
aria-label="Scroll to export output"
className="fixed bottom-6 right-6 z-30 flex size-10 items-center justify-center rounded-full bg-background/90 text-foreground shadow-md backdrop-blur transition-colors hover:bg-muted"
>
<HugeiconsIcon
icon={ChevronDownStandardIcon}
className="size-5"
/>
</button>
)}
<ImageLoraExportCard preselect={preselectImageLora} />
{hasNpu && <Q4nxConvertCard />}
</div>
<div className="@4xl/export-configure:sticky @4xl/export-configure:top-6 @4xl/export-configure:self-start">
<ExportSummaryCard
ready={canExport}
rows={summaryRows}
steps={exportGuideSteps}
cta={
showPanel ? undefined : (
<Button
size="lg"
data-tour="export-cta"
disabled={!canExport}
onClick={handleOpenPanel}
className={cn(
"w-full justify-center rounded-full text-ui-13p5 font-semibold tracking-tight",
"bg-action text-background shadow-sm hover:opacity-90",
"disabled:bg-[color-mix(in_oklab,var(--foreground)_calc(8%*var(--contrast-wash-gain,1)),transparent)] disabled:text-muted-foreground disabled:shadow-none dark:disabled:bg-[rgb(255_255_255_/_calc(0.06*var(--contrast-wash-gain,1)))]",
)}
>
Export Model
</Button>
)
}
/>
</div>
</div>
</div>
)}
</main>
</div>
);
}