Skip to content

Apple Silicon MLX backend

AIsketcher 0.5.0 adds a native Apple Silicon Metal/MLX backend (MlxFluxBackend) for four-step FLUX.2 [klein] 4B reference-image editing via mflux, alongside Apple Silicon MPS support for the restored dreamshaper-canny@1 and juggernaut-xl-canny@1 Canny ControlNet presets.

Both mlx and mflux are imported lazily only when a real MLX model load runs, so the base aisketcher package continues to install and run model-free tests on Linux, Windows, and CI hosts without Apple Silicon dependencies.

Install on Apple Silicon

Install the mlx extra on macOS arm64 (Apple Silicon, Python 3.11+ required by mflux):

python -m pip install "aisketcher[mlx]==0.5.0"

The mlx extra installs mlx>=0.32,<1 (macOS arm64) and mflux>=0.24,<1 (macOS arm64, Python >=3.11). On Python 3.10, upgrade to Python 3.11+ before using MlxFluxBackend.

To combine native MLX editing, Diffusers Canny ControlNet presets (dreamshaper-canny@1, juggernaut-xl-canny@1), and the local Gradio Studio:

python -m pip install "aisketcher[local,mlx,demo]==0.5.0"
aisketcher init --preset mlx-flux2-klein-edit@1 --device mlx
aisketcher studio

Preset and cache reuse with PresetManager

The curated MLX preset is mlx-flux2-klein-edit@1 (aliases: mlx, mlx-flux):

Field Value
Preset ID mlx-flux2-klein-edit@1
Pinned repository black-forest-labs/FLUX.2-klein-4B
Immutable revision e7b7dc27f91deacad38e78976d1f2b499d76a294
License Apache-2.0 (public, ungated)
First download 15.98 GB (15,980,131,531 bytes)
Control mode reference-image (not Canny ControlNet)
Resolved defaults 4 steps · guidance 1.0 · flow-match-euler · max 1024×1024
Default quantization 4-bit via Studio.from_preset("mlx-flux2-klein-edit@1")

mlx-flux2-klein-edit@1 reuses PresetManager policy v2 (pinned-commit-and-runtime-sha256-v2): every selected configuration, tokenizer, index, and SafeTensors payload is verified by SHA-256 before loading, and process-local stat receipts avoid rehashing an unchanged cache within the same process.

Because mlx-flux2-klein-edit@1 pins the exact same FLUX.2-klein-4B commit directory as flux2-klein-edit@1—and omits the separate FLUX.2-small-decoder snapshot—an existing verified FLUX.2-klein-4B cache is reused directly with zero extra download and zero Hugging Face Hub network calls in local_files_only=True mode.

Python workflow: 4-bit default and 8-bit option

Studio.from_preset("mlx-flux2-klein-edit@1", ...) configures 4-bit quantization automatically and resolves the verified local directory from PresetManager:

from aisketcher import Intent, PresetManager, SeedPlan, Studio

preset = "mlx-flux2-klein-edit@1"
models = PresetManager()
plan = models.plan_install(preset)
print(plan.download_bytes, plan.license_notice)

if not plan.installed:
    models.install(preset, confirm=True)

studio = Studio.from_preset(preset, preset_manager=models)
prepared = studio.prepare("sketch.png", max_side=768)

study = studio.explore(
    prepared,
    intent=Intent(
        prompt="A vibrant miniature fantasy kingdom made of layered paper craft",
        profile="graphic_design",
        structure="balanced",
    ),
    outputs=4,
    seed_plan=SeedPlan.scout(4),
)

selected = study.pick(0)
variations = studio.vary(
    selected,
    outputs=2,
    strength="subtle",
    locks=("structure",),
)
variations.export("mlx-design-study")
report = studio.replay("mlx-design-study/manifest.json", mode="strict")
assert not report.drift

8-bit quantization option

To run 8-bit precision explicitly (higher weight fidelity at higher peak MLX memory and per-image latency), construct MlxFluxBackend with quantize=8 and pass it to Studio:

from aisketcher import (
    MlxFluxBackend,
    MlxFluxModelConfig,
    MlxFluxSettings,
    PresetManager,
    Studio,
    get_preset,
)

models = PresetManager()
preset_def = get_preset("mlx-flux2-klein-edit@1")
base_model = preset_def.models[0]

backend = MlxFluxBackend(
    model=MlxFluxModelConfig(
        repo_id=base_model.repo_id,
        revision=base_model.revision,
        base_path=models.model_destination(base_model),
        quantize=8,
    ),
    settings=MlxFluxSettings(
        num_inference_steps=4,
        guidance_scale=1.0,
        quantize=8,
    ),
    local_files_only=True,
)
studio = Studio(backend, preset=preset_def.name, preset_manager=models)

Outputs execute sequentially with mx.clear_cache() and garbage collection between seeds (cleanup_between_outputs=True) so unified memory stays bounded and every seed remains deterministically replayable. Cooperative cancellation is supported at step and output boundaries via backend.request_cancel(), which raises MlxGenerationCancelled.

Measured Apple Silicon benchmarks (Apple M6 · 24 GB · Metal 4)

All measurements below were collected on real hardware—no estimates or extrapolations:

  • Hardware: Apple M6 (Mac18,5, 12-core GPU, 24 GB Unified Memory, Metal 4)
  • Software: macOS Darwin 27.0.0 · Python 3.12.15 · torch 2.15.0 · diffusers 0.43.0 · mlx 0.32.5 · mflux 0.24.0
  • Workload: docs/assets/pocket-kingdom/source.png prepared at 768×576, Canny 140/160, heritage seed 6764547109648557242 + 4-seed scout (6764547109648557242, 6854547109648557242, 6634547109688557242, 6764547109648557243) + 2 subtle structure-locked variations + Studio.replay(..., mode="strict")
Preset Backend / Device Download Steps / Precision Cold + 1st Warm (per image) Vary (per image) Peak Memory Strict Replay
dreamshaper-canny@1 Diffusers / MPS 3.58 GB 35 steps PNDM · fp16 + fp32 VAE 46.2 s 35.7 s (4 imgs: 142.6 s) 19.3 s 2.86 GB peak RSS Pass (0 drift)
mlx-flux2-klein-edit@1 (4-bit, default) MFLUX / MLX Metal 4 15.98 GB 4 steps FlowMatch · 4-bit 240.3 s* 61.6 s (denoise 28–36 s; 4 imgs: 246.5 s) 55.7 s 10.10 GB MLX peak (2.78 GB RSS) Pass (0 drift)
mlx-flux2-klein-edit@1 (8-bit) MFLUX / MLX Metal 4 15.98 GB 4 steps FlowMatch · 8-bit 81.5 s 97.7 s (4 imgs: 390.7 s) 82.0 s 11.61 GB MLX peak (2.78 GB RSS) Pass (0 drift)
juggernaut-xl-canny@1 Diffusers / MPS 9.44 GB 30 steps UniPC · fp16 + fp32 VAE 33.0 s (1 img) Single-image recommended on 24 GB MPS** — — Pass

* 4-bit cold time includes first-ever Metal shader compilation and on-load 4-bit quantization; subsequent runs use the compiled cache (see the 8-bit 81.5 s cold load).

** On 24 GB MPS, per-seed MPS pipeline reload isolation can pressure 24 GB unified memory on multi-seed runs; use dreamshaper-canny@1 or mlx-flux2-klein-edit@1 for fast multi-seed Apple Silicon scouting, and juggernaut-xl-canny@1 on CUDA or single-image MPS renders.

Choosing between dreamshaper-canny@1 and mlx-flux2-klein-edit@1 on Apple Silicon

  • Choose dreamshaper-canny@1 when you want fast multi-seed Canny line locking (35.7 s/image warm, 19.3 s/variation, 2.86 GB RSS) and a compact 3.58 GB download.
  • Choose mlx-flux2-klein-edit@1 (4-bit default) when you want modern four-step semantic reference-image editing natively on Apple Silicon without CUDA, using 10.10 GB MLX peak memory and 61.6 s/image warm.

Visual QA galleries (Apple M6 · Metal 4)

All visual QA sheets below are real locally generated outputs recorded in docs/assets/v05-quality-qa/provenance.json.

Five-panel heritage seed comparison (6764547109648557242)

Five-panel side-by-side comparison at seed 6764547109648557242: Input Sketch, 2023 Lykon/DreamShaper, v0.2–v0.4 SDXL Base regression, v0.5 DreamShaper 8 Canny, and v0.5 MLX FLUX.2 4-bit

Left to right: Input Sketch · 2023 Lykon/DreamShaper reference · v0.2–v0.4 raw sdxl-base-1.0 regression · v0.5 dreamshaper-canny@1 · v0.5 mlx-flux2-klein-edit@1 (4-bit MLX).

Four-seed MLX FLUX.2 Klein 4-bit scout

Four-seed scout generated with mlx-flux2-klein-edit@1 4-bit on Apple M6 Metal 4

mlx-flux2-klein-edit@1 (4-bit default) · 4 explicit seeds (6764547109648557242, 6854547109648557242, 6634547109688557242, 6764547109648557243) · 4 steps FlowMatch · 246.5 s total (61.6 s/image warm) · Strict Replay Pass (0 drift).

Four-seed DreamShaper 8 Canny scout

Four-seed scout generated with dreamshaper-canny@1 on Apple M6 MPS

dreamshaper-canny@1 (Restored Classic Structure) · same 4 explicit seeds · 35 steps PNDM · 142.6 s total (35.7 s/image warm) · Strict Replay Pass (0 drift).

Next