Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Select weight variants for worker hardware

Bittiff0e4f5e8a20
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index a33d8ff..064e5c5 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -31,6 +31,7 @@ This alpha update adds LAN generation workers, Linux support, expanded color gra
## Fixes and improvements
- Updated the bundled SlopFab runtime to API 1.18 for refmod export and support for version-5 refmod bundles.
+- LAN workers select weight downloads using their own GPU type and VRAM, even when a different variant is already downloaded on the client.
- Continue preserves the full joined video and audio from Slopfab. Adjacent source and continuation scenes use that shared decode in preview and export, preserving context across the cut. Regenerate older Continue scenes to apply the fix.
- The timeline playhead follows playback without waiting for editor updates.
- Character sheets give side and back views explicit orientation instructions, keeping reference identity and clothing without copying the front-facing pose.
diff --git a/src-tauri/src/worker/client.rs b/src-tauri/src/worker/client.rs
index 754cf23..ca1bc63 100644
--- a/src-tauri/src/worker/client.rs
+++ b/src-tauri/src/worker/client.rs
@@ -563,7 +563,7 @@ impl Workers {
}
pub(crate) fn plan(&self, connection: &Connection, request: &GenerationRequest, settings: &BTreeMap<String, ProviderSetting>) -> Result<serde_json::Value, String> {
- let (job, sources) = build_job(request, settings)?;
+ let (job, sources) = build_job(request, settings, &connection.info.gpus)?;
let cancel = self.register(&request.job_id, connection)?;
let result = self.send_files(connection, &job, &sources, &cancel)
.and_then(|_| connection.post::<serde_json::Value>("/v1/plan", &job));
@@ -576,9 +576,9 @@ impl Workers {
// Export needs the VAEs only; keep the other weights off the network.
let mut settings = settings.clone();
if let Some(slopfab) = settings.get_mut("slopfab") {
- slopfab.options.retain(|option, _| matches!(option.as_str(), "videoVae" | "audioVae"));
+ slopfab.options.retain(|option, _| matches!(option.as_str(), "videoVae" | "audioVae" | "workerWeightSources"));
}
- let (job, sources) = build_job(request, &settings)?;
+ let (job, sources) = build_job(request, &settings, &connection.info.gpus)?;
let cancel = self.register(&request.job_id, connection)?;
let result = self.send_files(connection, &job, &sources, &cancel).and_then(|_| {
let export = RefmodExport { job, name: name.into(), description: description.into() };
@@ -595,7 +595,7 @@ impl Workers {
/// frames wait in this process's render store like a local render.
pub(crate) fn enqueue(&self, connection: Connection, request: GenerationRequest, settings: &BTreeMap<String, ProviderSetting>) -> Result<(), String> {
crate::media::artifacts::generated_file_stem(&request.job_id)?;
- let (job, sources) = build_job(&request, settings)?;
+ let (job, sources) = build_job(&request, settings, &connection.info.gpus)?;
let cancel = self.register(&request.job_id, &connection)?;
let workers = self.clone();
let latents = request.save_latents_path.clone();
@@ -851,10 +851,11 @@ fn file_ref(kind: PathKind, value: &str, sources: &mut HashMap<String, PathBuf>)
}
/// Replaces every path of a resolved local request with a token for the worker.
-pub(crate) fn build_job(request: &GenerationRequest, settings: &BTreeMap<String, ProviderSetting>) -> Result<(RemoteJob, HashMap<String, PathBuf>), String> {
+pub(crate) fn build_job(request: &GenerationRequest, settings: &BTreeMap<String, ProviderSetting>, gpus: &[GpuDevice]) -> Result<(RemoteJob, HashMap<String, PathBuf>), String> {
let mut request = request.clone();
let mut settings: BTreeMap<String, ProviderSetting> = settings.iter()
.filter(|(name, _)| name.as_str() == "slopfab").map(|(name, value)| (name.clone(), value.clone())).collect();
+ super::variants::select(&mut settings, gpus)?;
let mut files = Vec::new();
let mut indices: HashMap<String, usize> = HashMap::new();
let mut sources = HashMap::new();
@@ -921,7 +922,7 @@ mod tests {
continuation_source_frames: Some(85),
..Default::default()
};
- let (job, sources) = build_job(&request, &settings).unwrap();
+ let (job, sources) = build_job(&request, &settings, &[]).unwrap();
assert!(!job.settings.contains_key("openrouter"), "credentials never leave this computer");
assert_eq!(job.files.len(), 3, "a repeated path is sent once");
assert_eq!(job.files[0], FileRef::Url { url: "https://example.com/t.safetensors".into(), lora: false });
@@ -934,7 +935,7 @@ mod tests {
assert_eq!(wire["request"]["continuationOverlapFrames"], 39);
assert_eq!(wire["request"]["continuationSourceFrames"], 85);
assert_eq!(sources.len(), 2);
- assert!(build_job(&GenerationRequest { reference_paths: vec![folder.path().join("missing.png").to_string_lossy().into_owned()], ..Default::default() }, &BTreeMap::new()).is_err());
+ assert!(build_job(&GenerationRequest { reference_paths: vec![folder.path().join("missing.png").to_string_lossy().into_owned()], ..Default::default() }, &BTreeMap::new(), &[]).is_err());
}
#[test]
@@ -1062,7 +1063,7 @@ mod tests {
reference_paths: vec![reference.to_string_lossy().into_owned()],
..Default::default()
};
- let (job, _) = build_job(&request, &settings).unwrap();
+ let (job, _) = build_job(&request, &settings, &connection.info.gpus).unwrap();
assert!(job.files.iter().filter(|file| matches!(file, FileRef::Url { .. })).count() == 4, "downloads are sent as URLs");
let plan = workers.plan(&connection, &request, &settings).unwrap();
eprintln!("plan: {plan}");
diff --git a/src-tauri/src/worker/mod.rs b/src-tauri/src/worker/mod.rs
index ef518f4..86f48df 100644
--- a/src-tauri/src/worker/mod.rs
+++ b/src-tauri/src/worker/mod.rs
@@ -1,5 +1,6 @@
//! The desktop side of LAN workers. The protocol and the worker itself are in
//! slopus-core, which `slopus-worker` uses without any UI framework.
mod client;
+mod variants;
pub use client::{WorkerList, Workers};
diff --git a/src-tauri/src/worker/variants.rs b/src-tauri/src/worker/variants.rs
new file mode 100644
index 0000000..a4bcb0d
--- /dev/null
+++ b/src-tauri/src/worker/variants.rs
@@ -0,0 +1,224 @@
+//! Resolve template download variants using the actual destination worker.
+use crate::{
+ project::{ProviderOption, ProviderSetting},
+ slopfab::GpuDevice,
+};
+use serde::Deserialize;
+use std::{collections::BTreeMap, path::Path};
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+struct Variant {
+ url: String,
+ gpu_model: String,
+ min_vram_gb: f64,
+}
+
+pub(super) fn select(
+ settings: &mut BTreeMap<String, ProviderSetting>,
+ gpus: &[GpuDevice],
+) -> Result<(), String> {
+ let Some(engine) = settings.get_mut("slopfab") else {
+ return Ok(());
+ };
+ let Some(metadata) = engine.options.remove("workerWeightSources") else {
+ return Ok(());
+ };
+ let ProviderOption::String(metadata) = metadata else {
+ return Err("Invalid worker weight variants.".into());
+ };
+ let variants: BTreeMap<String, Vec<Variant>> = serde_json::from_str(&metadata)
+ .map_err(|e| format!("Invalid worker weight variants: {e}"))?;
+ for role in [
+ "transformer",
+ "textEncoder",
+ "videoVae",
+ "audioVae",
+ "tokenizer",
+ ] {
+ let Some(entries) = variants.get(role).filter(|entries| !entries.is_empty()) else {
+ continue;
+ };
+ let Some(ProviderOption::String(value)) = engine.options.get(role) else {
+ continue;
+ };
+ if !value.trim().is_empty()
+ && !value.to_ascii_lowercase().starts_with("https://")
+ && !value.to_ascii_lowercase().starts_with("http://")
+ {
+ // A manually located file remains an explicit choice. A client
+ // download, however, must be reconsidered for this worker.
+ let original = slopus_core::weights::recorded_download_url(Path::new(value));
+ if !original.is_some_and(|url| {
+ entries.iter().any(|entry| {
+ slopus_core::weights::download_url(&entry.url)
+ .is_ok_and(|candidate| candidate.as_str() == url)
+ })
+ }) {
+ continue;
+ }
+ }
+ let mut best: Option<&Variant> = None;
+ for entry in entries {
+ if !entry.min_vram_gb.is_finite() || entry.min_vram_gb < 0.0 {
+ return Err(format!("Invalid {role} weight VRAM requirement."));
+ }
+ let model = entry.gpu_model.trim().to_lowercase();
+ let compatible = model.is_empty() && entry.min_vram_gb == 0.0
+ || gpus.iter().any(|gpu| {
+ gpu.name.to_lowercase().contains(&model)
+ && (gpu.memory_bytes as f64 / 1024f64.powi(3)).ceil() >= entry.min_vram_gb
+ });
+ if compatible
+ && best.is_none_or(|current| {
+ (!model.is_empty(), entry.min_vram_gb)
+ > (!current.gpu_model.trim().is_empty(), current.min_vram_gb)
+ })
+ {
+ best = Some(entry);
+ }
+ }
+ let selected = best.ok_or_else(||format!("No {role} download variant matches the worker's GPU and VRAM. Add a compatible source in Generator settings."))?;
+ let url = slopus_core::weights::download_url(&selected.url)?;
+ engine
+ .options
+ .insert(role.into(), ProviderOption::String(url.to_string()));
+ }
+ Ok(())
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::slopfab::GenerationRequest;
+ use crate::worker::client::build_job;
+ use serde_json::json;
+ use slopus_core::worker::protocol::FileRef;
+
+ fn settings(path: &str) -> BTreeMap<String, ProviderSetting> {
+ BTreeMap::from([("slopfab".into(),ProviderSetting { enabled:true,model:None,options:BTreeMap::from([
+ ("transformer".into(),ProviderOption::String(path.into())),
+ ("workerWeightSources".into(),ProviderOption::String(json!({"transformer":[
+ {"url":"https://example.com/small.safetensors","gpuModel":"","minVramGb":0},
+ {"url":"https://example.com/large.safetensors","gpuModel":"","minVramGb":24},
+ {"url":"https://example.com/5090.safetensors","gpuModel":"RTX 5090","minVramGb":32}
+ ]}).to_string()))
+ ]) })])
+ }
+
+ #[test]
+ fn remote_jobs_reselect_urls_using_destination_gpu_and_vram() {
+ for (name, gb, expected) in [
+ ("RTX 3060", 12.0, "small"),
+ ("RTX 4090", 24.0, "large"),
+ ("NVIDIA GeForce RTX 5090", 31.4, "5090"),
+ ("AMD Radeon", 32.0, "large"),
+ ] {
+ // The UI/client previously chose an entirely different GPU's file.
+ let settings = settings("https://example.com/5090.safetensors");
+ let devices = [GpuDevice {
+ name: name.into(),
+ memory_bytes: (gb * 1024f64.powi(3)) as u64,
+ }];
+ let (job, uploads) =
+ build_job(&GenerationRequest::default(), &settings, &devices).unwrap();
+ assert_eq!(
+ job.files,
+ vec![FileRef::Url {
+ url: format!("https://example.com/{expected}.safetensors"),
+ lora: false
+ }]
+ );
+ assert!(uploads.is_empty());
+ assert!(!job.settings["slopfab"]
+ .options
+ .contains_key("workerWeightSources"));
+ assert_eq!(
+ settings["slopfab"].options["transformer"],
+ ProviderOption::String("https://example.com/5090.safetensors".into())
+ );
+ }
+ let (job, _) = build_job(
+ &GenerationRequest::default(),
+ &settings("https://example.com/large.safetensors"),
+ &[],
+ )
+ .unwrap();
+ assert_eq!(
+ job.files,
+ vec![FileRef::Url {
+ url: "https://example.com/small.safetensors".into(),
+ lora: false
+ }]
+ );
+ }
+
+ #[test]
+ fn client_download_records_do_not_pin_worker_variants_but_custom_files_still_upload() {
+ let folder = tempfile::tempdir().unwrap();
+ let url =
+ slopus_core::weights::download_url("https://example.com/large.safetensors").unwrap();
+ let path = folder
+ .path()
+ .join(slopus_core::weights::destination_name(&url));
+ std::fs::write(&path, b"data").unwrap();
+ std::fs::write(
+ path.with_extension("complete.json"),
+ json!({"url":url.as_str(),"bytes":4}).to_string(),
+ )
+ .unwrap();
+ let (job, uploads) = build_job(
+ &GenerationRequest::default(),
+ &settings(&path.to_string_lossy()),
+ &[],
+ )
+ .unwrap();
+ assert_eq!(
+ job.files,
+ vec![FileRef::Url {
+ url: "https://example.com/small.safetensors".into(),
+ lora: false
+ }]
+ );
+ assert!(uploads.is_empty());
+ let custom = folder.path().join("custom.safetensors");
+ std::fs::write(&custom, b"custom").unwrap();
+ let (job, uploads) = build_job(
+ &GenerationRequest::default(),
+ &settings(&custom.to_string_lossy()),
+ &[],
+ )
+ .unwrap();
+ assert!(matches!(&job.files[0],FileRef::Upload {name,..} if name=="custom.safetensors"));
+ assert_eq!(uploads.len(), 1);
+ }
+
+ #[test]
+ fn no_matching_variant_fails_instead_of_using_the_client_choice() {
+ let mut settings = settings("https://example.com/large.safetensors");
+ settings.get_mut("slopfab").unwrap().options.insert(
+ "workerWeightSources".into(),
+ ProviderOption::String(
+ json!({"transformer":[
+ {"url":"https://example.com/large.safetensors","gpuModel":"","minVramGb":24}
+ ]})
+ .to_string(),
+ ),
+ );
+ let devices = [
+ GpuDevice {
+ name: "GPU A".into(),
+ memory_bytes: 12 * 1024u64.pow(3),
+ },
+ GpuDevice {
+ name: "GPU B".into(),
+ memory_bytes: 12 * 1024u64.pow(3),
+ },
+ ];
+ assert!(
+ build_job(&GenerationRequest::default(), &settings, &devices)
+ .unwrap_err()
+ .contains("worker's GPU and VRAM")
+ );
+ }
+}
diff --git a/src/lib/settings.ts b/src/lib/settings.ts
index 7c8fc65..69e118a 100644
--- a/src/lib/settings.ts
+++ b/src/lib/settings.ts
@@ -138,11 +138,15 @@ export function templateUsable(template: GeneratorTemplate): boolean {
}
}
-/** The weight a LAN worker should use: a local file is sent (or, if it was
- * downloaded, its URL is), otherwise the download variant for its GPU. */
+/** Downloaded client weights do not pin a worker to the client's GPU variant.
+ * Explicit local files without a matching download entry remain uploads. */
function workerWeight(value: string, sources: WeightSource[] | undefined): string {
- if (value && !isDownloadUrl(value)) return value;
- return chooseWeightSource(sources ?? [], selectedWorker()?.gpus ?? [])?.url ?? value;
+ const pathKey = (path: string) => { const normalized = path.replaceAll("\\", "/").replace(/^\/\/\?\//, ""); return /^[a-z]:\//i.test(normalized) ? normalized.toLowerCase() : normalized; };
+ const downloaded = sources?.some((source) => source.downloadedPath && pathKey(source.downloadedPath) === pathKey(value));
+ if (value && !isDownloadUrl(value) && !downloaded) return value;
+ // The native job builder makes the authoritative choice from the connected
+ // worker's info; its GPU may differ from this UI's last discovery snapshot.
+ return chooseWeightSource(sources ?? [], selectedWorker()?.gpus ?? [])?.url ?? sources?.[0]?.url ?? value;
}
export function templateNeedsDownload(template: GeneratorTemplate): boolean {
@@ -518,6 +522,12 @@ export function engineProviderSetting(settings: EngineSettings, base?: ProviderS
delete options.generationMode;
delete options.promptEmbedding;
delete options.motionCache;
+ delete options.workerWeightSources;
+ if (remote && sources) {
+ options.workerWeightSources = JSON.stringify(Object.fromEntries(Object.entries(sources)
+ .filter(([role, entries]) => entries?.length && !(mode === "animate" && (role === "textEncoder" || role === "tokenizer")))
+ .map(([role, entries]) => [role, entries!.map(({ url, gpuModel, minVramGb }) => ({ url, gpuModel, minVramGb }))])));
+ }
if (motionCache && mode !== "animate") options.motionCache = true;
if (mode === "animate") options.generationMode = "animate";
if (mode === "animate") {
diff --git a/src/lib/workers.test.ts b/src/lib/workers.test.ts
index 14399e5..90f4292 100644
--- a/src/lib/workers.test.ts
+++ b/src/lib/workers.test.ts
@@ -84,6 +84,40 @@ describe("LAN generation workers", () => {
expect(options).not.toHaveProperty("motionCache");
});
+ it.each([12, 32])("selects worker variants with %s GB even when another variant is downloaded locally", async (vram) => {
+ const template = downloadable();
+ template.paths.transformer = "D:\\Models\\client.safetensors";
+ template.sources!.transformer![1].downloadedPath = "d:/models/client.safetensors";
+ const original = structuredClone(template);
+ await choose({ selectedId: "aaaaaaaaaaaaaaaa", workers: [worker({ gpus: [{name:"RTX 4090",memoryBytes:vram * 1024 ** 3}] })] });
+ const options = engineProviderSetting(template.paths, undefined, "sage2", [], "prompt", [], false, template.sources).options;
+ expect(options.transformer).toBe(`https://example.com/${vram === 12 ? "small" : "large"}.safetensors`);
+ expect(JSON.parse(options.workerWeightSources as string).transformer).toHaveLength(2);
+ expect(options.workerWeightSources).not.toContain("downloadedPath");
+ expect(options.workerWeightSources).not.toContain("client.safetensors");
+ expect(template).toEqual(original);
+ // Local generation keeps the locally chosen file, with no stale worker metadata.
+ await choose({ selectedId: null, workers: [] });
+ const local = engineProviderSetting(template.paths, {enabled:true,model:null,options}, "sage2", [], "prompt", [], false, template.sources).options;
+ expect(local.transformer).toBe(template.paths.transformer);
+ expect(local).not.toHaveProperty("workerWeightSources");
+ });
+
+ it("keeps explicit custom files while passing variants for native worker validation", async () => {
+ const template = downloadable();
+ template.paths.transformer = "D:/custom/model.safetensors";
+ await choose({ selectedId: "aaaaaaaaaaaaaaaa", workers: [worker()] });
+ const options = engineProviderSetting(template.paths, undefined, "sage2", [], "prompt", [], false, template.sources).options;
+ expect(options.transformer).toBe(template.paths.transformer);
+ expect(options.workerWeightSources).toBeDefined();
+ });
+
+ it("does not reuse one worker's hardware when switching to an unknown worker", async () => {
+ await choose({ selectedId: "aaaaaaaaaaaaaaaa", workers: [worker()] });
+ await choose({ selectedId: "bbbbbbbbbbbbbbbb", workers: [] });
+ expect(selectedWorker()).toEqual({ id: "bbbbbbbbbbbbbbbb", name: "Worker", gpus: [] });
+ });
+
it("still needs a source for every required model on a worker", async () => {
await choose({ selectedId: "aaaaaaaaaaaaaaaa", workers: [worker()] });
const template = downloadable();
diff --git a/src/lib/workers.ts b/src/lib/workers.ts
index a953a85..0dcc6b7 100644
--- a/src/lib/workers.ts
+++ b/src/lib/workers.ts
@@ -63,9 +63,10 @@ export const remoteWorkerSelected = (): boolean => selectedWorker() !== null;
function mirror(list: WorkerList) {
const previous = selectedWorker();
+ const remembered = previous?.id === list.selectedId ? previous : null;
const worker = list.workers.find((item) => item.id === list.selectedId);
const next: SelectedWorker | null = list.selectedId
- ? { id: list.selectedId, name: worker?.name ?? previous?.name ?? "Worker", gpus: worker?.online ? worker.gpus : previous?.gpus ?? [] }
+ ? { id: list.selectedId, name: worker?.name ?? remembered?.name ?? "Worker", gpus: worker?.online ? worker.gpus : remembered?.gpus ?? [] }
: null;
if (JSON.stringify(next) === JSON.stringify(previous)) return;
try {