Abstract
We present a novel technique for constructing differentiable order-type operations, including soft ranking, soft top-k selection, and soft permutations. Our approach leverages an efficient closed-form formula for the inverse of the function LapSum, defined as the sum of Laplace distributions. This formulation ensures low computational and memory complexity in selecting the highest activations, enabling losses and gradients to be computed in $O(n\log{}n)$ time. Through extensive experiments, we demonstrate that our method outperforms state-of-the-art techniques for high-dimensional vectors and large $k$ values. Furthermore, we provide efficient implementations for both CPU and CUDA environments, underscoring the practicality and scalability of our method for large-scale ranking and differentiable ordering problems.
Introduction
In modern deep learning, the requirement for differentiability is paramount. Neural networks learn via gradient descent, necessitating functions that possess a usable slope at every point. However, fundamental operations such as sorting, ranking, and top-k selection are inherently discrete and "jagged." Small changes in input values often result in zero gradients (when ranks remain unchanged) or undefined gradients (at the moment of a rank jump). This discontinuity traditionally prevents networks from learning these tasks directly through standard backpropagation.
Existing solutions, such as those based on Optimal Transport or various "soft" sorting approximations, frequently encounter two significant hurdles: high computational complexity (often $O(n^2)$) and the lack of closed-form solutions, necessitating expensive iterative algorithms like Sinkhorn that are difficult to differentiate through efficiently.
Methodology: The LapSum Framework
The core innovation of this work is LapSum, a framework built upon the sum of cumulative density functions (CDFs) of the Laplace distribution. While various distributions could theoretically "soften" a ranking, the Laplace distribution is uniquely suited for this task because the sum of its CDFs possesses a closed-form inverse.
By treating input values as centers of Laplace distributions, LapSum allows for:
- Efficient Computation: Once the input vector is sorted ($O(n \log n)$), the LapSum function and its inverse can be calculated in linear time ($O(n)$).
- Analytical Differentiation: The existence of a closed-form inverse formula allows for exact gradients during backpropagation without the need to unroll iterative loops.
- Trainable Softness: The method incorporates a parameter $\alpha$ (alpha) that acts as a temperature setting. A high $\alpha$ approximates traditional "hard" sorting, while a lower $\alpha$ provides a smoother surface for easier optimization during the early stages of training.
Experimental Evaluation
LapSum was evaluated across several standard benchmarks to demonstrate its versatility and scalability:
- CIFAR-100: Testing top-k classification performance when training from scratch.
- ImageNet-1K & ImageNet-21K-P: Fine-tuning ResNeXt-101 models to evaluate ranking performance in high-dimensional spaces (up to 10,000+ classes).
- MNIST: Evaluating k-Nearest Neighbors (k-NN) classification and soft permutations, where the model must reorder digit sequences correctly.
Results and Scalability
LapSum demonstrates superior scalability compared to existing methods. In runtime and memory benchmarks, it consistently outperformed competitors like NeuralSort and Optimal Transport-based approaches. Notably, for dimensions as high as $n=10^7$, LapSum remained functional and efficient, whereas many alternative methods failed due to memory limitations at much lower dimensions.
Key performance highlights include:
- State-of-the-Art Accuracy: On ImageNet-21K-P, LapSum achieved a top-1 accuracy of 40.48%, significantly higher than DiffSortNets (35.96%) and SinkhornSort (36.93%).
- Robust k-NN: The method matched or exceeded specialized k-NN optimization techniques on MNIST and CIFAR-10.
- Permutation Accuracy: On Large-MNIST tasks, LapSum identified correct orderings with higher precision than Gumbel-Sinkhorn, particularly as the sequence length increased.
Conclusion
LapSum provides a highly efficient, $O(n \log n)$ framework for differentiable ranking and sorting. By leveraging the unique properties of the Laplace distribution, it bypasses the computational bottlenecks of iterative solvers and $O(n^2)$ approximations. While the efficiency gains are currently specific to the Laplace distribution, the method's scalability and performance on large-scale datasets like ImageNet-21K-P establish it as a powerful tool for complex structured prediction and ranking tasks in deep learning.
Summary updated