arXiv:2611.09501cs.LGNov 2026Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:2611.09501

e-means: outperforming k-means (in one-tenth the epochs)

Swann Bessa, Pierre-Emmanuel Mazaré, Gergely Szilvasy, Hugo Touvron, David Picard, Matthijs Douze, Hervé Jégou

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Swann Bessa¹,², Pierre-Emmanuel Mazaré¹, Gergely Szilvasy¹, Hugo Touvron¹, David Picard², Matthijs Douze¹, Hervé Jégou¹

¹FAIR at Meta, ²École Nationale des Ponts et Chaussées

Lloyd's k-means algorithm is a long-running standard for clustering, with applications in data analysis, retrieval, quantization and data curation. In this paper, we introduce an exponential moving average optimization procedure for k-means with mini-batch updates, powered by modern deep learning machinery and new insights. We also establish scaling laws on how decay rate and batch size impact final performance. This gives us a formulaic rule to fix them for multiple problem sizes and embedding datasets, without the need for any hyperparameter sweep.

The resulting clustering algorithm, coined e-means, is much faster than Lloyd k-means and converges to lower losses, frequently even beating k-means++. On a wide array of embeddings datasets, it beats the loss of Lloyd k-means at 25 epochs in 1.4 to 2.6 epochs, which translates to 10-45x GPU wall-clock speedups compared to state-of-the-art k-means implementations. As an example, e-means partitions DINO10B, a dataset of 10 billion DINO embeddings, into 16 million clusters in only 2.5 epochs, reaching a loss below Lloyd's at 25 epochs.

Library: https://github.com/faiss/... /e Means

Website: https://e-means.github.io

Correspondence: Swann Bessa at swann@meta.com

Meta

Figure

Figure

Figure 1 e-means vs Faiss-GPU and Flash-KMeans on the DINO10B dataset (1024 dimensions). Left: Test loss as a function of the number of epochs (passes over the 100M training vectors). e-means converges to a lower loss than the two implementations of k-means, and outperforms their loss at 25 epochs in just 2 epochs.

Right: aggregated GPU runtime to reach k-means' loss at 25 epochs on H100 GPUs for various dataset sizes (k≈n/500k \approx n/500 is a power of 2). Flash-KMeans is limited to one node, so we used our own implementation of k-means to run it above 100M scale. e-means saves about 10x compute relatively to the state-of-the-art implementations. On very large datasets, combining e-means with an IVF yields further speedups, see Appendix M.

1 Introduction

Given a fixed dataset X={x1,x2,…,xn}⊂RdX = \{x_1, x_2, \ldots, x_n\} \subset \mathbb{R}^d and an integer kk, kk-means aims at finding a set of kk centroids C=(c1,…,ck)C = (c_1, \ldots, c_k) minimizing the mean squared distance between samples and their nearest centroid:

MSE(X,C)=1n∑i=1n∥xi−ca(i)∥2,wherea(i)=arg⁡min⁡j∈{1,…,k}∥xi−cj∥2.(1)\mathrm{MSE}(X,C) = \frac{1}{n} \sum_{i=1}^{n} \|x_i - c_{a(i)}\|^2, \quad \text{where} \quad a(i) = \arg\min_{j \in \{1,\ldots,k\}} \|x_i - c_j\|^2. \tag{1}

This problem has applications in clustering, compression, indexing for retrieval, image segmentation or data curation, to mention only a few. Recently, it has also been used in LLM stacks to compress the attention cache (Liu et al., 2024; Hooper et al., 2024) or sparsify the attention (Wang et al., 2020; Zhu et al., 2025).

The full-batch k-means algorithm, also referred to as the Lloyd algorithm, starts from an initial set of centroids. At each iteration, Lloyd performs full-dataset assignment to the centroids and then updates each centroid as a mean of its assigned points. The optimization is guaranteed to converge to a local minimum in a finite number of iterations (Lloyd, 1982). In practice, the number of iterations (or epochs) is capped.

Another line of work, known as mini-batch k-means, updates the centroids from mini-batches rather than from the whole dataset. It has proven itself a low-latency alternative to full-batch Lloyd for web-scale clustering (MacQueen, 1967; Sculley, 2010). It is also used in streaming settings, where the incoming data may undergo concept drift (Apache Spark, 2014; Bidaurrazaga et al., 2021), codebook learning inside VQ-VAEs being an example (van den Oord et al., 2017).

Where mini-batch k-means has been compared to Lloyd, it typically has a higher approximation error, though with faster convergence. For static fixed datasets, Lloyd remains the default in the literature, reaching the lowest MSE when run with enough iterations or combined with initialization schemes (Hartigan and Wong, 1979; Franti and Sieranoja, 2019; Arthur and Vassilvitskii, 2007; Béjar, 2013). Sculley (2010)'s mini-batch k-means and MacQueen (1967)'s sequential formulation are the most influential mini-batch implementations with a gradient descent update rule. In both, a centroid is the running mean of the points assigned to it throughout the training (Bottou and Bengio, 1994).

Our approach, e-means, applies a specialized optimization procedure based on exponential moving average (EMA) updates (van den Oord et al., 2017) with mini-batches. Where VQ-VAEs use EMA to track a shifting embedding distribution, we apply several modifications to retarget it at the canonical k-means problem, i.e. minimizing MSE on a fixed dataset. Our method comes with a scaling law that sets its batch size and decay rate from the problem configuration, so e-means requires as little hyperparameter tuning as Lloyd. It consistently converges to lower losses an order of magnitude faster than Lloyd, vastly outperforming previous mini-batch k-means approaches and requiring unlike them no hyperparameter sweep.

In summary, with e-means we make the following contributions:

  • A modern optimization strategy for mini-batch k-means: We specialize the original EMA algorithm to k-means in multiple ways: we couple it with a decaying schedule on the learning rate, we improve the initialization and the dead-cluster revival strategy, and we introduce a finalization stage that reduces the training loss for a negligible runtime penalty at the end of the training. Our proposal significantly improves mini-batch k-means while being robust to a wide array of configurations (Section 3).

  • Scaling laws for automatic hyperparameter tuning: we explore how the batch size and the decay/learning rate influence clustering performance, and how their optimal values scale with the input configuration (Section 3.3). From that study, we provide equations to automatically select hyperparameters from the problem configuration.

  • A scalable method and package for practitioners: we evaluate e-means on a wide collection of embeddings datasets. On average, it takes two epochs to drop below Lloyd's converged test MSE. We compare its speed-loss tradeoff to state-of-the-art libraries, Faiss (Douze et al., 2024) on CPU, Flash-KMeans (Yang et al., 2026) on GPU (Section 4).

  • DINO10B, a new 10B dataset of DINO features (Siméoni et al., 2025) to evaluate clustering at very large scale (Appendix K). It also serves as a benchmark for approximate nearest neighbor search.

References (54)