cs.AIAug 7, 2026

Fast LapSum: Exact Differentiable Top-k at Million Scale

Authors: Łukasz StruskiJoanna WojciechowiczJakub AntczakMarcin MazurKamil KsiążekJacek Tabor

Organizations: Faculty of Mathematics and Computer Science, Jagiellonian University, Kraków, Poland. · Wrocław University of Science and Technology, Wrocław, Poland. · Centre for Credible Artificial Intelligence, Warsaw University of Technology, Warsaw, Poland.

Abstract

The top-kk operation is a fundamental building block of modern sparse computation, enabling token routing, expert activation, memory selection, and attention pruning. Yet standard hard top-kk blocks gradients, while existing continuous (soft) relaxations remain too costly for large-scale models. We introduce Fast LapSum, an exact-budget soft top-kk primitive whose GPU solver runs in linear time after sorting. Unlike prior linear-time methods such as DFTopK, which relax the normalization constraint, Fast LapSum is, to our knowledge, the first method to preserve an exact selection mass of kk while remaining fully differentiable end-to-end. Our solver combines a linear-time threshold computation with an analytical vector--Jacobian product, and for extreme scales employs probabilistic bracketing to sort only the uncertain middle band of kernel-noised scores. The resulting overhead is almost negligible: the solver processes 10610^6, 10710^7, and 10810^8 scores in 0.410.41, 1.151.15, and 5.235.23,ms, respectively. This makes exact soft top-kk practical for sparse routing, retrieval, and large-scale optimization. We demonstrate Fast LapSum on two demanding applications operating over millions of coordinates inside the training loop: generating megapixel sparse adversarial examples with an exact soft budget of 0.02%{\sim}0.02\% of an image's pixels, achieving an order-of-magnitude speedup over state-of-the-art methods, and training a fully differentiable sparse image coder from scratch.

Explore similar work

CardsList
  1. LaPrune: Controllable Differentiable Sparsity at Million Scale

    Aug 4, 2026Jakub Antczak, Joanna Wojciechowicz, Łukasz Struski +1SparsityTop-K