Image models such as FLUX show nothing until the last of many steps. mlx-taef is a set of tiny decoders, written for MLX on Apple Silicon, that turn the model's in-progress data (its latent) into a viewable picture at any step.
You need it if you generate images with mflux, the MLX image-generation tool, and want to watch them form.
- Preview an mflux generation every few steps.
- Decode in ~30 ms where the model's full decoder (its VAE) takes ~0.3 s (M1 Max, 512×512; TAEF1 2026-08-09, TAEF2 2026-09-17).
- Decode in a fraction of the full decoder's memory by calling the small decoder directly (
decode_flux_latent.py), not the preview. - Work with FLUX.1, FLUX.2 Klein, Z-Image, Qwen-Image, Krea 2 and Stable Diffusion (Variants).
pip install mlx-taefimport mlx.core as mx
from mlx_taef import TAEF2
taef = TAEF2.from_pretrained() # downloads + converts on first call
img = taef.decode(latents) # NHWC float in [0, 1]
img_uint8 = taef.decode_image(latents) # uint8 NHWC ready for PIL- Live previews or low-memory decode: this library.
- Faster generation itself:
mlx-teacache, which skips redundant denoising steps when the schedule is cacheable. Its benchmarks page has its figures. - Both: use them together. The benchmarks page has the measured combination.
pip install mlx-taef
# With the mflux preview callback:
pip install "mlx-taef[mflux]"Or with uv:
uv add mlx-taef
# With mflux:
uv add "mlx-taef[mflux]"Pin an exact version in a project that needs reproducibility:
pip install "mlx-taef==0.9.2"Verify the install:
mlx-taef --helpWhat to know before you install:
- Python 3.11 or newer, and Apple Silicon (
mlxitself runs only on Apple Silicon). Python 3.10 users stay on mlx-taef 0.8.4, or move to Python 3.11 or newer. - The first
from_pretrained()call, and creating aLivePreviewCallback, download the weights and convert them to MLX. Later calls reuse the cached copy. A failure during that download or conversion is not covered byon_error. - The base install pulls in no PyTorch. The
mfluxextra does, because mflux depends on it. In this repository,torchis used only to generate test fixtures. - The
mfluxextra accepts mflux 0.24 and every later release, with no upper bound. A CI job tests the newest mflux every Monday, and mlx-taef is changed only when something breaks. Tested up to mflux 0.24.0. - Pillow 13 or newer is required wherever mlx-taef needs Pillow; older releases are affected by GHSA-5x8w-8jj5-q52h.
Register LivePreviewCallback on an mflux model and it saves a preview image every every steps (FLUX.2 Klein shown):
from mflux.models.common.config.model_config import ModelConfig
from mflux.models.flux2 import Flux2Klein
from mlx_taef.integrations.mflux import LivePreviewCallback
model = Flux2Klein(quantize=4, model_config=ModelConfig.flux2_klein_base_4b())
preview = LivePreviewCallback(
flux=model, # the variant (here TAEF2) is inferred from the model; pass variant= to override
every=5,
save_to="preview.png",
# latent_height / latent_width are auto-detected from the generation config;
# pass both only if you want to override.
)
model.callbacks.register(preview)
model.generate_image(
prompt="a red apple on a wooden table",
num_inference_steps=25,
width=512,
height=512,
seed=42,
)What decides whether the picture is right:
flux=modelpicks the matching decoder from the model's mflux config (the FLUX.1, FLUX.2 Klein, Z-Image, Qwen-Image and Krea 2 families).variant=overrides it. A model outside those families raises when the callback is created, before the preview decoder loads, and names the override. Forcingvariant=on a model outside those families can give a wrong picture with no error.- TAEF2 decodes the latent exactly as mflux hands it to the callback. When you passed
flux=model, versions before 0.8.2 applied the Flux2 VAE's batch-norm inverse first, and previews came out dark and oversaturated. It is off by default;auto_bn=Truewithflux=model, or explicitbn_mean=/bn_var=, turn it on and log a warning. - A model that offers its prediction of the finished image (Krea 2 today) gets that decoded instead of the noisy in-loop latent.
preview_source="latents"turns this off. - If a preview fails, the callback by default logs one warning, stops previewing for that generation, and lets mflux finish the image. Pass
on_error="raise"to fail fast. The next generation starts previewing again. - Previews are approximate. mflux still makes the final image with its full decoder.
Frame-by-frame GIFs, the command that builds them, and how the callback picks its decoder and handles errors are on the mflux live previews page. EXAMPLES.md holds captured frames, final images and, for most models, the measured gain, with runnable scripts in examples/.
mlx-taef ports madebyollin's TAESD family of tiny autoencoders to MLX, plus a port of taew2.1 for Qwen-Image and Krea 2. All share one API.
| Variant | latent_channels | For | HF source |
|---|---|---|---|
TAESD |
4 | Stable Diffusion 1.x | madebyollin/taesd |
TAESDXL |
4 | Stable Diffusion XL | madebyollin/taesdxl |
TAEF1 |
16 | FLUX.1 | madebyollin/taef1 |
TAEF2 |
32 | FLUX.2 Klein | madebyollin/taef2 |
ZImage |
16 | Z-Image / Z-Image-Turbo (shares the FLUX.1 16-ch latent contract) | reuses madebyollin/taef1 |
QwenImage |
16 | Qwen-Image / Qwen-Image-Edit (Wan 2.1 VAE 16-ch latent) | ionden/taew2.1 |
Krea2 |
16 | Krea 2 Turbo (generates on the Qwen-Image stack, shares its Wan 2.1 VAE) | reuses ionden/taew2.1 |
v0.9.2 — released on PyPI (2026-11-15). Setting LivePreviewCallback.save_to to a string after the callback is created now works the same as passing it to the constructor. Older releases are in the release history.
- Benchmarks and the side-by-side images and timings in COMPARISON.md.
- Release history, the CHANGELOG and the ROADMAP.
- Research note: The latent in the callback is not the latent the decoder wants reads nine mflux image models and shows that a shared VAE does not mean a shared latent layout.
Questions and results go to GitHub Discussions; bugs go to Issues.
MIT. Mirrors upstream madebyollin/taesd license. Pretrained weights belong to their respective authors (madebyollin).
- madebyollin for the upstream TAESD-family models and weights.
- Apple ML Explore for MLX.
- mflux-community/mflux for the MLX-native FLUX runner this library integrates with.
Other MLX libraries for Apple Silicon:
- mlx-teacache — TeaCache residual caching to skip redundant FLUX denoising steps.
- mlx-model-doctor — validate an MLX / Hugging Face model repo before you load it (config, tokenizer, safetensors, memory).
- mlx-quant-fidelity — measure how much quality a quantization costs (KL divergence, top-token flips, perplexity delta).
By Denis Ineshin · ineshin.space
