AI media harness for planning, generating, and editing locally
TypeScript
Warn before downloads exceed VRAM
Bittia862ae40e0e6
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.mdindex cf107b7..f94379a 100644--- a/RELEASE_NOTES.md+++ b/RELEASE_NOTES.md@@ -4,6 +4,8 @@ Changes since 0.3.2.## What's new+- **Download memory warnings.** MiniMax generators and shared weights now have minimum VRAM limits. Downloads warn when no variant of a needed weight fits the detected GPU, with Cancel and Download anyway options. Existing downloads and custom limits are preserved.+- **Single Shot continuity.** With Context video, use the Clown Context overlap recipe: hold the first 22 frames of Previous video's 39-frame tail, regenerate the final 17, and replace the overlap in joined video and audio. Keystone and Capstone remain sampling context; original source files stay intact. Requires updated workers.- **LoRA controls.** Enable MiniMax H3 LoRAs globally, drag the library to set application order, and add scene overrides in Generation. Global adapters remain active and appear read only in scenes. Step counts and sampling recipes follow the effective stack, with conflicting recipes blocked.diff --git a/docs/generator-weights.md b/docs/generator-weights.mdindex 811df3e..f5363f4 100644--- a/docs/generator-weights.md+++ b/docs/generator-weights.md@@ -186,6 +186,34 @@ FastH3 Omni uses its Omni transformer on all GPUs, without a W4A8 fallback.Saved Fast templates using the old fallback switch to Omni; an existing Omni download is reused when available.Other local weights and customized download variants are preserved.+Bundled MiniMax weights declare these minimum GPU memory capacities:++| Weight | Minimum VRAM (GB) |+| --- | ---: |+| First/Last Frame W4A8 / INT8 | 12 / 21 |+| References hybrid W4A8 / INT8 | 12 / 21 |+| FastH3 Omni INT8 | 22 |+| Singularity INT8 | 21 |+| Animate INT8 | 21 |+| H3 Qwen3-VL 32B text encoder | 16 |+| H3 video VAE FP16 / INT8 | 6 / 3 |+| Sol H3 VAE | 6 |+| H3 audio VAE FP32 | 1 |+| MiniMax Music3 transformer / text encoder / audio VAE | 3 / 9 / 1 |++Before a generator or shared-component download starts transferring files, Slopus+warns if all GPU-compatible variants for any needed weight exceed the detected+GPU capacity. The warning lists the GPUs and the unmet minimums, with **Cancel**+and **Download anyway** actions. Continuing selects the smallest GPU-compatible+variant when none fits. A known downloaded dependency is also checked when+downloading the rest of a generator. For example, H3's shared 16 GB text encoder+still triggers a warning on a 12 GB GPU even though its W4A8 transformer fits.+Capacities are not added across GPUs or across model files. Unknown GPU capacity+does not trigger a low-memory warning and uses the smallest compatible variant.+This checks GPU capacity, not the memory currently free while other apps run.+Existing unrestricted bundled sources receive these limits once; custom positive+limits, GPU rules, URLs and downloaded paths are preserved.+Templates awaiting downloads appear under **Download**. Once theirweights are downloaded, they move into **Generators**. Removing or losing theirdownloaded files moves them back to **Download**.@@ -197,6 +225,8 @@ prefers a matching GPU-specific variant, then the highest memory tier that fits;ties preserve the listed order. Leave the GPU field blank and VRAM at zero for auniversal fallback. Windows hardware detection includes NVIDIA, AMD, and Intel.Memory tiers account for the small amount of VRAM reserved by the driver.+If every compatible variant exceeds the detected capacity, downloading requires+accepting the memory warning. A zero minimum leaves that variant unrestricted.Click the template's download icon or **Download weights** in its editor todownload missing weights. Files go into `weights` beside `Slopus.exe`. If thatdiff --git a/src/components/WeightSourcesEditor.tsx b/src/components/WeightSourcesEditor.tsxindex c29eb16..2d2662b 100644--- a/src/components/WeightSourcesEditor.tsx+++ b/src/components/WeightSourcesEditor.tsx@@ -11,6 +11,7 @@ export function WeightSourcesEditor({ label, sources, disabled, onChange }: {const update = (index: number, patch: Partial<WeightSource>) => onChange(sources.map((source, i) => i === index ? { ...source, ...patch } : source));return <Expander className="weight-sources" header={`Download variants${sources.length > 0 ? ` (${sources.length})` : ""}`}description="Among matching GPUs, the highest minimum VRAM that fits is used">+ <p className="settings-caption">If no variant fits the detected VRAM, downloading asks for confirmation. Zero leaves a variant unrestricted.</p><p className="settings-caption">GPU model matches part of the device name, such as “RTX 5090”. Leave it blank for any GPU.</p>{sources.map((source, index) => <div className="weight-source" key={`${index}-${source.url}`}><label>Download URL<input className="text-field" aria-label={`${label} variant ${index + 1} URL`} defaultValue={source.url} disabled={disabled} onBlur={(event) => {diff --git a/src/lib/h3Components.ts b/src/lib/h3Components.tsindex 5e5bfbe..cef49be 100644--- a/src/lib/h3Components.ts+++ b/src/lib/h3Components.ts@@ -29,7 +29,8 @@ export function initialH3Components(): H3Components {{ id: H3_FAST_VIDEO_VAE_ID, name: "MiniMax H3 Video VAE INT8", type: "video", path: root + "vae/minimax_h3_video_vae_int8_convrot.safetensors" },{ id: H3_AUDIO_VAE_ID, name: "MiniMax H3 Audio VAE", type: "audio", path: root + "vae/minimax_h3_audio_vae_fp32.safetensors" },{ id: H3_TEXT_ENCODER_ID, name: "Qwen3 VL 32B MiniMax H3", type: "textEncoder", path: root + "text_encoders/qwen3vl_32b_minimax_h3_nvfp4_awq.safetensors" },- ].map((entry) => ({ ...entry, type: entry.type as H3ComponentType, sources: [{ url: entry.path, gpuModel: "", minVramGb: 0 }] })) };+ ].map((entry) => ({ ...entry, type: entry.type as H3ComponentType, sources: [{ url: entry.path, gpuModel: "",+ minVramGb: entry.type === "textEncoder" ? 16 : entry.type === "audio" ? 1 : entry.id === H3_FAST_VIDEO_VAE_ID ? 3 : 6 }] })) };}function normalizeComponents(value: unknown): H3Components {diff --git a/src/lib/settings.test.ts b/src/lib/settings.test.tsindex 61cb9ba..9adb4e0 100644--- a/src/lib/settings.test.ts+++ b/src/lib/settings.test.ts@@ -66,7 +66,7 @@ describe("generator templates", () => {sources: { transformer: [{ ...int8, downloadedPath: cached }] } };saveGeneratorTemplateSettings({ templates: [previous], defaultTemplateId: previous.id, catalogVersion: 16 });const upgraded = loadGeneratorTemplateSettings();- expect(upgraded.catalogVersion).toBe(17);+ expect(upgraded.catalogVersion).toBe(18);expect(upgraded.templates[0]).toMatchObject({ name: "My music", paths: { transformer: cached },sources: { transformer: [template.sources!.transformer![0], { ...int8, downloadedPath: cached }] } });expect(loadGeneratorTemplateSettings()).toEqual(upgraded);@@ -252,7 +252,7 @@ describe("generator templates", () => {expect(original.name).toBe("First/Last Frame");expect(references).toEqual({ ...original, id: "minimax-h3-references", name: "References",paths: { ...original.paths, transformer },- sources: { ...original.sources, transformer: [{ ...original.sources!.transformer![0], url: transformer }, { url: "https://huggingface.co/koongrizzly/MiniMax_H3_int4_W4A8_ConvRot_Pruned/resolve/main/diffusion_models/minimax_h3_ref2va_hybrid_b20-49_pruned_w4a8_mixed.safetensors", gpuModel: "", minVramGb: 0 }] },+ sources: { ...original.sources, transformer: [{ ...original.sources!.transformer![0], url: transformer }, { url: "https://huggingface.co/koongrizzly/MiniMax_H3_int4_W4A8_ConvRot_Pruned/resolve/main/diffusion_models/minimax_h3_ref2va_hybrid_b20-49_pruned_w4a8_mixed.safetensors", gpuModel: "", minVramGb: 12 }] },});expect(loadGeneratorTemplateSettings().templates.map(({ name }) => name)).toEqual(["Default", "First/Last Frame", "References", "FastH3 Omni", "Singularity", "Animate", "MOSS Image", "Fibo 2.0 Edit Turbo", "Fibo 2.0 Base", "YuE2", "MiniMax Music3"]);});@@ -271,7 +271,7 @@ describe("generator templates", () => {expect(generatorOwned(settings.templates[2])).toEqual(generatorOwned(minimaxFastTemplate()));expect(generatorOwned(settings.templates[3])).toEqual(generatorOwned(minimaxSingularityTemplate()));expect(settings.defaultTemplateId).toBe(template.id);- expect(settings.catalogVersion).toBe(17);+ expect(settings.catalogVersion).toBe(18);expect(loadGeneratorTemplateSettings()).toEqual(settings);saveGeneratorTemplateSettings({ ...settings, templates: [settings.templates[0]] });expect(loadGeneratorTemplateSettings().templates).toHaveLength(1);@@ -292,7 +292,7 @@ describe("generator templates", () => {const settings = loadGeneratorTemplateSettings();expect(generatorOwned(settings.templates)).toEqual(generatorOwned([custom, minimaxSingularityTemplate(), viggleAnimateTemplate(), mossImageTemplate(), fiboImageTemplate(), fiboBaseTemplate(), ...musicTemplates()]));expect(settings.defaultTemplateId).toBe(custom.id);- expect(settings.catalogVersion).toBe(17);+ expect(settings.catalogVersion).toBe(18);expect(loadGeneratorTemplateSettings()).toEqual(settings);saveGeneratorTemplateSettings({ ...settings, templates: [custom] });expect(generatorOwned(loadGeneratorTemplateSettings().templates)).toEqual(generatorOwned([custom]));@@ -334,8 +334,8 @@ describe("generator templates", () => {const videoVae = "https://huggingface.co/Comfy-Org/MiniMax-H3/blob/main/vae/minimax_h3_video_vae_int8_convrot.safetensors";expect(fast).toEqual({ ...original, id: "minimax-h3-fast", name: "FastH3 Omni", defaultSteps: 8,paths: { ...original.paths, transformer, videoVae },- sources: { ...original.sources, transformer: [{ url: transformer, gpuModel: "", minVramGb: 0 }],- videoVae: [{ url: videoVae, gpuModel: "", minVramGb: 0 }] },+ sources: { ...original.sources, transformer: [{ url: transformer, gpuModel: "", minVramGb: 22 }],+ videoVae: [{ url: videoVae, gpuModel: "", minVramGb: 3 }] },});saveGeneratorTemplateSettings({ templates: [fast], defaultTemplateId: "", catalogVersion: 4 });expect(loadGeneratorTemplateSettings().templates[0].defaultSteps).toBe(8);@@ -357,7 +357,7 @@ describe("generator templates", () => {localStorage.setItem("slopus.generator-templates.v1", JSON.stringify({ templates: [template], catalogVersion: 8 }));const settings = loadGeneratorTemplateSettings();expect(generatorOwned(settings.templates)).toEqual(generatorOwned([minimaxFastTemplate(), mossImageTemplate(), fiboImageTemplate(), fiboBaseTemplate(), ...musicTemplates()]));- expect(settings.catalogVersion).toBe(17);+ expect(settings.catalogVersion).toBe(18);expect(templateNeedsDownload(settings.templates[0])).toBe(true);expect(loadGeneratorTemplateSettings()).toEqual(settings);});@@ -372,7 +372,7 @@ describe("generator templates", () => {const otherPaths = { ...template.paths };localStorage.setItem("slopus.generator-templates.v1", JSON.stringify({ templates: [template], catalogVersion: 10 }));const settings = loadGeneratorTemplateSettings();- expect(settings.catalogVersion).toBe(17);+ expect(settings.catalogVersion).toBe(18);expect(settings.templates).toHaveLength(5);expect(settings.templates[0]).toMatchObject({ id: template.id, name: "FastH3 Omni", defaultSteps: 8,paths: { ...otherPaths, transformer: minimaxFastTemplate().paths.transformer },@@ -395,7 +395,7 @@ describe("generator templates", () => {localStorage.setItem("slopus.generator-templates.v1", JSON.stringify({ templates: [template, references, fast], catalogVersion: 12 }));const settings = loadGeneratorTemplateSettings();const migrated = settings.templates[0];- expect(migrated.sources!.transformer).toContainEqual({ url: expectedUrl, gpuModel: "", minVramGb: 0 });+ expect(migrated.sources!.transformer).toContainEqual({ url: expectedUrl, gpuModel: "", minVramGb: 12 });expect(migrated.sources!.transformer!.some((source) => source.url.includes("ref2va") || source.downloadedPath === oldFallback.downloadedPath)).toBe(false);expect(migrated.paths.transformer).toBe(selection === "url" || selection === "downloaded" ? expectedUrl : previousPath);expect(migrated.name).toBe(template.name);@@ -424,7 +424,7 @@ describe("generator templates", () => {expect(migrated.name).toBe("My Omni");expect(migrated.defaultSteps).toBe(12);expect(migrated.sources!.transformer!.map((source) => source.url)).not.toContain(fallback.url);- expect(migrated.sources!.transformer).toContainEqual(expect.objectContaining({ url: omniUrl, gpuModel: "", minVramGb: 0 }));+ expect(migrated.sources!.transformer).toContainEqual(expect.objectContaining({ url: omniUrl, gpuModel: "", minVramGb: 22 }));expect(migrated.sources!.transformer).toContainEqual({ url: "https://example.com/custom.safetensors", gpuModel: "Custom GPU", minVramGb: 8 });expect(migrated.paths.transformer).toBe(selection === "custom" ? "D:/custom.safetensors" : selection === "cached omni" ? "D:/weights/omni.safetensors" : omniUrl);expect(settings.defaultTemplateId).toBe(selection === "custom" || selection === "cached omni" ? template.id : "");@@ -468,7 +468,7 @@ describe("generator templates", () => {template.paths[field] = downloadedPath;localStorage.setItem("slopus.generator-templates.v1", JSON.stringify({ templates: [template], catalogVersion: 1 }));const settings = loadGeneratorTemplateSettings();- expect(settings.catalogVersion).toBe(17);+ expect(settings.catalogVersion).toBe(18);expect(settings.templates[0].paths[field]).toBe(downloadedPath);expect(settings.templates[0].sources![field]).toEqual(minimaxOriginalTemplate().sources![field]!.map((source, index) =>index === 0 ? { ...source, downloadedPath } : source));@@ -503,9 +503,9 @@ describe("generator templates", () => {localStorage.setItem("slopus.generator-templates.v1", JSON.stringify({ templates: [template], defaultTemplateId: template.id, catalogVersion: 2 }));const settings = loadGeneratorTemplateSettings();const migrated = settings.templates[0];- expect(settings.catalogVersion).toBe(17);+ expect(settings.catalogVersion).toBe(18);expect(migrated.sources!.textEncoder).toEqual([- { url: originalUrl, gpuModel: "", minVramGb: 0, ...(selection === "cached original" ? { downloadedPath: cachedOriginal } : {}) },+ { url: originalUrl, gpuModel: "", minVramGb: 16, ...(selection === "cached original" ? { downloadedPath: cachedOriginal } : {}) },custom,]);expect(migrated.paths.textEncoder).toBe(selection === "url" || selection === "downloaded" ? originalUrldiff --git a/src/lib/settings.ts b/src/lib/settings.tsindex fef527c..740fa3b 100644--- a/src/lib/settings.ts+++ b/src/lib/settings.ts@@ -13,7 +13,7 @@* silently drops that path.*/import { isSigmaShift, type SigmaShifts } from "./sampling";-import { normalizeH3Library, resolveH3Components, type H3Components } from "./h3Components";+import { initialH3Components, normalizeH3Library, resolveH3Components, type H3Components } from "./h3Components";import { generatorModel } from "./generatorModels";export { generatorModel, GENERATOR_MODELS } from "./generatorModels";import { latentUpscalerPath, otherWeightPaths, TAEH3_URL } from "./upscalers";@@ -275,7 +275,7 @@ export function musicTemplates(): GeneratorTemplate[] {// Selection rounds detected GiB up: a minimum tier of 9 means strictly// more than 8 GiB, keeping 8 GiB cards on the INT8 fallback....(modelType === "yue2" && id === "transformer" ? [{ url: "https://huggingface.co/Comfy-Org/YuE2/resolve/main/checkpoints/yue2_3b_bf16.safetensors", gpuModel: "", minVramGb: 9 }] : []),- { url, gpuModel: "", minVramGb: 0 },+ { url, gpuModel: "", minVramGb: modelType === "minimax_music3" ? id === "transformer" ? 3 : id === "textEncoder" ? 9 : 1 : 0 },]])) };});}@@ -323,10 +323,10 @@ export function minimaxOriginalTemplate(): GeneratorTemplate {videoVae: `${root}vae/minimax_h3_video_vae_fp16.safetensors`,audioVae: `${root}vae/minimax_h3_audio_vae_fp32.safetensors`, tokenizer: "",};- const sources: GeneratorTemplate["sources"] = Object.fromEntries(ENGINE_PATH_FIELDS.filter(({ id }) => paths[id]).map(({ id }) => [id, [{ url: paths[id], gpuModel: "", minVramGb: 0 }]]));+ const sources: GeneratorTemplate["sources"] = Object.fromEntries(ENGINE_PATH_FIELDS.filter(({ id }) => paths[id]).map(({ id }) => [id, [{ url: paths[id], gpuModel: "", minVramGb: id === "textEncoder" ? 16 : id === "videoVae" ? 6 : id === "audioVae" ? 1 : 0 }]]));sources.transformer = [{ url: paths.transformer, gpuModel: "", minVramGb: 21 },- { url: MINIMAX_FL2VA_W4A8_URL, gpuModel: "", minVramGb: 0 },+ { url: MINIMAX_FL2VA_W4A8_URL, gpuModel: "", minVramGb: 12 },];return { id: "minimax-h3-original", name: "First/Last Frame", modelType: MINIMAX_H3_MODEL_TYPE, defaultSteps: 20, attention: "sage2", paths, sources };}@@ -345,7 +345,7 @@ export function minimaxReferencesTemplate(): GeneratorTemplate {"https://huggingface.co/Comfy-Org/MiniMax-H3/resolve/main/diffusion_models/minimax_h3_ref2va_pruned_int8_convrot.safetensors");return { ...template, sources: { ...template.sources, transformer: [{ url: template.paths.transformer, gpuModel: "", minVramGb: 21 },- { url: MINIMAX_REF2VA_W4A8_URL, gpuModel: "", minVramGb: 0 },+ { url: MINIMAX_REF2VA_W4A8_URL, gpuModel: "", minVramGb: 12 },] } };}@@ -356,8 +356,8 @@ export function minimaxFastTemplate(): GeneratorTemplate {return { ...template,paths: { ...template.paths, videoVae },sources: { ...template.sources,- transformer: [{ url: template.paths.transformer, gpuModel: "", minVramGb: 0 }],- videoVae: [{ url: videoVae, gpuModel: "", minVramGb: 0 }] },+ transformer: [{ url: template.paths.transformer, gpuModel: "", minVramGb: 22 }],+ videoVae: [{ url: videoVae, gpuModel: "", minVramGb: 3 }] },};}@@ -367,7 +367,7 @@ export function minimaxSingularityTemplate(): GeneratorTemplate {return { ...template, id: "minimax-h3-singularity", name: "Singularity", defaultSteps: 4,loras: [{ loraId: TURBO_LORA.id, enabled: true, strength: 1 }],paths: { ...template.paths, transformer },- sources: { ...template.sources, transformer: [{ url: transformer, gpuModel: "", minVramGb: 0 }] },+ sources: { ...template.sources, transformer: [{ url: transformer, gpuModel: "", minVramGb: 21 }] },};}@@ -378,14 +378,14 @@ export function viggleAnimateTemplate(): GeneratorTemplate {additionalSafetensors: [{ id: "animate-conditioning", name: "Animate conditioning", url: ANIMATE_CONDITIONING_URL, role: "promptEmbedding" }],loras: [{ loraId: VIGGLE_ANIMATE_LORA.id, enabled: true, strength: 1 }],paths: { ...template.paths, transformer },- sources: { ...template.sources, transformer: [{ url: transformer, gpuModel: "", minVramGb: 0 }] },+ sources: { ...template.sources, transformer: [{ url: transformer, gpuModel: "", minVramGb: 21 }] },};}const initialTemplateSettings = (paths = EMPTY_ENGINE_SETTINGS): GeneratorTemplateSettings => normalizeTemplateSettings({templates: [{ id: "default", name: "Default", modelType: MINIMAX_H3_MODEL_TYPE, defaultSteps: DEFAULT_GENERATION_STEPS, attention: "sage2", paths: copyPaths(paths) }, minimaxOriginalTemplate(), minimaxReferencesTemplate(), minimaxFastTemplate(), minimaxSingularityTemplate(), viggleAnimateTemplate(), mossImageTemplate(), fiboImageTemplate(), fiboBaseTemplate(), ...musicTemplates()],defaultTemplateId: "default",- catalogVersion: 17,+ catalogVersion: 18,})!;const normalizeTemplateSettings = (value: unknown, shareComponents = true): GeneratorTemplateSettings | null => {@@ -452,7 +452,7 @@ const normalizeTemplateSettings = (value: unknown, shareComponents = true): Gene...shared,defaultTemplateId: !shareComponents ? requestedDefault : shared.templates.find((template) => template.id === requestedDefault && templateUsable(template))?.id?? shared.templates.find(templateUsable)?.id ?? "",- catalogVersion: typeof record.catalogVersion === "number" && [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17].includes(record.catalogVersion) ? record.catalogVersion : 0,+ catalogVersion: typeof record.catalogVersion === "number" && [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18].includes(record.catalogVersion) ? record.catalogVersion : 0,};};@@ -664,6 +664,29 @@ export function loadGeneratorTemplateSettings(): GeneratorTemplateSettings {normalized = normalizeTemplateSettings({ ...normalized, catalogVersion: 17 }, false)!;localStorage.setItem(GENERATOR_TEMPLATES_KEY, JSON.stringify(normalized));}+ if ((normalized.catalogVersion ?? 0) < 18) {+ const canonical = (url: string) => url.trim().replace("/blob/", "/resolve/");+ const bundled = [minimaxOriginalTemplate(), minimaxReferencesTemplate(), minimaxFastTemplate(), minimaxSingularityTemplate(), viggleAnimateTemplate(), ...musicTemplates()];+ const limits = new Map([+ ...bundled.flatMap((template) => Object.values(template.sources ?? {}).flat()),+ ...initialH3Components().templates.flatMap((entry) => entry.sources),+ ].map((source) => [canonical(source.url), source.minVramGb]));+ // Only replace the old unrestricted defaults; retain user limits, GPU+ // rules, custom URLs and downloaded paths, including shared components.+ const upgrade = (source: WeightSource): WeightSource => {+ const minimum = limits.get(canonical(source.url));+ return minimum && source.minVramGb === 0 && !source.gpuModel.trim()+ ? { ...source, minVramGb: minimum } : source;+ };+ normalized.templates = normalized.templates.map((template) => ({ ...template,+ sources: Object.fromEntries(Object.entries(template.sources ?? {}).map(([field, sources]) => [field, sources!.map(upgrade)])),+ }));+ if (normalized.h3Components) normalized.h3Components = { ...normalized.h3Components,+ templates: normalized.h3Components.templates.map((entry) => ({ ...entry, sources: entry.sources.map(upgrade) })),+ };+ normalized = normalizeTemplateSettings({ ...normalized, catalogVersion: 18 }, false)!;+ localStorage.setItem(GENERATOR_TEMPLATES_KEY, JSON.stringify(normalized));+ }const shared = normalizeTemplateSettings(normalized)!;if (!normalized.h3Components) localStorage.setItem(GENERATOR_TEMPLATES_KEY, JSON.stringify(shared));return shared;diff --git a/src/lib/weightDownloadVram.test.ts b/src/lib/weightDownloadVram.test.tsnew file mode 100644index 0000000..3ec11d3--- /dev/null+++ b/src/lib/weightDownloadVram.test.ts@@ -0,0 +1,177 @@+// @vitest-environment jsdom+import { beforeEach, expect, it, vi } from "vitest";+import { invoke } from "@tauri-apps/api/core";+import { askNative } from "./nativeShell";+import { loadGeneratorTemplateSettings, saveGeneratorTemplateSettings, type WeightGpu } from "./settings";+import { cancelWeightDownload, downloadH3Component, downloadTemplateWeights, getWeightDownloadState } from "./weightDownloads";++vi.mock("@tauri-apps/api/core", () => ({ invoke: vi.fn() }));+vi.mock("@tauri-apps/api/event", () => ({ listen: vi.fn(async () => () => undefined) }));+vi.mock("./persistence", () => ({ isTauri: () => true }));+vi.mock("./nativeShell", () => ({ askNative: vi.fn() }));++let devices: WeightGpu[];+const gpu = (gb: number, name = "Test GPU"): WeightGpu => ({ name, memoryBytes: gb * 1024 ** 3 });+const downloads = () => vi.mocked(invoke).mock.calls.filter(([command]) => command === "download_weight")+ .map(([, args]) => (args as { url: string }).url);++beforeEach(() => {+ localStorage.clear(); vi.clearAllMocks(); devices = [gpu(8)];+ vi.mocked(askNative).mockResolvedValue(false);+ vi.mocked(invoke).mockImplementation(async (command, args: any) => {+ if (command === "weight_download_hardware") return devices;+ if (command === "find_downloaded_weights") return {};+ if (command === "check_weight_files") return Object.fromEntries(args.paths.map((path: string) => [path, true]));+ if (command === "download_weight") return `D:/weights/${args.url.split("/").pop()}`;+ });+});++it("waits for a decision before any transfer and cancels without a download error", async () => {+ let decide!: (answer: boolean) => void;+ vi.mocked(askNative).mockImplementation(() => new Promise((resolve) => { decide = resolve; }));+ const pending = downloadTemplateWeights("minimax-h3-original");+ await vi.waitFor(() => expect(askNative).toHaveBeenCalledOnce());+ expect(downloads()).toEqual([]);+ expect(askNative).toHaveBeenCalledWith(expect.objectContaining({+ title: "Not enough GPU memory", okLabel: "Download anyway", cancelLabel: "Cancel",+ message: expect.stringContaining("Test GPU: 8 GB VRAM"),+ }));+ const message = vi.mocked(askNative).mock.calls[0][0].message;+ expect(message).toContain("12 GB VRAM");+ expect(message).toContain("16 GB VRAM");+ expect(message).not.toContain("21 GB VRAM"); // Report the smallest alternative.+ decide(false);+ await pending;+ expect(downloads()).toEqual([]);+ expect(getWeightDownloadState()).toMatchObject({ active: false, completed: 0, error: null });+ await downloadTemplateWeights("fibo2-edit-turbo"); // A declined warning releases the queue.+ expect(downloads()).toHaveLength(3);+});++it("downloads the smallest matching variant after accepting the warning", async () => {+ vi.mocked(askNative).mockResolvedValue(true);+ await downloadTemplateWeights("minimax-h3-original");+ expect(askNative).toHaveBeenCalledOnce();+ expect(downloads()).toHaveLength(4);+ expect(downloads()[0]).toContain("w4a8_convrot_pruned");+ expect(getWeightDownloadState()).toMatchObject({ active: false, completed: 4, error: null });+});++it.each([12, 16, 21, 24])("checks the encoder independently of the transformer on a %s GB GPU", async (gb) => {+ devices = [gpu(gb)];+ vi.mocked(askNative).mockResolvedValue(true);+ await downloadTemplateWeights("minimax-h3-original");+ if (gb < 16) {+ expect(askNative).toHaveBeenCalledOnce();+ expect(vi.mocked(askNative).mock.calls[0][0].message).toContain("16 GB VRAM");+ expect(vi.mocked(askNative).mock.calls[0][0].message).not.toContain("at least 12");+ } else expect(askNative).not.toHaveBeenCalled();+ expect(downloads()[0]).toContain(gb < 21 ? "w4a8_convrot_pruned" : "int8_convrot");+});++it.each([[], [gpu(0)], [gpu(15.4)], [gpu(8), gpu(24)]].map((hardware) => ({ hardware })))("handles unknown capacity, reserved memory and multiple GPUs: $hardware", async ({ hardware }) => {+ devices = hardware;+ await downloadTemplateWeights("minimax-h3-original");+ expect(askNative).not.toHaveBeenCalled();+ expect(downloads()).toHaveLength(4);+});++it("does not add the VRAM of separate GPUs together", async () => {+ devices = [gpu(8, "GPU A"), gpu(8, "GPU B")];+ await downloadTemplateWeights("minimax-h3-original");+ expect(askNative).toHaveBeenCalledOnce();+ expect(downloads()).toEqual([]);+});++it("warns for a known local encoder when downloading the remaining generator weights", async () => {+ devices = [gpu(12)];+ const settings = loadGeneratorTemplateSettings();+ const encoder = settings.h3Components!.templates.find(({ id }) => id === settings.h3Components!.defaultTextEncoderId)!;+ encoder.path = "D:/weights/encoder.safetensors";+ encoder.sources[0].downloadedPath = encoder.path;+ saveGeneratorTemplateSettings(settings);+ await downloadTemplateWeights("minimax-h3-original");+ expect(askNative).toHaveBeenCalledOnce();+ expect(vi.mocked(askNative).mock.calls[0][0].message).toContain("16 GB VRAM");+ expect(downloads()).toEqual([]);+});++it("checks shared components when downloaded directly", async () => {+ await downloadH3Component("h3-text-encoder");+ expect(askNative).toHaveBeenCalledOnce();+ expect(downloads()).toEqual([]);+ vi.mocked(askNative).mockResolvedValue(true);+ await downloadH3Component("h3-text-encoder");+ expect(downloads()).toHaveLength(1);+ expect(getWeightDownloadState()).toMatchObject({ active: false, completed: 1, error: null });+});++it("does not treat an unrelated GPU's memory as sufficient for a restricted variant", async () => {+ devices = [gpu(8, "RTX small"), gpu(32, "Radeon large")];+ const settings = loadGeneratorTemplateSettings();+ const template = settings.templates.find(({ id }) => id === "fibo2-edit-turbo")!;+ template.sources!.transformer![0] = { ...template.sources!.transformer![0], gpuModel: "RTX", minVramGb: 16 };+ saveGeneratorTemplateSettings(settings);+ await downloadTemplateWeights(template.id);+ expect(askNative).toHaveBeenCalledOnce();+ expect(downloads()).toEqual([]);+});++it("does not override GPU model restrictions even when downloading anyway", async () => {+ const settings = loadGeneratorTemplateSettings();+ const template = settings.templates.find(({ id }) => id === "fibo2-edit-turbo")!;+ template.sources!.transformer![0].gpuModel = "Different GPU";+ saveGeneratorTemplateSettings(settings);+ vi.mocked(askNative).mockResolvedValue(true);+ await downloadTemplateWeights(template.id);+ expect(askNative).not.toHaveBeenCalled();+ expect(downloads()).toEqual([]);+ expect(getWeightDownloadState()?.error).toContain("matches this GPU");+});++it("respects cancellation while the warning is open", async () => {+ vi.mocked(askNative).mockImplementation(async () => { await cancelWeightDownload(); return true; });+ await downloadTemplateWeights("minimax-h3-original");+ expect(downloads()).toEqual([]);+ expect(getWeightDownloadState()).toMatchObject({ active: false, error: "Download cancelled." });+});++it("seeds all agreed minimums and upgrades old defaults once without losing custom values or files", () => {+ const settings = loadGeneratorTemplateSettings();+ const limits = Object.fromEntries(settings.templates.filter(({ modelType, id }) => id !== "default" && ["minimax-h3", "minimax_music3"].includes(modelType))+ .map((template) => [template.id, template.sources!.transformer!.map(({ minVramGb }) => minVramGb)]));+ expect(limits).toEqual({ "minimax-h3-original": [21, 12], "minimax-h3-references": [21, 12],+ "minimax-h3-fast": [22], "minimax-h3-singularity": [21], "viggle-animate": [21], minimax_music3: [3] });+ expect(Object.fromEntries(settings.h3Components!.templates.map((entry) => [entry.id, entry.sources[0].minVramGb]))).toEqual({+ "h3-video-vae": 6, "sol-h3-vae": 6, "h3-fast-video-vae": 3, "h3-audio-vae": 1, "h3-text-encoder": 16,+ });+ const music = settings.templates.find(({ id }) => id === "minimax_music3")!;+ expect(music.sources!.textEncoder![0].minVramGb).toBe(9);+ expect(music.sources!.audioVae![0].minVramGb).toBe(1);++ for (const template of settings.templates) for (const source of Object.values(template.sources ?? {}).flat()) source.minVramGb = 0;+ for (const entry of settings.h3Components!.templates) for (const source of entry.sources) source.minVramGb = 0;+ const original = settings.templates.find(({ id }) => id === "minimax-h3-original")!;+ original.paths.transformer = "D:/weights/original.safetensors";+ original.sources!.transformer![0].downloadedPath = original.paths.transformer;+ original.sources!.transformer![1].minVramGb = 10; // Custom positive limit.+ original.sources!.transformer!.push({ url: "https://example.com/custom", gpuModel: "", minVramGb: 0 });+ const encoder = settings.h3Components!.templates.find(({ id }) => id === "h3-text-encoder")!;+ encoder.path = "D:/weights/encoder.safetensors";+ encoder.sources[0].downloadedPath = encoder.path;+ encoder.sources[0].url = encoder.sources[0].url.replace("/blob/", "/resolve/");+ localStorage.setItem("slopus.generator-templates.v1", JSON.stringify({ ...settings, catalogVersion: 17 }));+ const migrated = loadGeneratorTemplateSettings();+ const updated = migrated.templates.find(({ id }) => id === original.id)!;+ expect(migrated.catalogVersion).toBe(18);+ expect(updated.paths.transformer).toBe(original.paths.transformer);+ expect(updated.sources!.transformer!.map(({ minVramGb }) => minVramGb)).toEqual([21, 10, 0]);+ expect(updated.sources!.transformer![0].downloadedPath).toBe(original.paths.transformer);+ expect(migrated.h3Components!.templates.find(({ id }) => id === encoder.id)).toMatchObject({+ path: encoder.path, sources: [{ ...encoder.sources[0], minVramGb: 16 }],+ });+ // After migration, setting an unrestricted custom limit stays unrestricted.+ updated.sources!.transformer![0].minVramGb = 0;+ saveGeneratorTemplateSettings(migrated);+ expect(loadGeneratorTemplateSettings().templates.find(({ id }) => id === original.id)!.sources!.transformer![0].minVramGb).toBe(0);+});diff --git a/src/lib/weightDownloads.test.ts b/src/lib/weightDownloads.test.tsindex d76e1d7..214aa94 100644--- a/src/lib/weightDownloads.test.ts+++ b/src/lib/weightDownloads.test.ts@@ -9,6 +9,7 @@ import { ANIMATE_CONDITIONING_URL, mossImageTemplate, fiboImageTemplate, enginePvi.mock("@tauri-apps/api/core", () => ({ invoke: vi.fn() }));vi.mock("@tauri-apps/api/event", () => ({ listen: vi.fn(async () => () => undefined) }));vi.mock("./persistence", () => ({ isTauri: () => true }));+vi.mock("./nativeShell", () => ({ askNative: vi.fn(async () => true) }));const files = new Set<string>();const source = (url: string, gpuModel = "", minVramGb = 0): WeightSource => ({ url, gpuModel, minVramGb });const saved = () => loadGeneratorTemplateSettings().templates.find((template) => template.id === "minimax-h3-original")!;diff --git a/src/lib/weightDownloads.ts b/src/lib/weightDownloads.tsindex 1cd9c67..b1f1f6b 100644--- a/src/lib/weightDownloads.ts+++ b/src/lib/weightDownloads.ts@@ -1,6 +1,7 @@import { invoke } from "@tauri-apps/api/core";import { listen } from "@tauri-apps/api/event";import { isTauri } from "./persistence";+import { askNative } from "./nativeShell";import { OTHER_WEIGHT_TEMPLATES, refreshOtherWeights, otherWeightPaths, saveOtherWeightPath } from "./upscalers";import { effectiveLoras, downloadableTemplateLoras, loadLoras, saveLoras, type Lora } from "./loras";import { chooseWeightSource, ENGINE_PATH_FIELDS, generatorPathFields, isDownloadUrl, loadGeneratorTemplateSettings, saveGeneratorTemplateSettings, templateNeedsDownload,@@ -9,6 +10,32 @@ import { chooseWeightSource, ENGINE_PATH_FIELDS, generatorPathFields, isDownloadexport type { WeightGpu } from "./settings";import { h3ComponentForField, type H3ComponentTemplate } from "./h3Components";export { chooseWeightSource };++const gpuSources = (sources: WeightSource[], devices: WeightGpu[]) => sources.filter((source) =>+ !source.gpuModel.trim() || devices.some((gpu) => gpu.name.toLowerCase().includes(source.gpuModel.trim().toLowerCase())));++// Downloads may proceed after a VRAM warning. Unknown hardware also uses the+// smallest variant, but GPU model restrictions still apply.+function chooseDownloadSource(sources: WeightSource[], devices: WeightGpu[]): WeightSource | null {+ return chooseWeightSource(sources, devices)+ ?? gpuSources(sources, devices).sort((a, b) => a.minVramGb - b.minVramGb)[0] ?? null;+}++async function confirmDownloadVram(name: string, weights: { label: string; sources: WeightSource[] }[], devices: WeightGpu[]): Promise<boolean> {+ const known = devices.filter((gpu) => Number.isFinite(gpu.memoryBytes) && gpu.memoryBytes > 0);+ if (!known.length) return true;+ const shortages = weights.flatMap(({ label, sources }) => {+ const candidates = gpuSources(sources, known);+ if (!candidates.length || chooseWeightSource(candidates, known)) return [];+ const minimum = Math.min(...candidates.map((source) => source.minVramGb));+ return [`${label}: at least ${minimum} GB VRAM`];+ });+ if (!shortages.length) return true;+ return askNative({ title: "Not enough GPU memory", kind: "warning",+ message: `${name} has weights whose download variants all require more VRAM than the matching GPU has.\n\nDetected GPU capacity:\n${known.map((gpu) => `${gpu.name}: ${Math.ceil(gpu.memoryBytes / 1024 ** 3)} GB VRAM`).join("\n")}\n\n${shortages.join("\n")}\n\nGeneration may run out of GPU memory. Download anyway?`,+ okLabel: "Download anyway", cancelLabel: "Cancel" });+}+export interface DownloadState {templateId: string;otherWeightId?: string;@@ -127,7 +154,7 @@ async function refreshH3Components() {downloadedPath: source.downloadedPath && exists?.[source.downloadedPath] !== false ? source.downloadedPath : found?.[source.url] }));let path = entry.path;if (!path || isDownloadUrl(path) || exists?.[path] === false) {- const source = chooseWeightSource(sources, devices ?? []);+ const source = chooseDownloadSource(sources, devices ?? []);path = source?.downloadedPath ?? source?.url ?? (exists?.[path] === false ? "" : path);}const tokenizer = entry.tokenizerUrl && (!entry.tokenizer || isDownloadUrl(entry.tokenizer) || exists?.[entry.tokenizer] === false)@@ -151,13 +178,18 @@ export function downloadH3Component(id: string): Promise<void> {const entry = loadGeneratorTemplateSettings().h3Components!.templates.find((item) => item.id === id);if (!entry) throw new Error("This template was removed.");const devices = await invoke<WeightGpu[]>("weight_download_hardware");- const source = chooseWeightSource(entry.sources, devices ?? []);+ const source = chooseDownloadSource(entry.sources, devices ?? []);const downloads: { source: WeightSource; tokenizer: boolean }[] = [];if (!entry.path || isDownloadUrl(entry.path)) {if (!source) throw new Error("No download source matches this GPU and its memory.");downloads.push({ source, tokenizer: false });}if (entry.tokenizer && isDownloadUrl(entry.tokenizer)) downloads.push({ source: { url: entry.tokenizer, gpuModel: "", minVramGb: 0 }, tokenizer: true });+ if (downloads.length && !await confirmDownloadVram(entry.name, [{ label: entry.name, sources: entry.sources }], devices ?? [])) {+ publish({ ...state!, active: false });+ return;+ }+ if (cancelled) throw new Error("Download cancelled.");publish({ ...state!, files: downloads.length });unlisten = await listen<{ requestId: string; downloaded: number; total: number | null }>("weight-download-progress", ({ payload }) => {if (payload.requestId === requestId && state?.active) publish({ ...state, downloaded: payload.downloaded, total: payload.total });@@ -218,7 +250,7 @@ export function refreshDownloadedWeights(): Promise<void> {return downloadedPath ? { ...remaining, downloadedPath } : remaining;});if (!restored.paths[id].trim() || isDownloadUrl(restored.paths[id])) {- const selected = chooseWeightSource(restored.sources[id]!, devices ?? []);+ const selected = chooseDownloadSource(restored.sources[id]!, devices ?? []);if (selected?.downloadedPath) { restored.paths[id] = selected.downloadedPath; changed = true; }}}@@ -258,12 +290,26 @@ async function runTemplateDownload(templateId: string): Promise<void> {const sources = template.sources?.[id] ?? [];if (!sources.length && required && template.modelType === "minimax-h3" && id !== "transformer") throw new Error(`Choose a ${label} template with a local file or download URL.`);if (!sources.length) return [];- const source = chooseWeightSource(sources, devices ?? []);+ const source = chooseDownloadSource(sources, devices ?? []);if (!source) throw new Error(`No ${ENGINE_PATH_FIELDS.find((field) => field.id === id)?.label} download matches this GPU and its memory.`);return [{ field: id, source, originalPath: template.paths[id], component: h3ComponentForField(template, id, loadGeneratorTemplateSettings().h3Components!) }];});const loraDownloads = downloadableTemplateLoras(effectiveLoras(template.loras, [], template.modelType));const additionalDownloads = (template.additionalSafetensors ?? []).filter((file) => !file.downloadedPath);+ const weights = generatorPathFields(template).map(({ id, label }) => {+ const path = template.paths[id].trim();+ const sources = template.sources?.[id] ?? [];+ // A known local weight still constrains the generator. Unidentified local+ // files have no trustworthy minimum and must not inherit a URL's limit.+ return { label, sources: path && !isDownloadUrl(path)+ ? sources.filter((source) => source.downloadedPath === path) : sources };+ });+ if (downloads.length + loraDownloads.length + additionalDownloads.length+ && !await confirmDownloadVram(template.name, weights, devices ?? [])) {+ publish({ ...state!, active: false });+ return;+ }+ if (cancelled) throw new Error("Download cancelled.");publish({ ...state!, files: downloads.length + loraDownloads.length + additionalDownloads.length });unlisten = await listen<{ requestId: string; downloaded: number; total: number | null }>("weight-download-progress", ({ payload }) => {if (payload.requestId === requestId && state?.active) publish({ ...state, downloaded: payload.downloaded, total: payload.total });