mp-kmeans
A mixed-precision algorithm of $k$-means is designed towards understanding of the low precision arithmetic for Euclidean distance computations. By performing simulations across data with various settings, we showcase that decreased precision for $k$-means computing only results in a minor increase in sum of squared errors while not necessarily leading to degrading performance regarding clustering results.
mp-kmeans is a CUDA-accelerated mixed-precision implementation of k-means designed for large-scale clustering workloads.
It provides multiple precision paths (FP16/BF16/FP32/FP64 and mixed fallback modes) to balance throughput and numerical stability.
Features
- Mixed-precision Euclidean distance kernels for GPU k-means.
- Uniform precision modes (
fp16,bf16,fp32,fp64) and mixed modes (e.g.fp16_fp32,fp16_fp64). - CUDA center update kernels with automatic empty-cluster reinitialization.
- Configurable normalization (
standard,l2,minmax) for robust behavior on unnormalized datasets.
Installation
pip install mp-kmeans
This package targets CUDA-enabled environments and depends on PyTorch with CUDA support.
Quick Start
import torch
from mp_kmeans import KMeansPlusPlus, make_blobs_gpu
X, _ = make_blobs_gpu(
n_samples=100_000,
n_features=128,
n_centers=100,
cluster_std=1.0,
random_state=42,
)
model = KMeansPlusPlus(
n_clusters=100,
kernel="fp16_fp32",
kappa=10.0,
max_iter=300,
tol=1e-8,
normalize="standard",
random_state=42,
)
model.fit(X)
print(model.n_iter_, model.inertia_)
Kernel Modes
- Uniform:
fp16_uniform,bf16_uniform,tf32_uniform,fp32_uniform,fp64_uniform - Mixed:
fp16_fp32,bf16_fp32,fp32_fp32,fp16_fp64,bf16_fp64,tf32_fp64,fp32_fp64 - Advanced:
fp64_fp16,fp64_bf16,fp64_tf32,fp64_fp32_gemm
Citation
@techreport{ccl24,
author = "Erin Carson and Xinye Chen and Xiaobo Liu",
title = "Computing $k$-means in Mixed Precision",
month = jul,
year = 2024,
type = "{ArXiv}:2407.12208 [math.{NA}]",
url = "https://arxiv.org/abs/2407.12208"
}
Metadata
Release files for mp-kmeans 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mp_kmeans-0.1.0.tar.gz | 559.2 kB | Without provenance | Details for mp_kmeans-0.1.0.tar.gz |
Release files / mp_kmeans-0.1.0.tar.gz
| Download URL | mp_kmeans-0.1.0.tar.gz |
|---|---|
| Size | 559.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b71b9310f1e20afba0afc986d71d8ef981415de4c34485aaebe3cf24a4d60f09
|
|
BLAKE2b-256 checksum How to use checksums |
5fcc121af020d7ac24c5d566a82fa5254b9d48c3c7fca7bf57524447d9699667
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.11
|
Security for mp-kmeans 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.