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(comfyui): auto-enable Flash Attention + minimal Create-tab nudge when missing
purple4ae1f66afa0a
diff --git a/src-tauri/src/commands/process.rs b/src-tauri/src/commands/process.rsindex 31795b53..d9078778 100644--- a/src-tauri/src/commands/process.rs+++ b/src-tauri/src/commands/process.rs@@ -686,6 +686,107 @@ pub fn start_ollama(state: State<'_, AppState>) -> Result<serde_json::Value, Str}}+/// Does `python` have a working flash-attn? Real import test (not pip-list):+/// a half-installed or ABI-mismatched wheel fails the import, and we must+/// never pass `--use-flash-attention` then — ComfyUI would error at startup.+/// The import loads torch, so allow up to 25 s; timeout counts as absent.+pub(crate) fn probe_flash_attention(python: &str) -> bool {+ if python.is_empty() {+ return false;+ }+ let mut cmd = Command::new(python);+ cmd.args(["-c", "from flash_attn import flash_attn_func"])+ .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 false,+ };+ for _ in 0..125 {+ match child.try_wait() {+ Ok(Some(status)) => return status.success(),+ Ok(None) => std::thread::sleep(std::time::Duration::from_millis(200)),+ Err(_) => return false,+ }+ }+ let _ = child.kill();+ false+}++/// Probe with per-python cache (the import costs ~5-10 s; only the first+/// check per python path pays it).+fn flash_attention_cached(state: &AppState, python: &str) -> bool {+ if let Some(v) = state.flash_attn_cache.lock().unwrap().get(python).copied() {+ return v;+ }+ let v = probe_flash_attention(python);+ state+ .flash_attn_cache+ .lock()+ .unwrap()+ .insert(python.to_string(), v);+ v+}++/// 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.+fn resolve_comfyui_python(comfy_path: &str, system_python: String) -> String {+ let portable_python = std::path::Path::new(comfy_path).parent().and_then(|p| {+ let candidate = p.join("python_embeded").join("python.exe");+ if candidate.exists() {+ Some(candidate.to_string_lossy().to_string())+ } else {+ None+ }+ });+ let bundled_python = portable_python.or_else(|| {+ let candidate = std::path::Path::new(comfy_path)+ .join("python_embeded")+ .join("python.exe");+ if candidate.exists() {+ Some(candidate.to_string_lossy().to_string())+ } else {+ None+ }+ });+ let venv_python =+ crate::python::resolve_comfyui_venv_python(std::path::Path::new(comfy_path));+ bundled_python.or(venv_python).unwrap_or(system_python)+}++/// Create-tab check (David 2026-06-11): flash-attn makes WAN-class video+/// sampling 4-5x faster (measured 27 s/it vs 108-160 s/it on his RTX 3060,+/// identical workload). The tab shows a minimal hint when it's missing.+#[tauri::command]+pub fn check_flash_attention(state: State<'_, AppState>) -> Result<serde_json::Value, String> {+ {+ let host = state.comfy_host.lock().unwrap().clone();+ if !is_local_host(&host) {+ return Ok(serde_json::json!({"available": false, "reason": "remote"}));+ }+ }+ let comfy_path = state+ .comfy_path+ .lock()+ .unwrap()+ .clone()+ .or_else(find_comfyui_path);+ let Some(comfy_path) = comfy_path else {+ return Ok(serde_json::json!({"available": false, "reason": "no_comfyui"}));+ };+ let system_python = state.python_bin.lock().unwrap().clone();+ let python = resolve_comfyui_python(&comfy_path, system_python);+ if python.is_empty() {+ return Ok(serde_json::json!({"available": false, "reason": "no_python"}));+ }+ let available = flash_attention_cached(&state, &python);+ Ok(serde_json::json!({"available": available, "python": python}))+}+#[tauri::command]pub fn start_comfyui(state: State<'_, AppState>) -> Result<serde_json::Value, String> {// If user pointed LU at a remote ComfyUI, we have no local process to spawn.@@ -794,6 +895,17 @@ pub fn start_comfyui(state: State<'_, AppState>) -> Result<serde_json::Value, Stcomfy_args.push("--cpu");println!("[ComfyUI] No NVIDIA driver detected — passing --cpu to ComfyUI (CPU inference fallback)");}+ // Auto-enable Flash Attention when the package actually imports in THIS+ // python (David 2026-06-11: measured 4-5x faster WAN video sampling vs+ // pytorch SDPA on a 12 GB 3060). ComfyUI only uses FA2 with the flag, so+ // an installed wheel does nothing without this. The real-import probe+ // guarantees we never pass the flag on a broken install (ComfyUI would+ // error at startup); probe result is cached per python path. CPU mode+ // skips it — flash-attn is CUDA-only.+ if !needs_cpu_fallback && flash_attention_cached(&state, &python) {+ comfy_args.push("--use-flash-attention");+ println!("[ComfyUI] flash-attn detected in {} — enabling Flash Attention", python);+ }let mut cmd = Command::new(&python);cmd.args(&comfy_args).current_dir(&comfy_path)diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rsindex f429d25a..8d270a02 100644--- a/src-tauri/src/main.rs+++ b/src-tauri/src/main.rs@@ -93,6 +93,7 @@ fn main() {// Process managementcommands::process::start_ollama,commands::process::start_comfyui,+ commands::process::check_flash_attention,commands::process::stop_comfyui,commands::process::comfyui_status,commands::process::find_comfyui,diff --git a/src-tauri/src/state.rs b/src-tauri/src/state.rsindex 048c91d2..2b542e64 100644--- a/src-tauri/src/state.rs+++ b/src-tauri/src/state.rs@@ -195,6 +195,11 @@ pub struct AppState {/// Default "auto" + empty indices = no env-var, runtime picks default/// (pre-v2.5.0 behaviour).pub gpu_selection: Mutex<GpuSelection>,+ /// flash-attn probe results, keyed by python path (David 2026-06-11:+ /// measured 4-5x faster WAN video sampling vs pytorch SDPA on a 3060).+ /// 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>>,}impl AppState {@@ -257,6 +262,7 @@ impl AppState {// Bug BB v2.5.0 — start in "auto" mode so existing installs are// unchanged until the user explicitly picks a GPU in Settings.gpu_selection: Mutex::new(GpuSelection::default()),+ flash_attn_cache: Mutex::new(HashMap::new()),}}}diff --git a/src/components/create/CreateView.tsx b/src/components/create/CreateView.tsxindex 7bdf28cd..41561836 100644--- a/src/components/create/CreateView.tsx+++ b/src/components/create/CreateView.tsx@@ -285,6 +285,21 @@ export function CreateView() {}}, [connected])+ // Flash-attention availability (David 2026-06-11): measured 4-5x faster+ // WAN-class video sampling vs pytorch SDPA on a 12 GB 3060. The backend+ // probes the SAME python that runs ComfyUI (cached, real import test) and+ // start_comfyui auto-passes --use-flash-attention when present — this hint+ // only nudges users who don't have it. One check per connect.+ const [flashAttn, setFlashAttn] = useState<{ available: boolean; reason?: string } | null>(null)+ useEffect(() => {+ if (connected !== true || flashAttn !== null) return+ let cancelled = false+ backendCall('check_flash_attention')+ .then((r: { available: boolean; reason?: string }) => { if (!cancelled) setFlashAttn(r) })+ .catch(() => { /* probe unavailable — show nothing */ })+ return () => { cancelled = true }+ }, [connected, flashAttn])+// Track when ComfyUI loading actually started (Bug B). Reset on connect.const isStartingNow = status?.starting || status?.processAliveuseEffect(() => {@@ -795,6 +810,24 @@ export function CreateView() {</div>)}+ {/* Flash-attention nudge — deliberately colorless/minimal (David+ 2026-06-11). Only when the probe POSITIVELY said it's missing;+ remote ComfyUI is excluded (we can't see that python). */}+ {!showNoModelsEmptyState && mode === 'video' && connected === true && flashAttn?.available === false && flashAttn.reason !== 'remote' && (+ <p className="px-1 text-[10px] leading-relaxed text-gray-500">+ flash attention is not installed in ComfyUI's Python — video generation runs ~4× slower without it.{' '}+ <a+ href="https://huggingface.co/lldacing/flash-attention-windows-wheel"+ target="_blank"+ rel="noreferrer"+ className="underline hover:text-gray-400"+ >+ prebuilt wheels+ </a>+ {' '}· pick the file matching your torch/CUDA/Python, pip install it into ComfyUI's Python, restart ComfyUI+ </p>+ )}+{/* I2V Image Upload — shown when SVD or FramePack model is selected */}{!showNoModelsEmptyState && isI2V && connected === true && (<div