Readers following visual generative models know that FID has always been one of the key evaluation metrics; lower values typically indicate more realistic generation. A natural question then arises: why not simply use FID directly as the loss function to train generative models? Could it be because FID is non-differentiable? Far from it. FID is actually differentiable, and there is no theoretical problem with using it as a loss; in practice, however, one encounters computational difficulties.
Recently, the paper 《Representation Fréchet Loss for Visual Generation》made some attempts to overcome these difficulties, successfully applying FID to generative model fine-tuning and noticeably improving the quality of single-step generation. In this post, I will briefly explore the underlying mathematical principles and implementation techniques.
Generative Metrics #
FID stands for "Fréchet Inception Distance", which we can understand by dividing it into two parts: "Fréchet Distance (FD)" and "Inception (I)".
Suppose there are two distributions
Substituting the mean vectors and covariance matrices of the respective encoded representations into the equation above yields what is called the "Fréchet Distance (FD)". As for the derivation of the equation above, interested readers can refer to "KL Divergence, Bhattacharyya Distance, and Wasserstein Distance Between Two Multivariate Normal Distributions".
If we select the encoder
Of course, whether for training or evaluation, using InceptionV3 is no longer strictly necessary nowadays; we can use other more advanced feature models, such as SigLIP, or compute the Fréchet Distance once for each of several different encoders and sum them up, and so on. We collectively refer to these approaches as "FD Loss".
Related Literature #
Although FID looks complex, it involves no non-differentiable operations, so using it as a loss is a very natural idea. As early as several years ago, there were already attempts in this direction, such as 《Image Generation Via Minimizing Fréchet Distance in Discriminator Feature Space》 and 《Backpropagating through Fréchet Inception Distance》.
However, early attempts did not produce particularly impressive results, with the fundamental reason being batch size. A standard loss function computes an individual loss for each single sample and then averages over all samples, whereas FID first computes the mean and covariance across all samples, and then substitutes them into Equation
"Requiring nonlinear operations across samples", "requiring a large batch size"—do these phrases sound familiar? In fact, "contrastive learning" in vision usually shares these two characteristics as well. Due to nonlinear operations across samples, we cannot achieve the effect of increasing batch size via gradient accumulation either, but this is not completely unsolvable—for example, "Can Contrastive Learning Use Gradient Accumulation?". As we will see later, the method FID uses to resolve the batch size issue is actually quite similar.
Furthermore, from the perspective of "using a pretrained model to extract features to construct a loss function", another related work is Perceptual Loss, but this is used as a per-sample reconstruction loss, typically for training models such as VAEs, and does not involve cross-sample statistical operations, so there is no real computational difficulty.
Gradient Computation #
Now let us derive things step by step to see what difficulties are actually encountered when using FD as a loss. The first issue to resolve is the gradient computation.
While
Here we use the second line of Eq.
For the derivatives of eigenvalues, one can refer to "Derivatives of SVD". The final result is analogous to how the derivative of
Combining these yields
This form may seem complicated, but eigh function, or by using the Newton-Schulz iteration schemes introduced in "Efficient Computation of Matrix Square Roots and Inverse Square Roots" and "Efficient Computation of Matrix r-th Roots and Inverse r-th Roots".
Ultra-Large Batches #
Introducing the notation:
Then
Note that
On the other hand, from the gradient formula
Constrained by compute, we can only try to simulate the effect of a large batch size using a small batch size, which is similar to the requirement in 'contrastive learning + gradient accumulation'.
Equivalent Loss #
Suppose that with a batch size of
We want to find an ideal equivalent loss such that the total gradient is equivalent to the sum of the gradients from each small batch, achieving an unbiased estimate. To this end, taking Eq.
What this equality means is that we can run forward passes sequentially in small batches to obtain
, and finally accumulate these gradients. This gradient is equivalent to the gradient with batch size
Filling the Gap with History #
Although the above scheme is theoretically feasible, because it requires
A natural idea is: for
This roughly maintains an averaging window of size
The extra cost is having to cache
Experimental Highlights #
The paper's experiments focus primarily on the post-training of generative models, aiming to improve the performance of original single-step generative models or fine-tune original multi-step generative models into single-step generative models via FD loss training. When mixing multiple different encoders to compute the FD loss, the paper uses a loss normalization trick to balance losses of different magnitudes:
We also discussed this trick in "Discussions on Multi-Task Learning (1): In the Name of Loss".
The paper's crowning achievement is pushing the performance (FID) of single-step generation to a brand-new height, surpassing all other single-step and multi-step generative models; this result appears to have reached the ceiling. Some charts are shown below:
Summary #
This article primarily analyzed from a theoretical perspective the difficulties of using FID as a loss function for generative models, and how to derive the corresponding techniques to overcome these difficulties from the derivation process.
Table 2, Figure 5 from Representation Fréchet Loss for Visual Generation (2604.28190v1); matching English original retained. Source attribution.
Table 4 from Representation Fréchet Loss for Visual Generation (2604.28190v1); matching English original retained. Source attribution.

