• bitcoinBitcoin(BTC)$64,051.00-1.40%
  • ethereumEthereum(ETH)$1,862.25-2.10%
  • tetherTether(USDT)$1.000.00%
  • binancecoinBNB(BNB)$560.90-1.10%
  • usd-coinUSDC(USDC)$1.000.00%
  • rippleXRP(XRP)$1.09-1.80%
  • solanaSolana(SOL)$74.01-3.60%
  • tronTRON(TRX)$0.3303431.20%
  • Figure HelocFigure Heloc(FIGR_HELOC)$1.043.70%
  • whitebitWhiteBIT Coin(WBT)$55.87-1.60%
  • HyperliquidHyperliquid(HYPE)$58.97-0.50%
  • dogecoinDogecoin(DOGE)$0.069034-2.30%
  • RainRain(RAIN)$0.0143001.20%
  • USDSUSDS(USDS)$1.000.00%
  • leo-tokenLEO Token(LEO)$9.64-1.10%
  • zcashZcash(ZEC)$496.33-3.10%
  • moneroMonero(XMR)$355.271.60%
  • chainlinkChainlink(LINK)$8.37-1.70%
  • cardanoCardano(ADA)$0.164486-4.10%
  • stellarStellar(XLM)$0.178040-2.10%
  • CantonCanton(CC)$0.119081-0.40%
  • daiDai(DAI)$1.000.00%
  • bitcoin-cashBitcoin Cash(BCH)$209.92-2.30%
  • USD1USD1(USD1)$1.000.00%
  • Ethena USDeEthena USDe(USDE)$1.000.00%
  • the-open-networkGram (prev. Toncoin)(GRAM)$1.45-2.50%
  • litecoinLitecoin(LTC)$46.33-1.10%
  • Global DollarGlobal Dollar(USDG)$1.00-0.10%
  • hedera-hashgraphHedera(HBAR)$0.071104-1.70%
  • Circle USYCCircle USYC(USYC)$1.130.00%
  • suiSui(SUI)$0.72-4.90%
  • paypal-usdPayPal USD(PYUSD)$1.000.00%
  • avalanche-2Avalanche(AVAX)$6.19-4.00%
  • crypto-com-chainCronos(CRO)$0.056519-2.20%
  • BlackRock USD Institutional Digital Liquidity FundBlackRock USD Institutional Digital Liquidity Fund(BUIDL)$1.000.00%
  • tether-goldTether Gold(XAUT)$4,070.340.50%
  • shiba-inuShiba Inu(SHIB)$0.000004-0.90%
  • uniswapUniswap(UNI)$3.810.90%
  • nearNEAR Protocol(NEAR)$1.82-3.90%
  • Ondo US Dollar YieldOndo US Dollar Yield(USDY)$1.14-0.40%
  • OndoOndo(ONDO)$0.393223-3.50%
  • World Liberty FinancialWorld Liberty Financial(WLFI)$0.057938-5.10%
  • BittensorBittensor(TAO)$189.39-2.50%
  • pax-goldPAX Gold(PAXG)$4,066.700.50%
  • okbOKB(OKB)$81.92-1.60%
  • AsterAster(ASTER)$0.640.90%
  • HTX DAOHTX DAO(HTX)$0.000002-0.40%
  • Ripple USDRipple USD(RLUSD)$1.000.00%
  • MemeCoreMemeCore(M)$1.193.10%
  • usddUSDD(USDD)$1.000.00%
TradePoint.io
  • Main
  • AI & Technology
  • Stock Charts
  • Market & News
  • Business
  • Finance Tips
  • Trade Tube
  • Blog
  • Shop
No Result
View All Result
TradePoint.io
No Result
View All Result

Meet Flash-KMeans: An IO-Aware, Exact K-Means That Runs Over 200× Faster Than FAISS on GPUs

June 15, 2026
in AI & Technology
Reading Time: 7 mins read
A A
Meet Flash-KMeans: An IO-Aware, Exact K-Means That Runs Over 200× Faster Than FAISS on GPUs
ShareShareShareShareShare

k-means has been an offline tool for decades. You run it once to preprocess data, then move on. A team of researchers from UC Berkeley and UT Austin released Flash-KMeans, a new open-source library that targets a different setting. Modern AI pipelines now call k-means inside training and inference loops. At that frequency, latency per call matters more than theoretical FLOPs.

Flash-KMeans is an IO-aware implementation of standard Lloyd’s k-means. It does not change the math, and it does not approximate. It only restructures how the algorithm moves data on a GPU. On an NVIDIA H200, the research team reported up to 17.9× end-to-end speedup over the best baseline. Against NVIDIA cuML they report 33×. Against FAISS they report over 200×.

YOU MAY ALSO LIKE

Moonshot’s Kimi K3 Reshapes the AI Conversation, Says Bessemer Partner

Don’t Give Up on AI Chips Yet, Says JoAnne Feeney

What is Flash-KMeans

Flash-KMeans is a batched k-means library written in Triton GPU kernels. It ships under Apache 2.0 and installs with pip install flash-kmeans.

The output is mathematically identical to standard Lloyd’s k-means. The speedup comes from kernel-level dataflow, not from skipping work. That separates it from algorithmic methods like triangle-inequality pruning or coreset sampling.

A standard Lloyd iteration has two stages. The assignment stage computes each point’s distance to every centroid, then picks the nearest. The update stage averages the points in each cluster to form new centroids. Both stages are simple arithmetic. On GPUs, both are bottlenecked by memory, not compute.

The Two Bottlenecks It Attacks

The first bottleneck is the assignment stage. Standard code builds a full distance matrix D of shape N×K in High Bandwidth Memory (HBM). It writes the matrix, then reads it back to run argmin. For N=65536, K=1024, d=128, B=32, the distance math takes 2.6ms. Writing and consuming D takes about 23ms. The matrix is the cost, not the arithmetic.

Flash-KMeans replaces this with FlashAssign. The design borrows from FlashAttention. FlashAssign streams tiles of points and centroids from HBM into on-chip SRAM. It fuses distance computation with an online argmin. The full N×K matrix is never materialized. This cuts the dominant IO complexity from O(NK) to O(Nd + Kd). At the kernel level, FlashAssign reaches up to 21.2×. In one case it cut assignment from 122.5ms to 5.8ms.

The second bottleneck is the centroid update stage. Standard code uses scatter-style atomic adds. Each thread adds its point into a shared sum buffer keyed by cluster id. Many threads hit the same ‘hot’ cluster at once. That causes atomic contention and hardware serialization. The research team measured only 50 GB/s effective bandwidth here on an H200.

Flash-KMeans replaces this with Sort-Inverse Update. It sorts the 1D assignment vector by cluster id using argsort. Identical cluster ids then form contiguous segments. Each thread block reduces a segment on-chip, then issues one atomic add per segment. The heavy point matrix is never physically permuted. Atomic operations drop from (O((K+NBN)d))(O((K + \frac{N}{B_N})d)) . The kernel reaches up to 6.3×.

Benchmark

The research team test it on an H200 with CUDA 12.8, FP16 data, and d=128. They sweep N, K, and batch size B. They compare against four optimized baselines: fast_pytorch_kmeans, fastkmeans, cuML, and FAISS.

Comparison Reported speedup Workload context
End-to-end vs best baseline up to 17.9× N=8M, K=1024 (large N, small K)
vs NVIDIA cuML 33× industry library
vs FAISS over 200× industry library
FlashAssign kernel up to 21.2× N=1M, K=8192 (assignment)
Sort-Inverse Update kernel up to 6.3× N=33M, K=4096 (update)
Out-of-core, large scale up to 10.5× N=400M, K=16384 vs fastkmeans

One failure mode matters for context. Standard PyTorch implementations run out of memory in large-K regimes. They cannot materialize the N×K matrix. FAISS is the industry-standard library under many production vector-search systems.

The library also runs out-of-core. On one billion points (K=32768, d=128), it finishes an iteration in 41.4s, against 261.8s for the baseline. It uses chunked stream overlap to hide PCIe transfer behind compute. A cache-aware compile heuristic also cuts tuning overhead by up to 175×, within 0.3% of tuned speed.

MTP Interactive Explainer

Marktechpost · Interactive Explainer

Flash-KMeans: exact k-means, rebuilt around GPU memory

Same Lloyd’s math as standard k-means — faster only because of dataflow. Run clustering live, watch the update bottleneck, and size the IO it removes.

17.9×end-to-end vs best baseline

33×vs NVIDIA cuML

200×+vs FAISS

1Bpoints, out-of-core

1 · Live clustering

2 · Update contention

3 · IO calculator





Iteration0

Centroid shift—

Statusidle

This runs real Lloyd’s k-means in your browser on 2-D points. The algorithm is identical to what Flash-KMeans accelerates — only the GPU dataflow differs. Each step = one assignment + one centroid update.

Press play. Standard scatter-update serializes when blocks write the same “hot” centroid (red stalls). Sort-Inverse Update sorts cluster IDs first, so each block merges contiguous segments with one atomic add — no conflict.


Standard atomicsO(N·d)

Sort-Inverse atomicsO((K+N/B)·d)

Measured std bandwidth50 GB/s

Kernel speedup6.3×

Standard updates issue one atomic add per token. Many threads hit the same centroid at once, causing contention. Sorting by cluster ID turns scatters into segment-level reductions in on-chip memory.

Standard — materialize N×K matrix, O(NK)—

FlashAssign — stream inputs, O(Nd+Kd)—

—less HBM traffic for the assignment step (theoretical)

Use Cases

Faster exact k-means changes what you can run online, not just offline.

  • Vector search indexing: FAISS builds its search indices with k-means. Faster k-means lets you re-index as data shifts, instead of rebuilding overnight.
  • Sparse attention routing: Routing Transformers and Tactic cluster tokens to route attention. Millisecond k-means makes this viable inside the inference loop.
  • KV-cache compression: ClusterKV clusters tokens in semantic space to compress the cache. Cheaper clustering makes per-layer, per-step compression practical.
  • Low-bit KV quantization: Recent methods cluster KV entries into codebooks, repeatedly. Faster clustering shrinks that preprocessing cost.
  • Diffusion Transformers: Sparse VideoGen2 calls batched k-means during forward passes. It permutes tokens by semantic similarity to exploit sparsity.

Using It

The API mirrors faiss and sklearn. The call below clusters a batched (B, N, d) tensor.

import torch
from flash_kmeans import batch_kmeans_Euclid

x = torch.randn(32, 75600, 128, device="cuda", dtype=torch.float16)
cluster_ids, centers, _ = batch_kmeans_Euclid(
    x, n_clusters=1000, tol=1e-4, verbose=True
)

A scikit-learn-style interface is also available.

from flash_kmeans import FlashKMeans

km = FlashKMeans(d=128, k=8192, niter=100)
labels = km.fit_predict(large_cpu_tensor)  # device=None uses all visible GPUs

The kernel auto-dispatches by shape and dtype. A small-D path handles d≤512. A split-D path handles larger d without materializing the distance matrix. Multi-GPU runs trigger automatically for large-N data held in CPU memory.

Key Takeaways

  • Flash-KMeans is exact, not approximate — same Lloyd’s math, sped up purely by GPU dataflow.
  • FlashAssign fuses distance + online argmin, cutting assignment IO from O(NK) to O(Nd+Kd) — up to 21.2×.
  • Sort-Inverse Update sorts cluster IDs into segments, replacing scatter atomics — up to 6.3×.
  • Reports up to 17.9× end-to-end, 33× over cuML, and over 200× over FAISS on an H200.
  • Scales out-of-core to one billion points and cuts tuning overhead up to 175×.

Check out the Paper and Repo. Also, feel free to follow us on Twitter and don’t forget to join our 150k+ML SubReddit and Subscribe to our Newsletter. Wait! are you on telegram? now you can join us on telegram as well.

Need to partner with us for promoting your GitHub Repo OR Hugging Face Page OR Product Release OR Webinar etc.? Connect with us


Credit: Source link

ShareTweetSendSharePin

Related Posts

Moonshot’s Kimi K3 Reshapes the AI Conversation, Says Bessemer Partner
AI & Technology

Moonshot’s Kimi K3 Reshapes the AI Conversation, Says Bessemer Partner

July 24, 2026
Don’t Give Up on AI Chips Yet, Says JoAnne Feeney
AI & Technology

Don’t Give Up on AI Chips Yet, Says JoAnne Feeney

July 24, 2026
Odd Lots: Claude Code Creator On The Era of Vibe Coding
AI & Technology

Odd Lots: Claude Code Creator On The Era of Vibe Coding

July 24, 2026
British Drivers Can’t Get Enough of the ‘Temu Range Rover’
AI & Technology

British Drivers Can’t Get Enough of the ‘Temu Range Rover’

July 24, 2026
Next Post
Exclusive | Anthropic downplays security risks of ‘Mythos’ and ‘Fable’ AI models after ban –

Exclusive | Anthropic downplays security risks of 'Mythos' and 'Fable' AI models after ban -

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

No Result
View All Result
Home Invasion at NFL star Saquon Barkley’s home

Home Invasion at NFL star Saquon Barkley’s home

July 22, 2026
Spain outlasts Argentina 1-0 to win World Cup championship

Spain outlasts Argentina 1-0 to win World Cup championship

July 22, 2026
Feyn AI Releases SQRL, a Text-to-SQL Model Family That Inspects the Database Before Writing a Query

Feyn AI Releases SQRL, a Text-to-SQL Model Family That Inspects the Database Before Writing a Query

July 19, 2026

About

Learn more

Our Services

Legal

Privacy Policy

Terms of Use

Bloggers

Learn more

Article Links

Contact

Advertise

Ask us anything

©2020- TradePoint.io - All rights reserved!

Tradepoint.io, being just a publishing and technology platform, is not a registered broker-dealer or investment adviser. So we do not provide investment advice. Rather, brokerage services are provided to clients of Tradepoint.io by independent SEC-registered broker-dealers and members of FINRA/SIPC. Every form of investing carries some risk and past performance is not a guarantee of future results. “Tradepoint.io“, “Instant Investing” and “My Trading Tools” are registered trademarks of Apperbuild, LLC.

This website is operated by Apperbuild, LLC. We have no link to any brokerage firm and we do not provide investment advice. Every information and resource we provide is solely for the education of our readers. © 2020 Apperbuild, LLC. All rights reserved.

No Result
View All Result
  • Main
  • AI & Technology
  • Stock Charts
  • Market & News
  • Business
  • Finance Tips
  • Trade Tube
  • Blog
  • Shop

© 2023 - TradePoint.io - All Rights Reserved!