Reconstruction vs. Generation: Taming Optimization Dilemma in Latent Diffusion Models
- Publication
- CVPR 2025Conference
- First submitted to arXiv
- arXiv:2501.01423
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{imagegenerationvavae2025,
title = {{Reconstruction vs. Generation: Taming Optimization Dilemma in Latent Diffusion Models}},
author = {Jingfeng Yao and Bin Yang and Xinggang Wang},
year = {2025},
eprint = {2501.01423},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2501.01423}
}
Take a VAE with 16× spatial compression and raise the channels per position from 16 to 64, and reconstruction rFID drops from 0.49 to 0.17, with small text and faces coming out much sharper.
Train a diffusion model of the same size on each of these three VAEs, with the same amount of training, and generation FID goes from 16.24 to 36.83.
Reconstruction gets better and generation gets worse. The same oddity turned up in the tables of the previous note, DC-AE. The 16-channel FLUX autoencoder is widely acknowledged as a strong reconstructor, yet a DiT trained on it had an FID more than twice as bad as with the 4-channel SD-VAE. Readers pressed for the reason in the issues, and the authors replied with a single line, "better autoencoder reconstruction performance does not necessarily translate to better diffusion generation performance."
This paper comes from Xinggang Wang's group at Huazhong University of Science and Technology. It calls the phenomenon the optimization dilemma of latent diffusion models and sets out to answer why high-dimensional latent spaces are hard to generate in, and whether reconstruction and generation can both be good. The authors' approach is to make the latent space follow a frozen DINOv2 while the VAE trains, and they name the result VA-VAE (Vision foundation model Aligned VAE). To test quickly enough, they also tuned DiT into a much faster-converging version along the way, called LightningDiT.
Defining the problem
Reading the specs first
The paper describes tokenizers with f and d. f is the spatial downsampling factor and d the number of channels per position. For a 256×256 image:
- f16d16 compresses it to 16×16×16, 4,096 numbers in all;
- f16d32 compresses it to 16×16×32, 8,192 numbers in all;
- f16d64 compresses it to 16×16×64, 16,384 numbers in all.
Stable Diffusion's SD-VAE is f8d4, 32×32×4, also 4,096 numbers, just with 4 times as many positions. The diffusion models in this paper all use patch size 1, so each position is one token, and a 256×256 image corresponds to 256 tokens. The authors say this follows the same idea as DC-AE, handing all of the compression to the tokenizer.
The larger d is, the more information each token can carry, and the better the reconstruction. That's also why SD3 and FLUX raised the channel count from 4 to 16.
The dilemma

Start with the gray dashed line. From d16 to d64 the points keep moving right, so reconstruction keeps improving; at the same time they keep dropping, so generation keeps getting worse. The generators are all the same LightningDiT-B, trained for 160 epochs, and the vertical axis is FID computed from 10,000 generated images (FID-10K).
The paper points out that systems at the time could only have one or the other.
The first route is to scale up the diffusion model. SD3's experiments showed that a high-dimensional tokenizer paired with a large enough model ends up generating better, but at a much higher training cost. The second route is to deliberately limit the tokenizer's reconstruction ability (for example by keeping the dimension low) so that the diffusion model converges fast, at the price of a detail ceiling set by the tokenizer; the paper puts SANA and the DC-AE it uses in this category too.
What goes wrong in high dimensions
The authors found an analogy on the discrete-tokenizer side. Enlarge the codebook of a model like VQGAN, and reconstruction improves, but many codes go unused, codebook utilization drops, and the autoregressive model downstream actually has a harder time learning.
A continuous VAE has no codebook, but the authors ran a dimensionality-reduction visualization of the d16, d32 and d64 latent features and saw that the higher the dimension, the more the distribution bunches up in a few high-density regions instead of spreading out. From this they infer that the trouble comes from "the inherent difficulty of learning unconstrained high-dimensional latent spaces from scratch," and what the diffusion model receives is a distribution whose shape is hard to learn.
Then why not simply initialize the VAE encoder with DINOv2's weights? The paper cites earlier attempts saying this doesn't work, and the authors said in an issue that they had tried it too; reconstruction training quickly washes out whatever properties the initialization brought. So alignment can't be done once at the starting point; it has to go into the loss function and keep pulling throughout training.
Solving the problem
An ordinary KL-VAE
The skeleton of VA-VAE follows the LDM recipe to the letter. The network structure comes from VQGAN with the quantization removed, replaced by continuous Gaussian latent variables regularized by a KL term. In the official f16d32 configuration, the base channel count is 128, with four downsamplings taking 256×256 to 16×16; the encoder outputs 64 channels, the first 32 the mean and the last 32 the log variance, and the reparameterization trick samples a 16×16×32 from them.
The loss is LDM's set too. Pixel L1 plus the LPIPS perceptual loss handle reconstruction; the KL term's weight is , so small it is little more than a formality; a PatchGAN discriminator joins at step 5,001, with its weight computed the adaptive way VQGAN does it.
DC-AE, the note before this one, dropped the KL term altogether. Here it stays, but a weight of can't pull anything anywhere. What really shapes the latent space is the next term.
VF loss

Let's follow one 256×256 image through.
The upper path is the KL-VAE from before, which gives a 16×16×32 .
The lower path resizes the same image to 224×224 and feeds it to a frozen DINOv2 ViT-L/14. Why 224? DINOv2's patches are 14×14, and 224 divided by 14 is exactly 16, so it outputs 16×16 patch tokens of 1024 dimensions each, matching the VAE's 16×16 positions one to one. Drop the CLS token and you have the feature map , taken from the last layer.
The two sides have different channel counts, 32 vs 1024, so a learnable linear projection first lifts to 1024 dimensions:
Here and . The official code implements as a bias-free 1×1 convolution, trained together with the VAE. Both of the losses that follow are computed between and .
Per-position alignment
The first term asks the VAE feature at each position to point in roughly the same direction as DINOv2's feature at the same position:
and are the two 1024-dimensional vectors at position , and is their cosine similarity, the dot product divided by the product of the two vectors' lengths, which lies between and . , so this averages over 256 positions.
The ReLU and the margin together decide when there's no penalty. The paper uses , so what's inside the parentheses is :
- a position with cosine similarity 0.7 gives , which ReLU turns into 0, so no penalty;
- similarity 0.2 gives a loss of 0.3;
- similarity gives a loss of 0.9.
As long as the direction roughly matches (cosine 0.5 or above), the VAE doesn't have to move any closer to DINOv2. The authors' intent is to leave some slack, so the latent space isn't over-regularized and reconstruction doesn't suffer for it.
Relative-structure alignment
The second term looks at the relationships between positions rather than at any single one. Pair up all positions, compute a 256×256 cosine similarity matrix on the VAE side and another on the DINOv2 side, and ask the two matrices to be close:
The paper's equation uses the unprojected ; the official code uses the projected in both terms.
A small example with 3 positions makes this term easiest to see. Say positions 1 and 2 are sky and position 3 is a dog:
| Pair | DINOv2 | VAE | Abs. diff | ReLU(diff − 0.25) |
|---|---|---|---|---|
| 1, 2 (sky, sky) | 0.90 | 0.80 | 0.10 | 0 |
| 1, 3 (sky, dog) | 0.10 | 0.55 | 0.45 | 0.20 |
| 2, 3 (sky, dog) | 0.15 | 0.30 | 0.15 | 0 |
Illustrative numbers made up for this note to show how is computed.
On the diagonal each position is paired with itself; both sides are 1 and the difference is 0. The matrix is symmetric, so (1, 3) and (3, 1) each contribute 0.20, for a total of 0.40; divided by , the loss is about 0.044.
Only the "sky vs dog" pair gets penalized. DINOv2 considers the two almost unrelated (0.10), but the VAE finds them somewhat alike (0.55). The other two pairs differ by less than 0.25 and are let off. What says is that the relative relationships only need to roughly agree, not match DINOv2's exactly.
Per-position alignment governs the absolute direction of each point; relative-structure alignment governs the distance relationships between points. The paper says that together they regularize both the local and the global structure of the feature space.
Adaptive weighting
The last issue is scale. The reconstruction loss and the KL term are summed over all pixels or dimensions, while the VF loss is an average; their magnitudes differ a lot, which makes direct weighting hard to tune.
The authors borrowed the way VQGAN sets its GAN loss weight. Before backpropagation, compute the gradients of the reconstruction loss and of the VF loss with respect to the weights of the encoder's last convolutional layer, and take the ratio of their norms:
Multiplied by this ratio, the VF loss produces gradients at that layer of the same size as the reconstruction loss. Then multiply by a manual coefficient :
In other words, at the encoder's exit the VF loss pulls with roughly a tenth of the reconstruction loss's strength. Whatever VAE training pipeline you plug this into, that proportion is lined up first, and only is left to fine-tune.
In the official implementation, this part comes down to the lines below (an excerpt from vavae/ldm/modules/losses/contperceptual.py, with torch.nn.functional shortened to F; z is already the projected ):
# z, aux_feature: (B, 1024, 16, 16)
z_flat = rearrange(z, 'b c h w -> b c (h w)')
aux_feature_flat = rearrange(aux_feature, 'b c h w -> b c (h w)')
z_norm = F.normalize(z_flat, dim=1)
aux_feature_norm = F.normalize(aux_feature_flat, dim=1)
z_cos_sim = torch.einsum('bci,bcj->bij', z_norm, z_norm) # (B, 256, 256)
aux_feature_cos_sim = torch.einsum('bci,bcj->bij', aux_feature_norm, aux_feature_norm)
diff = torch.abs(z_cos_sim - aux_feature_cos_sim)
# L_mdms (distmat_margin = 0.25)
vf_loss_1 = F.relu(diff - self.distmat_margin).mean()
# L_mcos (cos_margin = 0.5)
vf_loss_2 = F.relu(1 - self.cos_margin - F.cosine_similarity(aux_feature, z)).mean()
vf_loss = vf_loss_1 * self.distmat_weight + vf_loss_2 * self.cos_weight
# adaptive weight: gradients taken at encoder.conv_out.weight
vf_weight = torch.norm(nll_grads) / (torch.norm(vf_grads) + 1e-4)
vf_weight = torch.clamp(vf_weight, 0.0, 1e8).detach() * self.vf_weight # vf_weight = 0.1
The VF loss adds no parameters at all at inference. DINOv2 and the projection are only used during training and are thrown away afterward.
Training setup
The tokenizers used in the ablations are trained on ImageNet 256×256 for 50 epochs, with learning rate , global batch 256 (following MAR's setup), , and . The authors said in an issue that they trained the VAE on 32 to 64 GPUs.
The VA-VAE that was finally released and used for the leaderboard push was trained longer, and all the paper says about it is that it uses "a progressive training strategy" for "125 epochs." The details came from the authors in issue #8: start with and no margin, lower it to 0.1 at epoch 100, and switch the margins on at epoch 115. The config file added later says three stages of 100, 15 and 15, 130 epochs in total, and its comment gives the reason as "learning reconstruction is easier than learning alignment," so most of the time goes into alignment first, and reconstruction is briefly pulled back at the end.
LightningDiT
To judge whether a tokenizer is any good, you have to train a diffusion model in its latent space. The original DiT trains for 1,400 epochs, far too expensive to rerun for every tokenizer. So the authors first used SD-VAE to speed up DiT-XL/2's training recipe one item at a time:
| Change | FID-50K |
|---|---|
| DiT-XL/2 (original setup) | 19.50 |
| + Rectified Flow | 17.20 |
| + batch ×4, lr ×2 | 16.59 |
| + AdamW | 16.61 |
| + logit-normal time sampling | 13.99 |
| + velocity direction loss | 12.52 |
| + SwiGLU | 10.10 |
| + RMSNorm | 9.25 |
| + RoPE | 7.13 |
| + patch size 1 and VA-VAE | 4.29 |
Compiled from Table 1 of the paper. ImageNet 256×256 class-conditional generation, all trained for 80 epochs, no CFG.
The first half is training strategy. Rectified Flow connects data and noise with a straight line, and the model predicts the velocity along it; the batch goes from 256 to 1024 while the total number of samples seen stays the same; logit-normal sampling concentrates the training time steps in the middle range, as SD3 does; the velocity direction loss adds, on top of the mean squared error, a cosine distance between the predicted and target velocities, taken from FasterDiT by the same first author. The second half is LLaMA's set of Transformer components.
The authors state outright that none of these tricks is their own invention. They also observed that the tricks aren't fully independent of one another; gradient clipping helps on its own, but added after logit-normal sampling and the velocity direction loss, it makes things worse.
Still on SD-VAE, 80 epochs already reach 7.13. The original DiT trained for 1,400 epochs gets 9.62, so LightningDiT beats it with about 6% of the training.
The last row, from 7.13 to 4.29, changes two things at once: SD-VAE becomes VA-VAE, and the patch size goes from 2 to 1 (f8 with patch 2 becomes f16 with patch 1). A reader asked for the two to be separated in issue #4, and the authors supplied the numbers. With the same f16 and patch 1 but no alignment, f16d16 gets 5.58, and switching to VA-VAE gives 4.29; they promised "greater rigor in this aspect in the next version." Two months later, in v3, this row is still lumped together (the promised rigor must still be in transit).
Discussion
Once aligned, does dimension still drag down generation?
| tokenizer | rFID | PSNR | B | XL |
|---|---|---|---|---|
| d16 | 0.49 | 26.10 | 16.24 | 8.28 |
| d16 + MAE | 0.51 | 26.01 | 16.86 | 9.19 |
| d16 + DINOv2 | 0.55 | 25.29 | 15.79 | 8.71 |
| d32 | 0.26 | 28.59 | 22.62 | 10.92 |
| d32 + MAE | 0.28 | 28.33 | 19.89 | 9.92 |
| d32 + DINOv2 | 0.28 | 27.96 | 15.82 | 8.22 |
| d64 | 0.17 | 31.03 | 36.83 | 17.24 |
| d64 + MAE | 0.15 | 31.03 | 23.58 | 11.69 |
| d64 + DINOv2 | 0.14 | 30.71 | 24.00 | 11.98 |
Compiled from Table 2 of the paper. All f16; "+ MAE" and "+ DINOv2" are models aligned with the VF loss; B and XL are the FID-10K of LightningDiT-B (160 epochs) and LightningDiT-XL (80 epochs).
Note that the generation columns in this table are FID computed from 10,000 images, which runs higher than the usual 50,000-image version; the authors confirmed in issue #77 as well that these can't be compared directly with other papers' FID-50K.
The table can be read as four points:
- Without alignment, the dilemma is plain to see. rFID keeps improving from d16 to d32 to d64, while B's FID goes from 16.24 to 22.62 and 36.83, and XL's from 8.28 to 17.24.
- Aligned to DINOv2, d32 catches up with d16. B drops from 22.62 to 15.82, slightly below d16's 16.24; XL is 8.22, also slightly better than d16's 8.28. The price is a small step back in reconstruction, with rFID going from 0.26 to 0.28 and PSNR dropping 0.63 dB, but that is still far better than d16.
- d16 doesn't need alignment. With the VF loss, the L and XL FIDs actually get worse (L from 9.49 to 10.02, XL from 8.28 to 8.71). The authors read this as a low-dimensional space being able to learn a reasonable distribution on its own.
- d64 improves a lot, but not all the way. B drops from 36.83 to 24.00, still far behind aligned d32's 15.82.
A reader called out point 4 in issue #3: the VF loss seems to move the dilemma's sweet spot from d16 to d32 rather than make higher dimensions better. The authors responded that the detailed reconstruction of high-dimensional tokenizers inherently needs a larger generative model to absorb, and that the VF loss lowers the model size required. Both readings fit the table; the conclusion the table can support is "d32 with alignment gets more reconstruction than d16 without losing on generation."

The gap in convergence speed is even more direct. With the same LightningDiT-B on d32, the aligned tokenizer reaches FID 22.25 at 80k steps, already level with the unaligned version's 22.62 after the full 200k steps. The paper puts this gap at 2.54×; for d64 it is 2.76×.

So can scaling up the diffusion model solve the dilemma by itself? The authors scaled LightningDiT from 0.1B to 1.6B, training each size for 80 epochs.
The gap between unaligned d32 (gray) and d16 (green) does narrow as the model grows, but at 1.6B it is still 8.37 vs 6.68. For ImageNet, 1.6B is already a very large model, and the gap is still there. Aligned d32 (blue) nearly overlaps d16 at 0.6B and below, starts to lead from 1B up, and reaches 6.32 at 1.6B.
Align to whom, with which terms
Swapping in different vision foundation models as the alignment target, with the tokenizer trained for 50 epochs and LightningDiT-B for 160:
| Target | rFID | B |
|---|---|---|
| None | 0.26 | 22.62 |
| DINOv2 | 0.28 | 15.82 |
| CLIP | 0.33 | 18.93 |
| SAM | 0.26 | 19.80 |
| MAE | 0.28 | 19.89 |
Compiled from Table 4 of the paper. f16d32; B is LightningDiT-B's FID-10K.
All four help, and DINOv2 is the best. SAM (Meta's segmentation model, Segment Anything) and MAE barely hurt reconstruction, while CLIP sets rFID back the most.
Removing one term of the loss at a time (again f16d32 with DINOv2):
| Setting | PSNR | B |
|---|---|---|
| Full VF loss | 27.96 | 15.82 |
| No per-position term | 28.52 | 21.87 |
| No relative-structure term | 28.24 | 17.74 |
| No margin | 28.07 | 17.77 |
Compiled from Table 5 of the paper. When only one term is kept, the manual coefficient is halved to keep the comparison fair.
Per-position alignment does the heavy lifting; remove it, and FID falls almost back to the unaligned 22.62. Relative-structure alignment and the margin each contribute about 2 points.
The margin row doesn't quite square with the design motivation. The authors added the margin to avoid over-regularization and protect reconstruction, yet without the margin PSNR is 28.07, slightly higher than the full version's 27.96; what the margin actually improves is generation, from 17.77 to 15.82.
Does "a more uniform distribution" hold up?
Then there's the paper's hypothesis, that high-dimensional latent spaces are hard to learn because the distribution isn't spread out enough. The authors used kernel density estimation to measure three uniformity metrics, the coefficient of variation of the density, the Gini coefficient (lower is more uniform) and the normalized entropy (higher is more uniform). On d32, the Gini coefficients for no alignment, MAE alignment and DINOv2 alignment are 0.145, 0.101 and 0.096, and the FIDs are 22.62, 19.89 and 15.82, in exactly the same order.
At d64, DINOv2 is slightly better than MAE on all three metrics (Gini 0.141 vs 0.143), yet the FIDs are 24.00 vs 23.58, and MAE actually wins. The paper's own wording is "a possible positive correlation"; with six points and one counterexample, this explanation is better treated as an observation for now.
Later work sees it differently. Three months later, REPA-E used principal component analysis to plot the latent spaces of various VAEs and judged that SD-VAE's latent space is too noisy while VA-VAE's is over-smoothed and short on detail. Yet in its own code, the same paper trained the original DiT-XL for 400K steps with the VAE frozen and got gFID 19.82 for SD-VAE and 6.74 for VA-VAE. A different team with a different codebase, and the speedup from alignment is still there.
System level
Last comes the leaderboard combination, VA-VAE (trained for 125 epochs, rFID 0.28) with LightningDiT-XL (675 million parameters):
| Method | epochs | No CFG | CFG |
|---|---|---|---|
| DiT | 1,400 | 9.62 | 2.27 |
| SiT | 1,400 | 8.61 | 2.06 |
| MAR | 800 | 2.35 | 1.55 |
| REPA | 800 | 5.90 | 1.42 |
| LightningDiT | 64 | 5.14 | 2.11 |
| LightningDiT | 800 | 2.17 | 1.35 |
Compiled from Table 3 of the paper. ImageNet 256×256 class-conditional generation, FID-50K; MAR is a 945-million-parameter autoregressive model, and the others are all 675-million-parameter diffusion models.
The 1.35 at 800 epochs is the best of every method in the table, and the 2.17 without CFG also beats several methods in the paper's table that do use CFG (DiT's 2.27, LlamaGen's 2.18). It reaches 2.11 in just 64 epochs, better than DiT's 2.27 after 1,400 epochs, and the "21.8× Faster" in the paper's section title is exactly 1,400 divided by 64.
That multiple belongs to the whole system, which includes LightningDiT's eight training and architecture changes, f16 with patch 1, and VA-VAE. At the same 80 epochs, changing the training tricks alone takes FID from 19.50 to 7.13; changing the tokenizer and patch size takes it further, from 7.13 to 4.29.
The sampling setup also differs from the earlier experiments. The leaderboard runs use 250-step Euler integration, CFG interval (guidance applied only on part of the time steps) and a FLUX-like time-step shift; the 800-epoch training switches off logit-normal sampling at epoch 480.
CFG pushed only 3 channels
Issue #21 points out a detail inherited all the way from the original DiT. DiT's forward_with_cfg follows GLIDE's code and applies classifier-free guidance only to the first 3 channels of the output; in GLIDE's pixel space, the first 3 channels happen to be the predicted means of RGB. In VA-VAE's 32-channel latent space, guidance pushes only 3 of the channels.
The authors replied in February 2025 that with the fix, the required CFG scale drops from 6–10 to 1–2, with about the same best FID. Apart from Table 3 the paper doesn't use CFG, so the ablation conclusions are unaffected. But the official code keeps the original behavior, with a comment saying it's "for exact reproducibility reasons"; the leaderboard configs use CFG scales of 6.7 and 10.0, and the comment beside them explains why the scale is so large with two reasons, that a high-dimensional latent space needs stronger guidance and that CFG interval softens the side effects of a large scale ("only 3 of the 32 channels get guided" somehow didn't make the list).
Reproduction
Reports on GitHub roughly map out where the pitfalls are:
- The VAE has to be trained long enough, and rFID won't tell you. Someone trained a VA-VAE for 50 epochs with the official script; its rFID was nearly identical to the released one, but LightningDiT-XL trained on it for 800 epochs only reached FID 3.17 without CFG, against the paper's 2.17 (issue #50). The authors said the released version was trained for 125 epochs, and longer is better for generation; rFID has already converged by 50 epochs while generation ability keeps growing (issue #74). The only way to know whether a tokenizer is good is to actually train a diffusion model on it, and the authors suggest running LightningDiT-B/1 for 100k steps, which takes under 3 hours on 8 H100s.
- The latents need per-channel normalization. Someone plugged VA-VAE straight into the original DiT code and got an FID in the 130s; the cause was that training didn't normalize with the released per-channel means and standard deviations, while decoding did denormalize (issue #34).
- Long training runs hit NaN. More than one person reported that following the 800-epoch setup, the loss turns into NaN in the later part of training (issue #23). The authors suggested turning on QKNorm; someone did, and training did stabilize, but at the same step count FID slipped from 3.93 to 5.70 (issue #68). The authors' reply in July 2025 was "This might be an unresolved issue"; the 800-epoch version they released didn't use QKNorm and never ran into NaN.
VA-VAE's training code came out almost two months after the paper went public. Before that, the authors said in issue #1 that "Implementing it should be relatively straightforward, as described in Section 3 of the paper"; one reader implemented it and watched training collapse into solid-color images after 1,000 steps. The authors reproduced the same collapse on a single GPU; the cause was that the LDM code they built on had scale_lr switched on, which multiplies the learning rate by the number of gradient accumulation steps, the GPU count and the batch size.
Conclusion
On f16d32, a VF loss aligned to DINOv2 takes LightningDiT-B's FID from 22.62 to 15.82, level with the low-dimensional d16, while reconstruction rFID only slips from 0.26 to 0.28; convergence is 2.5 to 2.8 times faster, and it still pulls ahead when scaled up to 1.6B. The whole system reaches 1.35 on ImageNet 256. Even with alignment, d64 still loses to d32, so for now the sweet spot sits at 32 channels; and the explanation that "a more uniform distribution is easier to learn" still has too few data points behind it.
If you're training a tokenizer with 32 or more channels for a diffusion model, the VF loss is a very cheap step to add, since the official implementation is only a dozen or so lines and DINOv2 is needed only during training. Remember too to resize images to a size where DINOv2's patch grid lines up with the latent grid, to normalize the latents with per-channel statistics, and not to judge a tokenizer by rFID alone.
The setup that reached 1.35 used a CFG scale of 6.7, and it was pushing only the first 3 of 32 channels.