Introduction
At the heart of every diffusion model is the score function—the gradient of the log-density of the data. This function dictates how the model navigates from a noisy image back toward a "clean" one.
Currently, researchers estimate this score primarily in two ways:
- Neural Network Approximation: This method is biased and requires a lengthy training process.
- Single-Sample Monte Carlo (MC): While unbiased, this approach suffers from extremely high variance, making training highly unstable.
The fundamental challenge is that calculating the exact score requires summing over the entire training dataset for every single step, which is computationally intractable for large datasets. This paper introduces a novel Nearest Neighbour Score Estimator that seeks a middle ground: an estimator that uses multiple samples to drastically reduce noise while remaining efficient enough for practical, large-scale use.
The Nearest Neighbour Score Estimator
The authors' proposed estimator relies on a clever geometric observation: because diffusion noise is Gaussian, the training samples that contribute most to the score at any given point are simply those closest to it in Euclidean ($\ell_2$) space.
Key components of the method include:
- Self-Normalized Importance Sampling (SNIS): Instead of picking one random sample, the method uses a batch of $n$ samples.
- The $k$-NN Proposal: The authors utilize FAISS (a library for efficient similarity search) to quickly find the $k$ nearest neighbors in the training set to a noisy sample $\mathbf{z}$.
- The Estimator: They build a proposal distribution that prioritizes these $k$ neighbors. This allows them to estimate the score using a weighted average of just a few highly relevant training examples rather than the entire dataset.
This approach is standard in its use of importance sampling but highly novel in how it leverages the geometric structure of Gaussian noise to make the proposal distribution exceptionally accurate.
Experimental Setup
The authors evaluated their method on three standard computer vision benchmarks:
- CIFAR-10: Used for primary performance metrics and score analysis.
- CelebA ($64 \times 64$): Used to test the estimator on higher-dimensional face data.
- ImageNet ($64 \times 64$): Used to demonstrate scalability to large, diverse datasets.
To handle the massive memory requirements of ImageNet, the team utilized 8-bit quantization and Inverted File Indexes (IVF) to keep the $k$-NN search fast and memory-efficient. Despite adding a search step, the method only increases total training time by about 17% while providing much more stable gradients.
Key Insights and Results
Bias vs. Variance Trade-off
Compared to previous multi-sample methods like Stable Target Fields (STF), the $k$-NN approach exhibits significantly lower bias at intermediate noise levels. STF's bias stems from how it handles the "generating" sample in its batch, whereas the $k$-NN proposal matches the true posterior shape much more closely.
On CIFAR-10, the $k$-NN estimator's peak Mean Squared Error (MSE) was approximately 100 times lower than the STF estimator.
The "Aha" Moment on Generalization
Perhaps the most surprising finding is that when the $k$-NN estimator is used for sampling (completely replacing the neural network), it achieves a near-perfect FID of 0.5. However, it achieves this by perfectly reconstructing training images. This strongly suggests that the "generalization" we observe in standard diffusion models isn't inherent to the score function itself, but is actually a byproduct of the inductive bias (the "imperfections") of neural network architectures.
Consistency Training and Network-Free Integration
Models trained with the $k$-NN estimator reached lower FID scores (better image quality) faster than the baseline "improved Consistency Training" (iCT) method. For example, iCT + KNN achieved an FID of 3.59 on CIFAR-10, outperforming the reimplemented baseline of 3.67.
Furthermore, the authors proved that their estimator is accurate enough to replace a learned neural network for Probability-Flow ODE integration, effectively allowing them to "sample" directly from the training set's distribution without a parameterized model.
Limitations and Future Work
- Lack of Generalization: As noted, the estimator itself is a "memorizer." It is a powerful tool to help train models that generalize, or to analyze the diffusion process, but it cannot generate novel images on its own.
- The $\ell_2$ Metric: Euclidean distance works well for pixels under Gaussian noise, but it fails to capture high-level semantic similarity. Performing $k$-NN in a latent space (like that of a VAE or CLIP) is a highly promising future direction.
- Memory Overhead: While quantization helps, storing a searchable index of millions of high-resolution images remains a significant hardware challenge for scaling to the largest foundational models.
Summary updated