Edit photos by describing the change, on your own GPU. A free, open-source alternative to Nano Banana and ChatGPT image editing: photos stay on your computer, no daily limit. One installer for Windows, Mac and Linux sets up the best open model (Qwen-Image 2.1). MCP server for AI agents.
TypeScript ai-photo-editorcomfyui-alternativegenerative-fillimage-editingimage-generationinpaintinglinuxlocal-aimacosmcpmcp-servernano-banana-alternativeofflinephoto-editorprivacyqwen-imageqwen-image-2-1stable-diffusion-cppvulkanwindows
Vulkan: decode in 512 px tiles, under AMD's 2 GiB buffer limit
Gabriele Lozupone1140873ae036
diff --git a/crates/qls-core/src/config.rs b/crates/qls-core/src/config.rsindex a5c3146..4e62d75 100644--- a/crates/qls-core/src/config.rs+++ b/crates/qls-core/src/config.rs@@ -777,6 +777,15 @@ impl AppConfig {}}+ /// `--vae-tile-size` the engine runs with: the setting, at most+ /// [`crate::planner::VULKAN_VAE_TILE`] on Vulkan; 0 = no server-side tiling.+ pub fn server_vae_tile_size(&self) -> u32 {+ match self.gpu_backend {+ GpuBackend::Vulkan => self.vae_tile_size.min(crate::planner::VULKAN_VAE_TILE),+ _ => self.vae_tile_size,+ }+ }+/// SageAttention is requested and the engine and card support it.pub fn uses_sage_attention(&self) -> bool {self.sage_attention && !self.sage_unsupported && self.gpu_backend == GpuBackend::Cudadiff --git a/crates/qls-core/src/engine.rs b/crates/qls-core/src/engine.rsindex 8dffeaf..e6bdc9b 100644--- a/crates/qls-core/src/engine.rs+++ b/crates/qls-core/src/engine.rs@@ -214,7 +214,8 @@ pub fn plan_inputs(cfg: &AppConfig, image_sizes: Vec<Size>, mask: Option<(Size,upscale_tile: crate::planner::upscale_tile(cfg.upscale_tile_size, vram_total_mib, &cfg.upscaler().map(|u| u.0).unwrap_or_default()),upscaler: cfg.upscaler().map(|u| u.0),metal: cfg.gpu_backend == crate::config::GpuBackend::Metal,- server_vae_tiling: cfg.vae_tile_size > 0,+ vulkan: cfg.gpu_backend == crate::config::GpuBackend::Vulkan,+ server_vae_tiling: cfg.server_vae_tile_size() > 0,sage_attention: cfg.uses_sage_attention(),speed_factor: None,hide_uncalibrated: !crate::speed::trust_uncalibrated(cfg),@@ -1037,7 +1038,7 @@ impl Engine {let plan2 = plan.clone();let prompt = request.prompt.clone();let mask_img: Option<GrayImage> = mask.as_ref().map(|(m, _)| m.clone());- let opts = pipeline::BackendOptions { server_vae_tile_size: cfg.vae_tile_size };+ let opts = pipeline::BackendOptions { server_vae_tile_size: cfg.server_vae_tile_size() };let prepared = tokio::task::spawn_blocking(move || pipeline::prepare(&plan2, &prompt, seed, &images, mask_img.as_ref(), &opts)).await.map_err(AppError::internal)??;diff --git a/crates/qls-core/src/planner.rs b/crates/qls-core/src/planner.rsindex 6243aaa..bde728b 100644--- a/crates/qls-core/src/planner.rs+++ b/crates/qls-core/src/planner.rs@@ -384,6 +384,8 @@ pub struct PlanInputs {pub upscale_tile: u32,/// The Metal engine (Apple Silicon): much slower upscaler.pub metal: bool,+ /// The Vulkan engine: every decode in [`VULKAN_VAE_TILE`] tiles.+ pub vulkan: bool,/// The server was launched with `--vae-tiling` (tiles every decode by default).pub server_vae_tiling: bool,/// SageAttention is enabled (faster steps; used for estimates only).@@ -628,6 +630,12 @@ pub fn max_untiled_vae_area(vram_total_mib: Option<u64>) -> u64 {}}}+/// Decode tile side on Vulkan, whatever the card's memory. AMD's driver allows at most 2 GiB per+/// buffer, and a decode's largest tensor passes that at about 0.5 MP per tile: an RX 9070 XT+/// logged "Requested buffer size exceeds device buffer size limit" with 0.55-0.72 MP tiles and+/// decoded 1-1.4 MP in 24-57 s; an RX 6700 XT took 71 s for 1 MP with 768 px tiles and 6 s with+/// 256 px ones (2026-10-23). 512 px (0.26 MP) keeps about half of the limit free.+pub const VULKAN_VAE_TILE: u32 = 512;/// Overlap the server is launched with (`--vae-tile-overlap`), also sent with per-job tiles.pub const VAE_TILE_OVERLAP: f32 = 0.125;/// Pixels per latent of Qwen-Image 2.1's VAE.@@ -1153,16 +1161,21 @@ pub fn plan(req: &GenerationRequest, inputs: &PlanInputs, rec: &RecommendedSetti};// The server's `--vae-tiling` is only a fallback on large GPUs: a decode within the// budget is sent with tiling turned off (only an explicit choice overrides).- let vae_tiling = adv.vae_tiling.unwrap_or(server_tiling || auto_tiling);- if vae_tiling && adv.vae_tiling.is_none() && !inputs.server_vae_tiling && !quick_upscale {+ // Vulkan tiles every decode (`VULKAN_VAE_TILE`).+ let vae_tiling = adv.vae_tiling.unwrap_or(inputs.vulkan || server_tiling || auto_tiling);+ if vae_tiling && adv.vae_tiling.is_none() && !inputs.server_vae_tiling && !inputs.vulkan && !quick_upscale {optimized = true;notes.push("Memory optimization enabled for this size.".into());}// Large discrete GPUs: decode tiles shaped to the image (fewer, larger tiles); others keep// the server's square tiles.let large_gpu = !inputs.unified_memory && inputs.vram_total_mib.map(|m| m as f64 / 1024.0 >= 15.0).unwrap_or(false);- let vae_tile = (vae_tiling && large_gpu && !quick_upscale && total_area > LARGE_GPU_VAE_TILE_AREA)- .then(|| vae_decode_tile(working.canvas, LARGE_GPU_VAE_TILE_AREA));+ let vae_tile = if inputs.vulkan {+ (vae_tiling && !quick_upscale).then_some((VULKAN_VAE_TILE, VULKAN_VAE_TILE))+ } else {+ (vae_tiling && large_gpu && !quick_upscale && total_area > LARGE_GPU_VAE_TILE_AREA)+ .then(|| vae_decode_tile(working.canvas, LARGE_GPU_VAE_TILE_AREA))+ };if (working.content.area() as f64) < output.area() as f64 * 0.98 && matches!(mode, ResolvedMode::Generate | ResolvedMode::Edit | ResolvedMode::MultiReference | ResolvedMode::Compose) {notes.push(format!("Rendered at {}×{}, then enlarged to {}×{} with {}.",@@ -1958,6 +1971,26 @@ mod tests {assert!(plan(&r, &big, &rec()).unwrap().vae_tile.is_none(), "tiling off");}+ #[test]+ fn vulkan_decodes_every_size_in_small_tiles() {+ let t = Some((VULKAN_VAE_TILE, VULKAN_VAE_TILE));+ for (quality, vram) in [(Quality::Fast, 12_282), (Quality::Fast, 16_303), (Quality::Quality, 16_303), (Quality::Quality, 24_560), (Quality::Fast, 32_607)] {+ let mut r = req("a lighthouse at dusk");+ r.quality = quality;+ for server_vae_tiling in [true, false] {+ let i = PlanInputs { vram_total_mib: Some(vram), vulkan: true, server_vae_tiling, ..inputs(&[]) };+ let p = plan(&r, &i, &rec()).unwrap();+ assert!(p.vae_tiling, "{quality:?} {vram}");+ assert_eq!(p.vae_tile, t, "{quality:?} {vram}: untiled or 1 MP tiles pass AMD's 2 GiB buffer limit");+ assert!(!p.notes.iter().any(|n| n.contains("Memory optimization")), "not a memory note on Vulkan");+ }+ }+ let mut r = req("a lighthouse at dusk");+ r.advanced.vae_tiling = Some(false);+ let i = PlanInputs { vram_total_mib: Some(16_303), vulkan: true, ..inputs(&[]) };+ assert!(plan(&r, &i, &rec()).unwrap().vae_tile.is_none(), "an explicit off is kept");+ }+#[test]fn estimate_matches_benchmarks_roughly() {// Benchmarks ran at CFG 6.diff --git a/crates/qls-core/src/process.rs b/crates/qls-core/src/process.rsindex 0b767ab..fdd60a1 100644--- a/crates/qls-core/src/process.rs+++ b/crates/qls-core/src/process.rs@@ -75,11 +75,11 @@ pub fn build_server_args(cfg: &AppConfig, profile: &ModelProfile) -> Vec<String>// Falls back to flash/default attention for layers it can't handle.a.push("--sage-attn".into());}- if cfg.vae_tile_size > 0 {+ if cfg.server_vae_tile_size() > 0 {a.extend(["--vae-tiling".into(),"--vae-tile-size".into(),- cfg.vae_tile_size.to_string(),+ cfg.server_vae_tile_size().to_string(),"--vae-tile-overlap".into(),"0.125".into(),]);@@ -930,6 +930,11 @@ mod tests {assert!(s.contains("--fa"));assert!(!s.contains("--sage-attn"), "SageAttention is CUDA only");assert!(s.contains("qwen_image_2_1_prefix_cache_type=q8_0"));+ assert!(s.contains("--vae-tiling --vae-tile-size 512 "), "the default 768 is capped: {s}");+ cfg.vae_tile_size = 256;+ assert!(build_server_args(&cfg, cfg.profile()).join(" ").contains("--vae-tile-size 256 "), "smaller tiles are kept");+ cfg.vae_tile_size = 0;+ assert!(!build_server_args(&cfg, cfg.profile()).join(" ").contains("--vae-tiling"), "off stays off");}#[test]diff --git a/crates/qls-service/src/api.rs b/crates/qls-service/src/api.rsindex 7890ea9..128dd28 100644--- a/crates/qls-service/src/api.rs+++ b/crates/qls-service/src/api.rs@@ -572,8 +572,8 @@ async fn diagnostics_json(State(s): St) -> ApiResult<Json<Value>> {};let _ = writeln!(text, "{label}: {} ({state})", p.display());}- let _ = writeln!(text, "Device: {}, text encoder: {:?}, VRAM reserve: {} GiB, flash attention: {}, sage attention: {} (in use: {})", cfg.device, cfg.text_encoder_placement, cfg.vram_reserve_gib, cfg.flash_attention, cfg.sage_attention, cfg.uses_sage_attention());- let _ = writeln!(text, "VAE tile size: {}, upscale tile size: {}", cfg.vae_tile_size, cfg.upscale_tile_size);+ let _ = writeln!(text, "Device: {}, text encoder: {:?}, VRAM reserve: {} GiB, flash attention: {}, sage attention: {} (in use: {})", cfg.effective_device(), cfg.text_encoder_placement, cfg.vram_reserve_gib, cfg.flash_attention, cfg.sage_attention, cfg.uses_sage_attention());+ let _ = writeln!(text, "VAE tile size: {} (engine: {}), upscale tile size: {}", cfg.vae_tile_size, cfg.server_vae_tile_size(), cfg.upscale_tile_size);let up = diagnostics::upscaler_check(&cfg);let model = cfg.upscaler().map(|u| u.0).unwrap_or_default();let tile = qls_core::planner::upscale_tile(cfg.upscale_tile_size, cfg.planning_vram_mib(gpus.as_ref().and_then(|g| g.first()).map(|g| g.planning_mib())), &model);diff --git a/src/components/Settings.tsx b/src/components/Settings.tsxindex b0a9440..2979a03 100644--- a/src/components/Settings.tsx+++ b/src/components/Settings.tsx@@ -634,6 +634,7 @@ export function Settings() {<span>VAE tile size (px, 0 = off)</span><input className="input" type="number" min={0} max={2048} step={128} style={{ width: 90 }} value={cfg.vaeTileSize} onChange={(e) => set({ vaeTileSize: Math.max(0, Math.round(Number(e.target.value) || 0)) })} /></label>+ {cfg.gpuBackend === "vulkan" && <span className="muted" style={{ marginTop: -10 }}>With Vulkan, images are decoded in tiles of 512 px at most: larger tiles exceed the driver's buffer limit on AMD cards and get much slower.</span>}<div className="field"><span>Edit prefix cache</span><Seg<string>