Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Add generator backend and attention settings

Bittia4582542e2eb
diff --git a/src-tauri/src/slopfab.rs b/src-tauri/src/slopfab.rs
index 6ec5a22..4ddd039 100644
--- a/src-tauri/src/slopfab.rs
+++ b/src-tauri/src/slopfab.rs
@@ -32,8 +32,6 @@ pub fn default_dll_path() -> PathBuf {
const EXPECTED_CAPI_MAJOR: u32 = 1;
const NOT_READY: i32 = -7;
const CANCELLED: i32 = -8;
-const CUDA_ATTENTION: &str = "sage2";
-const VULKAN_ATTENTION: &str = "exact";
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum ComputePlatform {
@@ -57,13 +55,6 @@ impl ComputePlatform {
Self::Vulkan => 1,
}
}
-
- fn attention(self) -> &'static str {
- match self {
- Self::Cuda13 | Self::Cuda12 => CUDA_ATTENTION,
- Self::Vulkan => VULKAN_ATTENTION,
- }
- }
}
fn platform_from_cuda_probe(result: Result<i32, String>) -> ComputePlatform {
@@ -75,6 +66,11 @@ fn platform_from_cuda_probe(result: Result<i32, String>) -> ComputePlatform {
}
fn detect_platform(api: &ffi::Api) -> ComputePlatform {
+ // A toolkit can be installed on an AMD/Intel machine. Check for a usable
+ // NVIDIA device before treating the cuBLAS installation as CUDA support.
+ if !ffi::has_cuda_device() {
+ return ComputePlatform::Vulkan;
+ }
// Explicit "auto" makes Slopus's order deterministic even if the host
// process carries SLOPFAB_CUDA_VERSION. If this DLL instance was already
// initialized, the setter is expected to refuse the change and the loaded
@@ -90,6 +86,7 @@ pub struct SlopfabStatus {
pub dll_path: String,
pub version: Option<String>,
pub platform: Option<&'static str>,
+ pub cuda_available: bool,
pub detail: String,
pub models: Vec<ModelStatus>,
}
@@ -394,12 +391,20 @@ struct QueueItem {
#[derive(Clone)]
struct Configuration {
dll_path: PathBuf,
+ vulkan: bool,
+ attention: &'static str,
models: [(i32, &'static str, Option<PathBuf>); 5],
}
impl Configuration {
fn from_settings(settings: &BTreeMap<String, ProviderSetting>) -> Self {
let slopfab = settings.get("slopfab");
+ let string_option = |name: &str| {
+ slopfab.and_then(|setting| match setting.options.get(name) {
+ Some(ProviderOption::String(value)) => Some(value.as_str()),
+ _ => None,
+ })
+ };
let option = |name: &str| {
slopfab.and_then(|setting| match setting.options.get(name) {
Some(ProviderOption::String(value)) if !value.trim().is_empty() => {
@@ -413,6 +418,12 @@ impl Configuration {
// It is still READ so a project or a test that carries one keeps
// working; with none, use the DLL beside the executable.
dll_path: option("dllPath").unwrap_or_else(default_dll_path),
+ vulkan: string_option("inferenceBackend") == Some("vulkan"),
+ attention: match string_option("attention") {
+ Some("exact") => "exact",
+ Some("flash2") => "flash2",
+ _ => "sage2",
+ },
models: [
(0, "transformer", option("transformer")),
(1, "textEncoder", option("textEncoder")),
@@ -423,6 +434,14 @@ impl Configuration {
}
}
+ fn platform(&self, detected: ComputePlatform) -> ComputePlatform {
+ if self.vulkan {
+ ComputePlatform::Vulkan
+ } else {
+ detected
+ }
+ }
+
fn timing_profile(&self, version: &str, platform: ComputePlatform) -> String {
let models = self
.models
@@ -438,7 +457,7 @@ impl Configuration {
})
.collect::<Vec<_>>()
.join(";");
- format!("slopfab={version}|platform={}|{models}", platform.label())
+ format!("slopfab={version}|platform={}|attention={}|{models}", platform.label(), self.attention)
}
}
@@ -460,7 +479,8 @@ pub fn status(settings: &BTreeMap<String, ProviderSetting>) -> SlopfabStatus {
match ffi::Api::load(&configuration.dll_path) {
Ok(api) => match api.version() {
Ok(version) => {
- let platform = detect_platform(&api);
+ let detected = detect_platform(&api);
+ let platform = configuration.platform(detected);
let missing = models
.iter()
.filter(|model| !model.available && model.id != "tokenizer")
@@ -474,6 +494,7 @@ pub fn status(settings: &BTreeMap<String, ProviderSetting>) -> SlopfabStatus {
dll_path,
version: Some(version),
platform: Some(platform.label()),
+ cuda_available: detected != ComputePlatform::Vulkan,
detail: if missing == 0 {
"Runtime and required model paths are available.".into()
} else {
@@ -487,6 +508,7 @@ pub fn status(settings: &BTreeMap<String, ProviderSetting>) -> SlopfabStatus {
dll_path,
version: None,
platform: None,
+ cuda_available: false,
detail: error,
models,
},
@@ -496,6 +518,7 @@ pub fn status(settings: &BTreeMap<String, ProviderSetting>) -> SlopfabStatus {
dll_path,
version: None,
platform: None,
+ cuda_available: false,
detail: format!("slopfab is unavailable: {error}. Editing remains available."),
models,
},
@@ -510,7 +533,7 @@ pub fn resolve_plan(
let configuration = Configuration::from_settings(settings);
let api = ffi::Api::load(&configuration.dll_path)?;
api.version()?;
- let platform = detect_platform(&api);
+ let platform = configuration.platform(detect_platform(&api));
let handle = RequestHandle::new(&api)?;
configure_request(&api, handle.0, request, &configuration, platform, false)?;
let plan = api.resolve(handle.0)?;
@@ -571,7 +594,7 @@ fn configure_request(
api.set_seed(handle, generation_seed(request.seed)?)?;
api.set_resolution(handle, request.canvas_width, request.canvas_height)?;
api.set_inference_backend(handle, platform.backend())?;
- api.set_attention(handle, platform.attention())?;
+ api.set_attention(handle, configuration.attention)?;
api.set_verbose(handle, false)?;
if include_models {
api.set_reuse_models(handle, true)?;
@@ -619,7 +642,7 @@ fn run_generation(item: &QueueItem) -> Result<(OutputMetadata, rendered::Rendere
}
let api = ffi::Api::load(&item.configuration.dll_path)?;
let version = api.version()?;
- let platform = detect_platform(&api);
+ let platform = item.configuration.platform(detect_platform(&api));
let timing_profile = item.configuration.timing_profile(&version, platform);
diagnostics::debug(
"slopfab",
@@ -866,6 +889,8 @@ pub fn generate_reference_icon_batch(
};
let configuration = Configuration {
dll_path: batch.dll_path.clone(),
+ vulkan: backend == ComputePlatform::Vulkan,
+ attention: "sage2",
models: [
(0, "transformer", Some(batch.transformer.clone())),
(1, "textEncoder", Some(batch.text_encoder.clone())),
@@ -974,6 +999,24 @@ mod ffi {
};
pub enum Request {}
+
+ pub fn has_cuda_device() -> bool {
+ // CUDA's driver API uses the system calling convention on Windows.
+ // Keep the library alive until both calls have returned.
+ unsafe {
+ #[cfg(windows)]
+ let driver = libloading::os::windows::Library::load_with_flags(
+ "nvcuda.dll", 0x00000800, // LOAD_LIBRARY_SEARCH_SYSTEM32
+ ).map(Library::from);
+ #[cfg(not(windows))]
+ let driver = Library::new("libcuda.so.1");
+ let Ok(library) = driver else { return false };
+ let Ok(init) = library.get::<unsafe extern "system" fn(u32) -> i32>(b"cuInit\0") else { return false };
+ let Ok(count) = library.get::<unsafe extern "system" fn(*mut i32) -> i32>(b"cuDeviceGetCount\0") else { return false };
+ let mut devices = 0;
+ init(0) == 0 && count(&mut devices) == 0 && devices > 0
+ }
+ }
pub enum Generation {}
#[repr(C)]
#[derive(Clone, Copy)]
@@ -1451,7 +1494,36 @@ mod tests {
);
assert_eq!(ComputePlatform::Cuda13.backend(), 0);
assert_eq!(ComputePlatform::Vulkan.backend(), 1);
- assert_eq!(ComputePlatform::Vulkan.attention(), "exact");
+ }
+
+ #[test]
+ fn backend_preference_cannot_enable_cuda_without_cuda_hardware() {
+ let mut config = Configuration::from_settings(&BTreeMap::new());
+ assert_eq!(config.platform(ComputePlatform::Cuda13), ComputePlatform::Cuda13);
+ assert_eq!(config.platform(ComputePlatform::Cuda12), ComputePlatform::Cuda12);
+ assert_eq!(config.platform(ComputePlatform::Vulkan), ComputePlatform::Vulkan);
+ config.vulkan = true;
+ for detected in [ComputePlatform::Cuda13, ComputePlatform::Cuda12, ComputePlatform::Vulkan] {
+ assert_eq!(config.platform(detected), ComputePlatform::Vulkan);
+ }
+ }
+
+ #[test]
+ fn attention_defaults_to_sage_and_is_independent_of_backend() {
+ assert_eq!(Configuration::from_settings(&BTreeMap::new()).attention, "sage2");
+ for backend in ["cuda", "vulkan"] {
+ for attention in ["exact", "flash2", "sage2", "invalid"] {
+ let settings = serde_json::from_value(serde_json::json!({
+ "slopfab": { "enabled": true, "model": null,
+ "options": { "inferenceBackend": backend, "attention": attention } }
+ })).unwrap();
+ let config = Configuration::from_settings(&settings);
+ let expected = if attention == "invalid" { "sage2" } else { attention };
+ assert_eq!(config.attention, expected);
+ assert_eq!(config.vulkan, backend == "vulkan");
+ assert!(config.timing_profile("1.4.0", ComputePlatform::Vulkan).contains(&format!("attention={expected}|")));
+ }
+ }
}
#[test]
@@ -1488,6 +1560,25 @@ mod tests {
assert_eq!(plan.latent_frames, 1);
assert_eq!((plan.canvas_width, plan.canvas_height), (768, 768));
}
+
+ #[test]
+ fn bundled_dll_accepts_all_attention_modes_on_both_backends() {
+ if !default_dll_path().is_file() { return; }
+ let api = ffi::Api::load(&default_dll_path()).unwrap();
+ let request: GenerationRequest = serde_json::from_value(serde_json::json!({
+ "jobId": "attention-plan", "prompt": "A red toy car", "frames": 1, "stillImage": true,
+ "steps": 20, "seed": 1, "canvasWidth": 768, "canvasHeight": 768
+ })).unwrap();
+ let mut config = Configuration::from_settings(&BTreeMap::new());
+ for platform in [ComputePlatform::Cuda13, ComputePlatform::Vulkan] {
+ for attention in ["exact", "flash2", "sage2"] {
+ config.attention = attention;
+ let handle = RequestHandle::new(&api).unwrap();
+ configure_request(&api, handle.0, &request, &config, platform, false).unwrap();
+ assert_eq!(api.resolve(handle.0).unwrap().aligned_frames, 1);
+ }
+ }
+ }
#[test]
fn generation_seed_accepts_random_and_non_negative_values() {
assert!(generation_seed(-1).is_ok());
diff --git a/src/WorkQueue.integration.test.tsx b/src/WorkQueue.integration.test.tsx
index 9004059..77f37b5 100644
--- a/src/WorkQueue.integration.test.tsx
+++ b/src/WorkQueue.integration.test.tsx
@@ -46,7 +46,7 @@ it("keeps icon confirmation available after returning to the library", async ()
expect(screen.queryByRole("alertdialog", { name: "Generate reference icons?" })).toBeNull();
});
-it("cancels automatic generation and exposes the remembered choice in Video engine settings", async () => {
+it("cancels automatic generation and exposes the remembered choice in Generator settings", async () => {
const config = createProjectConfig({ name: "Cancel icons", prompt: "A quiet scene", aspectRatio: "16:9", resolution: "416p", targetDurationSeconds: 30 });
config.references = [{ id: "hero", kind: "text", name: "Hero", description: "A friendly explorer", intendedUse: ["character"], createdAt: "2026-09-08T00:00:00.000Z" }];
vi.mocked(listRecentProjects).mockResolvedValue({ projects: [{ folderPath: "C:/Cancel icons", config }], unreadable: [] });
diff --git a/src/components/ReferenceIconGenerationDialog.tsx b/src/components/ReferenceIconGenerationDialog.tsx
index 8fd09f0..04ce386 100644
--- a/src/components/ReferenceIconGenerationDialog.tsx
+++ b/src/components/ReferenceIconGenerationDialog.tsx
@@ -47,7 +47,7 @@ export function ReferenceIconGenerationDialog({ count, onAnswer }: {
</div>
<div className="exit-guard__body" id="reference-icon-generation-description">
<p>{count} {count === 1 ? "reference needs an icon" : "references need icons"}. Generate them now using the video engine? This uses your GPU; waiting videos take priority.</p>
- <p>Cancel skips this batch. You can change automatic generation in Settings → Video engine.</p>
+ <p>Cancel skips this batch. You can change automatic generation in Settings → Generator.</p>
</div>
<label className="reference-icon-option">
<input type="checkbox" checked={remember} onChange={(event) => setRemember(event.target.checked)} />
diff --git a/src/components/SettingsView.test.tsx b/src/components/SettingsView.test.tsx
index 3805a62..4d3c205 100644
--- a/src/components/SettingsView.test.tsx
+++ b/src/components/SettingsView.test.tsx
@@ -36,6 +36,60 @@ describe("the frame the tabs sit in", () => {
});
describe("the settings screen", () => {
+ it("defaults to Sage and remembers each generator's attention", () => {
+ const view = open();
+ editDefaultGenerator();
+ expect((screen.getByLabelText("Generator attention") as HTMLSelectElement).value).toBe("sage2");
+ expect(within(screen.getByLabelText("Generator attention")).getAllByRole("option").map((option) => option.textContent)).toEqual(["Exact attention", "Flash attention", "Sage attention"]);
+ fireEvent.change(screen.getByLabelText("Generator attention"), { target: { value: "flash2" } });
+ fireEvent.click(screen.getByRole("button", { name: "Generators" }));
+ fireEvent.click(screen.getByRole("button", { name: "New generator" }));
+ expect((screen.getByLabelText("Generator attention") as HTMLSelectElement).value).toBe("sage2");
+ view.unmount();
+ open();
+ editDefaultGenerator();
+ expect((screen.getByLabelText("Generator attention") as HTMLSelectElement).value).toBe("flash2");
+ });
+
+ it("switches NVIDIA between CUDA and Vulkan and keeps both choices after switching", async () => {
+ Object.defineProperty(window, "__TAURI_INTERNALS__", { configurable: true, value: {} });
+ vi.mocked(invoke).mockImplementation(async (command, args) => command === "slopfab_status" ? {
+ state: "ready", dllPath: "slopfab.dll", version: "1.4.0", cudaAvailable: true,
+ platform: (args as { settings: { slopfab: { options: { inferenceBackend: string } } } }).settings.slopfab.options.inferenceBackend === "vulkan" ? "Vulkan" : "CUDA 13",
+ detail: "Ready.", models: [],
+ } : null);
+ const view = open();
+ fireEvent.click(tab("Diagnostics"));
+ const backend = () => screen.getByLabelText("GPU backend") as HTMLSelectElement;
+ await waitFor(() => expect(backend().disabled).toBe(false));
+ expect(backend().value).toBe("cuda");
+ fireEvent.change(backend(), { target: { value: "vulkan" } });
+ await waitFor(() => expect(backend().disabled).toBe(false));
+ expect(backend().value).toBe("vulkan");
+ expect(within(backend()).getAllByRole("option")).toHaveLength(2);
+ view.unmount();
+ open();
+ fireEvent.click(tab("Diagnostics"));
+ await waitFor(() => expect(backend().disabled).toBe(false));
+ expect(backend().value).toBe("vulkan");
+ fireEvent.change(backend(), { target: { value: "cuda" } });
+ await waitFor(() => expect(backend().value).toBe("cuda"));
+ expect(localStorage.getItem("slopus.inference-backend.v1")).toBe("cuda");
+ });
+
+ it("locks machines without CUDA hardware to Vulkan despite a saved CUDA preference", async () => {
+ Object.defineProperty(window, "__TAURI_INTERNALS__", { configurable: true, value: {} });
+ localStorage.setItem("slopus.inference-backend.v1", "cuda");
+ vi.mocked(invoke).mockResolvedValue({ state: "ready", dllPath: "slopfab.dll", version: "1.4.0", platform: "Vulkan", cudaAvailable: false, detail: "Ready.", models: [] });
+ open();
+ fireEvent.click(tab("Diagnostics"));
+ await screen.findByText(/AMD and Intel GPUs use Vulkan/);
+ const backend = screen.getByLabelText("GPU backend") as HTMLSelectElement;
+ expect(backend.disabled).toBe(true);
+ expect(backend.value).toBe("vulkan");
+ expect(within(backend).getAllByRole("option")).toHaveLength(1);
+ });
+
it("remembers automatic reference icon generation and confirmation preferences", () => {
const view = open();
const automatic = () => screen.getByRole("checkbox", { name: "Automatic reference icon generation" }) as HTMLInputElement;
@@ -71,7 +125,7 @@ describe("the settings screen", () => {
it("opens on the engine, because that is what has to be set before anything renders", async () => {
open();
- expect(tab("Video engine").getAttribute("aria-selected")).toBe("true");
+ expect(tab("Generator").getAttribute("aria-selected")).toBe("true");
expect(screen.getByRole("heading", { name: "Generators" })).toBeTruthy();
expect(screen.queryByLabelText(/Transformer weights/)).toBeNull();
editDefaultGenerator();
@@ -101,7 +155,7 @@ describe("the settings screen", () => {
it("swaps panels when a tab is chosen, and follows the arrow keys", () => {
open();
expect(screen.getAllByRole("tab").map((item) => item.textContent?.replace(/\d+$/, ""))).toEqual([
- "Video engine", "Agents", "Appearance", "Diagnostics", "Updates",
+ "Generator", "Agents", "Appearance", "Diagnostics", "Updates",
]);
fireEvent.click(tab("Appearance"));
expect(screen.getByRole("radiogroup", { name: "Appearance" })).toBeTruthy();
@@ -119,11 +173,11 @@ describe("the settings screen", () => {
it("counts the paths still to set on the engine tab, from either tab", () => {
open();
// Four of the five fields are required and none is set yet.
- expect(within(tab("Video engine")).getByText("4")).toBeTruthy();
+ expect(within(tab("Generator")).getByText("4")).toBeTruthy();
fireEvent.click(tab("Appearance"));
// Still legible from the other side: what is unfinished is the reason the
// screen was opened, and hiding it behind a tab would bury it.
- expect(within(tab("Video engine")).getByText("4")).toBeTruthy();
+ expect(within(tab("Generator")).getByText("4")).toBeTruthy();
});
it("keeps the settings header short", () => {
diff --git a/src/components/SettingsView.tsx b/src/components/SettingsView.tsx
index 1032977..a6be5fb 100644
--- a/src/components/SettingsView.tsx
+++ b/src/components/SettingsView.tsx
@@ -1,5 +1,5 @@
import { AlertCircle, Check, ChevronLeft, FileText, FolderOpen, FolderSearch, LoaderCircle, Monitor, Moon, Plus, RefreshCw, RotateCcw, Sun, Trash2, X } from "lucide-react";
-import { useCallback, useEffect, useState, useSyncExternalStore, type ReactNode } from "react";
+import { useCallback, useEffect, useRef, useState, useSyncExternalStore, type ReactNode } from "react";
import { getDiagnosticLogInfo, revealDiagnosticLog, type DiagnosticLogInfo } from "../lib/diagnostics";
import { isTauri } from "../lib/persistence";
import { chooseEnginePath, getAgentModels, getEngineStatus, type ModelStatus, type SlopfabStatus } from "../lib/runtime";
@@ -9,6 +9,7 @@ import {
isEndpointProviderConfigured, loadAgentEndpointSettings,
loadGeneratorTemplateSettings, saveAgentEndpointSettings, saveGeneratorTemplateSettings,
loadDebugOptionsEnabled, saveDebugOptionsEnabled, subscribeDebugOptions,
+ loadInferenceBackend, saveInferenceBackend, type AttentionMode, type InferenceBackend,
type AgentEndpointSettings, type EndpointProviderId, type EndpointProviderSettings,
type EnginePathField, type EnginePathId, type EngineSettings, type GeneratorTemplateSettings,
} from "../lib/settings";
@@ -192,7 +193,9 @@ function PromptLlmSetting({ desktop }: { desktop: boolean }) {
</div>;
}
-function DiagnosticsSetting({ desktop }: { desktop: boolean }) {
+function DiagnosticsSetting({ desktop, status, onBackendChange }: { desktop: boolean; status: SlopfabStatus | null; onBackendChange: () => void }) {
+ const [backend, setBackend] = useState(loadInferenceBackend);
+ const cudaAvailable = status?.cudaAvailable === true;
const debugEnabled = useSyncExternalStore(subscribeDebugOptions, loadDebugOptionsEnabled);
const [info, setInfo] = useState<DiagnosticLogInfo | null>(null);
const [opening, setOpening] = useState(false);
@@ -217,6 +220,21 @@ function DiagnosticsSetting({ desktop }: { desktop: boolean }) {
};
return <>
+ <div className="generator-template-fields diagnostics-backend">
+ <label>
+ <span>GPU backend</span>
+ <select aria-label="GPU backend" value={cudaAvailable ? backend : "vulkan"} disabled={!desktop || !cudaAvailable} onChange={(event) => {
+ const next = event.target.value as InferenceBackend;
+ saveInferenceBackend(next);
+ setBackend(next);
+ onBackendChange();
+ }}>
+ {cudaAvailable && <option value="cuda">CUDA</option>}
+ <option value="vulkan">Vulkan</option>
+ </select>
+ </label>
+ <p>{!desktop ? "Available in the desktop app." : !status ? "Checking GPU backends…" : cudaAvailable ? "Choose CUDA or Vulkan for your NVIDIA GPU. Applies to new generations." : "AMD and Intel GPUs use Vulkan. CUDA requires a compatible NVIDIA GPU and CUDA runtime."}</p>
+ </div>
<label className="diagnostics-debug-option">
<input type="checkbox" checked={debugEnabled} onChange={(event) => saveDebugOptionsEnabled(event.target.checked)} aria-labelledby="debug-options-label" aria-describedby="debug-options-description" />
<span><b id="debug-options-label">Enable debug options</b><small id="debug-options-description">Show Debug Prompt in scene settings and Debug Icon Prompt in reference details.</small></span>
@@ -244,7 +262,7 @@ function DiagnosticsSetting({ desktop }: { desktop: boolean }) {
so whichever one the user came for was below the fold half the time. One tab
each, and neither scrolls on an ordinary window. */
const TABS = [
- { id: "engine", label: "Video engine" },
+ { id: "engine", label: "Generator" },
{ id: "llms", label: "Agents" },
{ id: "appearance", label: "Appearance" },
{ id: "diagnostics", label: "Diagnostics" },
@@ -260,6 +278,7 @@ export function SettingsView({ onClose, updates, initialTab = "engine" }: { onCl
const [templateSettings, setTemplateSettings] = useState<GeneratorTemplateSettings>(() => loadGeneratorTemplateSettings());
const [editingTemplateId, setEditingTemplateId] = useState<string | null>(null);
const [status, setStatus] = useState<SlopfabStatus | null>(null);
+ const probeRevision = useRef(0);
const [error, setError] = useState<string | null>(null);
const desktop = isTauri();
@@ -269,9 +288,13 @@ export function SettingsView({ onClose, updates, initialTab = "engine" }: { onCl
const settings = selectedTemplate.paths;
const probe = useCallback((paths?: EngineSettings) => {
- setStatus(null);
- void getEngineStatus(paths).then(setStatus).catch(() => setStatus(null));
- }, []);
+ const revision = ++probeRevision.current;
+ void getEngineStatus(paths, selectedTemplate.attention).then((next) => {
+ if (revision === probeRevision.current) setStatus(next);
+ }).catch(() => {
+ if (revision === probeRevision.current) setStatus(null);
+ });
+ }, [selectedTemplate.attention]);
/* Saved on every keystroke — there is no Save button here, so a half-typed
path must never be the reason generation is still broken after a restart.
@@ -324,7 +347,7 @@ export function SettingsView({ onClose, updates, initialTab = "engine" }: { onCl
probe({ ...EMPTY_ENGINE_SETTINGS });
};
- const updateTemplate = (updates: Partial<Pick<typeof selectedTemplate, "name" | "defaultSteps">>) => {
+ const updateTemplate = (updates: Partial<Pick<typeof selectedTemplate, "name" | "defaultSteps" | "attention">>) => {
setTemplateSettings((current) => {
const next = {
...current,
@@ -434,7 +457,7 @@ export function SettingsView({ onClose, updates, initialTab = "engine" }: { onCl
role="tabpanel"
aria-labelledby="settings-tab-diagnostics"
>
- <DiagnosticsSetting desktop={desktop} />
+ <DiagnosticsSetting desktop={desktop} status={status} onBackendChange={() => probe(settings)} />
</section>}
{tab === "engine" && <section
@@ -469,7 +492,7 @@ export function SettingsView({ onClose, updates, initialTab = "engine" }: { onCl
<header className="generator-editor__head">
<div>
<h2 id="generator-editor-heading">Edit generator</h2>
- <p>Set its name, generation steps, and model locations on this computer.</p>
+ <p>Set its name, generation steps, attention, and model locations on this computer.</p>
</div>
</header>
<div className="generator-template-fields">
@@ -484,6 +507,14 @@ export function SettingsView({ onClose, updates, initialTab = "engine" }: { onCl
if (Number.isInteger(value) && value >= 2 && value <= MAX_GENERATION_STEPS) updateTemplate({ defaultSteps: value });
}} />
</label>
+ <label>
+ <span>Attention</span>
+ <select aria-label="Generator attention" value={selectedTemplate.attention} onChange={(event) => updateTemplate({ attention: event.target.value as AttentionMode })}>
+ <option value="exact">Exact attention</option>
+ <option value="flash2">Flash attention</option>
+ <option value="sage2">Sage attention</option>
+ </select>
+ </label>
</div>
<div className={`settings-status settings-status--${status?.state ?? "checking"}`} role="status">
<span><i />{engineHeadline(status, desktop)}</span>
diff --git a/src/lib/runtime.ts b/src/lib/runtime.ts
index 4c59f6a..ffbb9fb 100644
--- a/src/lib/runtime.ts
+++ b/src/lib/runtime.ts
@@ -8,7 +8,7 @@ import {
import {
agentEndpointProviderSettings, endpointProviderSetting, engineProviderSetting,
loadDefaultGenerationSteps, loadEngineSettings, withAgentEndpointSettings,
- type EndpointProviderId, type EndpointProviderSettings, type EnginePathField,
+ type AttentionMode, type EndpointProviderId, type EndpointProviderSettings, type EnginePathField,
} from "./settings";
export type ProviderId = "claude" | "codex" | EndpointProviderId;
@@ -30,6 +30,7 @@ export interface SlopfabStatus {
dllPath: string;
version: string | null;
platform: string | null;
+ cudaAvailable?: boolean;
detail: string;
models: ModelStatus[];
}
@@ -131,9 +132,9 @@ export const CHECKING_PROVIDERS: ProviderStatus[] = [
/** Probes the engine paths on their own, with no project in hand — what the
* settings screen shows. */
-export async function getEngineStatus(settings = loadEngineSettings()): Promise<SlopfabStatus> {
+export async function getEngineStatus(settings = loadEngineSettings(), attention?: AttentionMode): Promise<SlopfabStatus> {
if (!isTauri()) return DEMO_STATUS.slopfab;
- return invoke<SlopfabStatus>("slopfab_status", { settings: { slopfab: engineProviderSetting(settings) } });
+ return invoke<SlopfabStatus>("slopfab_status", { settings: { slopfab: engineProviderSetting(settings, undefined, attention) } });
}
/** Opens the OS picker for one engine path. Returns null when the user cancels. */
diff --git a/src/lib/settings.test.ts b/src/lib/settings.test.ts
index 6348548..8cf605c 100644
--- a/src/lib/settings.test.ts
+++ b/src/lib/settings.test.ts
@@ -4,6 +4,9 @@ import { beforeEach, describe, expect, it } from "vitest";
import {
agentEndpointProviderSettings,
createGeneratorTemplate,
+ engineProviderSetting,
+ loadInferenceBackend,
+ saveInferenceBackend,
loadDefaultGenerationSteps,
loadAgentEndpointSettings,
loadEngineSettings,
@@ -24,10 +27,34 @@ describe("generator templates", () => {
id: "default",
name: "Default",
defaultSteps: 20,
+ attention: "sage2",
paths: { transformer: "D:\\Models\\main.safetensors" },
});
});
+ it("migrates missing or invalid attention to Sage", () => {
+ for (const attention of [undefined, "unsupported"]) {
+ localStorage.setItem("slopus.generator-templates.v1", JSON.stringify({
+ templates: [{ id: "old", name: "Old", attention }], defaultTemplateId: "old",
+ }));
+ expect(loadGeneratorTemplateSettings().templates[0].attention).toBe("sage2");
+ }
+ });
+
+ it("passes the default generator's attention and machine backend to the engine", () => {
+ const template = createGeneratorTemplate();
+ expect(template.attention).toBe("sage2");
+ expect(loadInferenceBackend()).toBe("cuda");
+ for (const attention of ["exact", "flash2", "sage2"] as const) {
+ template.attention = attention;
+ saveGeneratorTemplateSettings({ templates: [template], defaultTemplateId: template.id });
+ for (const inferenceBackend of ["cuda", "vulkan"] as const) {
+ saveInferenceBackend(inferenceBackend);
+ expect(engineProviderSetting(loadEngineSettings()).options).toMatchObject({ attention, inferenceBackend });
+ }
+ }
+ });
+
it("uses the selected default template for engine paths and step defaults", () => {
const fast = createGeneratorTemplate("Fast draft");
fast.defaultSteps = 8;
diff --git a/src/lib/settings.ts b/src/lib/settings.ts
index 09f9b82..0f96108 100644
--- a/src/lib/settings.ts
+++ b/src/lib/settings.ts
@@ -70,9 +70,30 @@ export interface GeneratorTemplate {
id: string;
name: string;
defaultSteps: number;
+ attention: AttentionMode;
paths: EngineSettings;
}
+export type AttentionMode = "exact" | "flash2" | "sage2";
+export type InferenceBackend = "cuda" | "vulkan";
+const INFERENCE_BACKEND_KEY = "slopus.inference-backend.v1";
+
+export function loadInferenceBackend(): InferenceBackend {
+ try {
+ return localStorage.getItem(INFERENCE_BACKEND_KEY) === "vulkan" ? "vulkan" : "cuda";
+ } catch {
+ return "cuda";
+ }
+}
+
+export function saveInferenceBackend(backend: InferenceBackend): void {
+ try {
+ localStorage.setItem(INFERENCE_BACKEND_KEY, backend);
+ } catch {
+ /* Keep the current settings screen usable if storage is unavailable. */
+ }
+}
+
export interface GeneratorTemplateSettings {
templates: GeneratorTemplate[];
defaultTemplateId: string;
@@ -96,12 +117,13 @@ export function createGeneratorTemplate(name = "New template"): GeneratorTemplat
id: `generator-template-${crypto.randomUUID()}`,
name,
defaultSteps: DEFAULT_GENERATION_STEPS,
+ attention: "sage2",
paths: copyPaths(EMPTY_ENGINE_SETTINGS),
};
}
const initialTemplateSettings = (paths = EMPTY_ENGINE_SETTINGS): GeneratorTemplateSettings => ({
- templates: [{ id: "default", name: "Default", defaultSteps: DEFAULT_GENERATION_STEPS, paths: copyPaths(paths) }],
+ templates: [{ id: "default", name: "Default", defaultSteps: DEFAULT_GENERATION_STEPS, attention: "sage2", paths: copyPaths(paths) }],
defaultTemplateId: "default",
});
@@ -123,7 +145,8 @@ const normalizeTemplateSettings = (value: unknown): GeneratorTemplateSettings |
&& candidate.defaultSteps <= MAX_GENERATION_STEPS
? candidate.defaultSteps
: DEFAULT_GENERATION_STEPS;
- return [{ id, name, defaultSteps, paths: pathsFrom(candidate.paths) }];
+ const attention = candidate.attention === "exact" || candidate.attention === "flash2" ? candidate.attention : "sage2";
+ return [{ id, name, defaultSteps, attention, paths: pathsFrom(candidate.paths) }];
});
if (templates.length === 0) return null;
const requestedDefault = typeof record.defaultTemplateId === "string" ? record.defaultTemplateId : "";
@@ -186,8 +209,8 @@ export function saveEngineSettings(settings: EngineSettings): void {
/** The `slopfab` provider setting these paths describe, with blanks dropped so
* an unset field falls through to whatever the project (or the Rust default)
* already had rather than overwriting it with "". */
-export function engineProviderSetting(settings: EngineSettings, base?: ProviderSetting): ProviderSetting {
- const options: ProviderSetting["options"] = { ...(base?.options ?? {}) };
+export function engineProviderSetting(settings: EngineSettings, base?: ProviderSetting, attention = defaultGeneratorTemplate().attention): ProviderSetting {
+ const options: ProviderSetting["options"] = { ...(base?.options ?? {}), attention, inferenceBackend: loadInferenceBackend() };
for (const field of ENGINE_PATH_FIELDS) {
const value = settings[field.id].trim();
if (value) options[field.id] = value;
diff --git a/src/styles/shell.css b/src/styles/shell.css
index c3343fc..df3f784 100644
--- a/src/styles/shell.css
+++ b/src/styles/shell.css
@@ -319,7 +319,8 @@
font-size: var(--text-xs);
}
-.generator-template-fields input {
+.generator-template-fields input,
+.generator-template-fields select {
min-width: 0;
width: 100%;
height: var(--field-height);
@@ -335,6 +336,17 @@
margin-bottom: var(--space-4);
}
+.diagnostics-backend {
+ grid-template-columns: 180px minmax(0, 1fr);
+ align-items: center;
+ margin: 0 0 var(--space-4);
+}
+
+.diagnostics-backend p {
+ color: var(--text-muted);
+ font-size: var(--text-sm);
+}
+
.generator-editor__head h2 {
margin: 0;
color: var(--text-primary);