E-means: 10x faster k-means at equal loss e-means.github.io · 222 points · 13 co...
HN Best 30 @best30
E-means: 10x faster k-means at equal loss e-means.github.io · 222 points · 13 comments · HN thread
TL;DR Meta FAIR open-sourced e-means, a replacement for Lloyd's algorithm for k-means clustering that uses mini-batch exponential-moving-average centroid updates. The authors report about 10x fewer epochs and 8–45x lower end-to-end wall-clock time than Lloyd-based implementations (Flash-KMeans on GPU, Faiss on CPU), while reaching lower loss.
- e-means replaces Lloyd's full-batch update with mini-batch updates using exponential moving averages of cluster sums and counts, so centroids stay in the convex hull of their assigned points.
- Batch size and step size are set automatically by two fitted scaling laws in n, k and T, so users need no extra hyperparameters compared with Lloyd.
- Dead-cluster revival splits large clusters (sampled proportionally to size) instead of resampling points from the batch; on DEEP with 1M vectors and k=16,384 it leaves 47 dead clusters versus 2,343 with the EnCodec-style approach.
- Reported speedups: test loss below Lloyd's at 25 epochs reached in 1.2 to 3 epochs; 10–45x wall-clock reduction on GPU vs Flash-KMeans and 8–15x on CPU vs Faiss.
- Lloyd is presented as a special case (full batch, step 1) that the authors' hyperparameter search finds to be highly suboptimal. The code is in the Faiss repo under faiss/contrib/e_means and the paper is arXiv:2611.09501.
Discussion The thread is short and mostly appreciative, with commenters focusing on where the method fits and whether its gains are real. The most detailed exchange is a commenter who tried e-means on a spherical mesh relaxation and found it worse, because that problem has no dataset and mini-batch sampling only adds noise. Others discuss the connection to EM and simulated annealing, the general value of approximate solutions to NP-hard problems, and skepticism that the hyperparameter laws were fit after the fact. One commenter reports a 146x GPU speedup in their own IVF index. Overall the mood is positive and curious.
- Impressive and clever, with the visualizations explaining it well (many): Several commenters praise the idea as obvious in hindsight and the explanatory visuals as clear. Some say they plan to try it later.
- Approximate solutions to NP-hard problems are the right framing (some): One commenter notes that for NP-hard problems approximations are enough, and others add that operations research is built on this premise and that randomized and sparse methods share it.
- Not better for problems without a dataset (a few): A commenter testing mesh relaxation on a sphere found e-means slower and noisier, since the centroids there can be computed exactly from geometry and sampling only adds noise.
- Hyperparameter scaling laws look post-hoc or unintuitive (a few): Some doubt the automatic batch and step laws, asking for intuition behind them and suspecting they were fit after the experiments.
- Theoretical link to EM or annealing (a few): One commenter suggests the update could be read as expectation maximization with a friction term, and notes that staying inside the convex hull is important.
- Would like it in scipy (a few): A commenter wants the method in scipy, since it is more available in common environments than Faiss.
Links from the comments
- Explanation of Lloyd-style relaxation of cells on a sphere, the setting where a commenter found e-means did not help
- Cambridge course notes on randomised algorithms, recommended in the thread
#kMeans #clustering #Lloyd #miniBatch #scalingLaws #machineLearning