The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
feat: AMD ComfyUI GPU support (rhodium92)
purple48a5aa4adb6d
diff --git a/src-tauri/src/commands/process.rs b/src-tauri/src/commands/process.rsindex 1ca420f1..b8cbf8ff 100644--- a/src-tauri/src/commands/process.rs+++ b/src-tauri/src/commands/process.rs@@ -1,6 +1,8 @@+use std::collections::HashMap;use std::fs;use std::path::{Path, PathBuf};use std::process::{Command, Stdio};+use std::sync::Mutex;use tauri::{Manager, State};use tracing::{error, info};@@ -88,8 +90,69 @@ pub fn needs_cpu_fallback() -> bool {if cfg!(target_os = "macos") {return false;}- let probe = Command::new("nvidia-smi").output();- !probe.map(|o| o.status.success()).unwrap_or(false)+ !nvidia_present()+}++/// Is an NVIDIA driver present (nvidia-smi exits 0)?+fn nvidia_present() -> bool {+ Command::new("nvidia-smi")+ .output()+ .map(|o| o.status.success())+ .unwrap_or(false)+}++/// User override for the ComfyUI CPU/GPU decision (settings.comfyGpuMode).+#[derive(Clone, Copy, PartialEq, Eq, Debug)]+pub enum ComfyGpuMode {+ /// Probe: NVIDIA fast-path, else the comfy python's torch GPU availability.+ Auto,+ /// Always pass `--cpu` (stable but slow — e.g. a card that OOMs on image gen).+ ForceCpu,+ /// Never pass `--cpu` (user vouches for a non-NVIDIA accel, e.g. DirectML).+ ForceGpu,+}++impl ComfyGpuMode {+ pub fn parse(s: &str) -> Self {+ match s.trim().to_ascii_lowercase().as_str() {+ "cpu" => ComfyGpuMode::ForceCpu,+ "gpu" => ComfyGpuMode::ForceGpu,+ _ => ComfyGpuMode::Auto,+ }+ }+}++/// Pure decision (all probes done by the caller): pass `--cpu` to ComfyUI?+///+/// - `baseline_needs_cpu`: `needs_cpu_fallback()` — false when NVIDIA present or macOS.+/// - `torch_gpu`: Some(true) = the comfy python's torch reports a usable GPU+/// (CUDA / ROCm / ZLUDA all answer via `torch.cuda.is_available()`),+/// Some(false) = no usable GPU, None = not probed / probe failed.+///+/// rhodium92 (AMD RX 6600 XT, 2026-07-01): before this, ANY non-NVIDIA box was+/// force-dropped to `--cpu`, so a ROCm/ZLUDA ComfyUI never used the AMD card.+pub fn decide_comfy_cpu_flag(+ mode: ComfyGpuMode,+ baseline_needs_cpu: bool,+ torch_gpu: Option<bool>,+) -> bool {+ match mode {+ ComfyGpuMode::ForceCpu => true,+ ComfyGpuMode::ForceGpu => false,+ ComfyGpuMode::Auto => {+ if !baseline_needs_cpu {+ // NVIDIA present (or macOS MPS) — the GPU is already fine.+ false+ } else {+ // No NVIDIA driver: a torch that reports a usable GPU (ROCm/ZLUDA)+ // means main.py won't crash on torch.cuda → run on the GPU.+ match torch_gpu {+ Some(true) => false,+ _ => true, // Some(false) = no GPU, None = probe failed → conservative --cpu+ }+ }+ }+ }}/// Skip these directories during ComfyUI search@@ -748,6 +811,85 @@ fn flash_attention_cached(state: &AppState, python: &str) -> bool {}}+/// GPU-aware version of the Bug J `--cpu` check used at ComfyUI start. Only+/// probes the comfy python's torch when it might change the answer (Auto + no+/// NVIDIA driver), so NVIDIA machines keep the EXACT fast-path they had before.+fn comfy_needs_cpu(+ python: &str,+ mode: ComfyGpuMode,+ cache: Option<&Mutex<HashMap<String, bool>>>,+) -> bool {+ let baseline = needs_cpu_fallback();+ let torch_gpu = if mode == ComfyGpuMode::Auto && baseline && !python.is_empty() {+ comfy_gpu_available_cached(python, cache)+ } else {+ None+ };+ decide_comfy_cpu_flag(mode, baseline, torch_gpu)+}++/// torch-GPU probe with an optional per-python cache (mirrors flash_attention_cached).+/// Only DEFINITIVE results are cached; a timeout returns None and is retried next start.+fn comfy_gpu_available_cached(+ python: &str,+ cache: Option<&Mutex<HashMap<String, bool>>>,+) -> Option<bool> {+ if let Some(c) = cache {+ if let Some(v) = c.lock().unwrap().get(python).copied() {+ return Some(v);+ }+ }+ match probe_comfy_gpu(python) {+ Some(v) => {+ if let Some(c) = cache {+ c.lock().unwrap().insert(python.to_string(), v);+ }+ Some(v)+ }+ None => {+ println!("[ComfyUI] GPU probe timed out — treating as no accel for this start (will retry)");+ None+ }+ }+}++/// Does `python`'s torch report a usable GPU (CUDA / ROCm / ZLUDA)?+///+/// `torch.cuda.is_available()` is SAFE — it never raises (unlike+/// `current_device()`): on a stock-CUDA torch on an AMD box it simply returns+/// False. So this cleanly separates "ROCm/ZLUDA torch → run on GPU" from "stock+/// torch, no GPU → --cpu". Some(true/false) = definitive, None = timeout / spawn fail.+pub(crate) fn probe_comfy_gpu(python: &str) -> Option<bool> {+ if python.is_empty() {+ return Some(false);+ }+ let mut cmd = Command::new(python);+ cmd.args([+ "-c",+ "import torch,sys; sys.exit(0 if torch.cuda.is_available() else 1)",+ ])+ .stdin(Stdio::null())+ .stdout(Stdio::null())+ .stderr(Stdio::null());+ #[cfg(target_os = "windows")]+ cmd.creation_flags(CREATE_NO_WINDOW);+ let mut child = match cmd.spawn() {+ Ok(c) => c,+ Err(_) => return None,+ };+ // 60 s ceiling: torch import is ~4 s warm but can lag during an app-boot disk+ // storm; a missing/broken torch exits non-zero fast.+ for _ in 0..300 {+ match child.try_wait() {+ Ok(Some(status)) => return Some(status.success()),+ Ok(None) => std::thread::sleep(std::time::Duration::from_millis(200)),+ Err(_) => return None,+ }+ }+ let _ = child.kill();+ None+}+/// Same bundled-portable → venv → system resolution order as start_comfyui,/// without the logging — used by check_flash_attention so the Create tab/// probes the EXACT interpreter that will run ComfyUI.@@ -901,7 +1043,8 @@ pub fn start_comfyui(state: State<'_, AppState>) -> Result<serde_json::Value, St// the underlying spawn-then-crash loop wastes the user's time on every// start). Detect NVIDIA via `nvidia-smi` and pass --cpu when absent,// except on macOS where PyTorch uses MPS and never calls cuda APIs.- let needs_cpu_fallback = needs_cpu_fallback();+ let gpu_mode = ComfyGpuMode::parse(&state.comfy_gpu_mode.lock().unwrap());+ let needs_cpu_fallback = comfy_needs_cpu(&python, gpu_mode, Some(&state.comfy_gpu_cache));let mut comfy_args: Vec<&str> = vec!["main.py","--listen", "127.0.0.1",@@ -1139,6 +1282,24 @@ pub fn find_comfyui() -> Result<serde_json::Value, String> {}}+/// Frontend-owned override for the ComfyUI CPU/GPU device decision+/// (settings.comfyGpuMode). "auto" | "cpu" | "gpu". Desktop-relevant only — the+/// web build points at a remote ComfyUI and never starts a local one.+#[tauri::command]+pub fn set_comfy_gpu_mode(mode: String, state: State<'_, AppState>) -> Result<serde_json::Value, String> {+ let normalized = match mode.trim().to_ascii_lowercase().as_str() {+ "cpu" => "cpu",+ "gpu" => "gpu",+ _ => "auto",+ };+ *state.comfy_gpu_mode.lock().unwrap() = normalized.to_string();+ // The mode can flip the target device, so drop cached probe results; the+ // next start re-probes cleanly under the new mode.+ state.comfy_gpu_cache.lock().unwrap().clear();+ println!("[ComfyUI] GPU mode = {}", normalized);+ Ok(serde_json::json!({ "mode": normalized }))+}+#[tauri::command]pub fn set_comfyui_path(path: String, state: State<'_, AppState>) -> Result<serde_json::Value, String> {// Resolve the path the user gave us to a directory that actually contains@@ -1443,7 +1604,8 @@ pub fn auto_start_comfyui(state: &AppState) {// Bug J: same --cpu fallback as start_comfyui to avoid the// "Found no NVIDIA driver" crash loop on non-NVIDIA systems.- let auto_needs_cpu = needs_cpu_fallback();+ let auto_gpu_mode = ComfyGpuMode::parse(&state.comfy_gpu_mode.lock().unwrap());+ let auto_needs_cpu = comfy_needs_cpu(&python, auto_gpu_mode, Some(&state.comfy_gpu_cache));let mut comfy_args: Vec<&str> = vec!["main.py","--listen", "127.0.0.1",@@ -1540,4 +1702,66 @@ mod tests {let b = needs_cpu_fallback();assert_eq!(a, b, "needs_cpu_fallback returned inconsistent results");}++ // ── AMD/ROCm ComfyUI GPU decision (rhodium92, 2026-07-01) ────────────++ #[test]+ fn comfy_gpu_mode_parse_maps_known_values_and_defaults_to_auto() {+ assert_eq!(ComfyGpuMode::parse("auto"), ComfyGpuMode::Auto);+ assert_eq!(ComfyGpuMode::parse("cpu"), ComfyGpuMode::ForceCpu);+ assert_eq!(ComfyGpuMode::parse("gpu"), ComfyGpuMode::ForceGpu);+ assert_eq!(ComfyGpuMode::parse("GPU"), ComfyGpuMode::ForceGpu);+ assert_eq!(ComfyGpuMode::parse(" Cpu "), ComfyGpuMode::ForceCpu);+ assert_eq!(ComfyGpuMode::parse("nonsense"), ComfyGpuMode::Auto);+ assert_eq!(ComfyGpuMode::parse(""), ComfyGpuMode::Auto);+ }++ #[test]+ fn decide_force_modes_ignore_baseline_and_probe() {+ // ForceCpu is always --cpu; ForceGpu is never --cpu, no matter what the+ // baseline check or the torch probe report.+ for &baseline in &[true, false] {+ for torch in [Some(true), Some(false), None] {+ assert!(+ decide_comfy_cpu_flag(ComfyGpuMode::ForceCpu, baseline, torch),+ "ForceCpu must always request --cpu"+ );+ assert!(+ !decide_comfy_cpu_flag(ComfyGpuMode::ForceGpu, baseline, torch),+ "ForceGpu must never request --cpu"+ );+ }+ }+ }++ #[test]+ fn decide_auto_nvidia_or_macos_never_uses_cpu() {+ // baseline_needs_cpu == false means NVIDIA present (or macOS MPS): the GPU+ // is already fine, so the torch probe is irrelevant and it's never --cpu.+ assert!(!decide_comfy_cpu_flag(ComfyGpuMode::Auto, false, None));+ assert!(!decide_comfy_cpu_flag(ComfyGpuMode::Auto, false, Some(false)));+ assert!(!decide_comfy_cpu_flag(ComfyGpuMode::Auto, false, Some(true)));+ }++ #[test]+ fn decide_auto_amd_rocm_or_zluda_torch_skips_cpu() {+ // No NVIDIA driver (baseline == true) but the comfy python's torch reports+ // a usable GPU (ROCm/ZLUDA) → run on the GPU, no --cpu. The rhodium92 fix.+ assert!(!decide_comfy_cpu_flag(ComfyGpuMode::Auto, true, Some(true)));+ }++ #[test]+ fn decide_auto_no_usable_gpu_falls_back_to_cpu() {+ // No NVIDIA and torch has no usable GPU (stock CUDA torch on an AMD box,+ // or a CPU-only install) → --cpu, exactly the pre-fix safe behaviour.+ assert!(decide_comfy_cpu_flag(ComfyGpuMode::Auto, true, Some(false)));+ // Probe failed / timed out → conservative --cpu (never risk the main.py+ // "Found no NVIDIA driver" crash loop).+ assert!(decide_comfy_cpu_flag(ComfyGpuMode::Auto, true, None));+ }++ #[test]+ fn probe_comfy_gpu_on_empty_python_is_definitive_false() {+ assert_eq!(probe_comfy_gpu(""), Some(false));+ }}diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rsindex bf4152dd..defcf16a 100644--- a/src-tauri/src/main.rs+++ b/src-tauri/src/main.rs@@ -103,6 +103,7 @@ fn main() {commands::process::find_comfyui,commands::process::detect_all_comfyui_installs,commands::process::set_comfyui_path,+ commands::process::set_comfy_gpu_mode,commands::process::set_comfyui_port,commands::process::set_comfyui_host,commands::process::set_ollama_host,diff --git a/src-tauri/src/state.rs b/src-tauri/src/state.rsindex 45edc06a..16485d6e 100644--- a/src-tauri/src/state.rs+++ b/src-tauri/src/state.rs@@ -230,6 +230,16 @@ pub struct AppState {/// The probe imports torch (~5-10 s), so only the first ComfyUI start //// Create-tab check per python pays it.pub flash_attn_cache: Mutex<HashMap<String, bool>>,+ /// ComfyUI GPU torch-availability probe, keyed by python path (2026-07-01,+ /// rhodium92 AMD RX 6600 XT). `torch.cuda.is_available()` is true for CUDA,+ /// ROCm AND ZLUDA builds — the exact condition under which ComfyUI's main.py+ /// won't crash on `torch.cuda.current_device()`. Lets an AMD/ROCm ComfyUI run+ /// on the GPU instead of being force-dropped to `--cpu`.+ pub comfy_gpu_cache: Mutex<HashMap<String, bool>>,+ /// Frontend-owned override for the ComfyUI CPU/GPU decision+ /// (settings.comfyGpuMode): "auto" (probe), "cpu" (force --cpu), "gpu"+ /// (never --cpu). Pushed via set_comfy_gpu_mode on boot + change.+ pub comfy_gpu_mode: Mutex<String>,}impl AppState {@@ -296,6 +306,8 @@ impl AppState {// unchanged until the user explicitly picks a GPU in Settings.gpu_selection: Mutex::new(GpuSelection::default()),flash_attn_cache: Mutex::new(HashMap::new()),+ comfy_gpu_cache: Mutex::new(HashMap::new()),+ comfy_gpu_mode: Mutex::new("auto".to_string()),}}}diff --git a/src/components/layout/AppShell.tsx b/src/components/layout/AppShell.tsxindex 3538d5d6..5d027b51 100644--- a/src/components/layout/AppShell.tsx+++ b/src/components/layout/AppShell.tsx@@ -106,6 +106,15 @@ export function AppShell() {}}, [appMode])+ // Push the persisted ComfyUI GPU override to the backend on boot + change+ // (rhodium92 AMD, 2026-07-01). The backend resets to "auto" each launch, so+ // without this a saved force-cpu / force-gpu wouldn't apply until the user+ // re-opened Settings. Desktop-only — the web build has no local ComfyUI.+ useEffect(() => {+ if (!isTauri()) return+ backendCall('set_comfy_gpu_mode', { mode: settings.comfyGpuMode || 'auto' }).catch(() => {})+ }, [settings.comfyGpuMode])+// ── Store backup/restore: survive NSIS updates that wipe WebView2 data ──const STORE_KEYS = ['chat-conversations', 'chat-settings', 'chat-models', 'lu-providers',diff --git a/src/components/settings/HardwareSettings.tsx b/src/components/settings/HardwareSettings.tsxindex ab4cae52..fd978039 100644--- a/src/components/settings/HardwareSettings.tsx+++ b/src/components/settings/HardwareSettings.tsx@@ -5,7 +5,7 @@import { useEffect, useMemo, useState } from 'react'import { useSettingsStore } from '../../stores/settingsStore'-import { backendCall } from '../../api/backend'+import { backendCall, isTauri } from '../../api/backend'import { Cpu, RefreshCw, AlertTriangle } from 'lucide-react'interface DetectedGpu {@@ -84,6 +84,15 @@ export function HardwareSettings() {setShowRestartHint(true)}+ const comfyGpuMode = (settings.comfyGpuMode || 'auto') as 'auto' | 'cpu' | 'gpu'+ const setComfyGpuMode = (mode: 'auto' | 'cpu' | 'gpu') => {+ updateSettings({ comfyGpuMode: mode })+ // Desktop-only command; the web build points at a remote ComfyUI and never+ // starts a local one, so this is a no-op there.+ if (isTauri()) backendCall('set_comfy_gpu_mode', { mode }).catch(() => {})+ setShowRestartHint(true)+ }+return (<div className="space-y-3"><div className="flex items-start gap-2.5 p-2.5 rounded-lg border border-amber-200 dark:border-amber-500/20 bg-amber-50 dark:bg-amber-500/[0.08] text-amber-900 dark:text-amber-200">@@ -178,6 +187,34 @@ export function HardwareSettings() {)}</div>+ <div className="pt-2 border-t border-white/[0.06]">+ <div className="text-[0.7rem] text-gray-700 dark:text-gray-300 font-medium mb-1">ComfyUI GPU (image / video)</div>+ <div className="grid grid-cols-1 gap-1">+ {([+ ['auto', 'Auto (recommended)', 'NVIDIA runs on the GPU. On an AMD / other card LU checks whether your ComfyUI has a GPU-capable torch (ROCm or ZLUDA) and uses it, otherwise falls back to CPU.'],+ ['gpu', 'Force GPU', 'Never fall back to CPU. Use if you run a DirectML / ROCm ComfyUI that LU cannot auto-detect. If your ComfyUI has no working GPU torch it will fail to start.'],+ ['cpu', 'Force CPU', 'Always run image / video on the CPU. Slow but stable — useful if generation crashes your GPU by running out of VRAM.'],+ ] as const).map(([val, label, help]) => (+ <label key={val} className="flex items-start gap-2 cursor-pointer p-1.5 rounded hover:bg-white/[0.04] border border-transparent has-[input:checked]:border-white/10 has-[input:checked]:bg-white/[0.03]">+ <input+ type="radio"+ name="comfy-gpu-mode"+ checked={comfyGpuMode === val}+ onChange={() => setComfyGpuMode(val)}+ className="mt-0.5"+ />+ <div className="flex-1 min-w-0">+ <div className="text-[0.65rem] text-gray-300">{label}</div>+ <div className="text-[0.55rem] text-gray-500 mt-0.5 leading-relaxed">{help}</div>+ </div>+ </label>+ ))}+ </div>+ <div className="text-[0.55rem] text-gray-500 mt-1 leading-relaxed">+ AMD image / video needs a ComfyUI built for your card (ROCm or ZLUDA). LU installs an NVIDIA / CPU ComfyUI by default. Takes effect on next ComfyUI start.+ </div>+ </div>+{showRestartHint && (vendor !== 'auto' || indices.length > 0) && (<div className="text-[0.6rem] text-amber-300 italic">GPU pick takes effect on next Ollama / ComfyUI spawn. Restart both via the Power button (top-right) or close LU to apply.diff --git a/src/lib/constants.ts b/src/lib/constants.tsindex 54f16c6b..64721c14 100644--- a/src/lib/constants.ts+++ b/src/lib/constants.ts@@ -52,6 +52,10 @@ export const DEFAULT_SETTINGS: Settings = {// 'auto' = evict the local text model only when it wouldn't co-exist with the// ComfyUI model in VRAM. Safest default (no eviction on unknown sizes).exclusiveVramMode: 'auto',+ // ComfyUI GPU device policy (rhodium92 AMD RX 6600 XT, 2026-07-01). 'auto' =+ // NVIDIA fast-path, else probe the comfy python's torch and use the GPU if it+ // is a ROCm/ZLUDA build, otherwise CPU. Existing NVIDIA users are unaffected.+ comfyGpuMode: 'auto',// ── v2.5.0 Codex sprint A/B/C defaults (ported from uselu) ──────codexArchitectMode: false,codexArchitectModel: '',diff --git a/src/stores/settingsStore.ts b/src/stores/settingsStore.tsindex c8621172..78a33563 100644--- a/src/stores/settingsStore.ts+++ b/src/stores/settingsStore.ts@@ -30,7 +30,10 @@ import { DEFAULT_SETTINGS, BUILT_IN_PERSONAS } from '../lib/constants'// 'local'). Same additive merge backfills it — without the bump, v10 blobs// skip migrate entirely and the header ModeSwitch renders with appMode// undefined, highlighting neither Local nor Cloud.-const STORE_VERSION = 11+// v12 (2.5.7): added settings.comfyGpuMode ('auto'|'cpu'|'gpu', default+// 'auto') for the AMD ComfyUI GPU path (rhodium92). Additive — the merge+// fills the default while preserving every existing value; NVIDIA unaffected.+const STORE_VERSION = 12interface SettingsState {settings: Settingsdiff --git a/src/types/settings.ts b/src/types/settings.tsindex 1820d30d..0acb5fc1 100644--- a/src/types/settings.ts+++ b/src/types/settings.ts@@ -99,6 +99,13 @@ export interface Settings {// local VRAM and are always skipped./** VRAM exclusivity policy for image/video generation. Default 'auto'. */exclusiveVramMode: 'auto' | 'always' | 'never'+ /** ComfyUI GPU device policy (rhodium92 AMD RX 6600 XT, 2026-07-01).+ * 'auto' — NVIDIA fast-path; on a non-NVIDIA box probe the ComfyUI python's+ * torch and run on the GPU if it reports one (ROCm/ZLUDA), else CPU.+ * 'cpu' — always force ComfyUI's --cpu (stable but slow).+ * 'gpu' — never force --cpu (for DirectML / setups the probe can't confirm).+ * Desktop-only effect — the web build points at a remote ComfyUI. */+ comfyGpuMode: 'auto' | 'cpu' | 'gpu'// ── v2.5.0 Codex sprint A/B/C settings (ported from uselu) ──────/*** Codex Architect/Editor split. When on, a separate `codexArchitectModel`