SFESS: Score Function Estimators for $k$-Subset Sampling

Klas Wijk, Ricardo Vinuesa, Hossein AzizpourICLR 2025

TL;DR

This paper introduces SFESS, a novel score function estimator for $k$-subset sampling that provides exact discrete samples and unbiased gradient estimates. By leveraging a Discrete Fourier Transform (DFT) for efficient computation and multi-sample control variates for variance reduction, the authors prove that score function estimators can compete with state-of-the-art pathwise gradient methods, with the added superpower of working on non-differentiable downstream models.

What Problem Does This Paper Address?

In machine learning, we often need to select a subset of exactly $k$ items from a pool of $n$ possibilities. This operation—$k$-subset sampling—is crucial for tasks like feature selection, $k$-nearest neighbors ($k$-NN), and learning discrete latent representations.

Comparison of gradient estimation techniques: score function, approximate pathwise, and relaxed sampling.

The challenge is that sampling discrete items is a non-differentiable operation, meaning you cannot easily backpropagate errors through it using standard gradient descent. To get around this, researchers typically use "relaxed" continuous approximations (like Gumbel-Softmax) or approximate pathwise gradients (like the Straight-Through estimator). However, these methods either introduce bias, force the model to train on "mushy" continuous samples instead of hard discrete ones, or require the downstream function to be fully differentiable.

Score function estimators (like REINFORCE) offer an alternative: they are unbiased, produce exact discrete samples, and treat the downstream function as a black box. Yet, they have been largely ignored for $k$-subset sampling because they suffer from notoriously high variance. This paper asks: Can we fix the high variance and make score function estimators viable for $k$-subset sampling?

Methods

The authors propose SFESS (Score Function Estimators for $k$-Subset Sampling). The approach relies on four key pillars:

  1. Conditional Poisson Formulation: The authors model the subset selection as a set of independent Bernoulli variables, conditioned on the constraint that exactly $k$ items are selected.
  2. The DFT Trick: To compute the score function (the gradient of the log probability), one must calculate the probability mass function (PMF) of a Poisson binomial distribution. Doing this naively requires iterating over all $2^n$ possible subsets—an impossible task for large $n$. Instead, the authors use a closed-form expression that utilizes a Discrete Fourier Transform (DFT). This reduces the time complexity to a highly efficient $O(n \log n)$ and can be computed rapidly on GPUs.
  3. Variance Reduction: To tame the notoriously high variance of score function estimators, they use a multi-sample control variate. By drawing $N$ samples and using the leave-one-out mean as a baseline, the variance drops dramatically.
  4. Forward Pass Approximation: Because exact conditional Poisson sampling is slow, they use standard Gumbel top-$k$ sampling in the forward pass as a fast, practical approximation.

Datasets and Downstream Tasks

The authors evaluate SFESS across several domains to prove its versatility:

  • Synthetic Toy Problem: A custom setup with known ground-truth gradients, used to directly measure the bias and variance of the estimators.
  • MNIST & Fashion MNIST: Standard image datasets used to evaluate the method on three distinct downstream tasks.
Overview of the three downstream tasks used to evaluate SFESS: feature selection, variational autoencoders, and stochastic k-nearest neighbors.

Key Insights and Ideas

  • Score functions are unfairly dismissed: Contrary to the prevailing wisdom that score function estimators are too unstable for subset sampling, they can be highly competitive if paired with the right variance reduction and efficient PMF computation.
  • Black-box compatibility is a major advantage: Because SFESS doesn't rely on backpropagating through the downstream function, it can optimize non-differentiable objectives. This opens the door to using $k$-subset sampling in reinforcement learning or systems with hard-coded, non-differentiable logic.
  • Signal processing meets probability: Using the Fast Fourier Transform (FFT) algorithm to compute the Poisson binomial PMF is a clever cross-pollination of techniques, turning an intractable combinatorial problem into a fast, hardware-accelerated operation.

Key Results

  • Toy Problem: SFESS with variance reduction (SFESS+VR) drastically reduced gradient error compared to vanilla SFESS, matching the low error of state-of-the-art biased methods like SIMPLE.
  • Feature Selection: On MNIST (selecting $k=50$ features), SFESS+VR achieved a Binary Cross Entropy (BCE) of 0.132, slightly edging out SIMPLE (0.133) and STGS (0.146).
  • Variational Autoencoders: For VAEs with discrete latents on MNIST, SFESS+VR achieved a loss of 90.04. This was a massive improvement over vanilla SFESS (205.72) and remained highly competitive with the best baseline, SIMPLE (81.90).
  • Stochastic $k$-NN: On MNIST, SFESS+VR reached 94.9% accuracy, tying with SIMPLE and performing comparably to Gumbel-Softmax baselines (95.0%).
  • Computational Overhead: Surprisingly, the wall-clock time increase for drawing 32 variance reduction samples was minor, making the method practically viable.

Limitations and Future Work

Limitations: * Multiple Evaluations: The variance reduction technique requires drawing multiple samples (e.g., $N=32$). This means the downstream function must be evaluated multiple times per training step, which could be computationally prohibitive for very large, expensive downstream models. * Forward Pass Bias: Using Gumbel top-$k$ sampling as a stand-in for true conditional Poisson sampling in the forward pass introduces a slight theoretical bias in practice.

Future Work: The authors suggest that future research could combine score-function and pathwise estimators for $k$-subset sampling. This hybrid approach has been highly successful for simple Bernoulli and categorical distributions (e.g., REBAR, MuProp) and could offer the "best of both worlds" for subset sampling.

Summary updated

BibTeX
@inproceedings{wijk2025sfess,
  author = {Klas Wijk and Ricardo Vinuesa and Hossein Azizpour},
  title = {{SFESS: Score Function Estimators for $k$-Subset Sampling}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=q87GUkdQBm},
}
Figure