| Data and objective | |
|---|---|
| number of training points | |
| dimension of each point | |
| number of clusters | |
| training point , a vector in | |
| centroid of cluster , a vector in | |
| index of the centroid nearest to | |
| mean squared distance from each point to its nearest centroid | |
| One e-means update | |
| batch size, the number of points read per update | |
| the current batch of points | |
| number of passes (epochs) over all points | |
| number of updates in a run, | |
| index of the current update, from to | |
| number of batch points assigned to cluster | |
| sum of the batch points assigned to cluster | |
| mean of the batch points assigned to cluster (named in this note) | |
| running count of cluster , decayed at every update | |
| running sum of cluster 's points, decayed at every update | |
| decay applied to and at each update | |
| fraction of the way from to that the centroid moves in one update (derived in this note) | |
| learning rate of a gradient step on the centroids, for comparison | |
| Schedule and revival | |
| step size | |
| peak step on the first update, set by the step law | |
| perturbation that splits a donor centroid into two | |
| Constants | |
| final step of the cosine schedule as a fraction of | |
| starting value of every running count | |
| tolerance of the batch law above the best batch's validation MSE | |
| The paper writes | |
| the paper's and | |
| the paper's | |
| the appendices' | |
Context. Given points in , k-means places centroids to minimize the mean squared distance from each point to its nearest centroid. It clusters data, compresses vectors, partitions vector databases for nearest-neighbor search, and compresses language-model attention caches. Lloyd's algorithm is the standard solver. Each iteration assigns every point to its nearest centroid, then moves each centroid to the mean of its assigned points. That requires one full pass over the dataset, and libraries stop after a fixed count, 25 by default in Faissa library for nearest-neighbor search and clustering of dense vectors, with CPU and GPU implementations of Lloyd's algorithm (Douze et al., 2024). Mini-batch k-meansSculley's (2010) variant of k-means. For each batch, assign its points to their nearest centroids, then move each centroid toward each of its points with step , where counts the points ever assigned to that centroid, so the centroid is the running mean of every point assigned to it since the start updates centroids after every small batch and makes faster early progress, yet where compared with Lloyd it typically levels off at a higher loss. Bessa et al. (2026) adapt the exponential moving average from VQ-VAEvector-quantized variational autoencoders (van den Oord et al., 2017), which replace each encoder output by its nearest vector in a learned codebook. One way to train the codebook keeps each code vector as an exponential moving average of the encoder outputs assigned to it codebook training to k-means on a fixed dataset. They pair it with fitted power laws that pick the batch size and step size automatically from , , and the pass budget.
The resulting method, e-means, matches the held-out loss of 25 Lloyd iterations in about two passes, with no hyperparameter sweep. Both methods spend almost all their compute assigning points to centroids, so one pass costs about the same in each. Lloyd moves the centroids once per pass, whereas e-means moves them after every batch, landing each move on the segment between the old centroid and the batch mean. For a million points in 16,384 clusters, its laws pick a batch size that gives 15 updates per pass. On four embedding datasets from 1 million to 1 billion vectors, e-means matched the held-out MSEthe MSE on test vectors never used in training, either a dataset's provided queries or 20,000 deduplicated vectors removed from it. The held-out set is split in half, into a validation set (used to fit the laws) and the test set that is reported of 25 Flash-KMeansa GPU implementation of Lloyd's algorithm (Yang et al., 2026) that compares points with centroids block by block and keeps only each point's nearest centroid so far, so it never stores the full matrix of point-to-centroid distances iterations in 1.4 to 2.6 passes. On GPUs that ran 9.5 to 45.5 times faster. With more passes, e-means edges below randomly seeded Lloyd and matches or slightly beats Lloyd started from greedy k-means++a seeding rule (Arthur and Vassilvitskii, 2007) that picks the starting centroids one at a time, each a data point drawn with probability proportional to its squared distance to the nearest centroid already chosen. The greedy variant in scikit-learn draws several candidates at each step and keeps the one that lowers the MSE most. Each choice depends on the previous ones, so the rule is hard to parallelize seeds, skipping that slow sequential seeding step.
Setting. For points and centroids , k-means minimizeswhere , the index of the centroid nearest to is the index of the centroid nearest to . One epochone pass over all training points. One Lloyd iteration is one epoch, and the paper counts both methods' budgets in epochs is one pass over all points, called a pass here. e-means reads the data in freshly shuffled batches the current batch of points of size the batch size, the number of points read per update. Clusters receive uneven numbers of points in a batch, and some receive none. For each cluster , e-means therefore tracks a decayed running count the running count of cluster , a positive number decayed by at each update and topped up by the batch count and a decayed running sum the running sum of cluster , a vector in decayed by at each update and topped up by the batch sum , setting the centroid to their ratio. On each batch it counts the the number of points of the current batch assigned to cluster points assigned to cluster , sums them into , the sum of the batch points assigned to cluster , and applies decay the decay, in , applied to and at each update. It changes over the run (the step is scheduled):
The update reads more clearly as a move on the centroid itself. Write , the mean of the batch points assigned to cluster (named in this note) for the mean of the batch points assigned to , substitute for the old running sum, and divide:Since the fraction of the way from to that cluster 's centroid moves in one update, (derived in this note) lies in , the new centroid always lands on the segment between and . It moves farther when is large relative to . Lloyd's update is the full-data extreme , with taken over the whole dataset. Sculley's mini-batch k-means takes the same form, with equal to divided by all points ever assigned to . Every past point keeps equal weight, even points assigned while the centroid sat elsewhere. e-means instead multiplies each past batch's weight by on every later update, so stale assignments fade.
A gradient step on the batch's squared error behaves differently. At learning rate the learning rate of a gradient step on the centroids, used here only for the comparison with SGD, gradient descent updates cluster to . Unlike , the factor has no upper cap of 1, so it overshoots whenever . The authors point to this difference when comparing with SGD and Adam below, to explain why gradient methods break down at large batches.
Schedule and initialization. A run of the number of passes (epochs) in a run passes makes the number of updates in a run, updates, indexed by the index of the current update, from to from to . To move quickly early and settle smoothly late, the step size the step size , the weight a new batch gets in and follows a cosine schedule from a peak the peak step, used on the first update and set by the step law down to the floor of the cosine schedule as a fraction of , fixed at 0.1 with :The run starts from data points drawn without replacement. Every running count starts at , so those initial centroids carry almost no weight once batches arrive.
Dead-cluster revival and final centroids. A centroid that stops receiving points wastes one of the slots. Every five updates, e-means checks for any dead clustera cluster that has stopped receiving points, so its centroid no longer moves and one of the centroids is wasted. e-means treats a cluster as dead when falls below a tenth of the mean count whose running count has fallen below a tenth of the mean count. To revive it, e-means draws a donor cluster with probability proportional to its count and splits the donor centroid. Each coordinate of the donor is multiplied by with alternating signs, where the size of the perturbation that splits a donor centroid, the machine epsilon of BF16 is the machine epsilon of BF16. One child replaces the donor, the other replaces the dead cluster, and each takes half the donor's count. When training finishes, e-means replaces each centroid with the mean of the points assigned to it during the last pass. That gives the best centroid for those assignments at almost no extra cost. An alternative ending keeps a slower moving average alongside the run when held-out MSE matters more than training MSE.
Scaling laws for batch size and peak step. To remove per-dataset tuning, the authors fit power laws for and in , , and alone. They fit by least squares on logarithms across about 75,000 runs on a single dataset, DEEPa benchmark of 96-dimensional image embeddings (Babenko and Lempitsky, 2016), used here at 1 million to 1 billion vectors, covering and :The rule rounds to the nearest power of two, caps it at , and divides it by 8 above 2 million points, where smaller batches ran just as fast. The peak step is capped at 1. Validation MSE rises sharply once the batch passes a threshold, so the batch law targets the largest batch within 0.2% of the best batch's validation MSE. Larger batches take larger steps, while more clusters or more points call for smaller steps. On held-out datasets, the batch law landed a median 0.19% above the best batch. Across four other datasets, the step law landed a median 0.07% above the best step. For , , and , these laws pick (about 4 points per cluster per batch) and (computed here).
Consequences and limits. On high-dimensional embeddings, e-means replaces 25 Lloyd iterations with 2 to 3 passes at equal or lower held-out loss, leaving only and to choose. That saving matters most when each pass is expensive, as in billion-scale vector search. Inverted-file indexesnearest-neighbor indexes that partition the database into the clusters of a k-means run and, for each query, scan only the clusters whose centroids are nearest to it built on e-means centroids reached the recall of Flash-KMeans' converged centroids sooner and ended at similar or better recall on most of eleven datasets. The code lives in Faiss under contrib/e_means. All tests use embedding or synthetic data, and the authors warn that laws fitted on one high-dimensional dataset are not optimal for very low-dimensional or tiny datasets. Matching Lloyd's training MSE takes more passes than matching held-out MSE. A few high-dimensional synthetic settings show late-pass overfitting in held-out MSE, and running past 25 passes did not help.
Passes to match Lloyd. Across every real dataset tested, e-means reaches Lloyd's 25-iteration held-out MSE within three passes, measured in 0.2-pass steps against randomly seeded Lloyd. Against Flash-KMeans on DEEP, DINO10Ba dataset released with the paper (CC-BY 4.0) of 10 billion 1024-dimensional patch embeddings, from a DINOv3 vision transformer applied to 60 million Flickr images of YFCC100M, quantized to one byte per coordinate and deduplicated, SPACEVa benchmark of 100-dimensional text embeddings from the BigANN 2021 challenge, and SimSearchNet++a benchmark of 256-dimensional image embeddings from the BigANN 2021 challenge (Douze et al., 2021), it needed 1.4 to 2.6 passes (Table 4, medians over 10 seeds, one seed at 1 billion). Those runs span 1 million to 1 billion vectors and from 16,384 to 1,048,576. Against Faiss on eleven datasets of the VIBE benchmarka vector-search benchmark of modern text and image embedding datasets (Jääsaari et al., 2025), with dimensions from 200 to 3,072 among those used here, it needed 1.6 to 2.6 passes. With 1,000 points per cluster across nine datasets, matching held-out MSE took 1.0 to 3.0 passes, while matching training MSE took 2.0 to 4.0. Across seven synthetic distributions (uniform, Gaussians with several spectra, and Gaussian mixtures), the median was 2.3 passes across dataset sizes. Sculley's method and a newer mini-batch variant (Zhu et al., 2024), both tuned on validation data, beat Lloyd after one pass yet level off above its 25-iteration loss. On all four convergence-plot datasets, e-means finishes below that baseline in both training and held-out MSE.
Wall-clock speedups. Assignment dominates each pass in both methods, so saved passes convert directly into wall-clock speedups once the assignment kernels match in speed. Run as plain Lloyd, the authors' GPU kernels match Flash-KMeans. At those pass counts, e-means ran 9.5 to 12.9 times faster than Flash-KMeans on one H100 GPU at 1 million vectors, and 21.2 to 45.5 times faster on eight H100s at 1 billion. e-means assigns in BF16 and Flash-KMeans in FP16. Switching e-means to 8-bit assignment moved held-out MSE by at most 0.13% relative to BF16. On the VIBE datasets, GPU speedups ran 8.0 to 22.8 times, and on 64 CPU cores against Faiss (both in FP32) they ran 9.0 to 15.0 times. On CPU, e-means also reached Faiss's 25-iteration loss well before SuperKMeansa CPU implementation of Lloyd's algorithm (Kuffo et al., 2026) that stops a point-to-centroid distance computation early (ADSampling, Gao and Long, 2023) once its partial sum shows the centroid is very unlikely to be the nearest. In the paper's tests it was the fastest such pruning method, ahead of Elkan's and Yinyang k-means.
Scaling to 10 billion vectors. The largest test partitions DINO10B's 10 billion vectors into (about 16.8 million) clusters. Twenty-five passes of Lloyd took 6,784 GPU-hours across 64 machines. Exact e-means matched Lloyd's held-out MSE in 2.5 passes and 779 GPU-hours on 32 machines, sized mainly to hold the data in memory. Adding an IVF indexan inverted-file index over the centroids. The centroids are grouped into buckets around a smaller set of meta-centroids (4,096 or 16,384 at 10 billion vectors), and each point compares itself only with the centroids in its few nearest buckets, which makes the assignment approximate over the centroids cut the cost to about 23 GPU-hours, or 3 hours on a single 8-GPU machine. Approximate assignment favors held-out MSE. Matching Lloyd's training MSE with IVF assignment took 4 passes, still 155 times fewer GPU-hours than Lloyd.
Comparison with greedy k-means++. In the authors' tests, standard k-means++ did not improve Lloyd's final MSE, whereas greedy k-means++ did. That makes greedily seeded Lloyd the strongest baseline. Table 5 compares four datasets at 1 million and 10 million vectors, reporting medians over 10 seeds. Three passes of e-means sit 0.21% to 0.40% below 25 randomly seeded Flash-KMeans iterations, while greedy seeding lowers Flash-KMeans by 0.08% to 0.54%. Against greedily seeded Flash-KMeans, 5 passes of e-means end lower by 0.06% to 0.33%. At 3 passes, e-means sits higher on 5 of 8 configurations by at most 0.19% (computed here from Table 5). Figure 5 compares 25 passes of e-means against Lloyd run to convergence on two VIBE datasets and SPACEV across 40 seeds. In those histograms (read from the figure), e-means finishes about 0.6% to 0.9% below greedily seeded Lloyd in held-out MSE, and about 0.9% to 2.1% below randomly seeded Lloyd, with disjoint distributions across seeds.
Seeding cost. Greedy k-means++ is sequential and slow at large . On the authors' 64-core CPU, scikit-learn's greedy k-means++ took 2,852 to 6,080 seconds to pick 16,384 seeds from 1 million vectors (Table 12). On the same CPU, an entire 5- or 10-pass e-means run took 22 to 72 seconds, making seeding 73 to 160 times longer. Starting e-means from greedy k-means++ seeds changed its MSE by at most 0.19%, so it uses random data points instead.
Ablations: dead-cluster revival matters most. Table 1 ablates components one at a time on DEEP (, , , medians over 30 seeds), and revival carries by far the largest gain. Dropping revival raises training MSE by 2.97% and held-out MSE by 2.24%. Without it, 26% of the 16,384 clusters end dead, holding fewer than ten points each, against 0.3% with revival. Refilling dead slots with random batch points, the VQ-VAE remedy, recovers only part of that loss (+2.06% training, +1.15% held-out). The cosine schedule and last-pass mean each move MSE by fractions of a percent. Against a constant step retuned on validation data at 3 passes, the cosine schedule lowers training MSE by 0.26% to 1.29% across all eight configurations tested, and lowers held-out MSE in five.
Moving average versus gradient steps. The authors also compared the moving-average rule against SGD, Adam, and SparseAdamPyTorch's variant of Adam for sparse gradients, which updates the moment estimates only for the rows that received a gradient, here the centroids that were assigned points on the centroids, each at its best tuned step over 5 passes. All four perform similarly at small batches. At large batches, the three gradient methods degrade far more than the moving average, and at a fixed large batch SGD collapses past a critical learning rate. The authors trace this behavior to the convex hull. A gradient step can push a centroid outside the convex hull of its assigned points, while the moving average keeps it a weighted mean of them because . Since GPU speed relies on large batches, that stability settles the choice of the moving average.
Terms
- k-means objective
- , each point measured to its nearest centroid
- Lloyd's algorithm
- assign every point, then move each centroid to the mean of its points, once per pass
- e-means update
- after every batch, , ,
- Step weight
- , so the centroid lands between its old position and
- Cosine schedule
- the step falls from to over the run
- Dead-cluster revival
- every 5 updates, split a donor in two for any cluster whose count is below a tenth of the mean
- Last-pass mean
- final centroids are the means of their last-pass points, the best centroids for those assignments
- Scaling laws
- and , fitted on DEEP
- Headline result
- Flash-KMeans' 25-iteration held-out MSE in 1.4 to 2.6 passes, 9.5 to 45.5 times faster on GPU
- Against greedy k-means++
- margin 0.06% to 0.33% at 5 passes, and the seeding took 73 to 160 times an e-means run on CPU
Sources
- Swann Bessa, Pierre-Emmanuel Mazaré, Gergely Szilvasy, Hugo Touvron, David Picard, Matthijs Douze, and Hervé Jégou. e-means: outperforming k-means (in one-tenth the epochs). arXiv preprint, 2026.
Connected notes
- Learning-rate schedules and batch sizeNanoGPT speedrun · Averaging out gradient noise
At a constant step , the bound on the last iterate keeps a term , where bounds the gradient norms. Decaying the step at the end shrinks that term quickly, and that is where the sharp loss drop of a warmup-stable-decay cooldown comes from.
- PPO and RLOO for language modelsReinforcement learning for reasoning · Fixed scales for stable training
The reproduction draws the reward head's weights with standard deviation , shifts the reward so reference summaries score 0 on average, and whitens advantages to mean 0 and variance 1 in each batch, so the signal reaching the policy has a fixed size.
- Maximal update parametrizationLazy training and feature learning · Predicting large runs from small ones
Under P the optimal learning rate, initialization scale and multipliers are nearly stable in width, so they can be tuned on a small proxy and copied, and a 40M proxy beat the published 6.7B GPT-3 at a tuning cost of 7% of its pretraining cost.
SGD's expected loss is the gradient-descent loss plus a term from noise injected while the loss is still of order one, so SGD noise matters only when the kernel decays more slowly than the gradient-descent loss.