Fast, Differentiable and Sparse Top-k: a Convex Analysis Perspective
Michael Eli Sander, Joan Puigcerver, Josip Djolonga, Gabriel Peyré, Mathieu Blondel
Abstract
The top-k operator returns a sparse vector, where the non-zero values correspond to the k largest values of the input. Unfortunately, because it is a discontinuous function, it is difficult to incorporate in neural networks trained end-to-end with backpropagation. Recent works have considered differentiable relaxations, based either on regularization or perturbation techniques. However, to date, no approach is fully differentiable and sparse. In this paper, we propose new differentiable and sparse top-k operators. We view the top-k operator as a linear program over the permutahedron, the convex hull of permutations. We then introduce a p-norm regularization term to smooth out the operator, and show that its computation can be reduced to isotonic optimization. Our framework is significantly more general than the existing one and allows for example to express top-k operators that select values in magnitude. On the algorithmic side, in addition to pool adjacent violator (PAV) algorithms, we propose a new GPU/TPU-friendly Dykstra algorithm to solve isotonic optimization problems. We successfully use our operators to prune weights in neural networks, to fine-tune vision transformers, and as a router in sparse mixture of experts.
Ask about this paper
Your agent reads all of it.
Lune indexed this paper to the last equation, along with the top-tier papers that cite it. Ask a question and the answer quotes them.
Cited by top-tier papers15
- Differentiable Clustering with Perturbed Spanning ForestsLawrence Stewart, Francis R. Bach, Felipe Llinares-López, Quentin BerthetNeurIPS 2023 · 16 citations
- Foundations of Top-k Decoding for Language ModelsGeorgy Noarov, Soham Mallick, Tao Wang, Sunay Joshi et al.NeurIPS 2025 · 14 citations
- A path-norm toolkit for modern networks: consequences, promises and challengesAntoine Gonon, Nicolas Brisebarre, Elisa Riccietti, Rémi GribonvalICLR 2024 · 13 citations
- OKRidge: Scalable Optimal k-Sparse Ridge RegressionJiachang Liu, Sam Rosen, Chudi Zhong, Cynthia RudinNeurIPS 2023 · 10 citations
- How Many Tokens Do 3D Point Cloud Transformer Architectures Really Need?Tuan Anh Tran, Duy M. H. Nguyen, Hoai-Chau Tran, Michael Barz et al.NeurIPS 2025 · 5 citations
Builds on15
- An Image is Worth 16x16 Words: Transformers for Image Recognition at ScaleAlexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn et al.ICLR 2021 · 21,477 citations
- Scaling Vision with Sparse Mixture of ExpertsCarlos Riquelme, Joan Puigcerver, Basil Mustafa, Maxim Neumann et al.NeurIPS 2021 · 1,213 citations
- Mixture-of-Experts with Expert Choice RoutingYanqi Zhou, Tao Lei, Hanxiao Liu, Nan Du et al.NeurIPS 2022 · 933 citations
- Efficient and Modular Implicit DifferentiationMathieu Blondel, Quentin Berthet, Marco Cuturi, Roy Frostig et al.NeurIPS 2022 · 386 citations
- BASE Layers: Simplifying Training of Large, Sparse ModelsMike Lewis, Shruti Bhosale, Tim Dettmers, Naman Goyal et al.ICML 2021 · 382 citations
Related papers
- Differentiable Top-k with Optimal TransportYujia Xie, Hanjun Dai, Minshuo Chen, Bo Dai et al.NeurIPS 2020 · 124 citations
- DTop-p MoE: Sparsity-Controlled Dynamic Top-p MoE for Foundation Model Pre-trainingCan Jin, Hongwu Peng, Mingcan Xiang, Qixin Zhang et al.ICML 2026 · 3 citations
- ReMoE: Fully Differentiable Mixture-of-Experts with ReLU RoutingZiteng Wang, Jun Zhu, Jianfei ChenICLR 2025
- Learnable Permutation for Structured Sparsity on Transformer ModelsZekai Li, Ji Liu, Guanchen Li, Yixing Xu et al.AAAI 2026
- Fast Differentiable Sorting and RankingMathieu Blondel, Olivier Teboul, Quentin Berthet, Josip DjolongaICML 2020 · 285 citations
