Learning to Be Guided: Shaping Latent Geometry for Classifier-Free Guidance

1New York University2New York University Shanghai3Georgia Institute of Technology
*Equal contribution†Corresponding authors

Easy to Diffuse ≠ Easy to Guide

  • (a)Conditional diffusion models are almost always sampled and evaluated with guidance (typically CFG).
  • (b)Meanwhile, improving a latent space for unguided generation does not necessarily improve guided generation.
  • (c)What makes a latent space CFG-compatible, and how can we learn one?
MethodgFID w/o CFG ↓gFID w/ CFG ↓
LDM13.09#43.31#4
VA-VAE (DINOv3-B)9.76#22.64#3
VA-VAE (DINOv3-L)9.01#12.44#2
LDM + PR (Ours)11.59#32.28#1

ImageNet 256×256, class-conditional, LightningDiT-XL/1, same budget for all (20 epochs for VAE, 80 epochs for DiT), evaluated over 50K samples.

TL;DR

Under exact score estimation, CFG sampling for a condition \(c\) follows the guided score

\[ \underbrace{\nabla_{z_t}\log p_t(z_t)}_{\text{marginal score}} \;+\;\underbrace{\omega\,\nabla_{z_t}\log p_t(c\mid z_t)}_{\text{guidance term}},\qquad \omega>1 . \]

Problem

Diffusability is not enough.

Beyond how easily the marginal distribution \(p_t(z_t)\) can be modeled, the guided score also depends on how conditions are arranged in the noise-corrupted latent space. Viewing conditions as discrete classes, we term this arrangement class geometry and ask which geometry works well with CFG.

Analysis

Separate centers, shrink spread.

Under a Gaussian class model, the oracle CFG correction contrasts the target class with its competitors. Larger inter-class separation and smaller intra-class spread make classes more distinguishable under noise. An ideal noisy-posterior objective captures this preference, with its gradient aligned with the correction.

Solution

Prototype Regularization.

The ideal objective cannot be optimized directly, since the latent space itself is being learned. We introduce Prototype Regularization (PR), a tractable surrogate that shapes class geometry with a prototype classifier on clean latents. It generalizes to cluster pseudo-labels, video latents, and continuous conditions.

Analysis

Why class geometry matters for CFG

Setup: rectified flow interpolates \(z_t=t\,z+(1-t)\,\epsilon\), \(\epsilon\sim\mathcal N(0,I)\), with noise at \(t=0\), clean data at \(t=1\).

1

What does CFG actually add?

CFG amplifies the displacement between the conditional and unconditional predictions. For the Bayes-optimal predictors \(v_c^\star=\mathbb E[v\mid z_t,t,C=c]\) and \(v_u^\star=\mathbb E[v\mid z_t,t]\), substituting \(v=(z-z_t)/(1-t)\) turns that displacement into a difference of posterior means of the clean latent:

\[ g_c^\star(z_t,t) := v_c^\star - v_u^\star = \frac{\mathbb E[z\mid z_t,t,C=c]-\mathbb E[z\mid z_t,t]}{1-t}. \]
(1)

The correction is how far knowing the class moves the estimate of the clean latent. To trace its dependencies, we need a model where it can be computed in closed form.

2

When is the correction large, and when does it vanish?

Take \(K\) classes with Gaussian priors \(p(z\mid c)=\mathcal N(z;\mu_c,\sigma^2 I)\) sharing one intra-class variance \(\sigma^2\). Writing \(q_j=\Pr(C=j\mid z_t,t)\) for the noisy class posterior, Eq. 1 becomes

\[ g_c^\star(z_t,t) = \frac{1-t}{(1-t)^2+t^2\class{cs}{\sigma^2}}\sum_{j\neq c} \class{cw}{q_j}\,\class{cc}{(\mu_c-\mu_j)}. \]
(2)

class contrast \(\mu_c-\mu_j\)posterior weight \(q_j\)intra-class variance \(\sigma^2\)

The correction sums displacements from each competitor mean toward the target mean, weighted by that competitor's posterior \(\class{cw}{q_j}\) (i.e., how confusable it remains at the noisy state \(z_t\)). Once the target class dominates the posterior (\(q_c\to 1\)), all competitor weights vanish, and so does the correction.

3

Which geometry keeps classes distinguishable under noise?

Step 2 says the correction lives as long as the posterior is uncertain. How soon it becomes certain depends on how far apart classes remain once noise is added. Since \(p(z_t\mid c)=\mathcal N\big(z_t;\,t\mu_c,\,(t^2\sigma^2+(1-t)^2)I\big)\), the squared standardized distance between two classes is

\[ \delta_{cj}^2(t) = \frac{t^2\,\class{cc}{\|\mu_c-\mu_j\|^2}}{t^2\class{cs}{\sigma^2}+(1-t)^2}. \]
(3)

To separate geometry from scale, fix reference means \(\mu_c^{\text{ref}}\in\mathbb R^d\) with \(\mathbb E_C[\mu_C^{\text{ref}}]=0\) and \(\mathbb E_C\|\mu_C^{\text{ref}}\|^2=d\), and vary only how a fixed total variance \(d\) is split:

\[ \class{cc}{\mu_c(\alpha)}=\sqrt{\alpha}\,\mu_c^{\text{ref}},\qquad \class{cs}{\sigma^2(\alpha)}=1-\alpha,\qquad \alpha\in(0,1). \]
(4)

Raising \(\alpha\) moves variance from intra-class \((1-\alpha)d\) to inter-class \(\alpha d\), pushing centers apart and shrinking intra-class spread. This increases \(\delta^2_{cj}(t)\) at every \(t\), making classes more distinguishable under noise, so the target posterior concentrates earlier.

Toy Example

Watch the correction appear and vanish

Setup: six Gaussian classes; the top one is the target. Both rows share the same samples and noise; only the geometry \(\alpha\) differs (Eq. 4). Distances are scaled to mimic a high-dimensional latent; for intuition only.

① Clean latentsTarget class highlighted. Larger α: farther-apart centers, smaller spread.
② Noised at tShade: target posterior \(q_c\). Arrows: \(g_c^\star\) on target samples, shared scale.
③ Along the trajectoryQuantities are averaged over all target samples. Dashed line marks the current t.
Entangledα = 0.001
Adjustableα = 0.030

Look for

Press play. With larger α, arrows are long while the class is uncertain, then vanish as the shade fills in. When entangled, arrows stay short and the shade fills only partially.

What it means

Under this model, CFG acts only while the class is uncertain. A separated geometry gives a stronger correction and settles the class earlier in denoising. PR is designed to build this geometry.
4

How do we turn this into a training objective?

To keep classes distinguishable under noise, we would ideally minimize the class uncertainty left at noise level \(t\), measured by the cross-entropy of the true noisy class posterior:

\[ \mathcal L_{\text{post}}(t)=\mathbb E_{z,c,\epsilon}\big[-\log q_c\big(tz+(1-t)\epsilon,\,t\big)\big]=H(C\mid Z_t). \]
(5)

Holding the posterior function \(q_c\) fixed, the per-sample descent direction on the clean latent \(z\) is proportional to the oracle correction \(g_c^\star\):

\[ \nabla_z\log q_c\big(tz+(1-t)\epsilon,\,t\big)=t\,\nabla_{z_t}\log q_c(z_t,t)=\frac{t^2}{1-t}\,g_c^\star(z_t,t),\quad t\in(0,1). \]
(6)

To turn Eq. 5 into a practical training objective, we also need to choose how \(z_t\) is sampled. A natural choice follows the training trajectory: drawing \(t\) from a time distribution \(\rho\) gives \(\mathcal L_\rho=\mathbb E_{t\sim\rho}[\mathcal L_{\text{post}}(t)]\), with \(\rho\) ranging from the whole trajectory (uniform \(\rho\)) to clean latents only (\(\rho\) concentrated at \(t=1\)). Within the family of class geometries defined in Eq. 4, every \(\mathcal L_\rho\) is non-increasing in \(\alpha\), so all of them favor the same geometry: more separated and compact classes.

The objective is aligned with CFG at two levels: (1) its per-sample gradient follows CFG's correction (Eq. 6), and (2) minimizing any \(\mathcal L_\rho\) promotes the separated, compact geometry that strengthens CFG (Step 3). In practice, one then needs to choose \(\rho\) and approximate \(q_c\).

Method

Prototype Regularization

\(\mathcal L_\rho\) cannot be minimized directly: the true posterior \(q_c\) is defined by the latent distribution we are still learning. Since the diffusion model trains in the latent space fixed by the autoencoder, PR instead optimizes a surrogate during autoencoder training, with the following choices of \(\rho\) and an approximation of \(q_c\):

  1. Clean-only supervision: \(\rho\) is a point mass at \(t=1\), so PR supervises the class posterior of clean latents.
  2. A prototype classifier in place of \(q_c\), with the same form as the Gaussian class posterior.
x Encoder latent z32 × 16 × 16 Decoder x̂ ℒLDMrecon, KL, LPIPS, GAN AvgPoolz̄ ∈ ℝ³² ℓ2 normalizez̃ = z̄ / ‖z̄‖ cos(z̃, p̃ⱼ) / τK prototypes ℒPRCE with c PR branchtraining only

More concretely, PR pools the latent to \(\bar z=\mathrm{AvgPool}(z)\in\mathbb R^{d_c}\), gives each class a learnable prototype \(p_j\), and normalizes both (\(\tilde z=\bar z/\|\bar z\|\), \(\tilde p_j=p_j/\|p_j\|\)):

\[ \pi_j(z)=\frac{\exp(\tilde z^\top\tilde p_j/\tau)}{\sum_{k=1}^{K}\exp(\tilde z^\top\tilde p_k/\tau)},\qquad \mathcal L_{\text{PR}}=-\log\pi_c(z). \]
(7)

With equal priors and equal-norm means, the clean Gaussian posterior is \(q_j\propto\exp(\mu_j^\top z/\sigma^2)\), and \(\pi_j\) has the same form on normalized features. Its negative gradient therefore mirrors Eq. 2:

Oracle CFG correction, Eq. 2

\[ g_c^\star\;\propto\;\sum_{j\neq c}\class{cw}{q_j}\,\class{cc}{(\mu_c-\mu_j)} \]

PR gradient, Eq. 8

\[ -\nabla_{\tilde z}\mathcal L_{\text{PR}}=\frac1\tau\sum_{j\neq c}\class{cw}{\pi_j}\,\class{cc}{(\tilde p_c-\tilde p_j)} \]

Prototypes stand in for class means and \(\pi_j\) for \(q_j\): each latent is pulled toward its target and away from the competitors it is most easily confused with.

Three design choices make PR work in practice:

Clean-only supervisionUniform \(\rho\) over-smooths the latent (i.e., it erases spatial variation). Supervising only clean latents (\(t=1\)) avoids this and performs best.
Pool before classifyingPR supervises only the pooled latent \(\bar z\); spatial variation around it remains free to encode the layout and detail needed for reconstruction.
Cosine, not linearNormalization leaves only angles to optimize; a linear head can lower the loss by inflating latent norms instead of separating classes.

The autoencoder is trained with

\[ \mathcal L=\mathcal L_{\text{LDM}}+\lambda_{\text{PR}}\,\mathcal L_{\text{PR}}, \]
(9)

where \(\lambda_{\text{PR}}\) is set adaptively by balancing encoder last-layer gradient norms against the reconstruction term. PR only needs a partition of the data, so cluster IDs of pretrained features can replace labels, and the diffusion model can later be conditioned on other signals, discrete or continuous.

class PrototypeReg(nn.Module):
    def __init__(self, num_classes, channels, tau):
        super().__init__()
        self.protos = nn.Parameter(torch.randn(num_classes, channels))
        self.tau = tau

    def forward(self, z, y):                               # z: (B, C, H, W), y: (B,)
        z_tilde = F.normalize(z.mean(dim=(2, 3)), dim=-1)  # latents: pool + normalize
        p = F.normalize(self.protos, dim=-1)               # prototypes: normalize
        logits = z_tilde @ p.t() / self.tau                # cosine similarity / tau
        return F.cross_entropy(logits, y)

# autoencoder step: lam_pr is adaptive (gradient-norm balanced)
loss = loss_ldm + lam_pr * pr(z, labels)

Results

Class geometry governs how much a model gains from guidance

Setup: ImageNet 256×256 on the VA-VAE codebase, using a convolution-based autoencoder with 32×16×16 latents, LightningDiT-XL/1, 20 epochs for VAE and 80 epochs for DiT. Guided numbers use the best guidance scale \(\omega^\star\) from a 5K-sample sweep; metrics evaluated over 50K samples.

Main comparison

MethodPurity@10 ↑Steps/s ↑gFID w/o CFG ↓gFID w/ CFG ↓IS ↑Recall ↑
LDM0.020#42.1613.09#43.31#4237.730.504
VA-VAE (DINOv3-B)0.053#31.659.76#22.64#3236.020.557
VA-VAE (DINOv3-L)0.071#21.619.01#12.44#2242.170.564
LDM + PR (Ours)0.279#12.1311.59#32.28#1269.850.585
Reconstruction is comparable.rFID 0.277 vs. 0.308 (LDM) and 0.275 (VA-VAE, DINOv3-L); PSNR within 0.15 dB and LPIPS within 0.002 of the best.
Guided ranking follows Purity.Purity@10, the share of a latent's 10 nearest neighbors that share its class, ranks methods as guided gFID does; unguided gFID does not.
Negligible overhead.Stage-1 throughput stays at 2.13 steps/s (LDM: 2.16), while VA-VAE's representation alignment costs about 25%.

Why does PR gain more from guidance?

Figure 2: energy allocation, target-class distinguishability along the trajectory, and CFG sweep for LDM, VA-VAE and LDM+PR
(a) Energy shifts to inter-class variance.Over 90% of LDM's energy is intra-class. VA-VAE shifts much of it to a shared global mean; PR moves it to inter-class variance.
(b) The class stays identifiable under noise.PR's target posterior is substantially higher along the trajectory, on noised validation latents and actual CFG samples, consistent with Step 3.
(c) It benefits from stronger guidance.PR peaks at a larger \(\omega^\star\) and degrades more slowly beyond it, giving a wider near-optimal range of guidance scales.

Is it really the geometry? Transplanting PR's class centers into LDM

Replace each LDM class center with a transplanted one, \(z'=z-\mu_c^{\text{LDM}}+\tilde\mu_c\), where \(\tilde\mu_c\) is PR's class center; keep intra-class deviations and retrain stage 2. Two controls set \(\tilde\mu_c\) to LDM's own centers with rescaled energy, or to random directions with PR's per-class norms.

gFID@50K ↓Share of PR's gain recovered
LatentCentersShapew/o CFGw/ CFG\(\omega^\star\)w/o CFGw/ CFG
LDM + PRnative11.592.282.5
LDMnative13.093.312.0
LDMLDM, rescaled32×16×1612.582.892.0
LDMPR32×16×1612.792.633.5
LDMPR32×1×112.652.524.0
LDMrandom dirs, PR norms32×1×113.743.164.5

Share recovered = (LDM − row) / (LDM − LDM+PR), computed from the gFID columns. All spaces using PR's centers or norms reach a larger \(\omega^\star\) than LDM.

Arrangement, not energy alone.At matched energy, PR centers beat LDM's own centers (66% vs. 41%, full shape) and random directions (77% vs. 15%, pooled).
A global channel offset.Pooled centers beat spatially resolved ones (2.52 vs. 2.63), so the useful class signal is mainly a channel-wise offset.
Intra-class spread matters too.Transplants recover most of the guided gain but little of the unguided one; they move centers and leave intra-class spread untouched.

Does PR generalize?

Cluster pseudo-labels

2.34Guided gFID with DINOv3-L clusters as PR labels, achieving 94% of the GT label gain

PR is applied with spherical K-means clusters (K = 1000) of DINOv3-L [CLS] tokens; the PR labels need not match the stage-2 condition.

PR labels (stage 1)Condition: ground truthCondition: DINO clusters
None3.31 / 13.093.58 / 13.31
Ground truth2.28 / 11.592.42 / 11.82
DINO clusters2.34 / 11.442.55 / 11.47

Guided / unguided gFID.

Video latents

152.7 → 140.1FVD with CFG on UCF-101

LeanVAE fine-tuned with PR (pooling over time and space), then Latte-XL/2 fine-tuned on top. Without CFG, FVD drops 287.3 → 275.7; action accuracy stays on par.

w/ CFGw/o CFG
Stage 1 / Stage 2FVD ↓Acc ↑FVD ↓Acc ↑
Official / Official167.092.9340.287.2
Official / Fine-tuned161.498.5302.092.7
Recon only / Fine-tuned152.799.0287.393.0
PR / Fine-tuned140.198.9275.793.0

Continuous Conditions (Text-to-image)

2.90 → 2.35gFID (val) with CFG, conditioned on CLIP-L text embeddings of image captions

PR is best on every guided metric. PR shapes latent geometry with categorical labels (e.g., GT labels, DINO clusters), yet beats continuous-alignment baselines.

w/ CFGw/o CFG
MethodgFID train ↓gFID val ↓CLIP ↑gFID train ↓gFID val ↓CLIP ↑
LDM3.152.900.277510.387.520.2577
VA-VAE (DINOv3-L)2.532.670.28148.025.650.2620
Cos. align (CLIP-L)2.933.040.27999.526.840.2590
Cos. align (DINOv3-L)2.862.780.27849.356.740.2585
PR (GT labels)2.512.350.28119.636.870.2570
PR (CLIP-L clusters)2.522.420.281310.157.360.2578
PR (DINOv3-L clusters)2.532.460.28189.416.720.2575

Limitations

BibTeX

@article{placeholder2026guided,
  title   = {Learning to Be Guided: Shaping Latent Geometry
             for Classifier-Free Guidance},
  author  = {One, Author and Two, Author and Three, Author and
             Four, Author and Five, Author and Six, Author and
             Seven, Author},
  journal = {arXiv preprint arXiv:XXXX.XXXXX},
  year    = {2026}
}