Pure MLX implementations of UMAP, t-SNE, PaCMAP, TriMap, DREAMS, and NNDescent for Apple Silicon. Metal GPU acceleration for both computation and video rendering. No scipy, no sklearn, no matplotlib.
Project description
mlx-vis
Pure MLX implementations of UMAP, t-SNE, PaCMAP, TriMap, DREAMS, and NNDescent for Apple Silicon. Metal GPU acceleration for both computation and video rendering. No scipy, no sklearn, no matplotlib.
Install
uv pip install mlx-vis
From source:
git clone https://github.com/hanxiao/mlx-vis.git
cd mlx-vis
uv pip install .
Requires mlx >= 0.20.0 and numpy >= 1.24.0.
Usage
import numpy as np
from mlx_vis import UMAP, TSNE, PaCMAP, TriMap, DREAMS, NNDescent
X = np.random.randn(10000, 128).astype(np.float32)
# UMAP
Y = UMAP(n_components=2, n_neighbors=15).fit_transform(X)
# t-SNE
Y = TSNE(n_components=2, perplexity=30).fit_transform(X)
# PaCMAP
Y = PaCMAP(n_components=2, n_neighbors=10).fit_transform(X)
# TriMap
Y = TriMap(n_components=2, n_iters=400).fit_transform(X)
# DREAMS (t-SNE + PCA regularization)
Y = DREAMS(n_components=2, lam=0.15).fit_transform(X)
# NNDescent (approximate k-NN graph)
indices, distances = NNDescent(k=15).build(X)
Submodule imports also work:
from mlx_vis.umap import UMAP
from mlx_vis.tsne import TSNE
from mlx_vis.pacmap import PaCMAP
from mlx_vis.trimap import TriMap
from mlx_vis.dreams import DREAMS
from mlx_vis.nndescent import NNDescent
Methods
| Method | Class | Main API | Output |
|---|---|---|---|
| UMAP | UMAP(n_components, n_neighbors, min_dist, ...) |
fit_transform(X) |
np.ndarray (n, d) |
| t-SNE | TSNE(n_components, perplexity, ...) |
fit_transform(X) |
np.ndarray (n, d) |
| PaCMAP | PaCMAP(n_components, n_neighbors, ...) |
fit_transform(X) |
np.ndarray (n, d) |
| TriMap | TriMap(n_components, n_iters, ...) |
fit_transform(X) |
np.ndarray (n, d) |
| DREAMS | DREAMS(n_components, lam, ...) |
fit_transform(X) |
np.ndarray (n, d) |
| NNDescent | NNDescent(k, n_iters, ...) |
build(X) |
(indices, distances) |
Visualization
All rendering runs on Metal GPU via MLX: coordinate mapping, circle-splatting, and color blending are fully vectorized MLX operations. Raw frames are piped to ffmpeg for PNG/video encoding. Zero matplotlib.
Static plots
from mlx_vis import UMAP, scatter_gpu
import numpy as np
X = np.random.randn(10000, 128).astype(np.float32)
labels = np.random.randint(0, 5, 10000)
Y = UMAP(n_components=2).fit_transform(X)
scatter_gpu(Y, labels=labels, theme="dark", save="plot.png")
Animation
Video frames are rendered on GPU and piped to ffmpeg with h264_videotoolbox hardware encoding. 500 frames of 15K points in 1.5 seconds on M3 Ultra.
UMAP:
https://github.com/user-attachments/assets/547b8ce2-17d4-4172-be59-ba83eafd1785
t-SNE:
https://github.com/user-attachments/assets/b8a4840b-7e71-4992-a26b-8332666af52a
PaCMAP:
https://github.com/user-attachments/assets/563c6a58-48e8-435d-b99d-5eafbb11be27
TriMap:
https://github.com/user-attachments/assets/eea51acf-b8da-4da1-9b23-6322bf300275
DREAMS:
https://github.com/user-attachments/assets/e6a3bb52-95f4-46d0-9a8d-f7714e85a18f
Benchmark on Fashion-MNIST 70,000 x 784, M3 Ultra:
| UMAP | t-SNE | PaCMAP | TriMap | DREAMS | |
|---|---|---|---|---|---|
| Iterations | 500 | 500 | 450 | 500 | 500 |
| Embedding | 3.5s | 3.9s | 2.4s | 2.8s | 4.0s |
| GPU render (800 frames) | 2.1s | 1.9s | 1.8s | 1.9s | 1.9s |
| Total | 5.6s | 5.8s | 4.2s | 4.7s | 5.9s |
from mlx_vis import UMAP, animate_gpu
import numpy as np, time
X = np.random.randn(10000, 128).astype(np.float32)
labels = np.random.randint(0, 5, 10000)
snaps, times = [], []
t0 = time.time()
def cb(epoch, Y_np):
snaps.append(Y_np.copy())
times.append(time.time() - t0)
Y = UMAP(n_components=2, n_epochs=200).fit_transform(X, epoch_callback=cb)
animate_gpu(snaps, labels=labels, timestamps=times,
method_name="umap-mlx", fps=120, theme="dark",
save="animation.mp4")
Full Fashion-MNIST example:
python -m mlx_vis.examples.fashion_mnist --method umap --theme dark
python -m mlx_vis.examples.fashion_mnist --method all
License
Apache-2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mlx_vis-0.2.0.tar.gz.
File metadata
- Download URL: mlx_vis-0.2.0.tar.gz
- Upload date:
- Size: 36.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ebc3cf721c123ccf02f8c5cd2d3b6d2397436cc8fee426d501932141c39c64c6
|
|
| MD5 |
3c6180ae8b1cd57c0d63cb9564e64988
|
|
| BLAKE2b-256 |
1aae2a8a50d5a62231689cefa08b3c86bc311ffbd60900d2d9b50c2eccd27eb4
|
File details
Details for the file mlx_vis-0.2.0-py3-none-any.whl.
File metadata
- Download URL: mlx_vis-0.2.0-py3-none-any.whl
- Upload date:
- Size: 41.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b44e5d84e6cf88980102ef93ecbae94a36e762157cb9aad16073185788eda7a
|
|
| MD5 |
3c4fa0e6b8f878b0543790cb77d7f1e8
|
|
| BLAKE2b-256 |
b41cc0cc2e60f0176a172eb95951ea86a2e0735b070f81ea655282211bb62275
|