mlx-learn 0.1.2__tar.gz → 0.1.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mlx_learn-0.1.2/src/mlx_learn.egg-info → mlx_learn-0.1.4}/PKG-INFO +57 -6
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/README.md +53 -5
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/THIRD_PARTY_NOTICES.md +72 -4
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/pyproject.toml +2 -1
- {mlx_learn-0.1.2 → mlx_learn-0.1.4/src/mlx_learn.egg-info}/PKG-INFO +57 -6
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlx_learn.egg-info/SOURCES.txt +11 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlx_learn.egg-info/requires.txt +4 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlx_learn.egg-info/top_level.txt +1 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/__init__.py +1 -1
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_common/config.py +8 -6
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_common/device.py +2 -18
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_kernels/distance.py +21 -62
- mlx_learn-0.1.4/src/mlxlearn/_kernels/e_means.py +395 -0
- mlx_learn-0.1.4/src/mlxlearn/_kernels/e_means_bf16.py +404 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_kernels/kernels.py +14 -6
- mlx_learn-0.1.4/src/mlxlearn/_kernels/lloyd_bounds.py +76 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_kernels/svc_fused.py +2 -1
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_kernels/svc_predict.py +4 -2
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_solvers/_smo_block_native.cpp +53 -41
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_solvers/block_smo.py +11 -5
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_solvers/logistic.py +6 -4
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_solvers/pca.py +112 -31
- mlx_learn-0.1.4/src/mlxlearn/cluster/__init__.py +6 -0
- mlx_learn-0.1.4/src/mlxlearn/cluster/_e_means.py +603 -0
- mlx_learn-0.1.4/src/mlxlearn/cluster/_k_means.py +496 -0
- mlx_learn-0.1.4/src/mlxlearn/cluster/_recipe.py +150 -0
- mlx_learn-0.1.4/src/mlxlearn_common/__init__.py +5 -0
- mlx_learn-0.1.4/src/mlxlearn_common/_neighbors_plan.py +126 -0
- mlx_learn-0.1.4/src/mlxlearn_device/_binary32.py +395 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn_device/_neighbors.py +31 -5
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn_device/_neighbors_compact.py +81 -14
- mlx_learn-0.1.4/src/mlxlearn_device/_neighbors_fallback.py +298 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn_device/_neighbors_fused.py +171 -72
- mlx_learn-0.1.4/src/mlxlearn_device/_neighbors_general.py +329 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn_device/_neighbors_integer.py +4 -17
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn_device/_neighbors_screen.py +122 -54
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn_device/hessian_sketch.py +6 -3
- mlx_learn-0.1.2/src/mlxlearn_device/_neighbors_general.py +0 -127
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/LICENSE +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/MANIFEST.in +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/setup.cfg +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/setup.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlx_learn.egg-info/dependency_links.txt +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlx_learn.egg-info/not-zip-safe +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_common/__init__.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_common/arrays.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_common/base.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_common/diagnostics.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_common/preparation.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_common/rng.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_common/validation.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_kernels/__init__.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_kernels/_neighbors_cpu_native.cpp +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_kernels/_svc_cpu_native.cpp +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_kernels/logistic_input.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_kernels/neighbors_cpu.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_kernels/pca_input.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_kernels/svc_cpu.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_solvers/__init__.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_solvers/_metal_cg.h +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_solvers/_metal_loop.mm +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_solvers/_smo_native.cpp +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_solvers/fused_lbfgs.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_solvers/lbfgs.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_solvers/native_command.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_solvers/native_geometry.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_solvers/native_logistic.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_solvers/native_logistic_fused.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_solvers/native_smo.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/_solvers/smo.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/decomposition/__init__.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/decomposition/_pca.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/exceptions.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/linear_model/__init__.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/linear_model/_logistic.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/neighbors/__init__.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/neighbors/_base.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/neighbors/_classification.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/neighbors/_regression.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/neighbors/_unsupervised.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/patching/__init__.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/patching/_estimators.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/patching/_patch.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/patching/_registry.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/py.typed +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/svm/__init__.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn/svm/_classes.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn_device/__init__.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn_device/_compensated.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn_device/_duality.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn_device/_hessian_vector.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn_device/_logistic.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn_device/_native.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn_device/_native_cg.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn_device/_neighbors_paired.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn_device/_neighbors_precision.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn_device/_neighbors_registers.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn_device/_neighbors_shortlist.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn_device/_neighbors_small.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn_device/_neighbors_votes.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/src/mlxlearn_device/_newton.py +0 -0
- {mlx_learn-0.1.2 → mlx_learn-0.1.4}/tests/test_sklearn_compliance.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mlx-learn
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.4
|
|
4
4
|
Summary: MLX-accelerated classical machine learning with a scikit-learn compatible API for Apple silicon
|
|
5
5
|
Author: Bojan Tunguz
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -35,6 +35,9 @@ Requires-Dist: packaging>=23.0; extra == "test"
|
|
|
35
35
|
Provides-Extra: bench
|
|
36
36
|
Requires-Dist: pytest>=8.0; extra == "bench"
|
|
37
37
|
Requires-Dist: scipy>=1.10; extra == "bench"
|
|
38
|
+
Provides-Extra: e-means-bench
|
|
39
|
+
Requires-Dist: faiss-cpu>=1.12; extra == "e-means-bench"
|
|
40
|
+
Requires-Dist: h5py>=3.10; extra == "e-means-bench"
|
|
38
41
|
Provides-Extra: dev
|
|
39
42
|
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
40
43
|
Requires-Dist: scipy>=1.10; extra == "dev"
|
|
@@ -83,7 +86,7 @@ stock inheritance. See the [compatibility details](docs/support_matrix.md).
|
|
|
83
86
|
|
|
84
87
|
## Status
|
|
85
88
|
|
|
86
|
-
**`0.1.
|
|
89
|
+
**`0.1.4` — alpha.** The API may change. See [CHANGELOG.md](CHANGELOG.md).
|
|
87
90
|
|
|
88
91
|
| Estimator | Status |
|
|
89
92
|
|---|---|
|
|
@@ -93,10 +96,52 @@ stock inheritance. See the [compatibility details](docs/support_matrix.md).
|
|
|
93
96
|
| `mlxlearn.linear_model.LogisticRegression` | 0.1.0 |
|
|
94
97
|
| `mlxlearn.svm.SVC` (exact) | 0.1.0 |
|
|
95
98
|
| `mlxlearn.decomposition.PCA` | 0.1.2 |
|
|
96
|
-
| `
|
|
99
|
+
| `mlxlearn.cluster.EMeans` | 0.1.3; Metal GPU, paper/Faiss recipes |
|
|
100
|
+
| `mlxlearn.cluster.KMeans` | 0.1.3; Metal GPU, Lloyd clustering |
|
|
101
|
+
| `LinearRegression`, `Ridge`, `DBSCAN`, `TSNE` | planned, 0.2.x |
|
|
97
102
|
| `SVR`, `NuSVR`, `NuSVC` | deferred — will not ship until they implement the true objective |
|
|
98
103
|
| tree ensembles | out of scope |
|
|
99
104
|
|
|
105
|
+
## E-means clustering
|
|
106
|
+
|
|
107
|
+
Version 0.1.3 includes [e-means](https://arxiv.org/abs/2611.09501),
|
|
108
|
+
with Metal assignment and update kernels for Apple Silicon:
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
from mlxlearn.cluster import EMeans
|
|
112
|
+
|
|
113
|
+
model = EMeans(n_clusters=4096, max_iter=3, random_state=10).fit(X_train)
|
|
114
|
+
labels = model.predict(X_test)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
It supports the published recipe, a separately specified Faiss recipe,
|
|
118
|
+
last-epoch means, slow EMA, and spherical clustering. See the
|
|
119
|
+
[implementation guide](docs/e-means.md) and [reproducible paper-data benchmarks](benchmarks/e_means/README.md).
|
|
120
|
+
Measured results are in the [M4 Max benchmark report](docs/e-means-benchmarks-2026-11-14.md).
|
|
121
|
+
The [direct Faiss e-means comparison](docs/e-means-faiss-comparison-2026-11-14.md)
|
|
122
|
+
measures runtime, process memory, and held-out quality with matched Faiss recipes.
|
|
123
|
+
`precision="bfloat16"` enables native BF16 Metal assignment with float32
|
|
124
|
+
accumulation and state, plus the Faiss BF16 statistics semantics. The
|
|
125
|
+
[optimization and H100 protocol report](docs/e-means-h100-protocol-2026-11-14.md)
|
|
126
|
+
compares it with a matched Metal GEMM baseline and documents the limits of
|
|
127
|
+
comparison with published H100 times.
|
|
128
|
+
The subsequent [hardware-gap investigation](docs/e-means-gap-investigation-2026-11-14.md)
|
|
129
|
+
separates arithmetic throughput from implementation overhead and compares further
|
|
130
|
+
optimizations against a frozen native-BF16 implementation in fresh paired runs.
|
|
131
|
+
The [five-dataset 10M-vector comparison](docs/e-means-10m-comparison-2026-11-14.md)
|
|
132
|
+
measures matched FP32 Metal and original Faiss CPU runs: Metal is 3.98–18.95×
|
|
133
|
+
faster, with test-MSE differences within 0.061% in this single-seed campaign.
|
|
134
|
+
`EMeans` is an explicit estimator; it does not replace sklearn's `KMeans` through patching.
|
|
135
|
+
|
|
136
|
+
For full-batch Lloyd clustering, [Metal `KMeans`](docs/k-means.md) is available
|
|
137
|
+
through `from mlxlearn.cluster import KMeans`. It supports dense FP32 training,
|
|
138
|
+
explicit, random or k-means++ initialization, multiple restarts, and final
|
|
139
|
+
nearest-centroid labels and inertia. Use the direct estimator; it is not part
|
|
140
|
+
of `patch_sklearn()`.
|
|
141
|
+
|
|
142
|
+
The [four-method 10M-vector comparison](docs/k-means-10m-comparison-2026-11-15.md)
|
|
143
|
+
reports runtime, peak fit memory, and test MSE on five datasets.
|
|
144
|
+
|
|
100
145
|
## Requirements
|
|
101
146
|
|
|
102
147
|
- macOS on Apple silicon (arm64)
|
|
@@ -112,7 +157,7 @@ CI tests only valid pairs — see [`docs/support_matrix.md`](docs/support_matrix
|
|
|
112
157
|
pip install mlx-learn
|
|
113
158
|
```
|
|
114
159
|
|
|
115
|
-
Version `0.1.
|
|
160
|
+
Version `0.1.4` provides Apple silicon wheels for Python 3.10–3.13 with Metal
|
|
116
161
|
and C++ CPU extensions. Source builds can also include these optional extensions.
|
|
117
162
|
The KNN CPU extension handles small workloads and is compiled at build time;
|
|
118
163
|
fitting or querying never invokes the C++ compiler. A compatible wheel includes
|
|
@@ -289,8 +334,9 @@ CPU routines handle statistics, decision reductions and multiclass voting;
|
|
|
289
334
|
NumPy remains at the validation and public-array boundary, with portable
|
|
290
335
|
fallbacks if the optional extensions are unavailable. Automatic backend
|
|
291
336
|
thresholds remain conservative. See the
|
|
292
|
-
[working-set implementation
|
|
293
|
-
|
|
337
|
+
[working-set implementation](docs/svc-working-set-2026-10-31.md),
|
|
338
|
+
[kernel-row cache benchmarks](docs/svc-row-cache-2026-11-17.md), and
|
|
339
|
+
[earlier native-loop acceleration](docs/svc-native-2026-10-31.md).
|
|
294
340
|
|
|
295
341
|
KNN shares a NumPy-free GPU search core with `mlxlearn_device.fit_neighbors`.
|
|
296
342
|
Small neighbor counts use fused Metal distance/selection kernels, and GPU
|
|
@@ -413,6 +459,11 @@ distances, indices = index.query(mx.array([[0.2, 0.1]]), k=2)
|
|
|
413
459
|
mx.eval(distances, indices) # results remain MLX arrays
|
|
414
460
|
```
|
|
415
461
|
|
|
462
|
+
Version 0.1.4 shares memory-budget query planning between this
|
|
463
|
+
resident API and the NumPy interface, adds filtered candidate selection and
|
|
464
|
+
parallel exact fallback, and includes the M5 binary32 and wide-PCA correctness
|
|
465
|
+
fixes. See the [combined tests and benchmarks](docs/knn-integration-2026-11-17.md).
|
|
466
|
+
|
|
416
467
|
Performance depends on training size, feature count, query batch, neighbor count
|
|
417
468
|
and data distribution. Automatic KNN selects its owned CPU or GPU search under
|
|
418
469
|
the policy captured at fit; explicit device choices remain fixed. The linked
|
|
@@ -38,7 +38,7 @@ stock inheritance. See the [compatibility details](docs/support_matrix.md).
|
|
|
38
38
|
|
|
39
39
|
## Status
|
|
40
40
|
|
|
41
|
-
**`0.1.
|
|
41
|
+
**`0.1.4` — alpha.** The API may change. See [CHANGELOG.md](CHANGELOG.md).
|
|
42
42
|
|
|
43
43
|
| Estimator | Status |
|
|
44
44
|
|---|---|
|
|
@@ -48,10 +48,52 @@ stock inheritance. See the [compatibility details](docs/support_matrix.md).
|
|
|
48
48
|
| `mlxlearn.linear_model.LogisticRegression` | 0.1.0 |
|
|
49
49
|
| `mlxlearn.svm.SVC` (exact) | 0.1.0 |
|
|
50
50
|
| `mlxlearn.decomposition.PCA` | 0.1.2 |
|
|
51
|
-
| `
|
|
51
|
+
| `mlxlearn.cluster.EMeans` | 0.1.3; Metal GPU, paper/Faiss recipes |
|
|
52
|
+
| `mlxlearn.cluster.KMeans` | 0.1.3; Metal GPU, Lloyd clustering |
|
|
53
|
+
| `LinearRegression`, `Ridge`, `DBSCAN`, `TSNE` | planned, 0.2.x |
|
|
52
54
|
| `SVR`, `NuSVR`, `NuSVC` | deferred — will not ship until they implement the true objective |
|
|
53
55
|
| tree ensembles | out of scope |
|
|
54
56
|
|
|
57
|
+
## E-means clustering
|
|
58
|
+
|
|
59
|
+
Version 0.1.3 includes [e-means](https://arxiv.org/abs/2611.09501),
|
|
60
|
+
with Metal assignment and update kernels for Apple Silicon:
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from mlxlearn.cluster import EMeans
|
|
64
|
+
|
|
65
|
+
model = EMeans(n_clusters=4096, max_iter=3, random_state=10).fit(X_train)
|
|
66
|
+
labels = model.predict(X_test)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
It supports the published recipe, a separately specified Faiss recipe,
|
|
70
|
+
last-epoch means, slow EMA, and spherical clustering. See the
|
|
71
|
+
[implementation guide](docs/e-means.md) and [reproducible paper-data benchmarks](benchmarks/e_means/README.md).
|
|
72
|
+
Measured results are in the [M4 Max benchmark report](docs/e-means-benchmarks-2026-11-14.md).
|
|
73
|
+
The [direct Faiss e-means comparison](docs/e-means-faiss-comparison-2026-11-14.md)
|
|
74
|
+
measures runtime, process memory, and held-out quality with matched Faiss recipes.
|
|
75
|
+
`precision="bfloat16"` enables native BF16 Metal assignment with float32
|
|
76
|
+
accumulation and state, plus the Faiss BF16 statistics semantics. The
|
|
77
|
+
[optimization and H100 protocol report](docs/e-means-h100-protocol-2026-11-14.md)
|
|
78
|
+
compares it with a matched Metal GEMM baseline and documents the limits of
|
|
79
|
+
comparison with published H100 times.
|
|
80
|
+
The subsequent [hardware-gap investigation](docs/e-means-gap-investigation-2026-11-14.md)
|
|
81
|
+
separates arithmetic throughput from implementation overhead and compares further
|
|
82
|
+
optimizations against a frozen native-BF16 implementation in fresh paired runs.
|
|
83
|
+
The [five-dataset 10M-vector comparison](docs/e-means-10m-comparison-2026-11-14.md)
|
|
84
|
+
measures matched FP32 Metal and original Faiss CPU runs: Metal is 3.98–18.95×
|
|
85
|
+
faster, with test-MSE differences within 0.061% in this single-seed campaign.
|
|
86
|
+
`EMeans` is an explicit estimator; it does not replace sklearn's `KMeans` through patching.
|
|
87
|
+
|
|
88
|
+
For full-batch Lloyd clustering, [Metal `KMeans`](docs/k-means.md) is available
|
|
89
|
+
through `from mlxlearn.cluster import KMeans`. It supports dense FP32 training,
|
|
90
|
+
explicit, random or k-means++ initialization, multiple restarts, and final
|
|
91
|
+
nearest-centroid labels and inertia. Use the direct estimator; it is not part
|
|
92
|
+
of `patch_sklearn()`.
|
|
93
|
+
|
|
94
|
+
The [four-method 10M-vector comparison](docs/k-means-10m-comparison-2026-11-15.md)
|
|
95
|
+
reports runtime, peak fit memory, and test MSE on five datasets.
|
|
96
|
+
|
|
55
97
|
## Requirements
|
|
56
98
|
|
|
57
99
|
- macOS on Apple silicon (arm64)
|
|
@@ -67,7 +109,7 @@ CI tests only valid pairs — see [`docs/support_matrix.md`](docs/support_matrix
|
|
|
67
109
|
pip install mlx-learn
|
|
68
110
|
```
|
|
69
111
|
|
|
70
|
-
Version `0.1.
|
|
112
|
+
Version `0.1.4` provides Apple silicon wheels for Python 3.10–3.13 with Metal
|
|
71
113
|
and C++ CPU extensions. Source builds can also include these optional extensions.
|
|
72
114
|
The KNN CPU extension handles small workloads and is compiled at build time;
|
|
73
115
|
fitting or querying never invokes the C++ compiler. A compatible wheel includes
|
|
@@ -244,8 +286,9 @@ CPU routines handle statistics, decision reductions and multiclass voting;
|
|
|
244
286
|
NumPy remains at the validation and public-array boundary, with portable
|
|
245
287
|
fallbacks if the optional extensions are unavailable. Automatic backend
|
|
246
288
|
thresholds remain conservative. See the
|
|
247
|
-
[working-set implementation
|
|
248
|
-
|
|
289
|
+
[working-set implementation](docs/svc-working-set-2026-10-31.md),
|
|
290
|
+
[kernel-row cache benchmarks](docs/svc-row-cache-2026-11-17.md), and
|
|
291
|
+
[earlier native-loop acceleration](docs/svc-native-2026-10-31.md).
|
|
249
292
|
|
|
250
293
|
KNN shares a NumPy-free GPU search core with `mlxlearn_device.fit_neighbors`.
|
|
251
294
|
Small neighbor counts use fused Metal distance/selection kernels, and GPU
|
|
@@ -368,6 +411,11 @@ distances, indices = index.query(mx.array([[0.2, 0.1]]), k=2)
|
|
|
368
411
|
mx.eval(distances, indices) # results remain MLX arrays
|
|
369
412
|
```
|
|
370
413
|
|
|
414
|
+
Version 0.1.4 shares memory-budget query planning between this
|
|
415
|
+
resident API and the NumPy interface, adds filtered candidate selection and
|
|
416
|
+
parallel exact fallback, and includes the M5 binary32 and wide-PCA correctness
|
|
417
|
+
fixes. See the [combined tests and benchmarks](docs/knn-integration-2026-11-17.md).
|
|
418
|
+
|
|
371
419
|
Performance depends on training size, feature count, query batch, neighbor count
|
|
372
420
|
and data distribution. Automatic KNN selects its owned CPU or GPU search under
|
|
373
421
|
the policy captured at fit; explicit device choices remain fixed. The linked
|
|
@@ -12,11 +12,70 @@ a source file carries an upstream copyright header that is not accounted for her
|
|
|
12
12
|
|
|
13
13
|
## 1. Copied or derived source
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
### MLX Steel fragment layout and vector loads
|
|
16
|
+
|
|
17
|
+
`src/mlxlearn/_kernels/e_means_bf16.py` derives SIMD matrix fragment coordinate
|
|
18
|
+
mapping and contiguous vector-load techniques from MLX 0.32.4,
|
|
19
|
+
`mlx/backend/metal/kernels/steel/gemm/mma.h` and `loader.h`. The retained upstream
|
|
20
|
+
header is `Copyright © 2024 Apple Inc.`. The implementation was modified on
|
|
21
|
+
2026-11-14 for native BF16 fragments, fused centroid selection, ragged loads,
|
|
22
|
+
bounded row batching, and Python dispatch. The experimental predecessor is
|
|
23
|
+
`benchmarks/e_means/experimental_kernels.py`.
|
|
24
|
+
|
|
25
|
+
The following immutable benchmark records embed snapshots of that experimental
|
|
26
|
+
source, including its retained `Copyright © 2024 Apple Inc.` notice and source
|
|
27
|
+
SHA-256. Those embedded source copies are covered by this same attribution and
|
|
28
|
+
MIT license:
|
|
29
|
+
|
|
30
|
+
- `benchmarks/e_means/results/optimization/bf16-dispatch-sweep.json`
|
|
31
|
+
- `benchmarks/e_means/results/optimization/bf16-tile-sweep3.json`
|
|
32
|
+
- `benchmarks/e_means/results/optimization/bf16-tile-sweep4.json`
|
|
33
|
+
|
|
34
|
+
The next investigation retains the same attributed source in its verified
|
|
35
|
+
baseline archive/extraction and generated-kernel experiment records:
|
|
36
|
+
|
|
37
|
+
- `benchmarks/e_means/reference/metal-v2-source.zip`
|
|
38
|
+
- `benchmarks/e_means/results/gap_investigation/source/metal_v2_e_means_bf16.py`
|
|
39
|
+
- `benchmarks/e_means/results/gap_investigation/roofline.json`
|
|
40
|
+
- `benchmarks/e_means/results/gap_investigation/schedule.json`
|
|
41
|
+
- `benchmarks/e_means/results/gap_investigation/tiles.json`
|
|
42
|
+
- `benchmarks/e_means/results/gap_investigation/lowdim.json`
|
|
43
|
+
- `benchmarks/e_means/results/gap_investigation/coalescing.json`
|
|
44
|
+
|
|
45
|
+
`benchmarks/e_means/experiments/gap_assignment.py` and
|
|
46
|
+
`benchmarks/e_means/experiments/gap_coalescing.py` generate modified variants
|
|
47
|
+
of the attributed Metal source. Their modification notices identify the
|
|
48
|
+
2026-11-14 scheduling, tiling, and partial-result layout experiments. Raw JSON
|
|
49
|
+
records remain immutable, including the source snapshots and hashes captured
|
|
50
|
+
when each experiment ran; the frozen baseline loader verifies the extracted
|
|
51
|
+
source against the archive before reuse.
|
|
52
|
+
|
|
53
|
+
These source files are covered by the MIT license reproduced below. Historical
|
|
54
|
+
attestations for version 0.1.0a2 predate this addition.
|
|
16
55
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
56
|
+
```
|
|
57
|
+
MIT License
|
|
58
|
+
|
|
59
|
+
Copyright © 2024 Apple Inc.
|
|
60
|
+
|
|
61
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
62
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
63
|
+
in the Software without restriction, including without limitation the rights
|
|
64
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
65
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
66
|
+
furnished to do so, subject to the following conditions:
|
|
67
|
+
|
|
68
|
+
The above copyright notice and this permission notice shall be included in
|
|
69
|
+
all copies or substantial portions of the Software.
|
|
70
|
+
|
|
71
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
72
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
73
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
74
|
+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
75
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
76
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
77
|
+
IN THE SOFTWARE.
|
|
78
|
+
```
|
|
20
79
|
|
|
21
80
|
If a future change introduces derived code, it must be added to this section with:
|
|
22
81
|
|
|
@@ -164,6 +223,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
164
223
|
|
|
165
224
|
## 5. Algorithmic references
|
|
166
225
|
|
|
226
|
+
The e-means implementation follows Bessa et al., *e-means: outperforming
|
|
227
|
+
k-means (in one-tenth the epochs)*, arXiv:2611.09501v1 (2026), and the MIT-licensed
|
|
228
|
+
Faiss reference at revision `ebab8f784c1d177129602269d5ad966c525fbdcb`,
|
|
229
|
+
copyright Meta Platforms, Inc. and affiliates. The estimator and Metal kernels
|
|
230
|
+
were written for mlxlearn. Benchmarks load the upstream code from a separate
|
|
231
|
+
checkout which retains its license, use upstream dataset split fingerprints,
|
|
232
|
+
and credit the original datasets. Faiss is an optional benchmark dependency.
|
|
233
|
+
See [the benchmark guide](benchmarks/e_means/README.md).
|
|
234
|
+
|
|
167
235
|
The October 31, 2026 SVC optimization study inspected scikit-learn-intelex
|
|
168
236
|
commit `f50ab692e6296b573efaaa3d05304a8eb3fbcf8d` and oneDAL tag `2026.2.0`.
|
|
169
237
|
Their native working-set decomposition and persistent-model patterns informed
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "mlx-learn"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.4"
|
|
8
8
|
description = "MLX-accelerated classical machine learning with a scikit-learn compatible API for Apple silicon"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -35,6 +35,7 @@ dependencies = [
|
|
|
35
35
|
[project.optional-dependencies]
|
|
36
36
|
test = ["pytest>=8.0", "scipy>=1.10", "packaging>=23.0"]
|
|
37
37
|
bench = ["pytest>=8.0", "scipy>=1.10"]
|
|
38
|
+
e-means-bench = ["faiss-cpu>=1.12", "h5py>=3.10"]
|
|
38
39
|
dev = ["pytest>=8.0", "scipy>=1.10", "ruff>=0.6", "build>=1.2", "twine>=5.0"]
|
|
39
40
|
|
|
40
41
|
[project.urls]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mlx-learn
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.4
|
|
4
4
|
Summary: MLX-accelerated classical machine learning with a scikit-learn compatible API for Apple silicon
|
|
5
5
|
Author: Bojan Tunguz
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -35,6 +35,9 @@ Requires-Dist: packaging>=23.0; extra == "test"
|
|
|
35
35
|
Provides-Extra: bench
|
|
36
36
|
Requires-Dist: pytest>=8.0; extra == "bench"
|
|
37
37
|
Requires-Dist: scipy>=1.10; extra == "bench"
|
|
38
|
+
Provides-Extra: e-means-bench
|
|
39
|
+
Requires-Dist: faiss-cpu>=1.12; extra == "e-means-bench"
|
|
40
|
+
Requires-Dist: h5py>=3.10; extra == "e-means-bench"
|
|
38
41
|
Provides-Extra: dev
|
|
39
42
|
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
40
43
|
Requires-Dist: scipy>=1.10; extra == "dev"
|
|
@@ -83,7 +86,7 @@ stock inheritance. See the [compatibility details](docs/support_matrix.md).
|
|
|
83
86
|
|
|
84
87
|
## Status
|
|
85
88
|
|
|
86
|
-
**`0.1.
|
|
89
|
+
**`0.1.4` — alpha.** The API may change. See [CHANGELOG.md](CHANGELOG.md).
|
|
87
90
|
|
|
88
91
|
| Estimator | Status |
|
|
89
92
|
|---|---|
|
|
@@ -93,10 +96,52 @@ stock inheritance. See the [compatibility details](docs/support_matrix.md).
|
|
|
93
96
|
| `mlxlearn.linear_model.LogisticRegression` | 0.1.0 |
|
|
94
97
|
| `mlxlearn.svm.SVC` (exact) | 0.1.0 |
|
|
95
98
|
| `mlxlearn.decomposition.PCA` | 0.1.2 |
|
|
96
|
-
| `
|
|
99
|
+
| `mlxlearn.cluster.EMeans` | 0.1.3; Metal GPU, paper/Faiss recipes |
|
|
100
|
+
| `mlxlearn.cluster.KMeans` | 0.1.3; Metal GPU, Lloyd clustering |
|
|
101
|
+
| `LinearRegression`, `Ridge`, `DBSCAN`, `TSNE` | planned, 0.2.x |
|
|
97
102
|
| `SVR`, `NuSVR`, `NuSVC` | deferred — will not ship until they implement the true objective |
|
|
98
103
|
| tree ensembles | out of scope |
|
|
99
104
|
|
|
105
|
+
## E-means clustering
|
|
106
|
+
|
|
107
|
+
Version 0.1.3 includes [e-means](https://arxiv.org/abs/2611.09501),
|
|
108
|
+
with Metal assignment and update kernels for Apple Silicon:
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
from mlxlearn.cluster import EMeans
|
|
112
|
+
|
|
113
|
+
model = EMeans(n_clusters=4096, max_iter=3, random_state=10).fit(X_train)
|
|
114
|
+
labels = model.predict(X_test)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
It supports the published recipe, a separately specified Faiss recipe,
|
|
118
|
+
last-epoch means, slow EMA, and spherical clustering. See the
|
|
119
|
+
[implementation guide](docs/e-means.md) and [reproducible paper-data benchmarks](benchmarks/e_means/README.md).
|
|
120
|
+
Measured results are in the [M4 Max benchmark report](docs/e-means-benchmarks-2026-11-14.md).
|
|
121
|
+
The [direct Faiss e-means comparison](docs/e-means-faiss-comparison-2026-11-14.md)
|
|
122
|
+
measures runtime, process memory, and held-out quality with matched Faiss recipes.
|
|
123
|
+
`precision="bfloat16"` enables native BF16 Metal assignment with float32
|
|
124
|
+
accumulation and state, plus the Faiss BF16 statistics semantics. The
|
|
125
|
+
[optimization and H100 protocol report](docs/e-means-h100-protocol-2026-11-14.md)
|
|
126
|
+
compares it with a matched Metal GEMM baseline and documents the limits of
|
|
127
|
+
comparison with published H100 times.
|
|
128
|
+
The subsequent [hardware-gap investigation](docs/e-means-gap-investigation-2026-11-14.md)
|
|
129
|
+
separates arithmetic throughput from implementation overhead and compares further
|
|
130
|
+
optimizations against a frozen native-BF16 implementation in fresh paired runs.
|
|
131
|
+
The [five-dataset 10M-vector comparison](docs/e-means-10m-comparison-2026-11-14.md)
|
|
132
|
+
measures matched FP32 Metal and original Faiss CPU runs: Metal is 3.98–18.95×
|
|
133
|
+
faster, with test-MSE differences within 0.061% in this single-seed campaign.
|
|
134
|
+
`EMeans` is an explicit estimator; it does not replace sklearn's `KMeans` through patching.
|
|
135
|
+
|
|
136
|
+
For full-batch Lloyd clustering, [Metal `KMeans`](docs/k-means.md) is available
|
|
137
|
+
through `from mlxlearn.cluster import KMeans`. It supports dense FP32 training,
|
|
138
|
+
explicit, random or k-means++ initialization, multiple restarts, and final
|
|
139
|
+
nearest-centroid labels and inertia. Use the direct estimator; it is not part
|
|
140
|
+
of `patch_sklearn()`.
|
|
141
|
+
|
|
142
|
+
The [four-method 10M-vector comparison](docs/k-means-10m-comparison-2026-11-15.md)
|
|
143
|
+
reports runtime, peak fit memory, and test MSE on five datasets.
|
|
144
|
+
|
|
100
145
|
## Requirements
|
|
101
146
|
|
|
102
147
|
- macOS on Apple silicon (arm64)
|
|
@@ -112,7 +157,7 @@ CI tests only valid pairs — see [`docs/support_matrix.md`](docs/support_matrix
|
|
|
112
157
|
pip install mlx-learn
|
|
113
158
|
```
|
|
114
159
|
|
|
115
|
-
Version `0.1.
|
|
160
|
+
Version `0.1.4` provides Apple silicon wheels for Python 3.10–3.13 with Metal
|
|
116
161
|
and C++ CPU extensions. Source builds can also include these optional extensions.
|
|
117
162
|
The KNN CPU extension handles small workloads and is compiled at build time;
|
|
118
163
|
fitting or querying never invokes the C++ compiler. A compatible wheel includes
|
|
@@ -289,8 +334,9 @@ CPU routines handle statistics, decision reductions and multiclass voting;
|
|
|
289
334
|
NumPy remains at the validation and public-array boundary, with portable
|
|
290
335
|
fallbacks if the optional extensions are unavailable. Automatic backend
|
|
291
336
|
thresholds remain conservative. See the
|
|
292
|
-
[working-set implementation
|
|
293
|
-
|
|
337
|
+
[working-set implementation](docs/svc-working-set-2026-10-31.md),
|
|
338
|
+
[kernel-row cache benchmarks](docs/svc-row-cache-2026-11-17.md), and
|
|
339
|
+
[earlier native-loop acceleration](docs/svc-native-2026-10-31.md).
|
|
294
340
|
|
|
295
341
|
KNN shares a NumPy-free GPU search core with `mlxlearn_device.fit_neighbors`.
|
|
296
342
|
Small neighbor counts use fused Metal distance/selection kernels, and GPU
|
|
@@ -413,6 +459,11 @@ distances, indices = index.query(mx.array([[0.2, 0.1]]), k=2)
|
|
|
413
459
|
mx.eval(distances, indices) # results remain MLX arrays
|
|
414
460
|
```
|
|
415
461
|
|
|
462
|
+
Version 0.1.4 shares memory-budget query planning between this
|
|
463
|
+
resident API and the NumPy interface, adds filtered candidate selection and
|
|
464
|
+
parallel exact fallback, and includes the M5 binary32 and wide-PCA correctness
|
|
465
|
+
fixes. See the [combined tests and benchmarks](docs/knn-integration-2026-11-17.md).
|
|
466
|
+
|
|
416
467
|
Performance depends on training size, feature count, query batch, neighbor count
|
|
417
468
|
and data distribution. Automatic KNN selects its owned CPU or GPU search under
|
|
418
469
|
the policy captured at fit; explicit device choices remain fixed. The linked
|
|
@@ -26,7 +26,10 @@ src/mlxlearn/_kernels/__init__.py
|
|
|
26
26
|
src/mlxlearn/_kernels/_neighbors_cpu_native.cpp
|
|
27
27
|
src/mlxlearn/_kernels/_svc_cpu_native.cpp
|
|
28
28
|
src/mlxlearn/_kernels/distance.py
|
|
29
|
+
src/mlxlearn/_kernels/e_means.py
|
|
30
|
+
src/mlxlearn/_kernels/e_means_bf16.py
|
|
29
31
|
src/mlxlearn/_kernels/kernels.py
|
|
32
|
+
src/mlxlearn/_kernels/lloyd_bounds.py
|
|
30
33
|
src/mlxlearn/_kernels/logistic_input.py
|
|
31
34
|
src/mlxlearn/_kernels/neighbors_cpu.py
|
|
32
35
|
src/mlxlearn/_kernels/pca_input.py
|
|
@@ -49,6 +52,10 @@ src/mlxlearn/_solvers/native_logistic_fused.py
|
|
|
49
52
|
src/mlxlearn/_solvers/native_smo.py
|
|
50
53
|
src/mlxlearn/_solvers/pca.py
|
|
51
54
|
src/mlxlearn/_solvers/smo.py
|
|
55
|
+
src/mlxlearn/cluster/__init__.py
|
|
56
|
+
src/mlxlearn/cluster/_e_means.py
|
|
57
|
+
src/mlxlearn/cluster/_k_means.py
|
|
58
|
+
src/mlxlearn/cluster/_recipe.py
|
|
52
59
|
src/mlxlearn/decomposition/__init__.py
|
|
53
60
|
src/mlxlearn/decomposition/_pca.py
|
|
54
61
|
src/mlxlearn/linear_model/__init__.py
|
|
@@ -64,7 +71,10 @@ src/mlxlearn/patching/_patch.py
|
|
|
64
71
|
src/mlxlearn/patching/_registry.py
|
|
65
72
|
src/mlxlearn/svm/__init__.py
|
|
66
73
|
src/mlxlearn/svm/_classes.py
|
|
74
|
+
src/mlxlearn_common/__init__.py
|
|
75
|
+
src/mlxlearn_common/_neighbors_plan.py
|
|
67
76
|
src/mlxlearn_device/__init__.py
|
|
77
|
+
src/mlxlearn_device/_binary32.py
|
|
68
78
|
src/mlxlearn_device/_compensated.py
|
|
69
79
|
src/mlxlearn_device/_duality.py
|
|
70
80
|
src/mlxlearn_device/_hessian_vector.py
|
|
@@ -73,6 +83,7 @@ src/mlxlearn_device/_native.py
|
|
|
73
83
|
src/mlxlearn_device/_native_cg.py
|
|
74
84
|
src/mlxlearn_device/_neighbors.py
|
|
75
85
|
src/mlxlearn_device/_neighbors_compact.py
|
|
86
|
+
src/mlxlearn_device/_neighbors_fallback.py
|
|
76
87
|
src/mlxlearn_device/_neighbors_fused.py
|
|
77
88
|
src/mlxlearn_device/_neighbors_general.py
|
|
78
89
|
src/mlxlearn_device/_neighbors_integer.py
|
|
@@ -24,6 +24,8 @@ from contextlib import contextmanager
|
|
|
24
24
|
from dataclasses import dataclass, fields, replace
|
|
25
25
|
from typing import Any, Literal, get_args
|
|
26
26
|
|
|
27
|
+
from mlxlearn_common._neighbors_plan import DEFAULTS as _NEIGHBOR_DEFAULTS
|
|
28
|
+
|
|
27
29
|
__all__ = [
|
|
28
30
|
"Config",
|
|
29
31
|
"Tuning",
|
|
@@ -176,12 +178,12 @@ class Tuning:
|
|
|
176
178
|
pca_randomized_min_work: int = 8_000_000 # n_samples * n_features
|
|
177
179
|
|
|
178
180
|
# ---- blocking ---------------------------------------------------------------------
|
|
179
|
-
distance_block_bytes: int =
|
|
180
|
-
distance_block_bytes_max: int =
|
|
181
|
-
query_block_rows: int =
|
|
182
|
-
query_block_align: int =
|
|
183
|
-
cpu_distance_block_bytes: int =
|
|
184
|
-
cpu_query_block_rows: int =
|
|
181
|
+
distance_block_bytes: int = _NEIGHBOR_DEFAULTS.distance_block_bytes
|
|
182
|
+
distance_block_bytes_max: int = _NEIGHBOR_DEFAULTS.distance_block_bytes_max
|
|
183
|
+
query_block_rows: int = _NEIGHBOR_DEFAULTS.query_block_rows
|
|
184
|
+
query_block_align: int = _NEIGHBOR_DEFAULTS.query_block_align
|
|
185
|
+
cpu_distance_block_bytes: int = _NEIGHBOR_DEFAULTS.cpu_distance_block_bytes
|
|
186
|
+
cpu_query_block_rows: int = _NEIGHBOR_DEFAULTS.cpu_query_block_rows
|
|
185
187
|
|
|
186
188
|
# ---- solvers ----------------------------------------------------------------------
|
|
187
189
|
lbfgs_history: int = 10
|
|
@@ -20,10 +20,11 @@ The rules this module enforces:
|
|
|
20
20
|
from __future__ import annotations
|
|
21
21
|
|
|
22
22
|
import functools
|
|
23
|
-
import os
|
|
24
23
|
from contextlib import contextmanager
|
|
25
24
|
from dataclasses import dataclass
|
|
26
25
|
|
|
26
|
+
from mlxlearn_common._neighbors_plan import physical_memory_bytes
|
|
27
|
+
|
|
27
28
|
from ..exceptions import DeviceError
|
|
28
29
|
from .config import get_config
|
|
29
30
|
|
|
@@ -55,23 +56,6 @@ class DeviceInfo:
|
|
|
55
56
|
return f"mlx {self.mlx_version} on {self.kind} ({mem})"
|
|
56
57
|
|
|
57
58
|
|
|
58
|
-
@functools.lru_cache(maxsize=1)
|
|
59
|
-
def physical_memory_bytes() -> int | None:
|
|
60
|
-
"""Total physical memory, or ``None`` where the platform will not say.
|
|
61
|
-
|
|
62
|
-
Used to bound the SVM kernel cache and the distance-block target. On unified
|
|
63
|
-
memory this is also, usefully, the GPU's memory.
|
|
64
|
-
"""
|
|
65
|
-
try:
|
|
66
|
-
page_size = int(os.sysconf("SC_PAGE_SIZE"))
|
|
67
|
-
page_count = int(os.sysconf("SC_PHYS_PAGES"))
|
|
68
|
-
except (AttributeError, OSError, ValueError):
|
|
69
|
-
return None
|
|
70
|
-
if page_size <= 0 or page_count <= 0:
|
|
71
|
-
return None
|
|
72
|
-
return page_size * page_count
|
|
73
|
-
|
|
74
|
-
|
|
75
59
|
@functools.lru_cache(maxsize=1)
|
|
76
60
|
def gpu_available() -> bool:
|
|
77
61
|
"""Whether a Metal device is present *and* actually executes work.
|