Skip to content

armgit / kokon

Public Imported from GitHub
0

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.

Macs render Fast at 1 MP directly

Gabriele Lozupone438ed8372b7b
diff --git a/crates/qls-core/src/planner.rs b/crates/qls-core/src/planner.rs
index 556984e..7c18159 100644
--- a/crates/qls-core/src/planner.rs
+++ b/crates/qls-core/src/planner.rs
@@ -127,7 +127,7 @@ pub const MAX_UPSCALE_AREA: u64 = 40_000_000;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum Quality {
- /// ~1 MP (768² on Apple Silicon, then enlarged). Older versions' "turbo" maps here.
+ /// ~1 MP. Older versions' "turbo" maps here.
#[default]
#[serde(alias = "turbo")]
Fast,
@@ -335,8 +335,8 @@ pub struct PlanInputs {
/// Without a measurement, report `estimated_seconds` = 0 (unknown until the first image)
/// instead of the uncalibrated model, which only fits the hardware it was measured on.
pub hide_uncalibrated: bool,
- /// Apple Silicon (unified memory): the GPU is several times slower than the discrete
- /// cards the presets were tuned on, so Fast renders smaller (`UNIFIED_FAST_AREA`).
+ /// Apple Silicon (unified memory). Fast renders its full size here too: 768² plus the
+ /// upscaler took longer than 1 MP directly on an M2 Pro (5 min 25 s vs 4 min 20 s, 2026-10-10).
pub unified_memory: bool,
}
@@ -529,11 +529,6 @@ pub fn unified_memory_planning_mib(ram_mib: u64, text_encoder_mib: u64) -> u64 {
gpu_share.saturating_sub(text_encoder_mib)
}
-/// Working area of Fast (Auto resolution) on Apple Silicon. Sampling time grows faster than
-/// the area, so 768² takes well under half of 1 MP; the upscaler model then enlarges the
-/// result to the size Fast would have rendered.
-pub const UNIFIED_FAST_AREA: u64 = 768 * 768;
-
pub const PIXELS_PER_TOKEN: u64 = 256; // 8x VAE downscale, 2x2 patches
/// The noise schedule of every diffusion job: `sample_sigmas` of Qwen/Qwen-Image-2.1-Turbo's model_index.json
@@ -706,8 +701,6 @@ pub fn plan(req: &GenerationRequest, inputs: &PlanInputs, rec: &RecommendedSetti
let mut steps = TURBO_STEPS;
let batch_count = if mode == ResolvedMode::Upscale { 1 } else { adv.batch_count.unwrap_or(1).clamp(1, 8) };
let mut optimized = false;
- // Largest area actually rendered; the output keeps its size and is enlarged afterwards.
- let render_cap = (inputs.unified_memory && quality == Quality::Fast && req.resolution == ResolutionMode::Auto).then_some(UNIFIED_FAST_AREA);
// Diffusion always runs in one pass; larger outputs are enlarged with the upscaler
// model (user A/B test, 2026-10-06: the two-pass refine made results worse).
let mut upscale = None;
@@ -781,8 +774,7 @@ pub fn plan(req: &GenerationRequest, inputs: &PlanInputs, rec: &RecommendedSetti
let wanted = tier_area.unwrap_or(rec.area_balanced);
let area = cap_for_refs(wanted, 0.0, &mut notes);
let size = size_for_aspect(aspect, area, rec);
- let render = render_cap.map_or(size.area(), |c| c.min(size.area()));
- working = plan_working_canvas(size, &limits(render, rec));
+ working = plan_working_canvas(size, &limits(size.area(), rec));
output = size;
}
}
@@ -818,10 +810,7 @@ pub fn plan(req: &GenerationRequest, inputs: &PlanInputs, rec: &RecommendedSetti
let area = cap_for_sources(wanted, &inputs.image_sizes, &mut notes);
sources_reduced = area < wanted;
let full = plan_working_canvas(target, &limits(area, rec));
- working = match render_cap {
- Some(c) if c < area => plan_working_canvas(target, &limits(c, rec)),
- _ => full,
- };
+ working = full;
for (i, s) in inputs.image_sizes.iter().enumerate() {
let c = if i == 0 && *s == target { working } else { ref_canvas(*s, working.canvas.area(), rec) };
references.push(RefPlan { index: i, source: *s, canvas: c });
@@ -1047,25 +1036,16 @@ mod tests {
}
#[test]
- fn mac_fast_renders_smaller_and_keeps_the_output_size() {
+ fn mac_fast_renders_the_full_size() {
let mac = |sizes: &[(u32, u32)]| PlanInputs { unified_memory: true, vram_total_mib: Some(4600), upscaler: Some("4x-UltraSharp".into()), ..inputs(sizes) };
let mut r = req("a lighthouse at dusk");
r.quality = Quality::Fast;
let p = plan(&r, &mac(&[]), &rec()).unwrap();
- assert_eq!(p.output, Size::new(1024, 1024), "same output as Fast on a PC");
- assert_eq!(p.working, Size::new(768, 768));
- assert!(p.notes.iter().any(|n| n.contains("enlarged")));
- // Edits too: smaller render, source size kept.
+ assert_eq!((p.output, p.working), (Size::new(1024, 1024), Size::new(1024, 1024)), "no smaller render + upscale");
+ assert!(p.upscale.is_none());
let p = plan(&r, &mac(&[(1024, 768)]), &rec()).unwrap();
assert_eq!(p.output, Size::new(1024, 768));
- assert!(p.working.area() <= UNIFIED_FAST_AREA + 32 * 1024, "{:?}", p.working);
- // Other qualities, explicit sizes and PCs are unchanged.
- r.quality = Quality::Balanced;
- assert_eq!(plan(&r, &mac(&[]), &rec()).unwrap().working, Size::new(1024, 1024), "budget-capped 1 MP");
- r.quality = Quality::Fast;
- assert_eq!(plan(&r, &inputs(&[]), &rec()).unwrap().working, Size::new(1024, 1024));
- r.resolution = ResolutionMode::K1;
- assert_eq!(plan(&r, &mac(&[]), &rec()).unwrap().working, Size::new(1024, 1024));
+ assert!(p.upscale.is_none());
}
#[test]
diff --git a/docs/engineering-notes.md b/docs/engineering-notes.md
index 15355a7..83a22ab 100644
--- a/docs/engineering-notes.md
+++ b/docs/engineering-notes.md
@@ -116,8 +116,9 @@ Whenever a result is larger than what the model rendered (edits restored to the
outpaint, sizes above the VRAM budget) it is enlarged with ESRGAN ×4 and then resized down to
the exact size; Lanczos is only used for shrinking or factors below 1.1×.
-On Apple Silicon, Fast at Auto resolution renders at most 768² (`planner::UNIFIED_FAST_AREA`)
-and is enlarged to the 1 MP output, because Mac GPUs are several times slower.
+Apple Silicon renders Fast at its full ~1 MP like a PC. Rendering 768² and enlarging it was
+removed on 2026-10-10: on the M2 Pro 16 GB it took 5 min 25 s against 4 min 20 s for a direct
+1376×768 render (the ESRGAN pass on Metal costs more than the smaller render saves).
### Turbo (the only image model since 2026-10-09)
diff --git a/docs/platforms.md b/docs/platforms.md
index 9c9124d..fd536d4 100644
--- a/docs/platforms.md
+++ b/docs/platforms.md
@@ -8,7 +8,7 @@ so model behaviour is identical everywhere; only speed and memory differ.
| --- | --- | --- |
| Windows + NVIDIA | CUDA 12 build | ✅ verified (RTX 5070 Ti 16 GB, RTX 5070 12 GB) |
| Windows + AMD / Intel | Vulkan build (30 MB, uses the driver's Vulkan runtime) | 🟡 beta: works on NVIDIA (RTX 5070 Ti, 2K/20 steps, slower than CUDA); AMD / Intel to verify |
-| macOS + Apple Silicon | Metal build (universal binary, shaders embedded) | 🟡 beta: packaged 0.9.0 runs on an M2 Pro 16 GB (1024² in ~10 min, 512² in ~2 min, lightest mode) |
+| macOS + Apple Silicon | Metal build (universal binary, shaders embedded) | 🟡 beta: packaged 0.9.0 runs on an M2 Pro 16 GB (Turbo: ~1 MP in ~4 min 20 s, lightest mode) |
| Windows + AMD via ROCm | ROCm build | ✗ not planned: open crashes (#2008), DLL conflicts (#2012), black images with k-quants (#1385) |
| Linux | Vulkan / CUDA builds exist | later |
@@ -50,7 +50,7 @@ pass. Kokon uses CFG 1, which is one pass per step.
| --- | --- | --- |
| **Chip** | Apple M1 or newer (Intel Macs: no) | M-series Pro / Max / Ultra |
| **macOS** | 26 Tahoe (the engine binary's minimum) | latest |
-| **Unified memory** | 16 GB: works, but slowly (lightest mode, ~1 MP, ~10 min on an M2 Pro) | 32 GB+ (everything stays loaded, Quality 2K) |
+| **Unified memory** | 16 GB: works, but slowly (lightest mode, ~1 MP, ~4–5 min on an M2 Pro) | 32 GB+ (everything stays loaded, Quality 2K) |
| **Disk** | 15 GB free | 25 GB on the internal SSD |
16 GB Macs run in the lightest setup: 1 MP, with each model's weights loaded when it runs and
@@ -58,10 +58,10 @@ released afterwards. That costs only a few seconds per image; the GPU compute is
slow (on the M2 Pro 16 GB with the packaged 0.9.0: 512² ~2 min, 1024² ~10 min). The setup
screen says so before downloading, and recommends 32 GB and a Pro/Max/Ultra chip.
-**Fast on a Mac renders smaller** (2026-10-09): on unified memory, Fast at Auto resolution
-renders at most 768² (`planner::UNIFIED_FAST_AREA`) and the upscaler model enlarges the result
-to the size Fast renders on a PC (1 MP). Sampling cost grows faster than the area, so this is
-well under half the sampling time. Balanced, Quality and explicit sizes are unchanged.
+**Fast on a Mac renders 1 MP directly** (2026-10-10). From 2026-10-09 Fast rendered 768² and
+the upscaler enlarged it, but on the M2 Pro 16 GB with Turbo that took 5 min 25 s, against
+4 min 20 s for rendering 1376×768 directly: the ESRGAN pass on Metal costs more than the
+smaller render saves. So Macs now render like PCs.
### Why macOS paging does not help here (verified in the source, 2026-10-09)
@@ -166,9 +166,10 @@ so nobody with a base chip is surprised.
### Speed roadmap for Macs
1. ✅ **Turbo**: Qwen's official 8-step model, the only image model since 2026-10-09; the
- largest gain on every platform. See the Turbo notes in `docs/engineering-notes.md`. Mac speed not measured yet.
+ largest gain on every platform. See the Turbo notes in `docs/engineering-notes.md`. M2 Pro 16 GB:
+ about 4 min 20 s for a 1376×768 image.
2. ✅ Honest requirements: 16 GB works but slowly; 32 GB+ and a Pro/Max/Ultra chip recommended.
-3. ✅ Fast renders at 768² on Macs and enlarges (above).
+3. ❌ Rendering Fast at 768² and enlarging: slower than 1 MP directly, removed (above).
4. **Later: an MLX engine.** Apple's MLX framework (through [mflux](https://github.com/filipstrand/mflux))
may be faster than ggml's Metal backend; a community 4-bit MLX build of Qwen-Image 2.1
exists (about 6.7 s/step at 768² on an M1 Max, ~7 GB peak; ~78 s per 1024² image on an
diff --git a/src/components/Setup.tsx b/src/components/Setup.tsx
index 1d41f00..f470b52 100644
--- a/src/components/Setup.tsx
+++ b/src/components/Setup.tsx
@@ -213,7 +213,7 @@ export function Setup() {
{hw.gpu?.unified ? (
hw.gpu.memory_total_mib < 23 * 1024 ? (
<div className="setup-note">
- With {gb(hw.gpu.memory_total_mib)} of unified memory Kokon works, but slowly: model weights are read from disk as needed and images are made at about 1 megapixel, which took about 10 minutes on an M2 Pro. Fast renders smaller and enlarges the result, so it is quicker. 32 GB or more and a Pro, Max or Ultra chip are recommended. Close other apps while generating.
+ With {gb(hw.gpu.memory_total_mib)} of unified memory Kokon works, but slowly: model weights are read from disk as needed and images are made at about 1 megapixel, which takes about 4 to 5 minutes on an M2 Pro. 32 GB or more and a Pro, Max or Ultra chip are recommended. Close other apps while generating.
</div>
) : (
hw.gpu.memory_total_mib < 31 * 1024 && (