nowfound

Life & fun · August 29, 2025

PK

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…

In plain words

PyTorch K-Means is a lightweight, single-file implementation of K-Means clustering built entirely in PyTorch. It is designed for users working with large datasets on resource-constrained hardware. The implementation keeps data on CPU where memory is plentiful and moves only necessary chunks to GPU during computation, reducing memory requirements. It supports hierarchical clustering and resampling features, with results returned to CPU for post-processing.

written from the facts on this page · September 2026

From the sources

In the maker’s words, at launch

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!

More life & fun this month

the category →
  • TL

    Life & fun · 10d ago · louisabraham.github.io

  • Photosynthesis fires two of your iPhone

    Life & fun · 28d ago · photosynthesis.camera

  • SoloUno310

    Take control of hair pulling, nail biting & skin picking

    Life & fun · 28d ago · solouno.io

  • Scroll through all 43,252,003,274,489,856,000 reachable Rubik's Cube permutations.

    Life & fun · 26d ago · everycube.alen.is

  • The Interactive 3D Encyclopedia

    Life & fun · 21d ago · expeditione.fun

  • Hi HN, I built Eigendrum, a web tool that solves the 2D wave equation for arbitrary shapes so you can hear what they sound like as drums. How it works: * Solves -∇²u = λu using finite element analysis (Kφ = λMφ) on a triangle mesh. * Validated to <0.1% error against closed-form solutions for circles (Bessel zeros) and rectangles. * Sound model factors in strike location, Rayleigh damping, and mallet width. * Includes Kac drums I & II to demonstrate identical sound spectra from different geometries. * No frameworks, build steps, or dependencies. Repo and tests:…

    Life & fun · 27d ago · baselashraf81.github.io

Launched alongside, August 2025

the whole month →
  • Trace1,556

    Workflow Automations for the Human 👾 AI Workforce

    AI · 2025 · trace.so

  • IS

    I built the world's most impractical 1000-pixel display and anyone in the world can draw on it. It draws a single pixel at a time and takes 30-60 minutes to complete a single image. Anyone can participate in the project by voting for the next image to be drawn, and submitting images. https:&#x2F;&#x2F;kilopx.com&#x2F;

    Work · 2025 · benholmen.com

  • Job boards are dead. Your network is alive

    AI · 2025 · contra.com

  • KT

    Kitten TTS is an open-source series of tiny and expressive text-to-speech models for on-device applications. We are excited to launch a preview of our smallest model, which is less than 25 MB. This model has 15M parameters. This release supports English text-to-speech applications in eight voices: four male and four female. The model is quantized to int8 + fp16, and it uses onnx for runtime. The model is designed to run literally anywhere eg. raspberry pi, low-end smartphones, wearables, browsers etc. No GPU required! We're releasing this to give early users a sense of the latency and voices…

    Dev tools · 2025 · github.com

  • IW

    I was wondering how I can arrange objects along a spherical helix path, and read some articles on it. I ended up learning about parametric equations again, and make this visualization to document what I learned: https:&#x2F;&#x2F;visualrambling.space&#x2F;moving-objects-in-3d&#x2F; feel free to visit and let me know what you think!

    Life & fun · 2025 · visualrambling.space

  • TC

    For HTML Day 2025 [1], I made a web service that displays the current sky at your approximate location as a CSS gradient. Colours are simulated on-demand using atmospheric absorption and scattering coefficients. Updates every minute, without the use of client-side JavaScript. Source code and additional information is available on GitHub: https:&#x2F;&#x2F;github.com&#x2F;dnlzro&#x2F;horizon [1] https:&#x2F;&#x2F;html.energy&#x2F;html-day&#x2F;2025&#x2F;index.html

    Dev tools · 2025 · sky.dlazaro.ca