Nearest Neighbour Score Estimators for Diffusion Generative Models

Matthew Niedoba, Dylan Green, Saeid Naderiparizi, Vasileios Lioutas, Jonathan Wilder Lavington, Xiaoxuan Liang, Yunpeng Liu, Ke Zhang, Setareh Dabiri, Adam Scibior, Berend Zwartsenberg, Frank Wood

Abstract

Score function estimation is the cornerstone of both training and sampling from diffusion generative models. Despite this fact, the most commonly used estimators are either biased neural network approximations or high variance Monte Carlo estimators based on the conditional score. We introduce a novel nearest neighbour score function estimator which utilizes multiple samples from the training set to dramatically decrease estimator variance. We leverage our low variance estimator in two compelling applications. Training consistency models with our estimator, we report a significant increase in both convergence speed and sample quality. In diffusion models, we show that our estimator can replace a learned network for probability-flow ODE integration, opening promising new avenues of future research.

Introduction

At the heart of every diffusion model is the score function—the gradient of the log-density of the data. To generate an image, the model essentially follows this score function to move from random noise toward a high-probability data region. Currently, researchers face a trade-off when estimating this score. Monte Carlo (MC) estimators are mathematically unbiased but suffer from extremely high variance because they often rely on a single sample. Conversely, neural network approximators are fast and smooth but inherently biased; they do not perfectly represent the data distribution, which can lead to artifacts or blurry results. This paper introduces a Nearest Neighbour Score Estimator designed to bridge this gap, providing the low bias of multi-sample methods with the computational efficiency required for practical application.

Methodology

The proposed method utilizes Self-Normalized Importance Sampling (SNIS) to estimate the score. Instead of relying on a single training example, the estimator calculates a weighted average across multiple samples. The core innovation is the Nearest Neighbour Proposal. In diffusion models, noise is added via a Gaussian process, meaning the training examples most likely to have generated a specific noisy image are those closest to it in Euclidean ($\ell_2$) distance.

To make this approach scalable, the authors utilize FAISS (a library for efficient similarity search) to rapidly identify the $k$ nearest neighbours of a noisy sample from the entire training set. By calculating the score based on these $k$ neighbours, the estimator focuses its attention on the most relevant parts of the data distribution, which dramatically reduces variance compared to standard Monte Carlo techniques.

Experimental Setup

The researchers evaluated the estimator across three standard computer vision benchmarks:

  • CIFAR-10: Used for primary performance metrics and comparisons against analytic scores.
  • CelebA (64x64): Used to test the efficacy of the estimator on larger, more complex facial data.
  • ImageNet (64x64): Used to demonstrate scalability to massive, high-diversity datasets.

Key Insights and Results

Superior Accuracy and Convergence

On the CIFAR-10 dataset, the KNN estimator's peak Mean Squared Error (MSE) was approximately 100 times better than the previous state-of-the-art estimator, Stable Target Fields. When applied to the training of Consistency Models (iCT), the KNN-based approach reached lower (better) FID scores in less time than the standard baseline. The authors reported an FID of 3.59 on CIFAR-10 for single-step generation, outperforming several established distillation and consistency training methods.

The Generalization Paradox

One of the most striking findings involves the role of neural network bias. When the authors replaced the neural network with their near-perfect KNN estimator during the sampling phase, the model effectively stopped "creating" and began "memorizing." It produced an FID score of 0.5—indicating nearly perfect reconstruction of the training set—but failed to generate novel images. This suggests that the inductive biases of neural network architectures are actually what allow diffusion models to generalize and create new content rather than simply retrieving training data.

Limitations and Future Work

Despite its performance, the method has certain overhead requirements. Storing the entire training set in a searchable index requires significant RAM, though the authors mitigated this using 8-bit quantization. Furthermore, the current method relies on $\ell_2$ (pixel-wise) distance. While effective for Gaussian noise, $\ell_2$ does not always capture semantic similarity. Future research may explore performing the KNN search in a latent space (such as that of a VAE) to improve results. Additionally, the authors see potential in using this estimator to "bootstrap" new models from scratch without the need for a pre-trained teacher network, potentially simplifying the diffusion training pipeline.

Summary updated

BibTeX
@inproceedings{niedoba2024nearest,
  author = {Matthew Niedoba and Dylan Green and Saeid Naderiparizi and Vasileios Lioutas and Jonathan Wilder Lavington and Xiaoxuan Liang and Yunpeng Liu and Ke Zhang and Setareh Dabiri and Adam Scibior and Berend Zwartsenberg and Frank Wood},
  title = {{Nearest Neighbour Score Estimators for Diffusion Generative Models}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=hqNz4LDuhn},
}
Figure