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
fix(export): pass trust_remote_code for checkpoint exports (#14722)
Ryder982eb96099ec
diff --git a/studio/frontend/src/features/export/export-page.tsx b/studio/frontend/src/features/export/export-page.tsxindex d4ac13a9fdf..69c59e695d8 100644--- a/studio/frontend/src/features/export/export-page.tsx+++ b/studio/frontend/src/features/export/export-page.tsx@@ -111,6 +111,7 @@ import {reapRequest,reapSummaryLabel,} from "./lib/reap";+import { exportRemoteCodeConsent } from "./lib/remote-code-consent";import { saveDirectoryField } from "./lib/save-directory";import { exportUnsupportedText } from "./lib/unsupported-text";import {@@ -998,24 +999,25 @@ export function ExportPage() {exportMethod);const adapterExport = sourceMode === "checkpoint" && isAdapter;- // Consent gate for an HF source's custom (auto_map) code, before handing off to runExport.- // A local checkpoint/model the user exported is trusted by default.- let trustRemoteCode = modelSource !== "hf";+ // 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;- if (sourceMode !== "checkpoint") {- const remoteCodeOk = await confirmRemoteCodeIfNeeded({- modelName: source,- hfToken: actionHfToken || null,- // An HF source can need trust_remote_code via its YAML default with no auto_map to review;- // signal it so a YAML-only model does not export with it false.- requiresTrustRemoteCode: modelSource === "hf",- onApprove: (fingerprint) => {- trustRemoteCode = true;- approvedRemoteCodeFingerprint = fingerprint;- },- });- if (!remoteCodeOk) return;- }+ 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") {diff --git a/studio/frontend/src/features/export/lib/remote-code-consent.ts b/studio/frontend/src/features/export/lib/remote-code-consent.tsnew file mode 100644index 00000000000..78be2184f27--- /dev/null+++ b/studio/frontend/src/features/export/lib/remote-code-consent.ts@@ -0,0 +1,34 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++export function exportRemoteCodeConsent({+ sourceMode,+ modelSource,+ source,+ checkpointPath,+}: {+ sourceMode: "checkpoint" | "model";+ modelSource: "hf" | "local";+ source: string;+ checkpointPath: string | null;+}): {+ scanTarget: string;+ requiresTrustRemoteCode: boolean;+ trustByDefault: boolean;+} {+ if (sourceMode === "checkpoint") {+ // Scan the checkpoint folder itself: the scan adds its LoRA base, so the fingerprint covers the+ // same targets the export worker gates. A base-only scan misses a full fine-tune's copied code.+ return {+ scanTarget: checkpointPath ?? source,+ requiresTrustRemoteCode: false,+ trustByDefault: false,+ };+ }+ return {+ scanTarget: source,+ // An HF source can need trust_remote_code via its YAML default with no auto_map to review.+ requiresTrustRemoteCode: modelSource === "hf",+ trustByDefault: modelSource !== "hf",+ };+}diff --git a/studio/frontend/src/features/export/stores/export-runtime-store.ts b/studio/frontend/src/features/export/stores/export-runtime-store.tsindex b217d03da26..438ebe6ab6c 100644--- a/studio/frontend/src/features/export/stores/export-runtime-store.ts+++ b/studio/frontend/src/features/export/stores/export-runtime-store.ts@@ -481,6 +481,9 @@ export const useExportRuntimeStore = create<ExportRuntimeStore>()((set, get) =>await runRecoverableOp(() =>loadCheckpoint({checkpoint_path: checkpointPath,+ trust_remote_code: params.trustRemoteCode,+ approved_remote_code_fingerprint:+ params.approvedRemoteCodeFingerprint ?? null,hf_token: params.loadToken ?? null,// REAP scores and slices 16-bit expert weights....(params.reap ? { load_in_4bit: false } : {}),diff --git a/studio/frontend/tests/export-gguf-token-fallback.test.ts b/studio/frontend/tests/export-gguf-token-fallback.test.tsindex ba276d30f8d..e8bb91fcc39 100644--- a/studio/frontend/tests/export-gguf-token-fallback.test.ts+++ b/studio/frontend/tests/export-gguf-token-fallback.test.ts@@ -144,3 +144,22 @@ test("disabling imatrix excludes a previously entered path", async () => {assert.equal(body.imatrix, false);assert.equal(body.imatrix_path, null);});++test("a checkpoint load forwards the remote-code approval", async () => {+ stub.resetStub();+ await useExportRuntimeStore.getState().runExport(+ params({+ sourceMode: "checkpoint",+ checkpointPath: "/studio/outputs/k2-horizon/checkpoint-60",+ source: "checkpoint-60",+ trustRemoteCode: true,+ approvedRemoteCodeFingerprint: "fp123",+ }),+ );+ const load = stub.calls.find((entry) => entry.name === "loadCheckpoint");+ assert.ok(load, "no load request was made");+ const body = load.args[0] as Record<string, unknown>;+ assert.equal(body.checkpoint_path, "/studio/outputs/k2-horizon/checkpoint-60");+ assert.equal(body.trust_remote_code, true);+ assert.equal(body.approved_remote_code_fingerprint, "fp123");+});diff --git a/studio/frontend/tests/export-remote-code-consent.test.ts b/studio/frontend/tests/export-remote-code-consent.test.tsnew file mode 100644index 00000000000..323b3f6b755--- /dev/null+++ b/studio/frontend/tests/export-remote-code-consent.test.ts@@ -0,0 +1,52 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++import assert from "node:assert/strict";+import test from "node:test";++import { exportRemoteCodeConsent } from "../src/features/export/lib/remote-code-consent.ts";++test("a checkpoint export scans the checkpoint folder and starts untrusted", () => {+ assert.deepEqual(+ exportRemoteCodeConsent({+ sourceMode: "checkpoint",+ // The model-mode toggle may still read "local" from an earlier visit.+ modelSource: "local",+ source: "checkpoint-60",+ checkpointPath: "/studio/outputs/k2-horizon/checkpoint-60",+ }),+ {+ scanTarget: "/studio/outputs/k2-horizon/checkpoint-60",+ requiresTrustRemoteCode: false,+ trustByDefault: false,+ },+ );+});++test("an HF model export scans the repo and needs approval to trust it", () => {+ assert.deepEqual(+ exportRemoteCodeConsent({+ sourceMode: "model",+ modelSource: "hf",+ source: "IFM/K2-Horizon-3.7B",+ checkpointPath: null,+ }),+ {+ scanTarget: "IFM/K2-Horizon-3.7B",+ requiresTrustRemoteCode: true,+ trustByDefault: false,+ },+ );+});++test("a local model export stays trusted by default", () => {+ assert.deepEqual(+ exportRemoteCodeConsent({+ sourceMode: "model",+ modelSource: "local",+ source: "/models/k2",+ checkpointPath: null,+ }),+ { scanTarget: "/models/k2", requiresTrustRemoteCode: false, trustByDefault: true },+ );+});