
A new optimization rule for k-means clustering achieves up to 45x wall-clock speedups by replacing traditional Lloyd iterations with exponential moving averages.

Lloyd’s algorithm has long dominated the k-means clustering problem by recomputing cluster statistics from scratch across the entire dataset in every iteration. While reliable, this approach often traps optimization in local minima and incurs significant computational overhead. E-means introduces an optimization rule that replaces full-batch updates with mini-batch exponential moving averages (EMA). This shift allows the algorithm to track recent assignments rather than the entire history of a point’s movement, which is effective for navigating complex optimization landscapes. By ensuring centroids remain within the convex hull of assigned points, the EMA update rule provides stability at higher learning rates compared to traditional gradient descent methods.
Technical benchmarks across 24 embedding and synthetic datasets show that e-means reaches a test loss below Lloyd’s 25-epoch baseline in just 1.2 to 3 epochs. This efficiency translates to a 10–45× wall-clock reduction on GPU when measured against Flash-KMeans and an 8–15× reduction on CPU against Faiss. Unlike previous mini-batch attempts like MacQueen’s update, which suffered from staleness by accumulating statistics indefinitely, e-means utilizes a cosine-scheduled decay rate to forget older, potentially poor assignments. This allows the model to refine its centroids with increasing precision as training progresses, culminating in a finalization stage that further reduces training loss with negligible runtime impact.
E-means eliminates the requirement for manual hyperparameter tuning through two derived scaling laws that automatically determine the optimal batch size (B) and step size (α0) based on the number of points (n), clusters (k), and epochs (T). The "default law" targets high throughput, while the "quality law" optimizes for the lowest possible mean squared error (MSE). On held-out datasets, these scaling laws demonstrated a regret as low as 0.07%, indicating strong generalization across varying problem scales. This automation ensures that practitioners can deploy e-means as a drop-in replacement without the trial-and-error typically associated with stochastic optimization.
To address the "dead cluster" phenomenon—where centroids end up with zero assigned points—e-means implements a proportional split revival strategy. Traditional methods, such as those used in EnCodec, often resample dead centroids from the incoming batch, which can still leave up to 14.3% of the codebook unused on datasets like DEEP. In contrast, the e-means revival policy samples an active cluster proportional to its size and splits it, reducing the percentage of dead clusters to just 0.3%. This preservation of codebook capacity is vital for the large-scale vector quantization tasks common in modern machine learning pipelines.
Algorithmic efficiency benchmarks for e-means have generated significant interest regarding its integration into existing vector search workflows. On Hacker News, user real_faxenoff reported substantial real-world gains, stating,
"i adapted the method to my IVF index (the code-daemon project) and achieved a 146x speedup on the GPU."This sentiment reflects a broader recognition that approximate solutions to NP-hard problems are valuable when they arrive orders of magnitude faster.
Technical practitioners have expressed a desire for wider accessibility beyond specialized libraries. User wood_spirit noted that while the visualization and logic are clear, they
"hope it gets added to scipy - it’s much more available in the envs many use than facebooks own faiss library."Other discussions centered on the intuition behind the automatic hyperparameter laws, with users questioning the non-obvious nature of the scaling equations despite their empirical success. The consensus among engineering teams remains focused on the trade-off between speed and quality, with many viewing the 45x speedup as a significant advancement for large-scale data processing tasks.
The e-means implementation is currently available within the Faiss contrib directory for engineering teams looking to integrate these gains. The transition from Lloyd-based workflows involves minimal code changes, as the scaling laws handle the internal parameterization. When deploying, developers should choose between the default and quality laws based on their specific latency requirements. In testing on the SIFT dataset, the proportional split policy reduced the imbalance factor to 1.186, compared to 1.404 when cluster revival was disabled, ensuring that the resulting centroids are more representative of the underlying data distribution. This combination of algorithmic speed and structural robustness positions e-means as a high-performance alternative for building efficient vector indices and training VQ-VAEs.
Primary source
E-means (opens in a new tab)Pulse Wire Briefing
Real-time security & systems dispatches, straight to your inbox.





A per-seat decision model for mixed estates choosing between $122-per-device renewals, Windows 11 upgrades and hardware replacement.

Language models are trained to guess, not to say "I don't know." Here is why they fabricate citations and numbers, plus the validation workflow we use.

Each style wins one axis and loses another. How caching, schema change, clients, operations and latency decide it, plus the hybrid most teams end up running.
Discussion (…)