FlashML-org/flashlib
Fast and memory-efficient classical machine learning operators
FlashLib – GPU‑accelerated classic ML operators
FlashLib is an open‑source Python library that implements a wide range of traditional machine‑learning algorithms (clustering, nearest‑neighbour search, dimensionality reduction, regression, etc.) as GPU kernels built with Triton and the CuteDSL language. It exposes each algorithm both as a simple flash_* function and as an scikit‑learn‑style class, letting you drop it into existing PyTorch pipelines with minimal code changes.
Quick start
# Install the core package (CPU‑only fallback works for all ops)
pip install flashlib
# Optional: install the fast CuTe‑DSL kernels (NVIDIA GPUs only)
pip install 'flashlib[cutedsl]'
import torch
from flashlib import flash_kmeans
# 1 M vectors, 128‑dim, already on the GPU
x = torch.randn(1_000_000, 128, device='cuda')
labels, centroids, n_iter = flash_kmeans(x, n_clusters=1024, max_iters=20)
All primitives follow the same pattern – a top‑level function (flash_*) for one‑shot use and a class (KMeans, PCA, IVFFlat, …) for the familiar fit/transform API.
What the library offers
| Family | Example primitives | Typical use‑case |
|---|---|---|
| Clustering | flash_kmeans, flash_dbscan, flash_hdbscan, flash_spectral_clustering |
Group large point clouds, segment embeddings, etc. |
| Nearest‑neighbour search | flash_knn, IVFFlat, IVFPQ, CAGRA |
Fast ANN retrieval for recommendation, similarity search, retrieval‑augmented generation |
| Decomposition | flash_pca, flash_truncated_svd |
Dimensionality reduction, whitening, low‑rank approximation |
| Manifold learning | flash_umap, flash_tsne |
Visualising high‑dimensional data on the GPU |
| Regression / Classification | flash_linear_regression, flash_logistic_regression, flash_random_forest, flash_multinomial_nb |
Traditional supervised models that benefit from GPU acceleration |
| Pre‑processing | flash_standard_scaler |
Scaling / centering large tensors |
| Low‑level linear algebra | gemm, gemm_bf16, eigh, polar, … |
Building custom kernels or benchmarking GPU math |
ANN indexes – a deeper look
- IVFFlat – classic inverted‑file index;
nprobecontrols the trade‑off between speed and recall. Matches the behaviour of FAISS / cuVS at the same(nlist, nprobe)settings. - IVFPQ – adds product‑quantisation compression; each 128‑dim vector can be stored as 16 bytes (≈32× smaller) while still supporting fast distance‑approximation.
- CAGRA – graph‑based ANN that builds a proximity graph once and then traverses it with a fused Triton kernel. The implementation keeps the whole priority queue in registers and uses bf16 reads with an exact fp32 re‑rank, giving higher query‑per‑second (QPS) than cuVS CAGRA on H100 for recall between 0.9 – 0.99.
Performance‑aware tooling
The flashlib.info submodule can estimate runtime, FLOPs and memory traffic for any primitive in ~5 µs on a CPU, without importing heavy GPU libraries. This makes it handy for:
- Budgeting a pipeline before launching on a GPU cluster.
- Allowing LLM‑based agents to reason about cost in environments where no GPU is available.
import flashlib.info as info
est = info.estimate(
"kmeans",
shape=(100_000, 64),
params={"K": 256, "max_iters": 20},
device="H200"
)
print(est.summary_line())
How it fits into the ecosystem
- Built on Triton – gives the same low‑level control as custom CUDA kernels while staying in Python.
- Optional CuteDSL kernels – for NVIDIA GPUs they provide a noticeable speed boost; the library still works (with a slower fallback) without them.
- API compatibility – scikit‑learn‑style classes mean you can swap a CPU‑based estimator for its GPU counterpart with a single import change.
- Benchmarks – the repository includes scripts (e.g.,
benchmarks/vs_cuml/cagra.py) that compare FlashLib against FAISS, cuVS and cuML on H100, showing competitive or superior throughput at comparable recall.
Citation
If you use FlashLib in research, cite the accompanying paper:
@misc{yang2026flashlib,
title = {FlashLib: Bringing Flash Magic to Classical Machine Learning Operators},
author = {Yang, Shuo and Xi, Haocheng and Zhao, Yilong and Mang, Qiuyang and
Wang, Zhe and Sun, Shanlin and Keutzer, Kurt and Gonzalez, Joseph E. and
Han, Song and Xu, Chenfeng and Stoica, Ion},
year = {2026},
url = {https://flashml-org.github.io/},
}
License
Apache License 2.0 – free for commercial and academic use.
Bottom line: FlashLib brings GPU speed to a broad suite of classical ML tools, letting data‑scientists and engineers run k‑means, PCA, ANN search, and many other algorithms on millions of vectors in seconds, all with a familiar Pythonic API.
Related
- Project
- Project
- Project
- Project
- Project