Py

PyTorch K-Means GPU-friendly, single-file, hierarchical and resampling

Hacker News

PyTorch K-Means GPU-friendly, single-file, hierarchical and resampling

I built a small, self-contained K-Means implementation in pure PyTorch: https://gitlab.com/hassonofer/pt_kmeans I was working on dataset sampling and approximate nearest neighbor search, and tried several existing libraries for large-scale K-Means. I couldn't find something that was fast, simple, and would run comfortably on my own workstation without hitting memory limits. Maybe I missed an existing solution, but I ended up writing one that fit my needs. The core insight: Keep your data on CPU (where you have more RAM) and intelligently move only the necessary chunks to GPU for computation during the iterative steps. Results always come back to CPU for easy post-processing. (Note: For K-Means++ initialization when computing on GPU, the full dataset still needs to fit on the GPU.) It offers a few practical features: - Chunked Computations: Memory-efficient processing of large datasets by only moving necessary data chunks to the GPU, preventing Out-Of-Memory errors - Cluster splitting: Refine existing clusters by splitting a single cluster into multiple sub-clusters - Zero Dependencies: Single file, only requires PyTorch. Copy-paste into any project - Advanced Clustering: Hierarchical K-Means with optional resampling (following recent research), cluster splitting utilities. - Device Flexibility: Explicit device control - data can live anywhere, computation happens where you specify (any accelerator PyTorch supports) Future plans: - Add support for memory-mapped files to handle even bigger datasets - Explore PyTorch distributed for multi-node K-Means The implementation handles both L2 and cosine distances, includes K-Means++ initialization. Available on PyPI (`pip install pt_kmeans`) and the full implementation is at: https://gitlab.com/hassonofer/pt_kmeans Would love feedback on the approach and any use cases I might have missed!

Share card

Actual performance

10points
Made the leaderboard

Launch Intel predictions

Analyze your own launch →
Indie HackersFits the IH revenue-focused audience · Strong signals: supports · Missing: reddit linkedin, podcasting, created
88%88% predicted probability of success on Indie Hackers, based on ML models trained on real launch data.
best fitHighest predicted score across all platforms for this description.
Product HuntOn track for Day 1 leaderboard · Strong signals: single · Missing: mac, agents, macos
61%61% predicted probability of success on Product Hunt, based on ML models trained on real launch data.
Hacker NewsStrong engagement from HN community · Strong signals: exist, existing, io · Missing: https docs, excited, just released
57%57% predicted probability of success on Hacker News, based on ML models trained on real launch data.
nativeThis product was originally launched on this platform.
AppSumoMay struggle as an AppSumo deal · Strong signals: friendly, efficient · Missing: plus, platform, intuitive
48%48% predicted probability of success on AppSumo, based on ML models trained on real launch data.
TrustMRRLess likely to generate early MRR · Strong signals: way · Missing: mobile apps, ios, personal
41%41% predicted probability of success on TrustMRR, based on ML models trained on real launch data.
Acquire.comPre-revenue stage for this audience · Missing: arr, mrr, revenue
16%16% predicted probability of success on Acquire.com, based on ML models trained on real launch data.
BetaListMay not resonate with beta-testers · Missing: web3, chat, crypto
0%0% predicted probability of success on BetaList, based on ML models trained on real launch data.

Correct prediction on native model

Similar products

Go
Gource visualizations rendered without a GPU71%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Gource visualizations rendered without a GPU

Hacker News27
La
Lambda Echelon GPU Cluster55%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Lambda Echelon GPU Cluster

Hacker News3
GP
GPU PaaS61%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

GPU PaaS

Hacker News6
Sl
Slurmq – GPU quota enforcement for Slurm50%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Slurmq – GPU quota enforcement for Slurm

Hacker News3
GP
GPU Accelerated PDAL62%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

GPU Accelerated PDAL

Hacker News1
No
Noc_vec, a single file C library for vectors, matrices and quaternions52%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Noc_vec, a single file C library for vectors, matrices and quaternions

Hacker News3
Ll
Llamaphone- Single-file Front end for Llamafile62%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Llamaphone- Single-file Front end for Llamafile

Hacker News3
Ru
Run Jest on single file upon file save45%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Run Jest on single file upon file save

Hacker News1
A
A Clojure REPL that is beginner friendly60%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

A Clojure REPL that is beginner friendly

Hacker News4
Postcard Panda
Postcard Panda40%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Eco-Friendly Postcards

Indie Hackers1$400/mob2b