LatentDragon F32C128

An arXiv paper is coming soon.

Inputs at 1024x1024, their reconstructions, and PCA views of the 32x32 latents

An image autoencoder with 32x downsampling and a 128-channel latent, trained with LatentDragon. Its API is the same as AutoencoderKL, so it can stand in for a diffusers VAE.

Downsampling 32x (256x256 image -> 8x8 latent, 1024x1024 -> 32x32)
Latent channels 128
Input / output RGB in [-1, 1], height and width multiples of 32
Parameters 82.0M: encoder 10.2M, decoder 71.8M
Compute at 256x256 encoder 9.4 GMACs, decoder 29.0 GMACs
Architecture LatentMaid blocks (depthwise 3x3 + SwiGLU), per-position layer norm, no attention

The network is fully convolutional and nothing in it reads a statistic of the whole image, so it runs at any resolution that is a multiple of 32.

Architecture

The encoder and decoder stages with their parameters and compute, and the LatentMaid block

Both parts are stacks of LatentMaid blocks. Each encoder stage starts by folding 2x2 pixels into channels and each decoder stage ends by unfolding them again, so the stage widths grow as the image shrinks. Depth goes where the image is small: 63M of the decoder's 72M parameters sit in its two lowest-resolution stages, while its compute is spread across the stages (about 6.5 GMACs in each of the three middle ones). The encoder holds 10M parameters in total.

The LatentMaid block replaces the standard block's two 3x3 convolutions with a depthwise 3x3 convolution for mixing space and a SwiGLU MLP for mixing channels, which together factorize the full convolution. Its norm acts on each position separately, so the network has no group norm and no attention.

Usage

The model class ships in this repo (modeling_latentdragon.py), so load it with trust_remote_code=True. It needs only torch and diffusers.

import torch
from diffusers import AutoModel

vae = AutoModel.from_pretrained("KBlueLeaf/LatentDragon-F32C128", trust_remote_code=True).eval()

x = torch.rand(1, 3, 1024, 1024) * 2 - 1               # image in [-1, 1]
with torch.no_grad():
    posterior = vae.encode(x).latent_dist              # DiagonalGaussianDistribution
    z = posterior.mode()                               # [1, 128, 32, 32]
    x_rec = vae.decode(z).sample                       # [1, 3, 1024, 1024]

encode returns AutoencoderKLOutput and decode returns DecoderOutput, the same as AutoencoderKL. The posterior is narrow (the KL weight was 1e-6), so use posterior.mode(). For fp16, run under torch.autocast("cuda", torch.float16); the output projection always runs in fp32.

Latent statistics

config.json stores statistics of the latent (the posterior mean) for normalising it before training a generative model: latents_mean and latents_std per channel, and latents_mean_all (-0.0005) and latents_std_all (0.932) over all channels. They were measured on the ImageNet validation set at 256 px.

mean = torch.tensor(vae.config.latents_mean).view(1, -1, 1, 1)
std = torch.tensor(vae.config.latents_std).view(1, -1, 1, 1)
z_norm = (z - mean) / std
z = z_norm * std + mean                                # before vae.decode

scaling_factor is 1.0; use the statistics above instead. The scale depends on the data, so latent_stats.json holds the same statistics for every evaluation set and size below:

Data Size Mean Std Per-channel std Largest value
ImageNet val (held out) 256 -0.0005 0.932 0.88 to 1.30 10.5
ImageNet val (held out) 512 -0.0123 0.864 0.78 to 1.34 9.0
Anime images, 50k (in-domain) 256 -0.0009 1.068 0.94 to 1.52 15.6
Anime images, 50k (in-domain) 512 -0.0044 0.953 0.76 to 1.60 11.8
LAION-COCO, 50k (in-domain) 256 +0.0003 0.960 0.83 to 1.77 12.1
LAION-COCO, 50k (in-domain) 512 -0.0032 0.874 0.72 to 1.83 11.3

Reconstruction

50,000 images per row. The short side is resized with bilinear (antialiased) and centre-cropped; the latent is the posterior mean; fp16. rFID is against the same resized images. The in-domain rows are images from the training sets whose short side is at least 512 px.

Data Size PSNR SSIM LPIPS (VGG) LPIPS (Alex) rFID
ImageNet val (held out) 256 28.38 0.808 0.103 0.038 0.30
ImageNet val (held out) 512 30.89 0.846 0.109 0.039 0.14
Anime images, 50k (in-domain) 256 29.71 0.924 0.047 0.021 0.47
Anime images, 50k (in-domain) 512 33.96 0.960 0.031 0.012 0.13
LAION-COCO, 50k (in-domain) 256 30.62 0.904 0.055 0.022 0.26
LAION-COCO, 50k (in-domain) 512 33.26 0.924 0.051 0.020 0.12

Most ImageNet validation images are smaller than 512 px, so that row upscales its inputs.

Efficiency

Encoder and decoder are charted separately. Compared with other public VAEs, the encoder is small (10M parameters, 9.4 GMACs at 256x256) and the decoder spends its parameters in the low-resolution stages, where they are cheap, so both run much faster than the others. Its rFID (0.30) is close to VA-VAE's (0.28), better than SD-VAE's, DC-AE's and Qwen-Image's, and behind the 8x FLUX VAEs (0.11 to 0.18).

Quality against speed. Throughput is measured here; rFID on ImageNet 256 is taken from the literature, with a bar for the range across sources (papers differ in checkpoint and protocol). Circle area is the parameter count.

rFID against throughput for the encoder and the decoder
rFID values and sources
Model rFID shown Range Sources
SD-VAE / SDXL-VAE f8c4 0.63 0.606 to 0.9 0.63: DC-AE Table 5 (arXiv 2410.10733), third-party; 0.90: LDM Table 8 (2112.10752), original kl-f8; 0.606: AToken Table 4 (2509.14476); 0.67: SDXL-VAE, EQ-VAE Table 12 (2502.09509)
FLUX.1 / SD3 VAE f8c16 0.176 0.15 to 0.21 0.176: FLUX.1, BFL blog Table 1 (own); 0.15-0.18: FLUX.1, five third-party tables; 0.19-0.21: SD3 VAE, EQ-VAE / AToken / LoopVAE / l-DeTok
FLUX.2 VAE f8c32 0.1124 0.1085 to 0.27 0.1124: BFL blog Table 1 (own); 0.1085: RoAR-VAE Table 2 (2610.26216); 0.27: Na-VAE community page
Qwen-Image VAE f8c16 1.459 1.32 to 1.459 1.459: AToken Table 4 (2509.14476), third-party; 1.32: Na-VAE community page; its own report gives PSNR/SSIM only
DC-AE f32c32 0.69 0.69 to 0.77 0.69: DC-AE Table 2 (2410.10733, own); 0.77: MAETok Table 4 (2502.03444), third-party
VA-VAE f16c32 0.28 0.26 to 0.29 0.28: VA-VAE Table 2 (2501.01423, own); 0.279-0.2892: AToken, REPA-E, PS-VAE, RoAR-VAE, MAETok tables

LatentDragon's rFID is from this card's own ImageNet 256 evaluation (bilinear resize). The arXiv numbers are from the papers named; third-party values come from other papers' comparison tables.

Speed, memory and compute. Every model was loaded from its released weights and measured under the same setup: fp16 autocast, channels-last, torch.compile, RTX 5090. Circle area is the GMACs at 256x256 (one multiply-add counted once, by torch's operator-level counter). SD-VAE, SDXL-VAE, FLUX.1 VAE and SD3 VAE share one network and appear as one circle. VA-VAE was built from its published architecture with random weights, since speed does not depend on the weights.

Peak memory against throughput for the encoder and the decoder, circle area the GMACs

The next figure has this model's own numbers at every size and batch, from an earlier run, so the 1024 px compiled speeds differ from the comparison by a few percent.

Speed and memory of this model

Throughput and peak memory of this model's encoder and decoder against the batch size, at 256, 512 and 1024 px, compiled and eager. 1024 px at batch 64 does not fit in 32 GB.

Throughput and peak memory against batch size at three resolutions
The same numbers as a table

RTX 5090, fp16 autocast, channels-last. Images per second, with the peak memory in GiB in brackets. The weights alone take 0.31 GiB. "Compiled" is torch.compile with default settings.

Size Batch Encode Decode Encode, compiled Decode, compiled
256 1 224 (0.4) 118 (0.5) 500 (0.4) 268 (0.4)
256 4 841 (0.5) 403 (0.8) 1,832 (0.5) 888 (0.6)
256 16 1,876 (1.0) 632 (1.7) 3,601 (0.8) 978 (1.3)
256 64 1,738 (2.9) 588 (5.5) 3,337 (2.4) 964 (4.3)
512 1 223 (0.5) 119 (0.8) 398 (0.5) 234 (0.6)
512 4 462 (1.0) 156 (1.7) 984 (0.8) 275 (1.3)
512 16 433 (2.9) 147 (5.5) 899 (2.4) 274 (4.3)
512 64 422 (10.5) 145 (20.7) 887 (8.5) 277 (16.5)
1024 1 121 (1.0) 40 (1.7) 261 (0.8) 75 (1.3)
1024 4 108 (2.9) 35 (5.5) 231 (2.4) 72 (4.3)
1024 16 105 (10.5) 35 (20.7) 230 (8.5) 75 (16.5)
1024 64 out of memory out of memory out of memory out of memory

Examples

The figure at the top shows whole images scaled down. These are crops at full resolution from the same 1024x1024 inputs and reconstructions:

1:1 crops of the inputs and their reconstructions

Full-size files, each with input, reconstruction and the latent's PCA view side by side:

Sample 256 512 1024 Latent PCA at 2048
great wave 256 512 1024 2048
aldrin 256 512 1024 2048
pearl earring 256 512 1024 2048
starry night 256 512 1024 2048
earth 256 512 1024 2048

Latent PCA

The latent row of the teaser looks coarse because there is little to look at: a 1024x1024 image is only 32x32 latent cells. The same images at 2048x2048 give 64x64 cells, and the content is much easier to read:

PCA views of the latent at 1024 and 2048 px

Each view shows the three leading PCA directions of that image's latent as RGB, one square per latent cell, with the directions fitted at 2048 px and reused at 1024. Three directions hold under a tenth of a latent's variance, so a view shows where the latent changes, not everything it stores.

Training

  • Data: a 20M anime image dataset, LAION-COCO and COYO-HD-11M, random 256x256 crops.
  • Objective: MSE (1.0), LPIPS-VGG (0.1) and DINOv3 ViT-B features (250), both perceptual terms with a random shift of up to 16 px, and a KL of 1e-6.
  • Schedule: 200,000 steps at batch 256. From step 50,000 a PatchGAN critic joins with hinge loss and the adaptive weight, and the encoder is frozen, so the latent no longer moves while the decoder sharpens.
  • Optimization: Adam, learning rate 2e-3 under the DragonScale weight patch (unit-row weights), flat to step 150,000 then cosine decay; fp16 mixed precision; weight EMA 0.999. These are the EMA weights at step 200,000, with the patch baked back into plain weights.

The recipe is configs/ae/recipes/latentdragon/f32c128.py in the LatentDragon repository.

Loading with LatentDragon

With LatentDragon installed, the same folder loads as a full LatentDragon model (training, tiled decoding):

from latentdragon.io.hf import from_pretrained

model = from_pretrained("KBlueLeaf/LatentDragon-F32C128")

Limitations

  • Trained on 256x256 crops only. Larger sizes work and are evaluated above up to 512 px.
  • The latent is not regularised toward any semantic structure.
  • The remote code reimplements LatentDragon's inference path and matches it exactly on the released weights.
Downloads last month
-
Safetensors
Model size
82M params
Tensor type
F32
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support