Paper commentary
e-means: outperforming k-means (in one-tenth the epochs)
e-means clusters faster than Lloyd k-means using EMA centroid updates
- Problem Lloyd's k-means reads the whole dataset on every iteration, while mini-batch k-means converges fast but stops at a higher error. Choosing its batch size and step for a new problem has also required tuning.
- Method e-means updates each centroid as an exponential moving average over mini-batches, instead of a full pass. Scaling laws set the decay rate and batch size from the problem size and epoch budget, so no sweep is needed.
- Results e-means beats Lloyd's 25-epoch loss in 1.4 to 2.6 epochs, with 10-45x GPU wall-clock speedups over state-of-the-art k-means implementations.
Why Lloyd is slow and mini-batch stops short
k-means picks k centroids so that each vector sits close to its nearest one, measured as mean squared distance. Lloyd's algorithm solves this by alternating a full pass that assigns every vector to a centroid with a step that moves each centroid to the mean of its points. Each iteration therefore reads the whole dataset, and in practice the number of iterations is capped.
Mini-batch k-means is the cheaper route: it updates centroids from small batches, so it converges quickly on large data. The price is a higher approximation error than Lloyd reaches when given enough iterations. That is why Lloyd is still the default for static datasets, often combined with a good seeding scheme.
Earlier mini-batch methods decay their step, but none of them says how to choose the batch size or the step for a new problem. Exponential moving average centroids, common in vector-quantized autoencoders, were built to track shifting distributions, so their decay is usually left as a fixed constant. That family has not been compared with Lloyd's full-batch k-means, which leaves open whether an EMA-based mini-batch update can beat Lloyd in far fewer epochs without a sweep.
Decayed counts and sums per centroid
The core idea is to take the EMA update from vector-quantized autoencoders and aim it at a fixed dataset, where the goal is minimum MSE rather than tracking a moving target. Each cluster keeps a decayed count and a decayed sum of the points assigned to it, and its centroid is the ratio of the two. Because the centroids are never stored, the algorithm recomputes them from S_j and N_j whenever a batch needs them.
Old batches fade at a rate set by the decay, so each centroid behaves like a running mean with a short memory rather than a mean over the whole run.
Each batch contributes a count n_j and a sum s_j for cluster j, both taken from the nearest-centroid assignment of its points. The update N_j ← γN_j + (1−γ)n_j and S_j ← γS_j + (1−γ)s_j weights the old statistics by γ and the new batch by 1−γ. Because the two statistics decay in the same way, their ratio stays a weighted mean of the assigned points.
The step size is α = 1 − γ, the fraction of the way each centroid moves toward the points of its batch. The authors anneal α on a cosine curve with ε = 0.1, from a peak α0 at the first update down to 0.1 α0 at the last. The aim is to make centroids move less as training goes on, which progressively stabilizes their movement. They say they know of no earlier use of this schedule in this setting, and they ablate it in Appendix G.3.
Algorithm 1 chains these pieces: random initial centroids, then for each batch of a fresh shuffle, the algorithm assigns points and updates the statistics. Every five batches, dead clusters are revived, and the paper uses a threshold of 0.1 of the mean count. After T epochs the run has made M = T⌊n/B⌋ updates, and the final centroids are the means of the last epoch's assignments.
Reviving idle clusters and choosing the final centroids
Plain EMA has a weakness: a cluster can stop receiving points and stay unused, and the update alone never repairs it. Every five batches, e-means reassigns clusters whose count N_j falls below a fraction τ = 0.1 of the mean count. Each of these clusters gets its centroid rebuilt by splitting a donor cluster, the procedure Faiss uses for the same purpose.
Dead-cluster revival has the highest influence in the ablation of Table 1, and the authors call resampling vectors from the data the vanilla VQ-VAE solution that is suboptimal.
Resampling in place of revival raises train MSE by 2.06% and test MSE by 1.15%, so splitting a donor beats resampling. The other components move results by a fraction of a percent, and k-means++ initialization improves them slightly at T=3. The authors say k-means++ costs too much for low epoch counts, so training longer is the better choice there.
The paper offers two finalization strategies, and each one targets a different goal. Last-epoch-mean records the assignment of every training point in the last epoch and averages the points per cluster. Because it reuses those last-epoch assignments, its cost is negligible, and it is guaranteed to decrease the train MSE, so e-means uses it by default.
Slow-EMA keeps extra averages with a single half-life hyper-parameter h, accumulating counts and sums with a slower decay. These slow averages follow the same splitting logic but never feed back into training, so they target generalization to new vectors.
Finalization changes the numbers only a little: removing it moves train MSE by +0.14% and test MSE by +0.02%. Table 1 shows the last-epoch mean improving train MSE over no finalization, while slow-EMA improves test MSE. The authors note that both finalization schemes matter most when n/k is low.
Choosing the step and batch size from scaling laws
The method takes the number of points n, the cluster count k and the epoch budget T, and returns a batch size B and a peak step α0. Both targets are fitted as ordinary least squares on logarithms, so the laws are linear in log space. The authors fit the laws on validation MSE from the DEEP dataset only, and they observe that the resulting laws transfer to other datasets in a satisfactory manner.
For a fixed batch size B, the peak step law has the form α0 = min(c k^a_k B^a_B n^a_n T^a_T, 1), with one exponent per variable. The fitting target is the α0 that gives the lowest validation MSE, because a step that is too small under-trains and a step that is too large is unstable. The cap at 1 keeps the step a valid fraction of the way a centroid moves toward its assigned points.
The batch law targets the knee, which the authors define as the maximum batch size whose validation MSE is within +0.2% of the curve's minimum.
Table 2 reports the fitted coefficients, with an R² of 0.95 for the step law and 0.96 for the batch law. The LOSO setting leaves one n value out of the fit and evaluates on it, while OOD evaluates on other datasets such as SIFT, SPACEV and VIBE. The authors note a limitation: the laws were tuned for relatively high-dimensional datasets and are not optimal for very low-dimensional, tiny datasets.
Speed and loss against Lloyd and GPU k-means
The evaluation fixes the protocol before any run, so no hyperparameter gets tuned per experiment. Runs stop at 25 epochs, and test MSE on a held-out split is the score that the authors report. Lloyd at 25 epochs serves as the reference, since Faiss uses it as its default. The authors scale the batch size and decay from the scaling laws, and they initialize centroids by sampling the dataset uniformly without replacement.
Across four datasets at two scales, e-means ends with a lower loss than Lloyd started randomly or with k-means++. The mini-batch baselines, Sculley and Staleness-Reduction, beat Lloyd after one epoch but converge to a higher MSE. The margin over Lloyd is small on some datasets, and the paper says it comes from a fifth of the full passes over the data.
The authors also report that k-means++ cannot reduce the MSE as well as e-means on the evaluated datasets, even after discounting a faster implementation.
On average, e-means takes two epochs to drop below Lloyd's converged test MSE. On one H100, e-means reaches Lloyd@25 on GooAQ in 0.16 s, while Flash-KMeans takes 1.77 s, an 11.1× speedup. Across the eleven VIBE datasets, the GPU speedups over Flash-KMeans range from 8.0× to 22.8×. Flash-KMeans runs in fp16 while e-means runs in bf16, and the timings are medians over twenty seeds.
On 64 CPU cores, e-means takes 29.3 s on GooAQ against 274.0 s for Faiss, a 9.3× speedup.
Reduced precision changes only the nearest-centroid search, while counts and sums stay in FP32. Across the reported configurations, test MSE under FP8 and INT8 assignment stays within 0.13% of BF16. The FP8 and INT8 entries are all lower than the Flash-KMeans result after 25 iterations.
Limits of the evidence
The scaling laws were tuned on relatively high-dimensional datasets, so they aren't optimal for very low-dimensional and tiny datasets. The authors point to the local intrinsic dimensionality of the data as the quantity that matters, and it is usually unknown. That unknown makes refining the scaling law a key challenge for future work.
Some high-dimensional synthetic cells overfit, which the authors call the red cells. In those cells e-means reaches Lloyd's final test MSE within a few epochs, but its test MSE grows in the last epochs. As a result, the test MSE of e-means ends higher than Lloyd's in those cells.
The main experiments use random initialization for e-means, and they don't combine k-means++ with it.
In the optimizer comparison, Adam, SparseAdam and SGD roughly match EMA at small batch sizes. At large batch sizes, all of these optimizers degrade compared to EMA, and SGD typically collapses after a critical learning rate. The authors hypothesize that SGD steps don't keep the centroid inside the convex hull of its assigned points, while an EMA centroid always stays there.
For nearest-neighbour search with an inverted file index, e-means reaches the converged recall of Flash-KMeans much faster. Its recall is either better or similar on most datasets, with the clearest gains on CelebA and Landmark-DINO.
Paper info
- Authors
- Swann Bessa, Pierre-Emmanuel Mazaré, Gergely Szilvasy, Hugo Touvron, David Picard, Matthijs Douze, Hervé Jégou
- Venue
- arXiv · Preprint
- First published
- 2026-11-6
- Added
- 2026-11-9
- Updated
- 2026-11-6
- Version
- v1
- arXiv
- 2611.09501
- Category
- cs.LG · cs.AI
- Original paper terms
- CC BY 4.0
- What we show
- Paper info, commentary and permitted figures from the original paper
AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.
Abstract
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.
Quote from the paper
Swann Bessa, Pierre-Emmanuel Mazaré, Gergely Szilvasy, Hugo Touvron, David Picard, Matthijs Douze, Hervé Jégou (2026). e-means: outperforming k-means (in one-tenth the epochs). arXiv:2611.09501v1. https://arxiv.org/abs/2611.09501v1
BibTeX
@misc{bessa2026means,
title = {{e-means: outperforming k-means (in one-tenth the epochs)}},
author = {Swann Bessa and Pierre-Emmanuel Mazaré and Gergely Szilvasy and Hugo Touvron and David Picard and Matthijs Douze and Hervé Jégou},
year = {2026},
eprint = {2611.09501},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2611.09501v1}
}