Repository navigation
Releases
mlx-learn 0.1.9
mlx-learn 0.1.9 brings dense Ridge, Lasso, and ElasticNet to Apple silicon through direct imports and patch_sklearn(). Ridge uses precompiled Metal kernels for eligible fits and checks the solution against the training data. Lasso and ElasticNet support sample weights, multiple targets, positive coefficients, and warm starts, with dual-gap checks on the original data. LinearRegression gains streaming CPU moments and an exact Metal Gram path for eligible quantized designs.
On an M4 Max, cold LinearRegression fits ran 5.35–17.10× as fast as stock scikit-learn 1.9.1 across five measured workloads. For a 65,536 × 512 correlated float32 design with device="gpu", Lasso and ElasticNet ran 5.39× and 5.27× as fast on the first fit, respectively, and about 9× as fast warm. The fit timings exclude imports and patching. Regression benchmarks · Ridge benchmarks
Apple silicon wheels are available for CPython 3.10–3.13, along with a source distribution.
python -m pip install --upgrade mlx-learn==0.1.9mlx-learn 0.1.8
EMeans and OMeans now accept revival="cost". Every five mini-batches, this option moves centroids that contribute little to the fit and splits elongated clusters along their longest axis. Both estimators default to revival="mass". Models saved with 0.1.7 retain that setting when loaded.
Across five embedding datasets at 16,384 centroids on an M4 Max, cost-based revival lowered held-out mean squared error in 45 of 45 EMeans comparisons and 55 of 60 OMeans comparisons. The five OMeans exceptions were on FB-SSNPP below two epochs. One-epoch EMeans fits took 6–11% longer on M4 Max and M5 Ultra. One-epoch OMeans fits took 14–18% longer on M5 Ultra. EMeans measurements · OMeans measurements
Apple Silicon wheels are available for CPython 3.10–3.13, along with a source distribution.
python -m pip install --upgrade mlx-learn==0.1.8mlx-learn 0.1.7
mlx-learn 0.1.7 adds exact radius-neighbor search and dense ordinary least squares for Apple Silicon.
NearestNeighbors.radius_neighborsandradius_neighbors_graphuse a hybrid search that includes points on the radius boundary. The newRadiusNeighborsClassifierandRadiusNeighborsRegressoruse the same search. See the cold and warm comparisons with scikit-learn.LinearRegressionsupports dense, weighted and multi-output fits. The host solver handles nearly collinear designs and uses the installed scikit-learn version’s rank cutoff. Patched sparse and positive fits use scikit-learn. See the solver results and limitations.
PyPI provides Apple Silicon wheels for CPython 3.10 through 3.13 and a source distribution.
The full M4 Max performance check flagged eight kNN, logistic regression and PCA cases against stock scikit-learn. In paired measurements, 0.1.7 and 0.1.6 ran within 1.6% of each other on those eight workloads. Release benchmarks
python -m pip install --upgrade mlx-learn==0.1.7mlx-learn 0.1.6
Version 0.1.6 moves the k-means++ initialization of mlxlearn.cluster.KMeans to the GPU. For a given random_state, it selects the same starting centers as sklearn.cluster.kmeans_plusplus on the same machine, so fits keep the centers, iterations and inertia they had before, only faster.
python -m pip install --upgrade mlx-learn==0.1.6from mlxlearn.cluster import KMeans
model = KMeans(n_clusters=4096, random_state=10).fit(X_train) # init="k-means++" is the defaultK-means++ initialization on Metal
Before 0.1.6, KMeans called scikit-learn's helper on the CPU for k-means++, and with thousands of centers that took most of the fit. Now a Metal kernel proves in float32, with a rigorous error bound, which (candidate, row) pairs a new candidate center cannot change. For inputs with at least 256 features it first compares 64-dimensional images of the rows. The host evaluates the remaining pairs in float64, using the helper's own expressions for sampling and potentials. Every step is certified with interval bounds; if a seeding cannot be certified, the helper itself runs.
MNIST, 60,000 × 784 float32, random_state=10, MacBook Pro M4 Max. Seeding times are medians of three interleaved rounds against one run of the helper. Fit times compare the 0.1.6 default with the same fit routed to the helper, as in 0.1.5.
| Centers | Seeding, scikit-learn helper | Seeding, 0.1.6 | Default KMeans fit, 0.1.5 path |
Default KMeans fit, 0.1.6 |
|---|---|---|---|---|
| 1,024 | 26.9 s | 0.90 s | 27.5 s | 1.4 s |
| 2,048 | 54.2 s | 1.62 s | 54.9 s | 2.4 s |
| 4,096 | 108.6 s | 2.82 s | 110.4 s | 4.4 s |
| 8,192 | 217.1 s | 5.41 s | 218.7 s | 7.0 s |
At every size the 0.1.6 seeding selected the helper's rows, and the fits reached the same iterations and inertia. The default k-means++ fit is now also faster than init="random" (6.7–13.6 s here, ten restarts) and reaches lower inertia. The kernels compile in Metal's safe math mode. The products used for certification run in float64 on the host, so M5's TF32 matrix multiply does not affect them. Timings were measured on M4 Max; the tests also pass on M5 Ultra. K-means++ initialization · Measurements and scripts · PR #29
O-means: short fits keep the full search where it is faster
OMeans(assignment="auto") now keeps the full search for fits shorter than two epochs on M1 Ultra and M5 Ultra unless the probes are expected to cover at most 36% of the centroids, instead of one half. On M5 Ultra, one-epoch fits at 4,096 centroids on the MNIST family were 7–11% slower than EMeans with the two-level search; with the full search they run at 0.97× of EMeans' speed, the cost of OMeans' own loop. With the default cells and probes this affects 2,176 to 4,223 centroids at 512 features or more. M4 Max, fits of two epochs or more (the default is three), and assignment="two_level" are unchanged. The M1 Ultra limit was not measured in this regime and takes the stricter value. O-means guide · PR #30
MNIST-family benchmarks
The O-means results on MNIST, Fashion-MNIST and Kannada-MNIST from PR #28 are now part of a release. On M5 Ultra, OMeans.fit is 675–1,854× faster than scikit-learn's KMeans at 1,024 to 8,192 centroids, with held-out error between −0.89% and +0.44% of it. Results
The release provides Apple silicon wheels for Python 3.10–3.13 and a source distribution. Changelog · PyPI
mlx-learn 0.1.5
Version 0.1.5 adds mlxlearn.cluster.OMeans for clustering with many centroids on Apple silicon. O-means groups centroids into coarse cells and searches nearby cells during training. Final labels, predictions, and scores use a full centroid search. Training supports FP32 and BF16.
python -m pip install --upgrade mlx-learn==0.1.5from mlxlearn.cluster import OMeans
model = OMeans(n_clusters=16_384, max_iter=2, random_state=10).fit(X_train)
labels = model.predict(X_test)Across 18 datasets and three seeds, O-means reached EMeans' held-out mean squared error 4.44× as fast with FP32 on M5 Ultra and 4.13× as fast on M4 Max, using interpolated epoch budgets. The geometric-mean speedups at measured budgets were 3.96× and 3.67×, respectively. Inputs were already resident on the GPU for the timed calls. M5 Ultra benchmarks · M4 Max benchmarks
MNIST-family benchmarks
These benchmarks were added in PR #28 after the v0.1.5 tag. Each dataset has 60,000 training images with 784 features. The runs cover 1,024 to 8,192 centroids on M4 Max and M5 Ultra.
On M4 Max, OMeans.fit took 150–242 ms at 4,096 to 8,192 centroids, with held-out mean squared distance within 1% of scikit-learn's KMeans. The OMeans and EMeans timings include three epochs and final labeling and report medians across three seeds. The scikit-learn timings are single fits with default settings. Parentheses show the change in held-out mean squared distance relative to scikit-learn's KMeans.
| Dataset | Centroids | OMeans |
EMeans |
scikit-learn MiniBatchKMeans |
scikit-learn KMeans |
|---|---|---|---|---|---|
| MNIST | 4,096 | 150 ms (+0.25%) | 190 ms (+0.35%) | 23.9 s (+3.53%) | 109.4 s |
| MNIST | 8,192 | 228 ms (−0.06%) | 381 ms (−0.02%) | 90.0 s (+3.07%) | 218.0 s |
| Fashion-MNIST | 4,096 | 156 ms (−0.68%) | 194 ms (−0.73%) | 23.4 s (+3.88%) | 107.2 s |
| Fashion-MNIST | 8,192 | 242 ms (−0.82%) | 420 ms (−0.83%) | 89.4 s (+3.16%) | 217.7 s |
| Kannada-MNIST | 4,096 | 163 ms (−0.07%) | 197 ms (+0.02%) | 24.4 s (+2.74%) | 113.3 s |
| Kannada-MNIST | 8,192 | 230 ms (−0.93%) | 392 ms (−0.84%) | 93.1 s (+1.35%) | 223.4 s |
For training from GPU-resident inputs at two or three epochs, OMeans ran about 1.4× as fast as EMeans at 4,096 centroids and 2.0–2.3× as fast at 8,192 on M4 Max. On M5 Ultra, the corresponding speedups were 1.15–1.21× and 1.74–1.85×. At 1,024 and 2,048 centroids, assignment="auto" used the full search and training times were close to EMeans. At one epoch and 4,096 centroids, OMeans was 7–11% slower than EMeans on M5 Ultra. Full benchmark report and raw results · PR #28
The release provides Apple silicon wheels for Python 3.10–3.13 and a source distribution. O-means guide · Changelog · PyPI
mlx-learn 0.1.4
Install on Apple silicon with python -m pip install --upgrade mlx-learn==0.1.4. This release provides wheels for Python 3.10–3.13 and a source distribution.
E-means benchmarked against Lloyd at 25 iterations
The 0.1.3 benchmark gave e-means and Lloyd the same two or three passes over the data. The new benchmark adds the paper's 25-iteration Lloyd reference for held-out mean squared error. On each dataset, both Metal implementations start from identical centers and share FP32 assignment and statistics kernels. Lloyd runs for 25 iterations, e-means runs for two or three epochs, and both timers include fresh final labels and inertia. 0.1.3 equal-pass benchmark · 0.1.4 Lloyd-25 benchmark
| Dataset, 10M vectors and 65,536 centers | Lloyd at 25 iterations | E-means | E-means speedup | E-means test MSE vs. Lloyd |
|---|---|---|---|---|
| DEEP | 545.60 s | 63.33 s (2 epochs) | 8.62× | +0.196% |
| SPACEV | 672.73 s | 70.87 s (2 epochs) | 9.49× | +0.096% |
| SimSearchNet++ | 1,421.44 s | 159.60 s (2 epochs) | 8.91× | −0.189% |
| SIFT | 718.55 s | 109.22 s (3 epochs) | 6.58× | −0.280% |
The paper's GPU comparison searches e-means budgets in 0.2-epoch increments for the first run that reaches Flash-KMeans at 25 iterations, then reports medians across ten seeds at the 10M scale on H100. The Metal benchmark uses preset whole epochs and one timed fit per method with one seed on M4 Max. E-means reached lower test MSE on two of the four datasets and came within 0.20% on the other two. The 10M DINO prefix had no completed Lloyd-25 pair. E-means paper, §4.3 and Table 4 · Benchmark results and limits
Faster clustering and SVC fits
- Metal clustering. The shared FP32 assignment kernel on M4 Max emits only the winning score and center index per tile. In a matched 10M-vector DEEP run, fixed-center assignment fell from 22.88 to 14.77 s with identical labels and squared-distance bits. A separate two-update Lloyd fit including final labeling fell from 115.56 to 55.67 s, with identical labels and inertia. Peak active GPU memory fell from 5.82 to 4.04 GiB. The four-dataset same-session comparison against the earlier kernel measured 1.06–1.53× faster e-means fits. Assignment and fit benchmarks · Same-session control
- Exact Lloyd pruning. Lloyd can reuse a label when center separation proves it is still correct. Mixed tiles use a limited set of batch sizes to reduce shader compilation. On a separated-cluster workload, pruning alone cut fit time from 68.83 to 46.08 ms. The four 10M-vector Lloyd runs reused zero labels, so their gains came from the streaming assignment kernel. Lloyd pruning benchmark
- SVC kernel-row caching. The native solver reuses rows across working sets when the full Gram matrix exceeds
cache_size. At 200 MiB on M4 Max, standard MNIST fit time fell from 9.09 to 3.59 s (2.53×) and Fashion-MNIST from 10.29 to 4.59 s (2.24×) against the pre-cache build. On standard MNIST, all 450,000 decision scores matched the pre-cache build bit for bit, accuracy was 97.92%, and warm prediction on 10,000 images took 88.2 ms, down from 88.7 ms. SVC benchmarks
Exact nearest neighbors and numerical fixes
- Exact kNN. Both APIs share a memory-aware planner, with filtered candidate selection, parallel exact fallback, and a guard against incorrect ordering in very wide MLX sorts. At a 128 MiB workspace budget on M4 Max, the tighter planner cut a million-reference query batch from 112.57 to 43.63 ms and additional peak GPU memory from 134.6 to 33.4 MiB, with identical indices and distance bits. Integration benchmark · Memory-budget benchmark
- M5 and wide PCA. A shared binary32 matrix-multiplication kernel avoids TF32 operand rounding in affected paths across kNN, clustering, PCA, multinomial logistic regression, SVC, and Hessian sketches. Wide GPU full-SVD PCA now reorthogonalizes components, retains computed tail directions, and handles negative-stride inputs. Reorthogonalization added 11–22% to measured wide full-SVD fits without a tail. Changelog
mlx-learn 0.1.3
Install on Apple Silicon with python -m pip install --upgrade mlx-learn==0.1.3. This release provides wheels for Python 3.10–3.13 and a source distribution.
Added
mlxlearn.cluster.EMeans: Metal implementation of the paper and pinned Faiss e-means recipes, with FP32, FP16, and native BF16 assignment, spherical clustering, final labels, and inertia.mlxlearn.cluster.KMeans: dense FP32 Metal Lloyd clustering with scikit-learn-style methods, multiple initializations, bounded work tiles, final labels, and inertia.- Reproducible benchmark drivers, raw evidence, and reports for the paper datasets and the original Faiss reference.
The five-dataset 10M-vector comparison reports runtime, peak fit memory, and held-out quality against scikit-learn KMeans and Faiss e-means. See the changelog for details.
Both clustering estimators require an Apple Silicon Metal GPU and are imported directly from mlxlearn.cluster.
mlx-learn 0.1.2
Install from PyPI with python -m pip install --upgrade mlx-learn==0.1.2. Apple silicon wheels support Python 3.10–3.13.
Added
mlxlearn.decomposition.PCA, also available throughpatch_sklearn(), with
dense covariance and randomized GPU solvers, hostfullandarpacksolvers,
whitening, inverse transforms, and probabilistic scores.- Regression coverage for shifted inputs, per-feature covariance cancellation,
whitening, randomized component orthogonality and overflow, low residual
variance, batch-independent scores, and mixed-dtype or strided transforms.
Changed
- PCA routes each solver by its measured crossover:
covariance_eighreaches
the GPU from 8·10⁶ elements or 512 features,randomizedfrom 8·10⁶ elements,
whilefullandarpackuse the host. Below those floors, patched estimators
delegate fits to scikit-learn and direct estimators use the host path. See the
crossover study. - Float64 PCA input uses a parallel narrowing cast with a combined range check
for GPU work. Transforms select their backend before preparing input, avoiding
unused float32 casts on host projections. Small float64 batches use the host;
projection centers first when necessary to preserve precision. - High-component, low-rank randomized PCA tries a host randomized solve when the
GPU Gram iteration fails its numerical checks, using a full float64 SVD only
when the randomized result also fails validation. This removes the unnecessary
full-SVD slowdown while retaining the accuracy fallback.
Fixed
- Large offsets no longer erase float64 variation during narrowing. Covariance
centering guards check every feature, and shifted whitening agrees between
fit_transformandtransformon both CPU and GPU paths. - Randomized PCA preserves component orthogonality and resolvable singular values
on rapidly decaying spectra, rescales power iterations to prevent overflow,
and computes small residual variance without catastrophic cancellation. - Probabilistic PCA scores remain consistent across batch sizes when fitted
noise variance is small. - Mixed float32-fit/float64-query projections compute the mean offset in float64.
Tiny query variations, strided arrays, original-input range checks, and NaN/Inf
validation remain covered by regression tests.
Measured
- Reran 24 MNIST-family configurations, 18 earlier synthetic cases, and 12 scaling
cases through one million rows. With float64 input and 32 components,
million-row fits at 256 and 1,024 features measured 5.24× and 12.36×
faster than scikit-learn; full-training transforms measured 2.42× and
1.62× faster. Short-query results varied with the measurement sequence:
the 1,024-feature float64 query took 13.35 ms versus scikit-learn's 3.27 ms
immediately after the full-training transform, and 2.10 ms versus 2.76 ms
in a separate query-only run after fitting. See the
complete results, limitations, and reproduction commands.
LR, KNN and SVC benchmark evidence
Lossless benchmark results for the 2026-10-31 sklearn comparison. See the repository catalog for file hashes and restoration instructions.
KNN benchmark evidence — 2026-10-31
Losslessly compressed raw evidence for the KNN precision, dispatch, startup and Digits performance work. This is a data-only prerelease, not a package release.
The tag pins commit 94ab00b, whose 63 package source files exactly match the measured final source snapshot. The catalog records SHA-256 hashes and original paths for all 99 bundled files; all observations, failures and timing samples are retained. Smaller records and frozen source/runtime references are committed in the repository.
Use python tools/knn_evidence.py restore --download from the merged repository to verify and restore the original paths. See benchmarks/evidence/README.md and the attached catalog for details.
The bundles contain 11,277,842,439 original bytes in 138,613,022 compressed bytes. No benchmark evidence was overwritten or discarded.