Abstract
Cascade ranking is a widely adopted paradigm in large-scale information retrieval systems for Top-K item selection. However, the Top-K operator is non-differentiable, hindering end-to-end training. Existing methods include Learning-to-Rank approaches (e.g., LambdaLoss), which optimize ranking metrics like NDCG and suffer from objective misalignment, and differentiable sorting-based methods (e.g., ARF, LCRON), which relax permutation matrices for direct Top-K optimization but introduce gradient conflicts through matrix aggregation. A promising alternative is to directly construct a differentiable approximation of the Top-K selection operator, bypassing the use of soft permutation matrices. However, even state-of-the-art differentiable Top-K operators (e.g., LapSum) require $O(n \log n)$ complexity due to their dependence on sorting for solving the threshold. Thus, we propose DFTopK, a novel differentiable Top-K operator achieving optimal $O(n)$ time complexity. By relaxing normalization constraints, DFTopK admits a closed-form solution and avoids sorting. DFTopK also avoids the gradient conflicts inherent in differentiable sorting-based methods. We evaluate DFTopK on both the public benchmark RecFLow and an industrial system. Experimental results show that DFTopK significantly improves training efficiency while achieving superior performance, which enables us to scale up training samples more efficiently. In the online A/B test, DFTopK yielded a +1.77% revenue lift with the same computational budget compared to the baseline. To the best of our knowledge, this work is the first to introduce differentiable Top-K operators into recommendation systems and the first to achieve theoretically optimal linear-time complexity for Top-K selection.
Introduction
In modern recommendation systems, such as those powering Kuaishou or Amazon, billions of items are filtered through a multi-stage "cascade ranking" funnel. This architecture moves from broad matching to precise ranking, selecting the "Top-K" items at each stage to manage computational costs while maximizing relevance.
A fundamental challenge in this paradigm is that the Top-K operation is discrete and non-differentiable. This prevents the entire funnel from being trained end-to-end using standard gradient descent. Previous attempts to solve this have faced two major hurdles: computational bottlenecks (relying on $O(n \log n)$ sorting) and "gradient conflicts," where items are forced to compete for specific rank positions even if multiple items are equally valid "ground truth" candidates.
The DFTopK Approach
Researchers from Kuaishou and Xi’an Jiaotong University have developed DFTopK, the first differentiable Top-K selection operator that runs in linear time ($O(n)$). DFTopK reformulates Top-K selection as a continuous optimization problem with a closed-form solution, bypassing the need for full sorting.
Key Technical Innovations
- Linear Complexity: Instead of sorting the entire list, DFTopK identifies the $k$-th and $(k+1)$-th largest elements using algorithms like Introselect, achieving optimal $O(n)$ time complexity.
- Adaptive Thresholding: The operator calculates a threshold $\theta(x)$ as the midpoint between the $k$-th and $(k+1)$-th scores.
- Sigmoid Smoothing: By applying a temperature-scaled sigmoid function to the difference between each item's score and this threshold, DFTopK creates a "soft mask." Top-K items receive a probability near 1, while others are pushed toward 0.
- Relaxed Constraints: Unlike sorting-based methods that use soft permutation matrices, DFTopK relaxes strict "sum-to-K" constraints. This reduces coupling between items, preventing the model from penalizing one ground-truth item simply because another is ranked higher.
Experimental Evaluation
DFTopK was evaluated on the RecFlow public benchmark and within Kuaishou’s production system, which processes approximately 20 billion user-ad pairs daily.
As shown in the results, DFTopK consistently outperforms state-of-the-art differentiable operators like LapSum and NeuralSort. A critical insight from the evaluation is that the $O(n)$ efficiency of DFTopK allows for significantly larger negative sampling sizes during training within the same computational budget. This scalability directly translates to better model performance, as the model can learn from a much broader set of examples.
Real-World Impact and Conclusion
In a 15-day online A/B test at Kuaishou, DFTopK demonstrated substantial industrial value:
- +1.77% Revenue Lift through more efficient training data scaling.
- +1.5% Conversion Lift.
- 15.3% Reduction in average computation time per impression.
By localizing uncertainty to the decision boundary and achieving linear-time complexity, DFTopK provides a robust, scalable solution for end-to-end training in large-scale retrieval. The authors have open-sourced the implementation, suggesting potential applications beyond recommendations, such as differentiable Top-K sampling in Large Language Models (LLMs) or object detection in computer vision.
Summary updated