Here is a concise, engaging summary of the paper Prof-K: Probabilistic One-Pass Filtering for Efficient Top-k Selection.
TL;DR
Prof-K is a fast, distribution-agnostic top-$k$ selection algorithm that replaces expensive global sorting operations with a smart, single-pass filtering mechanism. By leveraging a tiny random sample to estimate a conservative threshold, it achieves 1.5$\times$ to 10$\times$ speedups over highly optimized baselines like PyTorch topk while providing rigorous mathematical guarantees of correctness.
What Problem Does This Paper Address?
Finding the $k$ largest elements in a dataset of size $N$ (top-$k$ selection) is a foundational operation used everywhere from database queries to modern machine learning workloads like sparse attention and Sparse Autoencoders (SAEs).
As datasets scale, exact top-$k$ algorithms become heavily bottlenecked on GPUs due to massive memory movement and synchronization overhead. Existing approximate methods try to solve this by estimating data distributions, but they rely on brittle heuristics that fail catastrophically when faced with heavy-tailed data or adversarial inputs. The authors tackle this challenge by designing an algorithm that is both incredibly fast and mathematically robust, regardless of what the underlying data looks like.
Methods
The core idea behind Prof-K is a four-stage, probabilistic one-pass filtering procedure:
- Sampling: Uniformly sample a tiny subset of indices ($S$) from the full dataset without replacement.
- Threshold Estimation: Sort this small sample and pick a specific rank ($t$) to act as a conservative threshold ($\tau$).
- Filtering: Stream through the full dataset exactly once, keeping only the elements greater than or equal to $\tau$ in a compact candidate buffer.
- Refinement: Run an exact top-$k$ routine on this tiny buffer to get the final answer. If the buffer overflows or collects fewer than $k$ elements, the algorithm safely falls back to an exact top-$k$ computation over the full dataset.
What makes Prof-K unique is its theoretical foundation. The authors prove that the rank of the sample-based threshold follows a negative hypergeometric distribution. This allows them to mathematically guarantee that the true top-$k$ elements will be captured with a user-specified probability (e.g., $1 - \epsilon$, where $\epsilon = 10^{-3}$).
Datasets
The authors evaluated Prof-K using two distinct setups:
- Synthetic Benchmarks: Large-scale tensors with sizes $N$ ranging from $2^{22}$ to $2^{30}$ and selection sizes $k$ from $2^5$ to $2^{19}$. To test robustness, they generated data using Uniform, Standard Normal, and heavy-tailed Pareto distributions.
- Real-World ML Workload: They integrated Prof-K into the training loop of a BatchTopK Sparse Autoencoder (SAE) using model activations from the
EleutherAI/pythia-70m-dedupedlanguage model trained on the OpenWebText dataset.
Key Insights and Ideas
- Distribution-Agnostic Guarantees: Because Prof-K samples uniformly by index rather than data value, its mathematical guarantees depend entirely on ranks. This makes the algorithm completely immune to outliers, heavy tails, or adversarial data distributions.
- Sublinear Sample Scaling: The authors derived an approximately optimal sample size that scales as $(kN)^{1/3}$. For a massive dataset of 1 billion elements ($N = 10^9$) and $k = 100$, the optimal sample size is only about 4,600 elements—a microscopic fraction of the input.
- Negligible Memory Footprint: State-of-the-art radix-based top-$k$ methods require $O(N)$ additional memory on the GPU, risking Out-Of-Memory (OOM) errors. Prof-K's auxiliary memory footprint is bounded by the tiny candidate buffer size, making it highly memory-efficient.
Key Results
- Substantial Speedups: Prof-K consistently outperformed native PyTorch
topkand the state-of-the-artRadiKimplementation, yielding 1.5$\times$ to 10$\times$ speedups on both high-end data center GPUs (DGX H100) and consumer hardware (RTX 3060). The largest gains occurred in the large-$N$, small-$k$ regime. - End-to-End Training Acceleration: In BatchTopK SAE training, replacing the exact top-$k$ operator with Prof-K resulted in a 2.27$\times$ kernel-level speedup, translating to a 4.25% reduction in total wall-clock training time.
- No Loss in Quality: Downstream training metrics—including normalized mean squared error (NMSE), cross-entropy degradation, and effective sparsity—remained completely indistinguishable from the exact baseline, proving that the probabilistic relaxation does not harm optimization.
Limitations and Future Work
While powerful, Prof-K's advantages diminish for smaller input sizes ($N$), where the overhead of sampling and filtering outweighs the benefits of avoiding a full sort. Additionally, when applied to batched operations, the probability of encountering a fallback event increases with the batch size, requiring careful hyperparameter tuning.
The authors note that their current implementation is limited to single-node GPU settings; extending Prof-K to distributed environments and broader machine learning architectures remains an open direction for future research.
Summary updated