flux2-swift-mlx

Generate images with Flux.2 models on Apple Silicon using Swift and MLX.

40|15|Updated Jan 17, 2026
One-click install
npx skills add https://github.com/VincentGourbin/flux-2-swift-mlx --skill flux2-swift-mlx-vincentgourbin
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: flux2-swift-mlx
Source: https://github.com/VincentGourbin/flux-2-swift-mlx
Command: npx skills add https://github.com/VincentGourbin/flux-2-swift-mlx --skill flux2-swift-mlx-vincentgourbin

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Running Flux.2 image generation models locally on Apple Silicon Macs requires a native Swift implementation with careful memory management, since models range from 4B to 32B parameters and can exceed available RAM without quantization. ## Core Features & Use Cases - Text-to-Image and Image-to-Image Generation: Generate images from prompts or transform reference images with configurable strength, supporting Klein 4B, Klein 9B, and Dev 32B models. - On-the-fly Quantization: Reduce transformer memory by 47% (qint8) or 72% (int4) so large models fit on 16-96 GB Macs, with a two-phase loading architecture that never holds the text encoder and transformer in memory simultaneously. - LoRA Support and Training: Load LoRA adapters for style transfer or train custom LoRAs on Apple Silicon with gradient checkpointing and YAML configuration. - Use Case: An iOS/macOS developer adds local image generation to a SwiftUI app by integrating the Flux2Core Swift package, selecting Klein 4B with qint8 quantization to generate 1024x1024 images in about 28 seconds on a 16 GB Mac. ## Quick Start Add the flux-2-swift-mlx Swift package to my project and generate a 1024x1024 image from a text prompt using the Klein 4B model with balanced quantization.

Frequently Asked Questions about flux2-swift-mlx

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I generate images with Flux.2 in Swift on a Mac?

Add the flux-2-swift-mlx Swift package, create a Flux2Pipeline with a model like .klein4B, call loadModels(), then call generateTextToImage with your prompt, dimensions, steps, and guidance. Klein 4B uses 4 steps and guidance 1.0, generating a 1024x1024 image in about 28 seconds.

Which Flux.2 model should I use for my Mac's RAM?

Klein 4B with int4 quantization fits in 8-16 GB RAM, Klein 9B with qint8 needs 24-32 GB, and Dev 32B requires 32 GB at int4 or 64 GB at qint8. The Flux2MemoryManager can recommend a configuration automatically based on system RAM.

Does Flux.2 Swift MLX support LoRA training on Apple Silicon?

Yes, it supports LoRA training on Klein 4B, Klein 9B, and Dev models using SimpleLoRATrainer or a YAML config with the flux2 train-lora CLI command. Enable gradient checkpointing to reduce activation memory by roughly 50% at the cost of slower training.

Can I use multiple reference images for image-to-image generation?

Yes, image-to-image supports up to 4 reference images for Klein models and 6 for Dev. Multi-image conditioning combines elements from references, while single-image mode uses a strength parameter from 0.0 to 1.0 to control how much of the original is preserved.

Why does Flux.2 generation run out of memory on my Mac?

Out-of-memory errors occur when quantization is too light for available RAM or image resolution is too high. Use more aggressive presets like .ultraMinimal, reduce dimensions to 512x512, or set memoryOptimization to .aggressive for periodic cache clearing during denoising.

Does quantization make Flux.2 image generation faster?

No, quantization reduces memory usage but not step time, since denoising is large-GEMM-bound rather than memory-bandwidth-bound. Measured on Klein 9B, qint8 steps are not faster than bf16; quantization buys memory headroom, not speed.