NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Adaptive Sampling for Efficient Softmax Approximation

Tavor Z. Baharav, Ryan Kang, Colin Sullivan, Mo Tiwari, Eric Luxenberg, David Tse, Mert PilanciNeurIPS 2024

TL;DR

This paper introduces AdaptiveSoftmax, a novel algorithm that efficiently approximates the top-k outputs of the softmax function, a common bottleneck in machine learning. By framing the problem as a statistical estimation task inspired by multi-armed bandits, AdaptiveSoftmax achieves significant speedups (over 10x, up to 30x for LLMs) with probabilistic guarantees, making it a valuable tool for high-dimensional applications.

What Problem Does This Paper Address?

The softmax function is a cornerstone of many machine learning models, particularly in classification and reinforcement learning, where it converts raw scores (logits) into a probability distribution. However, computing the full softmax, especially for large output spaces (e.g., vocabularies in Large Language Models), is computationally expensive. This cost arises from calculating the partition function (the denominator of the softmax) and its gradients. In many practical scenarios, only the top few most probable outputs are of interest, making the full computation of all probabilities wasteful. This paper addresses this inefficiency by proposing an adaptive sampling method that focuses computational effort on the most relevant parts of the softmax calculation.

Methods

The core of AdaptiveSoftmax lies in reframing the softmax computation as a statistical estimation problem. Instead of directly computing the full softmax, the algorithm uses techniques inspired by multi-armed bandit (MAB) problems. Specifically, it breaks down the problem into three main stages:

  1. Normalization Estimation: It first estimates the softmax partition function (the denominator) with a multiplicative accuracy of $\epsilon/4$ using an algorithm called NormalizationEstimation. This stage leverages importance sampling and bandit-like exploration to efficiently approximate the sum of exponentials.
  2. Best Arm Identification: It then identifies the index of the highest softmax probability (the "best arm") using a standard MAB algorithm, BestArmId. This stage efficiently narrows down the potential candidates for the top output.
  3. Arm Estimation: Finally, it estimates the value of the identified best arm's probability with a multiplicative accuracy of $\epsilon/4$ using EstimateArm.

The algorithm provides probabilistic guarantees (PAC - Probably Approximately Correct) on the accuracy of its top-k estimations. A key innovation is its adaptive nature, allocating more computational resources to arms (classes) that are likely to have higher probabilities, thus achieving efficiency gains.

Datasets

The paper evaluates AdaptiveSoftmax on a variety of real-world datasets:

  • Synthetic Datasets: Used to demonstrate the algorithm's scaling behavior with respect to dimensionality.
  • MNIST: A standard dataset for image classification (handwritten digits).
  • EuroSAT: A dataset of satellite imagery for land type classification.
  • Wikitext: Used for evaluating Large Language Models (LLMs).
  • Penn Treebank: Another dataset used for LLM evaluation.

The authors also mention that their code is publicly available, allowing for reproducibility.

Key Insights and Ideas

  • Softmax as a Statistical Estimation Problem: The paper's central insight is that computing the softmax can be viewed as a statistical estimation problem, amenable to techniques from multi-armed bandits. This shift allows for adaptive sampling and probabilistic guarantees.
  • Focus on Top-k Outputs: Recognizing that only the top few softmax outputs are often needed, the algorithm intelligently allocates computation, avoiding the expensive full computation.
  • Adaptive Sampling for Efficiency: By adaptively sampling based on estimated probabilities and variances, the algorithm significantly reduces the number of computations required, especially in high-dimensional settings.
  • Probabilistic Guarantees: The algorithm provides theoretical guarantees (PAC) on the accuracy of its estimations, ensuring reliability.
  • Partition Function Estimation is General: The method for estimating the softmax denominator is presented as a general technique applicable to other areas like kernel density estimation.

Key Results

  • Significant Speedups: AdaptiveSoftmax consistently outperforms brute-force softmax computation, yielding over 10x gains on most datasets.
  • LLM Performance: For LLMs like Mistral7B evaluated on Wikitext, the improvement reaches up to 30x.
  • Scalability: The algorithm demonstrates sublinear scaling in the dimensionality of the input vector ($d$), which is crucial for high-dimensional applications.
  • Robustness: The algorithm shows robustness to parameter choices, with $\epsilon=30\%$ and $\delta$ in the range of 90-99% yielding consistent performance improvements.

Limitations and Future Work

  • Inner Dimension Dependency: The paper notes that AdaptiveSoftmax is most beneficial when the inner dimension of the matrix-vector product is high. For small inner dimensions, standard BLAS operations might be more efficient.
  • Adaptivity vs. Batching: The adaptive nature of the algorithm, while beneficial for efficiency, can be inherently sequential, posing a challenge for achieving wall-clock time improvements on hardware where batching is dominant.
  • LLM Softmax Layer Size: In some LLMs, the final softmax layer might not be the primary computational bottleneck, limiting the overall speedup achievable by this method alone.

Future work directions include:

  • Hardware Optimization: Developing hardware-optimized implementations to translate sample complexity gains into wall-clock time improvements.
  • Combining with LSH: Exploring combinations with Locality-Sensitive Hashing (LSH) for potential subquadratic complexity in the number of classes ($n$).
  • Heterogeneous Arm Variances: Extending the algorithm to handle scenarios with varying variances across different output classes.
  • Top-k and Nucleus Sampling: Generalizing the algorithm to identify and estimate the top-k probabilities and applying it to nucleus sampling for LLM text generation.

Summary updated

BibTeX
@inproceedings{baharav2024adaptive,
  author = {Tavor Z. Baharav and Ryan Kang and Colin Sullivan and Mo Tiwari and Eric Luxenberg and David Tse and Mert Pilanci},
  title = {{Adaptive Sampling for Efficient Softmax Approximation}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=XsNA2b8GPz},
}
Figure