Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

1.7 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0

type DiffusionPickSource = "hub" | "lora" | "exported" | "local" | "external";

/** `displayRepoId` keeps the logical id for planning. */
export function diffusionPipelineLoadTarget(
  model: string,
  meta: { loadId?: string | null; source: DiffusionPickSource },
): { repoId: string; displayRepoId?: string; source: DiffusionPickSource; onDevice: boolean } {
  const loadId = meta.loadId?.trim();
  return loadId && loadId !== model.trim()
    ? { repoId: loadId, displayRepoId: model, source: meta.source, onDevice: true }
    : { repoId: model, source: meta.source, onDevice: meta.source === "local" };
}

/** A pinned snapshot is already on disk (and its revision may move), so only companions and a hosted denoiser, which it lacks, download. */
export function diffusionStagingEntries(
  entries: readonly {
    repo_id: string;
    files: string[];
    bytes: number;
    gguf_filename: string | null;
    checkpoint?: boolean;
    hosted_denoiser?: boolean;
  }[],
  repoId: string,
  opts: { filename?: string; displayRepoId?: string },
) {
  const planRepoId = opts.displayRepoId ?? repoId;
  return entries
    .map((e) => ({
      repoId: e.repo_id,
      files: e.files,
      bytes: e.bytes,
      ggufFilename: e.gguf_filename,
      // `??`: false is an answer; the fallback is only for older backends.
      checkpoint:
        e.checkpoint ?? (opts.filename ? e.files.includes(opts.filename) : e.repo_id === planRepoId),
      hostedDenoiser: e.hosted_denoiser,
    }))
    .filter((e) => planRepoId === repoId || !e.checkpoint || e.hostedDenoiser);
}